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

@@ -45,7 +45,7 @@ type Form struct {
hasSubmit bool
hasCancel bool
keyMap KeyMap
keyMap, customKeyMap KeyMap
}
var _ Widget = (*Form)(nil)
@@ -63,6 +63,8 @@ func (w *Form) Init(id string, style tcell.Style) {
w.focusable = true
w.submit = NewButton(fmt.Sprintf("%s-submit", id), style)
w.cancel = NewButton(fmt.Sprintf("%s-cancel", id), style)
w.keyMap = BlankKeyMap()
w.customKeyMap = BlankKeyMap()
}
func (w *Form) Id() string { return w.id }
@@ -90,14 +92,20 @@ func (w *Form) HandleResize(ev *tcell.EventResize) {
}
}
func (w *Form) SetKeyMap(km KeyMap) { w.keyMap = km }
func (w *Form) AddToKeyMap(km KeyMap) { w.keyMap.Merge(km) }
func (w *Form) SetKeyMap(km KeyMap, def bool) {
if def {
w.keyMap = km
} else {
w.customKeyMap = km
}
}
func (w *Form) AddToKeyMap(km KeyMap) { w.customKeyMap.Merge(km) }
func (w *Form) 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)
}
}
@@ -121,7 +129,9 @@ func (w *Form) HandleKey(ev *tcell.EventKey) bool {
w.updateWidgets()
return w.cursor > pre
}
return false
b1 := w.keyMap.Handle(ev)
b2 := w.customKeyMap.Handle(ev)
return b1 || b2
}
func (w *Form) HandleTime(ev *tcell.EventTime) {}
func (w *Form) Draw(screen tcell.Screen) {