4 Commits
v0.3.0 ... main

Author SHA1 Message Date
18ead7b486 Some work 2026-02-18 19:12:13 -06:00
4b51c5b00f Show/Hide Menu Functions 2026-02-18 15:56:20 -06:00
46a87f913b Bug Fixes 2026-02-02 13:38:33 -06:00
5581cf14c1 Bug Fixes 2026-02-02 13:35:13 -06:00
8 changed files with 122 additions and 121 deletions

View File

@@ -32,11 +32,10 @@ type Alert struct {
id string
style tcell.Style
x, y int
w, h int
active bool
visible bool
focusable bool
x, y int
w, h int
active bool
visible bool
layout *LinearLayout
title string
@@ -90,7 +89,6 @@ func (w *Alert) Init(id string, style tcell.Style) {
NewKey(BuildEK(tcell.KeyUp), w.SelectNext),
NewKey(BuildEK(tcell.KeyEnter), w.Do),
)
w.focusable = true
}
func (w *Alert) Id() string { return w.id }
func (w *Alert) HandleResize(ev *tcell.EventResize) {
@@ -131,23 +129,28 @@ func (w *Alert) SetActive(a bool) bool {
w.active = a
return w.active
}
func (w *Alert) Visible() bool { return w.visible }
func (w *Alert) SetVisible(a bool) { w.visible = a }
func (w *Alert) SetX(x int) { w.x = x }
func (w *Alert) SetY(y int) { w.y = y }
func (w *Alert) GetX() int { return w.x }
func (w *Alert) GetY() int { return w.y }
func (w *Alert) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
func (w *Alert) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *Alert) SetW(x int) { w.w = x }
func (w *Alert) SetH(y int) { w.h = y }
func (w *Alert) GetW() int { return w.w }
func (w *Alert) GetH() int { return w.y }
func (w *Alert) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *Alert) Focusable() bool { return w.focusable }
func (w *Alert) SetFocusable(b bool) { w.focusable = b }
func (w *Alert) Visible() bool { return w.visible }
func (w *Alert) SetVisible(a bool) { w.visible = a }
func (w *Alert) SetX(x int) { w.x = x }
func (w *Alert) SetY(y int) { w.y = y }
func (w *Alert) GetX() int { return w.x }
func (w *Alert) GetY() int { return w.y }
func (w *Alert) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
func (w *Alert) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *Alert) SetW(x int) { w.w = x }
func (w *Alert) SetH(y int) { w.h = y }
func (w *Alert) GetW() int { return w.w }
func (w *Alert) GetH() int { return w.y }
func (w *Alert) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *Alert) WantW() int {
return 4 + wh.Max(w.message.WantW(), (w.btnOk.WantW()+w.btnCancel.WantW()))
var okW, cancelW int
if !w.btnOk.Visible() {
okW = w.btnOk.WantW()
}
if !w.btnCancel.Visible() {
cancelW = w.btnCancel.WantW()
}
return 4 + wh.Max(w.message.WantW(), (okW+cancelW))
}
func (w *Alert) WantH() int {
@@ -167,13 +170,11 @@ func (w *Alert) SetMessage(msg string) { w.message.SetText(msg) }
func (w *Alert) SetOkPressed(b func() bool) {
w.btnOk.SetVisible(b != nil)
w.btnOk.SetFocusable(b != nil)
w.btnOk.SetOnPressed(b)
}
func (w *Alert) SetCancelPressed(b func() bool) {
w.btnCancel.SetVisible(b != nil)
w.btnCancel.SetFocusable(b != nil)
w.btnCancel.SetOnPressed(b)
}

View File

@@ -58,7 +58,6 @@ func (w *BorderedWidget) Init(id string, s tcell.Style) {
w.style = s
w.widget.SetVisible(true)
w.border = wh.BRD_CSIMPLE
w.widget.SetFocusable(true)
}
func (w *BorderedWidget) Id() string { return w.id }
@@ -96,8 +95,6 @@ func (w *BorderedWidget) Active() bool { return w.widget.Active() }
func (w *BorderedWidget) SetActive(a bool) bool { return w.widget.SetActive(a) }
func (w *BorderedWidget) Visible() bool { return w.widget.Visible() }
func (w *BorderedWidget) SetVisible(a bool) { w.SetVisible(a) }
func (w *BorderedWidget) Focusable() bool { return w.widget.Focusable() }
func (w *BorderedWidget) SetFocusable(b bool) { w.widget.SetFocusable(b) }
func (w *BorderedWidget) SetX(x int) { w.x = x }
func (w *BorderedWidget) SetY(y int) { w.y = y }
func (w *BorderedWidget) GetX() int { return w.x }

View File

@@ -36,10 +36,9 @@ type Button struct {
x, y int
w, h int
active bool
visible bool
focusable bool
keyMap *KeyMap
active bool
visible bool
keyMap *KeyMap
onPressed func() bool
logger func(string, ...any)
@@ -59,7 +58,6 @@ func (w *Button) Init(id string, style tcell.Style) {
w.visible = true
w.keyMap = NewKeyMap(NewKey(BuildEK(tcell.KeyEnter), func(ev *tcell.EventKey) bool { return w.onPressed() }))
w.onPressed = func() bool { return false }
w.focusable = true
}
func (w *Button) Id() string { return w.id }
func (w *Button) HandleResize(ev *tcell.EventResize) {
@@ -125,25 +123,23 @@ func (w *Button) SetActive(a bool) bool {
w.active = a
return w.active
}
func (w *Button) Visible() bool { return w.visible }
func (w *Button) SetVisible(a bool) { w.visible = a }
func (w *Button) SetX(x int) { w.x = x }
func (w *Button) SetY(y int) { w.y = y }
func (w *Button) GetX() int { return w.x }
func (w *Button) GetY() int { return w.y }
func (w *Button) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
func (w *Button) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *Button) SetW(x int) { w.w = x }
func (w *Button) SetH(y int) { w.h = y }
func (w *Button) GetW() int { return w.w }
func (w *Button) GetH() int { return w.h }
func (w *Button) WantW() int { return 4 + len(w.label) }
func (w *Button) WantH() int { return 3 }
func (w *Button) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *Button) Focusable() bool { return w.focusable }
func (w *Button) SetFocusable(b bool) { w.focusable = b }
func (w *Button) MinW() int { return len(w.label) + 2 }
func (w *Button) MinH() int { return 1 }
func (w *Button) Visible() bool { return w.visible }
func (w *Button) SetVisible(a bool) { w.visible = a }
func (w *Button) SetX(x int) { w.x = x }
func (w *Button) SetY(y int) { w.y = y }
func (w *Button) GetX() int { return w.x }
func (w *Button) GetY() int { return w.y }
func (w *Button) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
func (w *Button) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *Button) SetW(x int) { w.w = x }
func (w *Button) SetH(y int) { w.h = y }
func (w *Button) GetW() int { return w.w }
func (w *Button) GetH() int { return w.h }
func (w *Button) WantW() int { return 4 + len(w.label) }
func (w *Button) WantH() int { return 3 }
func (w *Button) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *Button) MinW() int { return len(w.label) + 2 }
func (w *Button) MinH() int { return 1 }
func (w *Button) SetLabel(l string) { w.label = l }
func (w *Button) SetOnPressed(p func() bool) { w.onPressed = p }

