diff --git a/ui/layout/flex.go b/ui/layout/flex.go index 6925ecb9..30141d5f 100644 --- a/ui/layout/flex.go +++ b/ui/layout/flex.go @@ -58,21 +58,19 @@ const ( Stretch ) -func (f *Flex) Init(ops *ui.Ops, cs Constraints) { - if f.constrained { - panic("Constrain must be called exactly once") - } +func (f *Flex) Init(ops *ui.Ops, cs Constraints) *Flex { f.ops = ops - f.constrained = true f.cs = cs + f.constrained = true f.taken = 0 f.maxCross = 0 f.maxBaseline = 0 + return f } func (f *Flex) begin() { if !f.constrained { - panic("must Constrain before adding a child") + panic("must Init before adding a child") } if f.begun { panic("must End before adding a child") diff --git a/ui/layout/stack.go b/ui/layout/stack.go index 5085180f..02ffca39 100644 --- a/ui/layout/stack.go +++ b/ui/layout/stack.go @@ -37,17 +37,18 @@ const ( W ) -func (s *Stack) Init(ops *ui.Ops, cs Constraints) { +func (s *Stack) Init(ops *ui.Ops, cs Constraints) *Stack { s.ops = ops s.cs = cs s.constrained = true s.maxSZ = image.Point{} s.baseline = 0 + return s } func (s *Stack) begin() { if !s.constrained { - panic("must Constrain before adding a child") + panic("must Init before adding a child") } if s.begun { panic("must End before adding a child")