tins2020/container.go

59 lines
988 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 {
ControlBase
2020-05-09 13:32:43 +00:00
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)
2020-05-09 13:32:43 +00:00
for _, child := range c.Children {
child.Arrange(ctx, bounds)
2020-05-09 13:32:43 +00:00
}
}
func (c *Container) Handle(ctx *Context, event sdl.Event) bool {
if c.ControlBase.Handle(ctx, event) {
return true
}
2020-05-09 13:32:43 +00:00
for _, child := range c.Children {
if child.Handle(ctx, event) {
return true
}
2020-05-09 13:32:43 +00:00
}
return false
2020-05-09 13:32:43 +00:00
}
func (c *Container) Init(ctx *Context) error {
c.ControlBase.Init(ctx)
2020-05-09 13:32:43 +00:00
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)
}
}