Work
This commit is contained in:
@@ -95,15 +95,7 @@ func (w *MenuItem) Draw(screen tcell.Screen) {
|
||||
if !w.visible {
|
||||
return
|
||||
}
|
||||
st := w.style
|
||||
if w.active {
|
||||
st = w.style.Reverse(true)
|
||||
}
|
||||
if w.disabled {
|
||||
st = st.Dim(true)
|
||||
st = st.Italic(true)
|
||||
}
|
||||
|
||||
st := w.style.Reverse(w.active).Dim(w.disabled).Italic(w.disabled)
|
||||
x, y := w.x, w.y
|
||||
wd := w.w
|
||||
wh.DrawText(x, y, wh.PadR(w.label, wd), st, screen)
|
||||
@@ -188,7 +180,7 @@ func (w *MenuItem) MoveUp(ev *tcell.EventKey) bool {
|
||||
st := w.cursor
|
||||
i := (w.cursor - 1 + len(w.items)) % len(w.items)
|
||||
for ; i != st; i = (i - 1 + len(w.items)) % len(w.items) {
|
||||
if !w.items[i].IsDisabled() {
|
||||
if !w.items[i].IsDisabled() && w.items[i].Visible() {
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -202,7 +194,7 @@ func (w *MenuItem) MoveDown(ev *tcell.EventKey) bool {
|
||||
st := w.cursor
|
||||
i := (st + 1) % len(w.items)
|
||||
for ; i != st; i = (i + 1) % len(w.items) {
|
||||
if !w.items[i].IsDisabled() {
|
||||
if !w.items[i].IsDisabled() && w.items[i].Visible() {
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -214,6 +206,7 @@ func (w *MenuItem) SetLabel(lbl string) { w.label = lbl }
|
||||
func (w *MenuItem) SetDisabled(d bool) { w.disabled = d }
|
||||
func (w *MenuItem) IsDisabled() bool { return w.disabled }
|
||||
|
||||
func (w *MenuItem) GetItems() []*MenuItem { return w.items }
|
||||
func (w *MenuItem) AddItems(iL ...*MenuItem) {
|
||||
w.items = append(w.items, iL...)
|
||||
for i := range w.items {
|
||||
@@ -221,3 +214,14 @@ func (w *MenuItem) AddItems(iL ...*MenuItem) {
|
||||
}
|
||||
}
|
||||
func (w *MenuItem) SetOnPressed(p func() bool) { w.onPressed = p }
|
||||
|
||||
func (w *MenuItem) 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user