3 Commits

Author SHA1 Message Date
5581cf14c1 Bug Fixes 2026-02-02 13:35:13 -06:00
16a92c8f99 Changed 'Tabbable/Focusable' logic to use Active 2026-02-02 13:29:51 -06:00
62ef3b5d44 Add 'Has' to layout flags 2026-01-29 06:12:52 -06:00
32 changed files with 396 additions and 350 deletions

View File

@@ -75,6 +75,7 @@ const (
LFSizeAll = LayoutFlag(0x11110000)
)
func (f LayoutFlag) Has(fl LayoutFlag) bool { return f&fl != 0 }
func (f LayoutFlag) Add(fl LayoutFlag) { f |= fl }
func (f LayoutFlag) Remove(fl LayoutFlag) { f = f &^ fl }
func (f LayoutFlag) ClearAll() {

View File

@@ -94,8 +94,7 @@ func (w *AbsoluteLayout) HandleKey(ev *tcell.EventKey) bool {
continue
}
} else {
if w.widgets[i].Focusable() {
w.widgets[i].SetActive(true)
if w.widgets[i].SetActive(true) {
return true
}
}
@@ -105,8 +104,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].SetActive(true)
if w.widgets[i].SetActive(true) {
return true
}
}
@@ -141,7 +139,10 @@ func (w *AbsoluteLayout) Draw(screen tcell.Screen) {
func (w *AbsoluteLayout) SetStyle(s tcell.Style) { w.style = s }
func (w *AbsoluteLayout) Active() bool { return w.active }
func (w *AbsoluteLayout) SetActive(a bool) { w.active = a }
func (w *AbsoluteLayout) SetActive(a bool) bool {
w.active = a
return w.Active()
}
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 }

View File

@@ -127,7 +127,10 @@ func (w *Alert) Draw(screen tcell.Screen) {
func (w *Alert) SetStyle(s tcell.Style) { w.style = s }
func (w *Alert) Active() bool { return w.active }
func (w *Alert) SetActive(a bool) { w.active = a }
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 }

View File

