Much Work
- Definable KeyMaps - Change 'Tabbable' to just use 'Focusable'
This commit is contained in:
@@ -34,17 +34,19 @@ type Prompt struct {
|
||||
id string
|
||||
style tcell.Style
|
||||
|
||||
x, y int
|
||||
w, h int
|
||||
active bool
|
||||
visible bool
|
||||
tabbable bool
|
||||
x, y int
|
||||
w, h int
|
||||
active bool
|
||||
visible bool
|
||||
focusable bool
|
||||
|
||||
title string
|
||||
message *Text
|
||||
field *Field
|
||||
btnOk, btnCancel *Button
|
||||
onOk func(string) bool
|
||||
|
||||
keyMap KeyMap
|
||||
}
|
||||
|
||||
var _ Widget = (*Prompt)(nil)
|
||||
@@ -64,7 +66,8 @@ func (w *Prompt) Init(id string, style tcell.Style) {
|
||||
w.btnOk.SetLabel("Ok")
|
||||
w.btnCancel = NewButton(fmt.Sprintf("%s-cancel", id), style)
|
||||
w.btnCancel.SetLabel("Cancel")
|
||||
w.tabbable = true
|
||||
w.focusable = true
|
||||
w.keyMap = BlankKeyMap()
|
||||
}
|
||||
func (w *Prompt) Id() string { return w.id }
|
||||
func (w *Prompt) HandleResize(ev *tcell.EventResize) {
|
||||
@@ -80,11 +83,22 @@ func (w *Prompt) HandleResize(ev *tcell.EventResize) {
|
||||
w.btnCancel.SetPos(Coord{X: w.x + 1, Y: w.y + w.h - 1})
|
||||
}
|
||||
|
||||
func (w *Prompt) SetKeyMap(km KeyMap) { w.keyMap = km }
|
||||
func (w *Prompt) AddToKeyMap(km KeyMap) { w.keyMap.Merge(km) }
|
||||
func (w *Prompt) RemoveFromKeyMap(km KeyMap) {
|
||||
for k := range km.Keys {
|
||||
w.keyMap.Remove(k)
|
||||
}
|
||||
for r := range km.Runes {
|
||||
w.keyMap.RemoveRune(r)
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Prompt) HandleKey(ev *tcell.EventKey) bool {
|
||||
if !w.active {
|
||||
return false
|
||||
}
|
||||
return false
|
||||
return w.keyMap.Handle(ev)
|
||||
}
|
||||
func (w *Prompt) HandleTime(ev *tcell.EventTime) {}
|
||||
func (w *Prompt) Draw(screen tcell.Screen) {
|
||||
@@ -101,24 +115,23 @@ func (w *Prompt) Draw(screen tcell.Screen) {
|
||||
w.GetPos().DrawOffset(w.btnCancel, screen)
|
||||
}
|
||||
|
||||
func (w *Prompt) Active() bool { return w.active }
|
||||
func (w *Prompt) SetActive(a bool) { w.active = a }
|
||||
func (w *Prompt) Visible() bool { return w.visible }
|
||||
func (w *Prompt) SetVisible(a bool) { w.visible = a }
|
||||
func (w *Prompt) SetX(x int) { w.x = x }
|
||||
func (w *Prompt) SetY(y int) { w.y = y }
|
||||
func (w *Prompt) GetX() int { return w.x }
|
||||
func (w *Prompt) GetY() int { return w.y }
|
||||
func (w *Prompt) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
|
||||
func (w *Prompt) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
|
||||
func (w *Prompt) SetW(x int) { w.w = x }
|
||||
func (w *Prompt) SetH(y int) { w.h = y }
|
||||
func (w *Prompt) GetW() int { return w.w }
|
||||
func (w *Prompt) GetH() int { return w.y }
|
||||
func (w *Prompt) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
|
||||
func (w *Prompt) Focusable() bool { return true }
|
||||
func (w *Prompt) SetTabbable(b bool) { w.tabbable = b }
|
||||
func (w *Prompt) Tabbable() bool { return w.tabbable }
|
||||
func (w *Prompt) Active() bool { return w.active }
|
||||
func (w *Prompt) SetActive(a bool) { w.active = a }
|
||||
func (w *Prompt) Visible() bool { return w.visible }
|
||||
func (w *Prompt) SetVisible(a bool) { w.visible = a }
|
||||
func (w *Prompt) SetX(x int) { w.x = x }
|
||||
func (w *Prompt) SetY(y int) { w.y = y }
|
||||
func (w *Prompt) GetX() int { return w.x }
|
||||
func (w *Prompt) GetY() int { return w.y }
|
||||
func (w *Prompt) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
|
||||
func (w *Prompt) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
|
||||
func (w *Prompt) SetW(x int) { w.w = x }
|
||||
func (w *Prompt) SetH(y int) { w.h = y }
|
||||
func (w *Prompt) GetW() int { return w.w }
|
||||
func (w *Prompt) GetH() int { return w.y }
|
||||
func (w *Prompt) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
|
||||
func (w *Prompt) Focusable() bool { return w.focusable }
|
||||
func (w *Prompt) SetFocusable(b bool) { w.focusable = b }
|
||||
func (w *Prompt) WantW() int {
|
||||
return w.btnOk.WantW() + w.btnCancel.WantW() + 4
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user