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

@@ -38,9 +38,11 @@ type AbsoluteLayout struct {
defAnchor AbsoluteAnchor
active bool
visible bool
tabbable bool
active bool
visible bool
focusable bool
keyMap KeyMap
cursor int
disableTab bool
@@ -76,20 +78,30 @@ func (w *AbsoluteLayout) Init(id string, s tcell.Style) {
w.style = s
w.visible = true
w.defAnchor = AnchorTL
w.keyMap = BlankKeyMap()
w.wCoords = make(map[Widget]Coord)
w.wAnchor = make(map[Widget]AbsoluteAnchor)
w.wManualSizes = make(map[Widget]Coord)
w.tabbable = true
w.focusable = true
}
func (w *AbsoluteLayout) Id() string { return w.id }
func (w *AbsoluteLayout) 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())
w.updateWidgetLayouts()
}
func (w *AbsoluteLayout) SetKeyMap(km KeyMap) { w.keyMap = km }
func (w *AbsoluteLayout) AddToKeyMap(km KeyMap) { w.keyMap.Merge(km) }
func (w *AbsoluteLayout) RemoveFromKeyMap(km KeyMap) {
for k := range km.Keys {
w.keyMap.Remove(k)
}
for r := range km.Runes {
w.keyMap.RemoveRune(r)
}
}
func (w *AbsoluteLayout) HandleKey(ev *tcell.EventKey) bool {
if !w.disableTab && ev.Key() == tcell.KeyTab {
fndP := -1
@@ -101,7 +113,7 @@ func (w *AbsoluteLayout) HandleKey(ev *tcell.EventKey) bool {
continue
}
} else {
if w.widgets[i].Focusable() && w.widgets[i].Tabbable() {
if w.widgets[i].Focusable() {
w.widgets[i].SetActive(true)
return true
}
@@ -112,7 +124,7 @@ func (w *AbsoluteLayout) HandleKey(ev *tcell.EventKey) bool {
return false
}
for i := 0; i < fndP; i++ {
if w.widgets[i].Focusable() && w.widgets[i].Tabbable() {
if w.widgets[i].Focusable() {
w.widgets[i].SetActive(true)
return true
}
@@ -143,26 +155,25 @@ func (w *AbsoluteLayout) Draw(screen tcell.Screen) {
}
}
func (w *AbsoluteLayout) Active() bool { return w.active }
func (w *AbsoluteLayout) SetActive(a bool) { w.active = a }
func (w *AbsoluteLayout) Visible() bool { return w.visible }
func (w *AbsoluteLayout) SetVisible(a bool) { w.visible = a }
func (w *AbsoluteLayout) Focusable() bool { return true }
func (w *AbsoluteLayout) SetTabbable(b bool) { w.tabbable = b }
func (w *AbsoluteLayout) Tabbable() bool { return w.tabbable }
func (w *AbsoluteLayout) SetX(x int) { w.x = x }
func (w *AbsoluteLayout) SetY(y int) { w.y = y }
func (w *AbsoluteLayout) GetX() int { return w.x }
func (w *AbsoluteLayout) GetY() int { return w.y }
func (w *AbsoluteLayout) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
func (w *AbsoluteLayout) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *AbsoluteLayout) GetW() int { return w.w }
func (w *AbsoluteLayout) GetH() int { return w.h }
func (w *AbsoluteLayout) SetW(wd int) { w.w = wd }
func (w *AbsoluteLayout) SetH(h int) { w.h = h }
func (w *AbsoluteLayout) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *AbsoluteLayout) WantW() int { return w.w }
func (w *AbsoluteLayout) WantH() int { return w.h }
func (w *AbsoluteLayout) Active() bool { return w.active }
func (w *AbsoluteLayout) SetActive(a bool) { w.active = a }
func (w *AbsoluteLayout) Visible() bool { return w.visible }
func (w *AbsoluteLayout) SetVisible(a bool) { w.visible = a }
func (w *AbsoluteLayout) Focusable() bool { return w.focusable }
func (w *AbsoluteLayout) SetFocusable(b bool) { w.focusable = b }
func (w *AbsoluteLayout) SetX(x int) { w.x = x }
func (w *AbsoluteLayout) SetY(y int) { w.y = y }
func (w *AbsoluteLayout) GetX() int { return w.x }
func (w *AbsoluteLayout) GetY() int { return w.y }
func (w *AbsoluteLayout) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
func (w *AbsoluteLayout) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *AbsoluteLayout) GetW() int { return w.w }
func (w *AbsoluteLayout) GetH() int { return w.h }
func (w *AbsoluteLayout) SetW(wd int) { w.w = wd }
func (w *AbsoluteLayout) SetH(h int) { w.h = h }
func (w *AbsoluteLayout) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *AbsoluteLayout) WantW() int { return w.w }
func (w *AbsoluteLayout) WantH() int { return w.h }
func (w *AbsoluteLayout) MinW() int {
// Find the highest value for x in all widgets GetX() + MinW()
var minW int