This commit is contained in:
2025-08-27 20:27:22 -05:00
parent 4361d7b5cf
commit f41e583089
4 changed files with 77 additions and 17 deletions

View File

@@ -243,6 +243,7 @@ func (w *Menu) SetType(tp MenuType) { w.menuType = tp }
func (w *Menu) SetLabel(lbl string) { w.label = lbl }
func (w *Menu) SetFocusable(f bool) {}
func (w *Menu) GetItems() []*MenuItem { return w.items }
func (w *Menu) GetItem(idx int) *MenuItem {
if len(w.items) > idx {
return w.items[idx]
@@ -299,7 +300,14 @@ func (w *Menu) MoveUp(ev *tcell.EventKey) bool {
if w.menuType != MenuTypeV {
return false
}
st := w.cursor
w.cursor = (w.cursor - 1 + len(w.items)) % len(w.items)
for !w.items[w.cursor].Visible() {
w.cursor = (w.cursor - 1 + len(w.items)) % len(w.items)
if w.cursor == st {
return true
}
}
return true
}
@@ -307,7 +315,14 @@ func (w *Menu) MoveDown(ev *tcell.EventKey) bool {
if w.menuType != MenuTypeV {
return false
}
st := w.cursor
w.cursor = (w.cursor + 1) % len(w.items)
for !w.items[w.cursor].Visible() {
w.cursor = (w.cursor + 1) % len(w.items)
if w.cursor == st {
return true
}
}
return true
}
@@ -320,3 +335,14 @@ func (w *Menu) CreateMenuItem(lbl string, do func() bool, subItems ...*MenuItem)
}
return d
}
func (w *Menu) FindItem(id string) *MenuItem {
for _, itm := range w.items {
if itm.Id() == id {
return itm
} else if wrk := itm.FindItem(id); wrk != nil {
return wrk
}
}
return nil
}