Wonkiness on layout

This commit is contained in:
2025-10-10 16:46:29 -05:00
parent 79a212e601
commit 7a1afd67ac
28 changed files with 362 additions and 156 deletions

View File

@@ -36,10 +36,10 @@ type Button struct {
x, y int
w, h int
active bool
visible bool
focusable bool
keyMap KeyMap
active bool
visible bool
focusable bool
keyMap, customKeyMap KeyMap
onPressed func() bool
logger func(string, ...any)
@@ -60,6 +60,7 @@ func (w *Button) Init(id string, style tcell.Style) {
w.keyMap = NewKeyMap(map[tcell.Key]func(ev *tcell.EventKey) bool{
tcell.KeyEnter: func(ev *tcell.EventKey) bool { return w.onPressed() },
})
w.customKeyMap = BlankKeyMap()
w.onPressed = func() bool { return false }
w.focusable = true
}
@@ -68,14 +69,20 @@ func (w *Button) HandleResize(ev *tcell.EventResize) {
w.w, w.h = ev.Size()
}
func (w *Button) SetKeyMap(km KeyMap) { w.keyMap = km }
func (w *Button) AddToKeyMap(km KeyMap) { w.keyMap.Merge(km) }
func (w *Button) SetKeyMap(km KeyMap, def bool) {
if def {
w.keyMap = km
} else {
w.customKeyMap = km
}
}
func (w *Button) AddToKeyMap(km KeyMap) { w.customKeyMap.Merge(km) }
func (w *Button) RemoveFromKeyMap(km KeyMap) {
for k := range km.Keys {
w.keyMap.Remove(k)
w.customKeyMap.Remove(k)
}
for r := range km.Runes {
w.keyMap.RemoveRune(r)
w.customKeyMap.RemoveRune(r)
}
}
@@ -83,7 +90,9 @@ func (w *Button) HandleKey(ev *tcell.EventKey) bool {
if !w.active {
return false
}
return w.keyMap.Handle(ev)
b1 := w.keyMap.Handle(ev)
b2 := w.customKeyMap.Handle(ev)
return b1 || b2
}
func (w *Button) HandleTime(ev *tcell.EventTime) {}