Some Updates
This commit is contained in:
21
wdgt_menu.go
21
wdgt_menu.go
@@ -140,6 +140,7 @@ func (w *Menu) HandleKey(ev *tcell.EventKey) bool {
|
||||
} else if w.items[w.cursor].HandleKey(ev) {
|
||||
// Active menuitem consumes this event
|
||||
if ev.Key() == tcell.KeyEnter {
|
||||
w.cursor = 0
|
||||
w.SetActive(false)
|
||||
}
|
||||
return true
|
||||
@@ -148,6 +149,21 @@ func (w *Menu) HandleKey(ev *tcell.EventKey) bool {
|
||||
return true
|
||||
}
|
||||
// See if we can find an item that matches the key pressed
|
||||
for i := range w.items {
|
||||
if wh.RuneEqualsNC(ev.Rune(), w.items[i].GetHotKey()) {
|
||||
if w.items[i].Active() {
|
||||
if w.items[i].HandleKey(ev) {
|
||||
// Reset the cursor
|
||||
w.cursor = 0
|
||||
w.SetActive(false)
|
||||
return true
|
||||
}
|
||||
}
|
||||
w.cursor = i
|
||||
// w.items[i].SetActive(true)
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -178,9 +194,11 @@ func (w *Menu) drawHMenu(screen tcell.Screen) {
|
||||
}
|
||||
x += 2
|
||||
if w.expanded || (w.active && !w.manualExpand) {
|
||||
// pos := w.GetPos()
|
||||
// TODO: Use DrawOffset?
|
||||
for i := range w.items {
|
||||
w.items[i].SetActive(w.active && w.cursor == i)
|
||||
// pos.DrawOffset(w.items[i], screen)
|
||||
w.items[i].SetPos(Coord{X: x, Y: y})
|
||||
w.items[i].Draw(screen)
|
||||
x += len(w.items[i].Label()) + 2
|
||||
@@ -371,8 +389,9 @@ func (w *Menu) MoveDown(ev *tcell.EventKey) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (w *Menu) CreateMenuItem(lbl string, do func() bool, subItems ...*MenuItem) *MenuItem {
|
||||
func (w *Menu) CreateMenuItem(lbl string, do func() bool, hotKey rune, subItems ...*MenuItem) *MenuItem {
|
||||
d := NewMenuItem(fmt.Sprintf("menuitem-%s", lbl), tcell.StyleDefault)
|
||||
d.SetHotKey(hotKey)
|
||||
d.SetLabel(lbl)
|
||||
d.SetOnPressed(do)
|
||||
if len(subItems) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user