package activities import ( "log" "muhq.space/muhqs-game/go/ui" ) // ButtonList is an Activity that tries to fill its vertical space with buttons // for the specified click handlers. // A last back button is appended calling activities.PopActivity() type ButtonList struct { ui.Collection } const ( // TODO: determine required with for the displayed labels BUTTON_LIST_BUTTON_WIDTH = 450 BUTTON_LIST_BUTTON_HEIGHT = 75 BUTTON_LIST_BUTTON_PADDING = 40 ) func NewButtonList(width, height int, labels []string, handlers []func(*ui.SimpleButton)) *ButtonList { bl := &ButtonList{ui.Collection{Width: width, Height: height}} if len(labels) != len(handlers) { log.Panic("labels and handler mismatch") } x := (width - BUTTON_LIST_BUTTON_WIDTH) / 2 y := BUTTON_LIST_BUTTON_HEIGHT for i, handler := range handlers { btn := ui.NewSimpleButton( x, y, BUTTON_LIST_BUTTON_WIDTH, BUTTON_LIST_BUTTON_HEIGHT, labels[i], handler, ) bl.AddWidget(btn) y = y + BUTTON_LIST_BUTTON_HEIGHT + BUTTON_LIST_BUTTON_PADDING } back := ui.NewSimpleButton( x, y, BUTTON_LIST_BUTTON_WIDTH, BUTTON_LIST_BUTTON_HEIGHT, "back", func(*ui.SimpleButton) { PopActivity() }, ) log.Println("add back button at", x, y) bl.AddWidget(back) return bl } func (bl *ButtonList) Layout(int, int) (int, int) { return bl.Width, bl.Height } func (bl *ButtonList) Update() error { if err := ui.Update(); err != nil { return err } return bl.Collection.Update() }