2020-05-10 15:16:18 +00:00
|
|
|
package tins2020
|
|
|
|
|
|
|
|
import "github.com/veandco/go-sdl2/sdl"
|
|
|
|
|
|
|
|
type ButtonBar struct {
|
|
|
|
Container
|
|
|
|
|
2020-05-11 00:49:53 +00:00
|
|
|
Background sdl.Color
|
|
|
|
ButtonLength int32
|
|
|
|
Orientation Orientation
|
|
|
|
Buttons []Control
|
2020-05-10 15:16:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2020-05-11 00:49:53 +00:00
|
|
|
length := b.ButtonLength
|
2020-05-10 15:16:18 +00:00
|
|
|
switch b.Orientation {
|
|
|
|
case OrientationHorizontal:
|
2020-05-11 00:49:53 +00:00
|
|
|
if length == 0 {
|
|
|
|
length = bounds.H
|
|
|
|
}
|
2020-05-10 15:16:18 +00:00
|
|
|
offset := bounds.X
|
|
|
|
for i := range b.Buttons {
|
2020-05-12 11:55:30 +00:00
|
|
|
b.Buttons[i].Arrange(ctx, Rect(offset, bounds.Y, length, bounds.H))
|
2020-05-10 15:16:18 +00:00
|
|
|
offset += length
|
|
|
|
}
|
|
|
|
default:
|
2020-05-11 00:49:53 +00:00
|
|
|
if length == 0 {
|
|
|
|
length = bounds.W
|
|
|
|
}
|
2020-05-10 15:16:18 +00:00
|
|
|
offset := bounds.Y
|
|
|
|
for i := range b.Buttons {
|
2020-05-12 11:55:30 +00:00
|
|
|
b.Buttons[i].Arrange(ctx, Rect(bounds.X, offset, bounds.W, length))
|
2020-05-10 15:16:18 +00:00
|
|
|
offset += length
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *ButtonBar) Render(ctx *Context) {
|
2020-05-11 09:44:50 +00:00
|
|
|
SetDrawColor(ctx.Renderer, b.Background)
|
2020-05-10 15:16:18 +00:00
|
|
|
ctx.Renderer.FillRect(b.Bounds.SDLPtr())
|
|
|
|
b.Container.Render(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
type Orientation int
|
|
|
|
|
|
|
|
const (
|
|
|
|
OrientationVertical Orientation = iota
|
|
|
|
OrientationHorizontal
|
|
|
|
)
|