2019-03-05 20:52:18 +00:00
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"opslag.de/schobers/geom"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ContainerBase struct {
|
|
|
|
ControlBase
|
|
|
|
Children []Control
|
|
|
|
}
|
|
|
|
|
|
|
|
func BuildContainerBase(controls ...Control) ContainerBase {
|
|
|
|
return ContainerBase{
|
|
|
|
Children: controls,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ContainerBase) AddChild(child ...Control) {
|
|
|
|
c.Children = append(c.Children, child...)
|
2021-08-19 10:27:34 +00:00
|
|
|
for _, child := range child {
|
|
|
|
child.SetSelf(child)
|
|
|
|
}
|
2019-03-05 20:52:18 +00:00
|
|
|
}
|
|
|
|
|
2019-04-11 21:38:32 +00:00
|
|
|
func (c *ContainerBase) Arrange(ctx Context, bounds geom.RectangleF32, offset geom.PointF32, parent Control) {
|
2019-03-05 20:52:18 +00:00
|
|
|
for _, child := range c.Children {
|
2019-04-11 21:38:32 +00:00
|
|
|
child.Arrange(ctx, bounds, offset, c)
|
2019-03-05 20:52:18 +00:00
|
|
|
}
|
2019-04-11 21:38:32 +00:00
|
|
|
c.ControlBase.Arrange(ctx, bounds, offset, parent)
|
2019-03-05 20:52:18 +00:00
|
|
|
}
|
|
|
|
|
2021-08-19 10:27:34 +00:00
|
|
|
func (c *ContainerBase) BoundsUnclipped(ctx Context, path ControlPath) geom.RectangleF32 {
|
|
|
|
if len(path) == 0 {
|
|
|
|
return c.bounds
|
|
|
|
}
|
|
|
|
next := path[0]
|
|
|
|
for _, child := range c.Children {
|
|
|
|
if child == next {
|
|
|
|
return child.BoundsUnclipped(ctx, path[1:])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
panic("child not found in path")
|
|
|
|
}
|
|
|
|
|
2020-12-12 13:41:44 +00:00
|
|
|
func (c *ContainerBase) DesiredSize(ctx Context, size geom.PointF32) geom.PointF32 {
|
|
|
|
var max geom.PointF32
|
|
|
|
for _, child := range c.Children {
|
|
|
|
s := child.DesiredSize(ctx, size)
|
|
|
|
max = geom.MaxPtF32(max, s)
|
|
|
|
}
|
|
|
|
return max
|
|
|
|
}
|
|
|
|
|
2020-05-15 17:00:43 +00:00
|
|
|
func (c *ContainerBase) Handle(ctx Context, e Event) bool {
|
|
|
|
if c.ControlBase.Handle(ctx, e) {
|
|
|
|
return true
|
|
|
|
}
|
2019-03-05 20:52:18 +00:00
|
|
|
for _, child := range c.Children {
|
2020-05-15 17:00:43 +00:00
|
|
|
if child.Handle(ctx, e) {
|
|
|
|
return true
|
|
|
|
}
|
2019-03-05 20:52:18 +00:00
|
|
|
}
|
2020-05-15 17:00:43 +00:00
|
|
|
return false
|
2019-03-05 20:52:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ContainerBase) Render(ctx Context) {
|
|
|
|
c.RenderBackground(ctx)
|
|
|
|
for _, child := range c.Children {
|
|
|
|
child.Render(ctx)
|
|
|
|
}
|
|
|
|
}
|