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

@@ -28,15 +28,16 @@ import (
type RelativeLayout struct {
id string
style tcell.Style
x, y int
w, h int
widgetRelations map[Widget][]widgetRelation
widgets []Widget
active bool
visible bool
tabbable bool
active bool
visible bool
focusable bool
x, y int
w, h int
keyMap KeyMap
}
var _ Widget = (*RelativeLayout)(nil)
@@ -74,18 +75,26 @@ func (w *RelativeLayout) Init(id string, style tcell.Style) {
w.id = id
w.style = style
w.visible = true
w.tabbable = true
w.focusable = true
w.keyMap = BlankKeyMap()
}
func (w *RelativeLayout) Id() string { return w.id }
func (w *RelativeLayout) 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())
// TODO: Trickle-down HandleResize
}
func (w *RelativeLayout) HandleKey(ev *tcell.EventKey) bool { return false }
func (w *RelativeLayout) SetKeyMap(km KeyMap) { w.keyMap = km }
func (w *RelativeLayout) AddToKeyMap(km KeyMap) { w.keyMap.Merge(km) }
func (w *RelativeLayout) RemoveFromKeyMap(km KeyMap) {
for k := range km.Keys {
w.keyMap.Remove(k)
}
for r := range km.Runes {
w.keyMap.RemoveRune(r)
}
}
func (w *RelativeLayout) HandleKey(ev *tcell.EventKey) bool { return w.keyMap.Handle(ev) }
func (w *RelativeLayout) HandleTime(ev *tcell.EventTime) {}
func (w *RelativeLayout) Draw(screen tcell.Screen) {
if !w.visible {
@@ -105,26 +114,25 @@ func (w *RelativeLayout) Draw(screen tcell.Screen) {
*/
}
func (w *RelativeLayout) Active() bool { return w.active }
func (w *RelativeLayout) SetActive(a bool) { w.active = a }
func (w *RelativeLayout) Visible() bool { return w.visible }
func (w *RelativeLayout) SetVisible(a bool) { w.visible = a }
func (w *RelativeLayout) Focusable() bool { return true }
func (w *RelativeLayout) SetTabbable(b bool) { w.tabbable = b }
func (w *RelativeLayout) Tabbable() bool { return w.tabbable }
func (w *RelativeLayout) SetX(x int) { w.x = x }
func (w *RelativeLayout) SetY(y int) { w.y = y }
func (w *RelativeLayout) GetX() int { return w.x }
func (w *RelativeLayout) GetY() int { return w.y }
func (w *RelativeLayout) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *RelativeLayout) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
func (w *RelativeLayout) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *RelativeLayout) SetW(wd int) { w.w = wd }
func (w *RelativeLayout) SetH(h int) { w.h = h }
func (w *RelativeLayout) GetW() int { return w.w }
func (w *RelativeLayout) GetH() int { return w.h }
func (w *RelativeLayout) WantW() int { return 1 }
func (w *RelativeLayout) WantH() int { return 1 }
func (w *RelativeLayout) Active() bool { return w.active }
func (w *RelativeLayout) SetActive(a bool) { w.active = a }
func (w *RelativeLayout) Visible() bool { return w.visible }
func (w *RelativeLayout) SetVisible(a bool) { w.visible = a }
func (w *RelativeLayout) Focusable() bool { return w.focusable }
func (w *RelativeLayout) SetFocusable(b bool) { w.focusable = b }
func (w *RelativeLayout) SetX(x int) { w.x = x }
func (w *RelativeLayout) SetY(y int) { w.y = y }
func (w *RelativeLayout) GetX() int { return w.x }
func (w *RelativeLayout) GetY() int { return w.y }
func (w *RelativeLayout) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *RelativeLayout) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
func (w *RelativeLayout) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *RelativeLayout) SetW(wd int) { w.w = wd }
func (w *RelativeLayout) SetH(h int) { w.h = h }
func (w *RelativeLayout) GetW() int { return w.w }
func (w *RelativeLayout) GetH() int { return w.h }
func (w *RelativeLayout) WantW() int { return 1 }
func (w *RelativeLayout) WantH() int { return 1 }
func (w *RelativeLayout) MinW() int {
// Find the highest value for x in all widgets GetX() + MinW()
var minW int