package tins2020 import "github.com/veandco/go-sdl2/sdl" type ButtonBar struct { Container Background sdl.Color Orientation Orientation Buttons []Control } const buttonBarWidth = 96 func (b *ButtonBar) Init(ctx *Context) error { for i := range b.Buttons { b.AddChild(b.Buttons[i]) } return b.Container.Init(ctx) } func (b *ButtonBar) Arrange(ctx *Context, bounds Rectangle) { b.Container.Arrange(ctx, bounds) switch b.Orientation { case OrientationHorizontal: length := bounds.H offset := bounds.X for i := range b.Buttons { b.Buttons[i].Arrange(ctx, RectSize(offset, bounds.Y, length, length)) offset += length } default: length := bounds.W offset := bounds.Y for i := range b.Buttons { b.Buttons[i].Arrange(ctx, RectSize(bounds.X, offset, length, length)) offset += length } } } func (b *ButtonBar) Handle(ctx *Context, event sdl.Event) { b.Container.Handle(ctx, event) } func (b *ButtonBar) Render(ctx *Context) { ctx.Renderer.SetDrawColor(b.Background.R, b.Background.G, b.Background.B, b.Background.A) ctx.Renderer.FillRect(b.Bounds.SDLPtr()) b.Container.Render(ctx) } type Orientation int const ( OrientationVertical Orientation = iota OrientationHorizontal )