krampus19/alui/container.go

56 lines
1.1 KiB
Go
Raw Permalink Normal View History

2019-12-19 05:59:45 +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...)
2019-12-19 05:59:45 +00:00
}
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
}
func (c *Container) Handle(e allg5.Event) {
c.ControlBase.Handle(e)
for _, child := range c.Children {
child.Handle(e)
}
}
2019-12-19 05:59:45 +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)
}
}