So much work

This commit is contained in:
2025-08-06 16:15:08 -05:00
parent 1474caffaa
commit 81c7ec8324
20 changed files with 1386 additions and 376 deletions

80
menu.go
View File

@@ -27,13 +27,14 @@ import (
)
type Menu struct {
id string
label string
style tcell.Style
active bool
visible bool
x, y int
w, h int
id string
label string
style tcell.Style
active bool
visible bool
tabbable bool
x, y int
w, h int
menuType MenuType
cursor int
@@ -76,6 +77,7 @@ func (w *Menu) Init(id string, style tcell.Style) {
return false
},
})
w.tabbable = true
}
func (w *Menu) Id() string { return w.id }
func (w *Menu) HandleResize(ev *tcell.EventResize) {}
@@ -146,21 +148,24 @@ func (w *Menu) drawVMenu(screen tcell.Screen) {
y++
}
}
func (w *Menu) Active() bool { return w.active }
func (w *Menu) SetActive(a bool) { w.active = a }
func (w *Menu) Visible() bool { return w.visible }
func (w *Menu) SetVisible(a bool) { w.visible = a }
func (w *Menu) SetX(x int) { w.x = x }
func (w *Menu) SetY(y int) { w.y = y }
func (w *Menu) GetX() int { return w.x }
func (w *Menu) GetY() int { return w.y }
func (w *Menu) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *Menu) SetW(x int) { w.w = x }
func (w *Menu) SetH(y int) { w.h = y }
func (w *Menu) GetW() int { return w.w }
func (w *Menu) GetH() int { return w.y }
func (w *Menu) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *Menu) Focusable() bool { return true }
func (w *Menu) Active() bool { return w.active }
func (w *Menu) SetActive(a bool) { w.active = a }
func (w *Menu) Visible() bool { return w.visible }
func (w *Menu) SetVisible(a bool) { w.visible = a }
func (w *Menu) SetX(x int) { w.x = x }
func (w *Menu) SetY(y int) { w.y = y }
func (w *Menu) GetX() int { return w.x }
func (w *Menu) GetY() int { return w.y }
func (w *Menu) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
func (w *Menu) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *Menu) SetW(x int) { w.w = x }
func (w *Menu) SetH(y int) { w.h = y }
func (w *Menu) GetW() int { return w.w }
func (w *Menu) GetH() int { return w.y }
func (w *Menu) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *Menu) Focusable() bool { return true }
func (w *Menu) SetTabbable(b bool) { w.tabbable = b }
func (w *Menu) Tabbable() bool { return w.tabbable }
func (w *Menu) WantW() int {
var maxW int
@@ -186,6 +191,37 @@ func (w *Menu) WantH() int {
return ret + len(w.items)
}
}
func (w *Menu) MinW() int {
labels := []string{w.label}
for i := range w.items {
labels = append(labels, w.items[i].label)
}
switch w.menuType {
case MenuTypeH:
wrk := 0
for i := range labels {
wrk += len(labels[i])
}
return wrk
case MenuTypeV:
return h.Longest(labels)
}
return 0
}
func (w *Menu) MinH() int {
switch w.menuType {
case MenuTypeH:
return 1
case MenuTypeV:
if len(w.label) > 0 {
return 1 + len(w.items)
}
return len(w.items)
}
return 0
}
func (w *Menu) SetType(tp MenuType) { w.menuType = tp }
func (w *Menu) SetLabel(lbl string) { w.label = lbl }
func (w *Menu) SetFocusable(f bool) {}