2020-05-09 13:32:43 +00:00
|
|
|
package tins2020
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/veandco/go-sdl2/sdl"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Container struct {
|
2020-05-10 15:16:18 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2020-05-10 15:16:18 +00:00
|
|
|
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 {
|
2020-05-10 15:16:18 +00:00
|
|
|
child.Arrange(ctx, bounds)
|
2020-05-09 13:32:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-11 09:44:50 +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 {
|
2020-05-11 09:44:50 +00:00
|
|
|
if child.Handle(ctx, event) {
|
|
|
|
return true
|
|
|
|
}
|
2020-05-09 13:32:43 +00:00
|
|
|
}
|
2020-05-11 09:44:50 +00:00
|
|
|
return false
|
2020-05-09 13:32:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Container) Init(ctx *Context) error {
|
2020-05-10 15:16:18 +00:00
|
|
|
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
|
|
|
|
}
|
2020-05-10 15:16:18 +00:00
|
|
|
|
|
|
|
func (c *Container) Render(ctx *Context) {
|
|
|
|
c.ControlBase.Render(ctx)
|
|
|
|
|
|
|
|
for _, child := range c.Children {
|
|
|
|
child.Render(ctx)
|
|
|
|
}
|
|
|
|
}
|