talc/pkg/menu/menu.go
2020-03-18 02:41:33 +01:00

82 lines
1.2 KiB
Go

package menu
import (
"sync"
"github.com/gdamore/tcell"
)
type Menu struct {
model *menuModel
once sync.Once
MenuView
}
// func (m *Menu) SetLines(lines []string) {
// m.Init()
// mm := m.model
// mm.width = 0
// mm.height = len(lines)
// mm.lines = lines
// for _, l := range lines {
// if len(l) > mm.width {
// mm.width = len(l)
// }
// }
// m.MenuView.SetModel(mm)
// }
func (m *Menu) SetCurrent(option Option) {
m.Init()
mm := m.model
mm.SetCurrent(option)
m.MenuView.SetModel(mm)
}
// func (m *Menu) SetOptions(options []Option) {
// m.Init()
// mm := m.model
// mm.SetOptions(options)
// m.MenuView.SetModel(mm)
// }
func (m *Menu) SetStyle(style tcell.Style) {
m.model.style = style
m.MenuView.SetStyle(style)
}
func (m *Menu) SetSelectedStyle(style tcell.Style) {
m.MenuView.SetSelectedStyle(style)
}
func (m *Menu) EnableCursor(on bool) {
m.Init()
m.model.cursor = on
}
func (m *Menu) HideCursor(on bool) {
m.Init()
m.model.hide = on
}
func (m *Menu) Init() {
m.once.Do(func() {
mm := &menuModel{
width: 0,
cursor: true,
hide: false,
}
m.model = mm
m.MenuView.Init()
m.MenuView.SetModel(mm)
})
}
func NewMenu() *Menu {
m := &Menu{}
m.Init()
return m
}