mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +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
|
Stretch
|
||||||
)
|
)
|
||||||
|
|
||||||
func (f *Flex) Init(ops *ui.Ops, cs Constraints) {
|
func (f *Flex) Init(ops *ui.Ops, cs Constraints) *Flex {
|
||||||
if f.constrained {
|
|
||||||
panic("Constrain must be called exactly once")
|
|
||||||
}
|
|
||||||
f.ops = ops
|
f.ops = ops
|
||||||
f.constrained = true
|
|
||||||
f.cs = cs
|
f.cs = cs
|
||||||
|
f.constrained = true
|
||||||
f.taken = 0
|
f.taken = 0
|
||||||
f.maxCross = 0
|
f.maxCross = 0
|
||||||
f.maxBaseline = 0
|
f.maxBaseline = 0
|
||||||
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Flex) begin() {
|
func (f *Flex) begin() {
|
||||||
if !f.constrained {
|
if !f.constrained {
|
||||||
panic("must Constrain before adding a child")
|
panic("must Init before adding a child")
|
||||||
}
|
}
|
||||||
if f.begun {
|
if f.begun {
|
||||||
panic("must End before adding a child")
|
panic("must End before adding a child")
|
||||||
|
|||||||
+3
-2
@@ -37,17 +37,18 @@ const (
|
|||||||
W
|
W
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Stack) Init(ops *ui.Ops, cs Constraints) {
|
func (s *Stack) Init(ops *ui.Ops, cs Constraints) *Stack {
|
||||||
s.ops = ops
|
s.ops = ops
|
||||||
s.cs = cs
|
s.cs = cs
|
||||||
s.constrained = true
|
s.constrained = true
|
||||||
s.maxSZ = image.Point{}
|
s.maxSZ = image.Point{}
|
||||||
s.baseline = 0
|
s.baseline = 0
|
||||||
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Stack) begin() {
|
func (s *Stack) begin() {
|
||||||
if !s.constrained {
|
if !s.constrained {
|
||||||
panic("must Constrain before adding a child")
|
panic("must Init before adding a child")
|
||||||
}
|
}
|
||||||
if s.begun {
|
if s.begun {
|
||||||
panic("must End before adding a child")
|
panic("must End before adding a child")
|
||||||
|
|||||||
Reference in New Issue
Block a user