tins2020/container.go

40 lines
652 B
Go
Raw Normal View History

2020-05-09 13:32:43 +00:00
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
}