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

@@ -35,12 +35,12 @@ type Field struct {
label string
value string
cursor int
visible bool
active bool
tabbable bool
x, y int
w, h int
cursor int
visible bool
active bool
focusable bool
x, y int
w, h int
filter func(*tcell.EventKey) bool
onChange func(prev, curr string)
@@ -71,12 +71,23 @@ func (w *Field) Init(id string, style tcell.Style) {
tcell.KeyEnd: w.handleEnd,
tcell.KeyCtrlU: w.clearValueBeforeCursor,
})
w.tabbable = true
w.focusable = true
}
func (w *Field) Id() string { return w.id }
func (w *Field) HandleResize(ev *tcell.EventResize) { w.w, w.h = ev.Size() }
func (w *Field) SetKeyMap(km KeyMap) { w.keyMap = km }
func (w *Field) AddToKeyMap(km KeyMap) { w.keyMap.Merge(km) }
func (w *Field) RemoveFromKeyMap(km KeyMap) {
for k := range km.Keys {
w.keyMap.Remove(k)
}
for r := range km.Runes {
w.keyMap.RemoveRune(r)
}
}
func (w *Field) HandleKey(ev *tcell.EventKey) bool {
if !w.active {
return false
@@ -158,12 +169,11 @@ func (w *Field) WantW() int {
func (w *Field) WantH() int {
return 1
}
func (w *Field) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *Field) Focusable() bool { return true }
func (w *Field) SetTabbable(b bool) { w.tabbable = b }
func (w *Field) Tabbable() bool { return w.tabbable }
func (w *Field) MinW() int { return len(w.label) + wh.Max(15, len(w.value)) }
func (w *Field) MinH() int { return 1 }
func (w *Field) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *Field) Focusable() bool { return w.focusable }
func (w *Field) SetFocusable(b bool) { w.focusable = b }
func (w *Field) MinW() int { return len(w.label) + wh.Max(15, len(w.value)) }
func (w *Field) MinH() int { return 1 }
/* Non-Widget-Interface Functions */
func (w *Field) handleBackspace(_ *tcell.EventKey) bool {