Much Work

- Definable KeyMaps
- Change 'Tabbable' to just use 'Focusable'
This commit is contained in:
2025-09-04 11:09:34 -05:00
parent c1db729bb3
commit f571b13a31
26 changed files with 881 additions and 615 deletions

View File

@@ -27,14 +27,14 @@ import (
)
type MenuItem 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
@@ -75,7 +75,7 @@ func (w *MenuItem) Init(id string, style tcell.Style) {
for i := range w.items {
w.items[i].SetActive(i == w.cursor)
}
w.tabbable = true
w.focusable = true
}
func (w *MenuItem) Id() string { return w.id }
func (w *MenuItem) HandleResize(ev *tcell.EventResize) {
@@ -83,6 +83,17 @@ func (w *MenuItem) HandleResize(ev *tcell.EventResize) {
// TODO: Trickle-down HandleResize
}
func (w *MenuItem) SetKeyMap(km KeyMap) { w.keyMap = km }
func (w *MenuItem) AddToKeyMap(km KeyMap) { w.keyMap.Merge(km) }
func (w *MenuItem) RemoveFromKeyMap(km KeyMap) {
for k := range km.Keys {
w.keyMap.Remove(k)
}
for r := range km.Runes {
w.keyMap.RemoveRune(r)
}
}
func (w *MenuItem) HandleKey(ev *tcell.EventKey) bool {
if !w.active {
return false
@@ -157,10 +168,9 @@ func (w *MenuItem) WantH() int {
}
return ret
}
func (w *MenuItem) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *MenuItem) Focusable() bool { return !w.disabled }
func (w *MenuItem) SetTabbable(b bool) { w.tabbable = b }
func (w *MenuItem) Tabbable() bool { return w.tabbable }
func (w *MenuItem) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *MenuItem) Focusable() bool { return w.focusable && !w.disabled }
func (w *MenuItem) SetFocusable(b bool) { w.focusable = b }
// How much width this item wants
func (w *MenuItem) Expand(e bool) {