ui/layout: allow one-line initialization of Flex and Stack

Returning itself from the Init methods allows the client to
initialize the layout instance on one line.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-06-27 12:44:15 +02:00
parent bf96bb8bdd
commit ef9384ceee
2 changed files with 7 additions and 8 deletions
+3 -2
View File
@@ -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")