You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
919 B
Go

package app
import (
"github.com/gdamore/tcell/v2"
"github.com/jordanorelli/astro-domu/internal/math"
"github.com/jordanorelli/blammo"
)
type menuList struct {
*blammo.Log
choices []string
selected int
}
func (m *menuList) handleEvent(ui *UI, e tcell.Event) bool {
switch t := e.(type) {
case *tcell.EventKey:
key := t.Key()
switch key {
case tcell.KeyDown:
m.selected = (m.selected + 1) % len(m.choices)
case tcell.KeyUp:
if m.selected == 0 {
m.selected = len(m.choices) - 1
} else {
m.selected--
}
}
default:
// ui.Debug("screen saw unhandled event of type %T", e)
}
return true
}
func (m *menuList) draw(b *buffer) {
for i, choice := range m.choices {
if i == m.selected {
b.writeString("▷ "+choice, math.Vec{0, i}, tcell.StyleDefault)
} else {
b.writeString(" "+choice, math.Vec{0, i}, tcell.StyleDefault)
}
}
}
func (m *menuList) setFocus(bool) {}