Much Work
- Definable KeyMaps - Change 'Tabbable' to just use 'Focusable'
This commit is contained in:
69
wdgt_menu.go
69
wdgt_menu.go
@@ -29,14 +29,14 @@ import (
|
||||
)
|
||||
|
||||
type Menu struct {
|
||||
id string
|
||||
label string
|
||||
style tcell.Style
|
||||
active bool
|
||||
visible bool
|
||||
tabbable bool
|
||||
x, y int
|
||||
w, h int
|
||||
id string
|
||||
label string
|
||||
style tcell.Style
|
||||
active bool
|
||||
visible bool
|
||||
focusable bool
|
||||
x, y int
|
||||
w, h int
|
||||
|
||||
menuType MenuType
|
||||
cursor int
|
||||
@@ -81,18 +81,25 @@ func (w *Menu) Init(id string, style tcell.Style) {
|
||||
return false
|
||||
},
|
||||
})
|
||||
w.tabbable = true
|
||||
w.focusable = true
|
||||
}
|
||||
func (w *Menu) Id() string { return w.id }
|
||||
func (w *Menu) HandleResize(ev *tcell.EventResize) {
|
||||
w.w, w.h = ev.Size()
|
||||
|
||||
// w.w = wh.Min(w.w, w.WantW())
|
||||
// w.h = wh.Min(w.h, w.WantH())
|
||||
|
||||
// TODO: Trickle-down HandleResize
|
||||
}
|
||||
|
||||
func (w *Menu) SetKeyMap(km KeyMap) { w.keyMap = km }
|
||||
func (w *Menu) AddToKeyMap(km KeyMap) { w.keyMap.Merge(km) }
|
||||
func (w *Menu) RemoveFromKeyMap(km KeyMap) {
|
||||
for k := range km.Keys {
|
||||
w.keyMap.Remove(k)
|
||||
}
|
||||
for r := range km.Runes {
|
||||
w.keyMap.RemoveRune(r)
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Menu) HandleKey(ev *tcell.EventKey) bool {
|
||||
if !w.active {
|
||||
return false
|
||||
@@ -165,24 +172,23 @@ func (w *Menu) drawVMenu(screen tcell.Screen) {
|
||||
y++
|
||||
}
|
||||
}
|
||||
func (w *Menu) Active() bool { return w.active }
|
||||
func (w *Menu) SetActive(a bool) { w.active = a }
|
||||
func (w *Menu) Visible() bool { return w.visible }
|
||||
func (w *Menu) SetVisible(a bool) { w.visible = a }
|
||||
func (w *Menu) SetX(x int) { w.x = x }
|
||||
func (w *Menu) SetY(y int) { w.y = y }
|
||||
func (w *Menu) GetX() int { return w.x }
|
||||
func (w *Menu) GetY() int { return w.y }
|
||||
func (w *Menu) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
|
||||
func (w *Menu) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
|
||||
func (w *Menu) SetW(x int) { w.w = x }
|
||||
func (w *Menu) SetH(y int) { w.h = y }
|
||||
func (w *Menu) GetW() int { return w.w }
|
||||
func (w *Menu) GetH() int { return w.y }
|
||||
func (w *Menu) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
|
||||
func (w *Menu) Focusable() bool { return true }
|
||||
func (w *Menu) SetTabbable(b bool) { w.tabbable = b }
|
||||
func (w *Menu) Tabbable() bool { return w.tabbable }
|
||||
func (w *Menu) Active() bool { return w.active }
|
||||
func (w *Menu) SetActive(a bool) { w.active = a }
|
||||
func (w *Menu) Visible() bool { return w.visible }
|
||||
func (w *Menu) SetVisible(a bool) { w.visible = a }
|
||||
func (w *Menu) SetX(x int) { w.x = x }
|
||||
func (w *Menu) SetY(y int) { w.y = y }
|
||||
func (w *Menu) GetX() int { return w.x }
|
||||
func (w *Menu) GetY() int { return w.y }
|
||||
func (w *Menu) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
|
||||
func (w *Menu) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
|
||||
func (w *Menu) SetW(x int) { w.w = x }
|
||||
func (w *Menu) SetH(y int) { w.h = y }
|
||||
func (w *Menu) GetW() int { return w.w }
|
||||
func (w *Menu) GetH() int { return w.y }
|
||||
func (w *Menu) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
|
||||
func (w *Menu) Focusable() bool { return true }
|
||||
func (w *Menu) SetFocusable(b bool) { w.focusable = b }
|
||||
|
||||
func (w *Menu) WantW() int {
|
||||
var maxW int
|
||||
@@ -241,7 +247,6 @@ func (w *Menu) MinH() int {
|
||||
}
|
||||
func (w *Menu) SetType(tp MenuType) { w.menuType = tp }
|
||||
func (w *Menu) SetLabel(lbl string) { w.label = lbl }
|
||||
func (w *Menu) SetFocusable(f bool) {}
|
||||
|
||||
func (w *Menu) GetItems() []*MenuItem { return w.items }
|
||||
func (w *Menu) GetItem(idx int) *MenuItem {
|
||||
|
||||
Reference in New Issue
Block a user