@@ 202,73 202,58 @@ func formatStack(gtx *layout.Context, f *formatter, widgets []layout.Widget) {
if ok {
st.Alignment = align
expect(f, ",")
- backup = *f
} else {
*f = backup
}
var children []layout.StackChild
- commaOK := false
- // First, lay out rigid children.
loop:
for {
switch peek(f) {
case ')':
break loop
- case ',':
- if !commaOK {
- errorf("unexpected ,")
- }
- commaOK = false
- expect(f, ",")
case 'r':
- expect(f, "r(")
- children = append(children, st.Rigid(gtx, func() {
+ w := func() {
+ expect(f, "r(")
formatExpr(gtx, f, widgets)
- }))
- expect(f, ")")
- commaOK = true
- case 'e':
- expect(f, "e(")
- f.skip++
- formatExpr(gtx, f, widgets)
- children = append(children, layout.StackChild{})
- f.skip--
- expect(f, ")")
- commaOK = true
- default:
- errorf("invalid flex child")
- }
- }
- // Then, lay out expanded children.
- *f = backup
- child := 0
- for {
- switch peek(f) {
- case ')':
- if f.skip == 0 {
- st.Layout(gtx, children...)
+ expect(f, ")")
+ if peek(f) == ',' {
+ expect(f, ",")
+ }
}
- return
- case ',':
- expect(f, ",")
- case 'r':
- expect(f, "r(")
+ backup := *f
f.skip++
- formatExpr(gtx, f, widgets)
+ w()
f.skip--
- expect(f, ")")
- child++
+ children = append(children, layout.Stacked(func() {
+ *f = backup
+ w()
+ }))
case 'e':
- expect(f, "e(")
- children[child] = st.Expand(gtx, func() {
+ w := func() {
+ expect(f, "e(")
formatExpr(gtx, f, widgets)
- })
- expect(f, ")")
- child++
+ expect(f, ")")
+ if peek(f) == ',' {
+ expect(f, ",")
+ }
+ }
+ backup := *f
+ f.skip++
+ w()
+ f.skip--
+ children = append(children, layout.Expanded(func() {
+ *f = backup
+ w()
+ }))
default:
- errorf("invalid flex child")
+ errorf("invalid stack child")
}
}
+ if f.skip == 0 {
+ backup := *f
+ st.Layout(gtx, children...)
+ *f = backup
+ }
}
func formatFlex(gtx *layout.Context, axis layout.Axis, f *formatter, widgets []layout.Widget) {
@@ 280,76 265,61 @@ func formatFlex(gtx *layout.Context, axis layout.Axis, f *formatter, widgets []l
if ok {
fl.Alignment = al
expect(f, ",")
- backup = *f
} else {
*f = backup
}
var children []layout.FlexChild
- commaOK := false
- // First, lay out rigid children.
loop:
for {
switch peek(f) {
case ')':
break loop
- case ',':
- if !commaOK {
- errorf("unexpected ,")
- }
- expect(f, ",")
case 'r':
- expect(f, "r(")
- children = append(children, fl.Rigid(gtx, func() {
+ w := func() {
+ expect(f, "r(")
formatExpr(gtx, f, widgets)
- }))
- expect(f, ")")
- commaOK = true
- case 'f':
- expect(f, "f(")
- parseFloat(f)
- expect(f, ",")
- f.skip++
- formatExpr(gtx, f, widgets)
- children = append(children, layout.FlexChild{})
- f.skip--
- expect(f, ")")
- commaOK = true
- default:
- errorf("invalid flex child")
- }
- }
- // Then, lay out flexible children.
- *f = backup
- child := 0
- for {
- switch peek(f) {
- case ')':
- if f.skip == 0 {
- fl.Layout(gtx, children...)
+ expect(f, ")")
+ if peek(f) == ',' {
+ expect(f, ",")
+ }
}
- return
- case ',':
- expect(f, ",")
- case 'r':
- expect(f, "r(")
+ backup := *f
f.skip++
- formatExpr(gtx, f, widgets)
+ w()
f.skip--
- expect(f, ")")
- child++
+ children = append(children, layout.Rigid(func() {
+ *f = backup
+ w()
+ }))
case 'f':
- expect(f, "f(")
- weight := parseFloat(f)
- expect(f, ",")
- children[child] = fl.Flex(gtx, weight, func() {
+ var weight float32
+ w := func() {
+ expect(f, "f(")
+ weight = parseFloat(f)
+ expect(f, ",")
formatExpr(gtx, f, widgets)
- })
- expect(f, ")")
- child++
+ expect(f, ")")
+ if peek(f) == ',' {
+ expect(f, ",")
+ }
+ }
+ backup := *f
+ f.skip++
+ w()
+ f.skip--
+ children = append(children, layout.Flexed(weight, func() {
+ *f = backup
+ w()
+ }))
default:
errorf("invalid flex child")
}
}
+ if f.skip == 0 {
+ backup := *f
+ fl.Layout(gtx, children...)
+ *f = backup
+ }
}
func parseInset(gtx *layout.Context, f *formatter, widgets []layout.Widget) layout.Inset {