40 lines
652 B
Go
40 lines
652 B
Go
|
package tins2020
|
||
|
|
||
|
import (
|
||
|
"github.com/veandco/go-sdl2/sdl"
|
||
|
)
|
||
|
|
||
|
type Container struct {
|
||
|
Children []Control
|
||
|
}
|
||
|
|
||
|
func NewContainer() *Container {
|
||
|
return &Container{}
|
||
|
}
|
||
|
|
||
|
func (c *Container) AddChild(child Control) {
|
||
|
c.Children = append(c.Children, child)
|
||
|
}
|
||
|
|
||
|
func (c *Container) Handle(ctx *Context, event sdl.Event) {
|
||
|
for _, child := range c.Children {
|
||
|
child.Handle(ctx, event)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (c *Container) Render(ctx *Context) {
|
||
|
for _, child := range c.Children {
|
||
|
child.Render(ctx)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (c *Container) Init(ctx *Context) error {
|
||
|
for _, child := range c.Children {
|
||
|
err := child.Init(ctx)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|