View File

@@ -148,9 +148,10 @@ func (w *Form) Draw(screen tcell.Screen) {
func (w *Form) SetStyle(s tcell.Style) { w.style = s }
func (w *Form) Active() bool { return w.active }
func (w *Form) SetActive(a bool) {
func (w *Form) SetActive(a bool) bool {
w.active = a
w.updateWidgets()
return w.active
}
func (w *Form) Visible() bool { return w.visible }
func (w *Form) SetVisible(a bool) { w.visible = a }

View File

@@ -52,7 +52,6 @@ type LinearLayout struct {
active bool
visible bool
focusable bool
disableTab bool
insetBorder bool
@@ -80,7 +79,6 @@ func (w *LinearLayout) Init(id string, s tcell.Style) {
w.id = id
w.style = s
w.visible = true
w.focusable = true
w.defFlags = LayoutFlag(LFAlignHCenter | LFAlignVCenter)
w.layoutFlags = make(map[Widget]LayoutFlag)
w.layoutWeights = make(map[Widget]int)
@@ -89,8 +87,7 @@ func (w *LinearLayout) Init(id string, s tcell.Style) {
if active == nil && len(w.widgets) > 0 {
// No widget is active, but we do have some
for i := range w.widgets {
if w.widgets[i].Focusable() {
w.widgets[i].SetActive(true)
if w.widgets[i].SetActive(true) {
return true
}
}
@@ -103,8 +100,7 @@ func (w *LinearLayout) Init(id string, s tcell.Style) {
if active == nil && len(w.widgets) > 0 {
// No widget is active, but we do have some
for i := len(w.widgets) - 1; i >= 0; i-- {
if w.widgets[i].Focusable() {
w.widgets[i].SetActive(true)
if w.widgets[i].SetActive(true) {
return true
}
}
@@ -172,22 +168,20 @@ func (w *LinearLayout) SetActive(a bool) bool {
}
return w.active
}
func (w *LinearLayout) Visible() bool { return w.visible }
func (w *LinearLayout) SetVisible(a bool) { w.visible = a }
func (w *LinearLayout) Focusable() bool { return w.focusable }
func (w *LinearLayout) SetFocusable(b bool) { w.focusable = b }
func (w *LinearLayout) SetX(x int) { w.x = x }
func (w *LinearLayout) SetY(y int) { w.y = y }
func (w *LinearLayout) GetX() int { return w.x }
func (w *LinearLayout) GetY() int { return w.y }
func (w *LinearLayout) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
func (w *LinearLayout) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *LinearLayout) GetW() int { return w.w }
func (w *LinearLayout) GetH() int { return w.h }
func (w *LinearLayout) SetW(wd int) { w.w = wd }
func (w *LinearLayout) SetH(h int) { w.h = h }
func (w *LinearLayout) getSize() Coord { return Coord{X: w.w, Y: w.h} }
func (w *LinearLayout) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *LinearLayout) Visible() bool { return w.visible }
func (w *LinearLayout) SetVisible(a bool) { w.visible = a }
func (w *LinearLayout) SetX(x int) { w.x = x }
func (w *LinearLayout) SetY(y int) { w.y = y }
func (w *LinearLayout) GetX() int { return w.x }
func (w *LinearLayout) GetY() int { return w.y }
func (w *LinearLayout) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
func (w *LinearLayout) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *LinearLayout) GetW() int { return w.w }
func (w *LinearLayout) GetH() int { return w.h }
func (w *LinearLayout) SetW(wd int) { w.w = wd }
func (w *LinearLayout) SetH(h int) { w.h = h }
func (w *LinearLayout) getSize() Coord { return Coord{X: w.w, Y: w.h} }
func (w *LinearLayout) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *LinearLayout) WantW() int {
var wantW int
for _, wd := range w.widgets {
@@ -291,8 +285,7 @@ func (w *LinearLayout) ActivateWidget(n Widget) {
func (w *LinearLayout) ActivateNext() bool {
var found bool
for i := range w.widgets {
if found && w.widgets[i].Focusable() {
w.widgets[i].SetActive(true)
if found && w.widgets[i].SetActive(true) {
return true
} else if w.widgets[i].Active() {
found = true
@@ -305,8 +298,7 @@ func (w *LinearLayout) ActivateNext() bool {
func (w *LinearLayout) ActivatePrev() bool {
var found bool
for i := len(w.widgets) - 1; i >= 0; i-- {
if found && w.widgets[i].Focusable() {
w.widgets[i].SetActive(true)
if found && w.widgets[i].SetActive(true) {
return true
} else if w.widgets[i].Active() {
found = true

View File

@@ -51,22 +51,20 @@ func (w *ShrinkWrap) Active() bool { return w.widget.Active() }
func (w *ShrinkWrap) SetActive(a bool) bool {
return w.widget.SetActive(a)
}
func (w *ShrinkWrap) Visible() bool { return w.widget.Visible() }
func (w *ShrinkWrap) SetVisible(v bool) { w.widget.SetVisible(v) }
func (w *ShrinkWrap) Focusable() bool { return w.widget.Focusable() }
func (w *ShrinkWrap) SetFocusable(t bool) { w.widget.SetFocusable(t) }
func (w *ShrinkWrap) SetX(x int) { w.widget.SetX(x) }
func (w *ShrinkWrap) SetY(y int) { w.widget.SetY(y) }
func (w *ShrinkWrap) GetX() int { return w.widget.GetX() }
func (w *ShrinkWrap) GetY() int { return w.widget.GetY() }
func (w *ShrinkWrap) GetPos() Coord { return w.widget.GetPos() }
func (w *ShrinkWrap) SetPos(pos Coord) { w.widget.SetPos(pos) }
func (w *ShrinkWrap) SetSize(size Coord) { w.widget.SetSize(size) }
func (w *ShrinkWrap) SetW(wd int) { w.widget.SetW(wd) }
func (w *ShrinkWrap) SetH(h int) { w.widget.SetH(h) }
func (w *ShrinkWrap) GetW() int { return w.widget.GetW() }
func (w *ShrinkWrap) GetH() int { return w.widget.GetH() }
func (w *ShrinkWrap) WantW() int { return w.widget.MinW() }
func (w *ShrinkWrap) WantH() int { return w.widget.MinH() }
func (w *ShrinkWrap) MinW() int { return w.widget.MinW() }
func (w *ShrinkWrap) MinH() int { return w.widget.MinH() }
func (w *ShrinkWrap) Visible() bool { return w.widget.Visible() }
func (w *ShrinkWrap) SetVisible(v bool) { w.widget.SetVisible(v) }
func (w *ShrinkWrap) SetX(x int) { w.widget.SetX(x) }
func (w *ShrinkWrap) SetY(y int) { w.widget.SetY(y) }
func (w *ShrinkWrap) GetX() int { return w.widget.GetX() }
func (w *ShrinkWrap) GetY() int { return w.widget.GetY() }
func (w *ShrinkWrap) GetPos() Coord { return w.widget.GetPos() }
func (w *ShrinkWrap) SetPos(pos Coord) { w.widget.SetPos(pos) }
func (w *ShrinkWrap) SetSize(size Coord) { w.widget.SetSize(size) }
func (w *ShrinkWrap) SetW(wd int) { w.widget.SetW(wd) }
func (w *ShrinkWrap) SetH(h int) { w.widget.SetH(h) }
func (w *ShrinkWrap) GetW() int { return w.widget.GetW() }
func (w *ShrinkWrap) GetH() int { return w.widget.GetH() }
func (w *ShrinkWrap) WantW() int { return w.widget.MinW() }
func (w *ShrinkWrap) WantH() int { return w.widget.MinH() }
func (w *ShrinkWrap) MinW() int { return w.widget.MinW() }
func (w *ShrinkWrap) MinH() int { return w.widget.MinH() }

View File

@@ -79,8 +79,7 @@ func (w *ScrollingWidgetList) Init(id string, s tcell.Style) {
if active == nil && len(w.widgets) > 0 {
// No widget is active, but we do have some
for i := range w.widgets {
if w.widgets[i].Focusable() {
w.widgets[i].SetActive(true)
if w.widgets[i].SetActive(true) {
return true
}
}
@@ -93,8 +92,7 @@ func (w *ScrollingWidgetList) Init(id string, s tcell.Style) {
if active == nil && len(w.widgets) > 0 {
// No widget is active, but we do have some
for i := len(w.widgets) - 1; i >= 0; i-- {
if w.widgets[i].Focusable() {
w.widgets[i].SetActive(true)
if w.widgets[i].SetActive(true) {
return true
}
}
@@ -165,22 +163,20 @@ func (w *ScrollingWidgetList) SetActive(a bool) bool {
}
return w.active
}
func (w *ScrollingWidgetList) Visible() bool { return w.visible }
func (w *ScrollingWidgetList) SetVisible(a bool) { w.visible = a }
func (w *ScrollingWidgetList) Focusable() bool { return w.focusable }
func (w *ScrollingWidgetList) SetFocusable(b bool) { w.focusable = b }
func (w *ScrollingWidgetList) SetX(x int) { w.x = x }
func (w *ScrollingWidgetList) SetY(y int) { w.y = y }
func (w *ScrollingWidgetList) GetX() int { return w.x }
func (w *ScrollingWidgetList) GetY() int { return w.y }
func (w *ScrollingWidgetList) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
func (w *ScrollingWidgetList) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *ScrollingWidgetList) GetW() int { return w.w }
func (w *ScrollingWidgetList) GetH() int { return w.h }
func (w *ScrollingWidgetList) SetW(wd int) { w.w = wd }
func (w *ScrollingWidgetList) SetH(h int) { w.h = h }
func (w *ScrollingWidgetList) getSize() Coord { return Coord{X: w.w, Y: w.h} }
func (w *ScrollingWidgetList) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *ScrollingWidgetList) Visible() bool { return w.visible }
func (w *ScrollingWidgetList) SetVisible(a bool) { w.visible = a }
func (w *ScrollingWidgetList) SetX(x int) { w.x = x }
func (w *ScrollingWidgetList) SetY(y int) { w.y = y }
func (w *ScrollingWidgetList) GetX() int { return w.x }
func (w *ScrollingWidgetList) GetY() int { return w.y }
func (w *ScrollingWidgetList) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
func (w *ScrollingWidgetList) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *ScrollingWidgetList) GetW() int { return w.w }
func (w *ScrollingWidgetList) GetH() int { return w.h }
func (w *ScrollingWidgetList) SetW(wd int) { w.w = wd }
func (w *ScrollingWidgetList) SetH(h int) { w.h = h }
func (w *ScrollingWidgetList) getSize() Coord { return Coord{X: w.w, Y: w.h} }
func (w *ScrollingWidgetList) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *ScrollingWidgetList) WantW() int {
var wantW int
for _, wd := range w.widgets {
@@ -284,8 +280,7 @@ func (w *ScrollingWidgetList) ActivateWidget(n Widget) {
func (w *ScrollingWidgetList) ActivateNext() bool {
var found bool
for i := range w.widgets {
if found && w.widgets[i].Focusable() {
w.widgets[i].SetActive(true)
if found && w.widgets[i].SetActive(true) {
return true
} else if w.widgets[i].Active() {
found = true
@@ -298,8 +293,7 @@ func (w *ScrollingWidgetList) ActivateNext() bool {
func (w *ScrollingWidgetList) ActivatePrev() bool {
var found bool
for i := len(w.widgets) - 1; i >= 0; i-- {
if found && w.widgets[i].Focusable() {
w.widgets[i].SetActive(true)
if found && w.widgets[i].SetActive(true) {
return true
} else if w.widgets[i].Active() {
found = true

View File

@@ -89,6 +89,28 @@ func (w *TopMenuLayout) ToggleMenu() bool {
return false
}
func (w *TopMenuLayout) ShowMenu() bool {
if w.menu != nil {
w.menu.SetActive(true)
if w.widget != nil {
w.widget.SetActive(false)
}
return true
}
return false
}
func (w *TopMenuLayout) HideMenu() bool {
if w.menu != nil {
w.menu.SetActive(false)
if w.widget != nil {
w.widget.SetActive(true)
}
return true
}
return false
}
func (w *TopMenuLayout) Id() string { return w.id }
func (w *TopMenuLayout) HandleResize(ev *tcell.EventResize) {
w.w, w.h = ev.Size()