tins2020/container.go
Sander Schobers 9641719579 Added intro dialog.
Refactored event handling to be able to "handle" events so no other controls will handle the same event again.
2020-05-11 11:44:50 +02:00

59 lines
988 B
Go

package tins2020
import (
"github.com/veandco/go-sdl2/sdl"
)
type Container struct {
ControlBase
Children []Control
}
func NewContainer() *Container {
return &Container{}
}
func (c *Container) AddChild(child Control) {
c.Children = append(c.Children, child)
}
func (c *Container) Arrange(ctx *Context, bounds Rectangle) {
c.ControlBase.Arrange(ctx, bounds)
for _, child := range c.Children {
child.Arrange(ctx, bounds)
}
}
func (c *Container) Handle(ctx *Context, event sdl.Event) bool {
if c.ControlBase.Handle(ctx, event) {
return true
}
for _, child := range c.Children {
if child.Handle(ctx, event) {
return true
}
}
return false
}
func (c *Container) Init(ctx *Context) error {
c.ControlBase.Init(ctx)
for _, child := range c.Children {
err := child.Init(ctx)
if err != nil {
return err
}
}
return nil
}
func (c *Container) Render(ctx *Context) {
c.ControlBase.Render(ctx)
for _, child := range c.Children {
child.Render(ctx)
}
}