neofeels/app/menu.go

69 lines
1.5 KiB
Go

package app
import (
"git.sr.ht/~rockorager/vaxis"
"git.sr.ht/~rockorager/vaxis/widgets/list"
"git.tilde.town/nbsp/neofeels/ui"
)
type MainMenu struct {
title string
list list.List
help string
}
func NewMainMenu() *MainMenu {
return &MainMenu{
` ___ __
/ _/__ ___ / /__
/ _/ -_) -_) (_-<
/_/ \__/\__/_/___/
neofeels 0.1.0`,
list.New([]string{
" record some feels ",
" manage your feels ",
" check out your neighbors ",
" browse global feels ",
" visit your subscriptions ",
" scribble some graffiti ",
" change your settings ",
" send some feedback ",
" see credits ",
" read documentation ",
}),
"↑↓/kj move ↵ enter q exit",
}
}
func (menu *MainMenu) Event(state *ui.State, event vaxis.Event) (processed bool) {
if key, ok := event.(vaxis.Key); ok && key.EventType == vaxis.EventPress {
switch key.String() {
case "Ctrl+c", "Ctrl+d", "q":
close(ui.Quit)
case "Down", "j":
menu.list.Down()
case "Up", "k":
menu.list.Up()
case "End":
menu.list.End()
case "Home":
menu.list.Home()
case "Enter":
ui.ViewChange <- NewCredits()
}
processed = true
}
win := state.Window()
win.New(win.Width/2-10, win.Height/2-8, 20, 5).Print(vaxis.Segment{Text: menu.title})
menu.list.Draw(vaxis.Window{
Vx: win.Vx,
Parent: nil,
Column: win.Width/2 - 14,
Row: win.Height/2 - 2,
Width: 28,
Height: 10,
})
win.New(win.Width/2-14, win.Height/2+9, 28, 1).Print(vaxis.Segment{Text: menu.help})
return
}