allg5/alui/container.go

56 lines
1.1 KiB
Go
Raw Normal View History

2020-03-08 09:10:41 +00:00
package alui
import (
"opslag.de/schobers/allg5"
"opslag.de/schobers/geom"
)
type Container struct {
ControlBase
Children []Control
}
func (c *Container) AddChild(child ...Control) {
c.Children = append(c.Children, child...)
}
func (c *Container) DesiredSize(ctx *Context) geom.PointF32 {
var size geom.PointF32
for _, child := range c.Children {
s := child.DesiredSize(ctx)
if geom.IsNaN32(s.X) || geom.IsNaN32(size.X) {
size.X = geom.NaN32()
} else {
size.X = geom.Max32(s.X, size.X)
}
if geom.IsNaN32(s.Y) || geom.IsNaN32(size.Y) {
size.Y = geom.NaN32()
} else {
size.Y = geom.Max32(s.Y, size.Y)
}
}
return size
}
2020-04-10 09:00:27 +00:00
func (c *Container) Handle(ctx *Context, e allg5.Event) {
c.ControlBase.Handle(ctx, e)
2020-03-08 09:10:41 +00:00
for _, child := range c.Children {
2020-04-10 09:00:27 +00:00
child.Handle(ctx, e)
2020-03-08 09:10:41 +00:00
}
}
func (c *Container) Layout(ctx *Context, bounds geom.RectangleF32) {
c.ControlBase.Layout(ctx, bounds)
for _, child := range c.Children {
child.Layout(ctx, bounds)
}
}
func (c *Container) Render(ctx *Context, bounds geom.RectangleF32) {
c.ControlBase.Render(ctx, bounds)
for _, child := range c.Children {
child.Render(ctx, bounds)
}
}