@@ -82,7 +82,10 @@ func (w *ArtWidget) Draw(screen tcell.Screen) {
func (w *ArtWidget) SetStyle(s tcell.Style) { w.style = s }
func (w *ArtWidget) Active() bool { return w.active }
func (w *ArtWidget) SetActive(a bool) { w.active = a }
func (w *ArtWidget) SetActive(a bool) bool {
w.active = a
return w.active
}
func (w *ArtWidget) Visible() bool { return w.visible }
func (w *ArtWidget) SetVisible(v bool) { w.visible = v }
func (w *ArtWidget) Focusable() bool { return w.focusable }

View File

@@ -53,7 +53,7 @@ func (w *BlankWidget) Draw(screen tcell.Screen) {}
func (w *BlankWidget) SetStyle(s tcell.Style) {}
func (w *BlankWidget) Active() bool { return false }
func (w *BlankWidget) SetActive(a bool) {}
func (w *BlankWidget) SetActive(a bool) bool { return false }
func (w *BlankWidget) Visible() bool { return true }
func (w *BlankWidget) SetVisible(v bool) {}
func (w *BlankWidget) Focusable() bool { return false }

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 }
@@ -93,11 +92,9 @@ func (w *BorderedWidget) Draw(screen tcell.Screen) {
func (w *BorderedWidget) SetStyle(s tcell.Style) { w.style = s }
func (w *BorderedWidget) Active() bool { return w.widget.Active() }
func (w *BorderedWidget) SetActive(a bool) { w.widget.SetActive(a) }
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

@@ -78,7 +78,10 @@ func (w *BufferWidget) Draw(screen tcell.Screen) { w.buffer.Draw(w.x, w.y,
func (w *BufferWidget) SetStyle(s tcell.Style) { w.style = s }
func (w *BufferWidget) Active() bool { return w.active }
func (w *BufferWidget) SetActive(a bool) { w.active = a }
func (w *BufferWidget) SetActive(a bool) bool {
w.active = a
return w.active
}
func (w *BufferWidget) Visible() bool { return w.visible }
func (w *BufferWidget) SetVisible(a bool) { w.visible = a }
func (w *BufferWidget) Focusable() bool { return w.focusable }

View File

@@ -121,7 +121,10 @@ func (w *Button) Draw(screen tcell.Screen) {
func (w *Button) SetStyle(s tcell.Style) { w.style = s }
func (w *Button) Active() bool { return w.active }
func (w *Button) SetActive(a bool) { w.active = a }
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 }

View File

@@ -160,7 +160,10 @@ func (w *Chat) Draw(screen tcell.Screen) {
func (w *Chat) SetStyle(s tcell.Style) { w.style = s }
func (w *Chat) Active() bool { return w.active }
func (w *Chat) SetActive(a bool) { w.active = a }
func (w *Chat) SetActive(a bool) bool {
w.active = a
return w.active
}
func (w *Chat) Visible() bool { return w.visible }
func (w *Chat) SetVisible(a bool) { w.visible = a }
func (w *Chat) Focusable() bool { return w.focusable }

View File

@@ -94,7 +94,10 @@ func (w *Checkbox) Draw(screen tcell.Screen) {
func (w *Checkbox) SetStyle(s tcell.Style) { w.style = s }
func (w *Checkbox) Active() bool { return w.active }
func (w *Checkbox) SetActive(a bool) { w.active = a }
func (w *Checkbox) SetActive(a bool) bool {
w.active = a
return w.active
}
func (w *Checkbox) Visible() bool { return w.visible }
func (w *Checkbox) SetVisible(a bool) { w.visible = a }
func (w *Checkbox) SetX(x int) { w.x = x }

View File

@@ -174,7 +174,10 @@ func (w *Cli) Draw(screen tcell.Screen) {
func (w *Cli) SetStyle(s tcell.Style) { w.style = s }
func (w *Cli) Active() bool { return w.active }
func (w *Cli) SetActive(a bool) { w.active = a }
func (w *Cli) SetActive(a bool) bool {
w.active = a
return w.active
}
func (w *Cli) Visible() bool { return w.visible }
func (w *Cli) SetVisible(a bool) { w.visible = a }
func (w *Cli) Focusable() bool { return true }

View File

@@ -131,12 +131,13 @@ func (w *DatePicker) Draw(screen tcell.Screen) {
func (w *DatePicker) SetStyle(s tcell.Style) { w.style = s }
func (w *DatePicker) Active() bool { return w.active }
func (w *DatePicker) SetActive(a bool) {
func (w *DatePicker) SetActive(a bool) bool {
if !w.active && a {
// Wasn't active, but turning on
w.dateFld.SetActive(true)
}
w.active = a
return w.active
}
func (w *DatePicker) Visible() bool { return w.visible }
func (w *DatePicker) SetVisible(a bool) { w.visible = a }

View File

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

View File

@@ -157,7 +157,10 @@ func (w *Field) Draw(screen tcell.Screen) {
func (w *Field) SetStyle(s tcell.Style) { w.style = s }
func (w *Field) Active() bool { return w.active }
func (w *Field) SetActive(a bool) { w.active = a }
func (w *Field) SetActive(a bool) bool {
w.active = a
return w.active
}
func (w *Field) Visible() bool { return w.visible }
func (w *Field) SetVisible(a bool) { w.visible = a }
func (w *Field) SetX(x int) { w.x = x }

View File

@@ -123,7 +123,10 @@ func (w *FilePicker) Draw(screen tcell.Screen) {
func (w *FilePicker) SetStyle(s tcell.Style) { w.style = s }
func (w *FilePicker) Active() bool { return w.active }
func (w *FilePicker) SetActive(a bool) { w.active = a }
func (w *FilePicker) SetActive(a bool) bool {
w.active = a
return w.active
}
func (w *FilePicker) Visible() bool { return w.visible }
func (w *FilePicker) SetVisible(a bool) { w.visible = a }
func (w *FilePicker) SetX(x int) { w.x = x }

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
}
}
@@ -162,7 +158,7 @@ func (w *LinearLayout) Draw(screen tcell.Screen) {
func (w *LinearLayout) SetStyle(s tcell.Style) { w.style = s }
func (w *LinearLayout) Active() bool { return w.active }
func (w *LinearLayout) SetActive(a bool) {
func (w *LinearLayout) SetActive(a bool) bool {
w.active = a
if w.active {
act := w.findActiveOrFirst()
@@ -170,11 +166,10 @@ func (w *LinearLayout) SetActive(a bool) {
act.SetActive(true)
}
}
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 }

View File

@@ -227,7 +227,10 @@ func (w *Menu) drawVMenu(screen tcell.Screen) {
func (w *Menu) SetStyle(s tcell.Style) { w.style = s }
func (w *Menu) Active() bool { return w.active }
func (w *Menu) SetActive(a bool) { w.active = a }
func (w *Menu) SetActive(a bool) bool {
w.active = a
return w.active
}
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 }

View File

@@ -199,11 +199,12 @@ func (w *MenuItem) Draw(screen tcell.Screen) {
func (w *MenuItem) SetStyle(s tcell.Style) { w.style = s }
func (w *MenuItem) Active() bool { return w.active }
func (w *MenuItem) SetActive(a bool) {
func (w *MenuItem) SetActive(a bool) bool {
w.active = a
if !w.manualExpand {
w.expanded = a
}
return w.active
}
func (w *MenuItem) Visible() bool { return w.visible }
func (w *MenuItem) SetVisible(a bool) { w.visible = a }

View File

@@ -116,7 +116,10 @@ func (w *Prompt) Draw(screen tcell.Screen) {
func (w *Prompt) SetStyle(s tcell.Style) { w.style = s }
func (w *Prompt) Active() bool { return w.active }
func (w *Prompt) SetActive(a bool) { w.active = a }
func (w *Prompt) SetActive(a bool) bool {
w.active = a
return w.active
}
func (w *Prompt) Visible() bool { return w.visible }
func (w *Prompt) SetVisible(a bool) { w.visible = a }
func (w *Prompt) SetX(x int) { w.x = x }

View File

@@ -114,7 +114,10 @@ func (w *RelativeLayout) Draw(screen tcell.Screen) {
func (w *RelativeLayout) SetStyle(s tcell.Style) { w.style = s }
func (w *RelativeLayout) Active() bool { return w.active }
func (w *RelativeLayout) SetActive(a bool) { w.active = a }
func (w *RelativeLayout) SetActive(a bool) bool {
w.active = a
return w.active
}
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 }

View File

@@ -259,9 +259,10 @@ func (w *Searcher) buildBuffer() {
func (w *Searcher) SetStyle(s tcell.Style) { w.style = s }
func (w *Searcher) Active() bool { return w.active }
func (w *Searcher) SetActive(a bool) {
func (w *Searcher) SetActive(a bool) bool {
w.active = a
w.search.SetActive(a)
return w.active
}
func (w *Searcher) Visible() bool { return w.visible }
func (w *Searcher) SetVisible(a bool) { w.visible = a }

View File

@@ -48,11 +48,11 @@ func (w *ShrinkWrap) Draw(screen tcell.Screen) { w.widget.Draw(screen)
func (w *ShrinkWrap) SetStyle(s tcell.Style) { w.widget.SetStyle(s) }
func (w *ShrinkWrap) Active() bool { return w.widget.Active() }
func (w *ShrinkWrap) SetActive(a bool) { w.widget.SetActive(a) }
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() }

View File

@@ -187,7 +187,10 @@ func (w *SimpleList) Draw(screen tcell.Screen) {
func (w *SimpleList) SetStyle(s tcell.Style) { w.style = s }
func (w *SimpleList) Active() bool { return w.active }
func (w *SimpleList) SetActive(a bool) { w.active = a }
func (w *SimpleList) SetActive(a bool) bool {
w.active = a
return w.active
}
func (w *SimpleList) Visible() bool { return w.visible }
func (w *SimpleList) SetVisible(a bool) { w.visible = a }
func (w *SimpleList) SetX(x int) { w.x = x }

View File

@@ -86,9 +86,9 @@ func (w *SimpleListWithHelp) Draw(screen tcell.Screen) {
func (w *SimpleListWithHelp) SetStyle(s tcell.Style) { w.style = s }
func (w *SimpleListWithHelp) Active() bool { return w.list.Active() }
func (w *SimpleListWithHelp) SetActive(a bool) {
w.list.SetActive(a)
func (w *SimpleListWithHelp) SetActive(a bool) bool {
w.help.SetVisible(a)
return w.list.SetActive(a)
}
func (w *SimpleListWithHelp) Visible() bool { return w.visible }
func (w *SimpleListWithHelp) SetVisible(a bool) { w.visible = a }

View File

@@ -80,7 +80,7 @@ func (w *Spinner) Draw(screen tcell.Screen) {
func (w *Spinner) SetStyle(s tcell.Style) { w.style = s }
func (w *Spinner) Active() bool { return false }
func (w *Spinner) SetActive(a bool) {}
func (w *Spinner) SetActive(a bool) bool { return false }
func (w *Spinner) Visible() bool { return w.visible }
func (w *Spinner) SetVisible(v bool) { w.visible = v }
func (w *Spinner) Focusable() bool { return false }

View File

@@ -155,7 +155,7 @@ func (w *ScrollingWidgetList) Draw(screen tcell.Screen) {
func (w *ScrollingWidgetList) SetStyle(s tcell.Style) { w.style = s }
func (w *ScrollingWidgetList) Active() bool { return w.active }
func (w *ScrollingWidgetList) SetActive(a bool) {
func (w *ScrollingWidgetList) SetActive(a bool) bool {
w.active = a
if w.active {
act := w.findActiveOrFirst()
@@ -163,6 +163,7 @@ func (w *ScrollingWidgetList) SetActive(a bool) {
act.SetActive(true)
}
}
return w.active
}
func (w *ScrollingWidgetList) Visible() bool { return w.visible }
func (w *ScrollingWidgetList) SetVisible(a bool) { w.visible = a }

View File

@@ -151,7 +151,10 @@ func (w *Table) Draw(screen tcell.Screen) {
func (w *Table) SetStyle(s tcell.Style) { w.style = s }
func (w *Table) Active() bool { return w.active }
func (w *Table) SetActive(a bool) { w.active = a }
func (w *Table) SetActive(a bool) bool {
w.active = a
return w.active
}
func (w *Table) Visible() bool { return w.visible }
func (w *Table) SetVisible(a bool) { w.visible = a }
func (w *Table) SetX(x int) { w.x = x }

View File

@@ -84,7 +84,10 @@ func (w *Text) Draw(screen tcell.Screen) {
func (w *Text) SetStyle(s tcell.Style) { w.style = s }
func (w *Text) Active() bool { return w.active }
func (w *Text) SetActive(a bool) { w.active = a }
func (w *Text) SetActive(a bool) bool {
w.active = a
return w.active
}
func (w *Text) Visible() bool { return w.visible }
func (w *Text) SetVisible(a bool) { w.visible = a }
func (w *Text) SetX(x int) { w.x = x }

View File

@@ -183,7 +183,10 @@ func (w *TimeField) Draw(screen tcell.Screen) {
func (w *TimeField) SetStyle(s tcell.Style) { w.style = s }
func (w *TimeField) Active() bool { return w.active }
func (w *TimeField) SetActive(a bool) { w.active = a }
func (w *TimeField) SetActive(a bool) bool {
w.active = a
return w.active
}
func (w *TimeField) Visible() bool { return w.visible }
func (w *TimeField) SetVisible(a bool) { w.visible = a }
func (w *TimeField) SetX(x int) { w.x = x }

View File

@@ -160,11 +160,12 @@ func (w *TopMenuLayout) Draw(screen tcell.Screen) {
func (w *TopMenuLayout) SetStyle(s tcell.Style) { w.style = s }
func (w *TopMenuLayout) Active() bool { return w.active }
func (w *TopMenuLayout) SetActive(a bool) {
func (w *TopMenuLayout) SetActive(a bool) bool {
w.active = a
if w.widget != nil {
w.widget.SetActive(a)
}
return w.active
}
func (w *TopMenuLayout) Visible() bool { return w.visible }
func (w *TopMenuLayout) SetVisible(a bool) { w.visible = a }

View File

@@ -40,11 +40,9 @@ type Widget interface {
Draw(tcell.Screen)
SetStyle(tcell.Style)
Active() bool
SetActive(bool)
SetActive(bool) bool
Visible() bool
SetVisible(bool)
Focusable() bool
SetFocusable(bool)
SetX(int)
SetY(int)
GetX() int