Sander Schobers
0cd5cb4ad1
Refactored some structs from public to internal. Separated navigation from game. Added utility methods for drawing text. Stackpanel will uses all available width when layouting.
42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"opslag.de/schobers/allg5"
|
|
"opslag.de/schobers/geom"
|
|
"opslag.de/schobers/krampus19/alui"
|
|
)
|
|
|
|
type mainMenu struct {
|
|
alui.ControlBase
|
|
|
|
ctx *Context
|
|
|
|
buttons alui.StackPanel
|
|
}
|
|
|
|
func (m *mainMenu) newButton(text string, onClick func()) alui.Control {
|
|
button := &alui.Button{Text: text, TextAlign: allg5.AlignCenter}
|
|
button.OnClick = onClick
|
|
return button
|
|
}
|
|
|
|
func (m *mainMenu) Enter(ctx *Context) error {
|
|
m.ctx = ctx
|
|
m.buttons.Orientation = alui.OrientationVertical
|
|
m.buttons.Children = append(m.buttons.Children, m.newButton("Play", func() { m.ctx.Navigation.playLevel("1") }))
|
|
m.buttons.Children = append(m.buttons.Children, m.newButton("Quit", func() { m.ctx.Navigation.quit() }))
|
|
return nil
|
|
}
|
|
|
|
func (m *mainMenu) Leave() {}
|
|
|
|
func (m *mainMenu) Handle(e allg5.Event) { m.buttons.Handle(e) }
|
|
|
|
func (m *mainMenu) Render(ctx *alui.Context, bounds geom.RectangleF32) {
|
|
buttonsHeight := m.buttons.DesiredSize(ctx).Y
|
|
width, center := bounds.Dx(), bounds.Center()
|
|
buttonsBounds := geom.RectF32(.25*width, center.Y-.5*buttonsHeight, .75*width, center.Y+.5*buttonsHeight)
|
|
m.buttons.Layout(ctx, buttonsBounds)
|
|
m.buttons.Render(ctx, buttonsBounds)
|
|
}
|