talc/pkg/menu/menu.go

62 lines
896 B
Go

package menu
import (
"sync"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/views"
)
type Menu struct {
model *menuModel
once sync.Once
MenuView
}
func (m *Menu) SetCurrent(option Option) {
m.Init()
mm := m.model
mm.SetCurrent(option)
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(app *views.Application) *Menu {
m := &Menu{}
m.Init()
m.app = app
return m
}