mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 15:45:38 +00:00
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:
+4
-6
@@ -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")
|
||||
|
||||
+3
-2
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user