layout: updated comment, avoid copying whole context in Flex

Signed-off-by: pierre <pierre.curto@gmail.com>
This commit is contained in:
pierre
2020-12-28 18:08:55 +01:00
committed by Elias Naur
parent 0416fffc09
commit 33103593a1
+9 -9
View File
@@ -65,9 +65,10 @@ func Rigid(widget Widget) FlexChild {
} }
} }
// Flexed returns a Flex child forced to take up w fraction of the // Flexed returns a Flex child forced to take up weight fraction of the
// of the space left over from Rigid children. The fraction is weight // space left over from Rigid children. The fraction is weight
// divided by the weight sum of all Flexed children. // divided by either the weight sum of all Flexed children or the Flex
// WeightSum if non zero.
func Flexed(weight float32, widget Widget) FlexChild { func Flexed(weight float32, widget Widget) FlexChild {
return FlexChild{ return FlexChild{
flex: true, flex: true,
@@ -86,6 +87,7 @@ func (f Flex) Layout(gtx Context, children ...FlexChild) Dimensions {
crossMin, crossMax := axisCrossConstraint(f.Axis, cs) crossMin, crossMax := axisCrossConstraint(f.Axis, cs)
remaining := mainMax remaining := mainMax
var totalWeight float32 var totalWeight float32
cgtx := gtx
// Lay out Rigid children. // Lay out Rigid children.
for i, child := range children { for i, child := range children {
if child.flex { if child.flex {
@@ -93,9 +95,8 @@ func (f Flex) Layout(gtx Context, children ...FlexChild) Dimensions {
continue continue
} }
macro := op.Record(gtx.Ops) macro := op.Record(gtx.Ops)
gtx := gtx cgtx.Constraints = axisConstraints(f.Axis, 0, remaining, crossMin, crossMax)
gtx.Constraints = axisConstraints(f.Axis, 0, remaining, crossMin, crossMax) dims := child.widget(cgtx)
dims := child.widget(gtx)
c := macro.Stop() c := macro.Stop()
sz := axisMain(f.Axis, dims.Size) sz := axisMain(f.Axis, dims.Size)
size += sz size += sz
@@ -129,9 +130,8 @@ func (f Flex) Layout(gtx Context, children ...FlexChild) Dimensions {
} }
} }
macro := op.Record(gtx.Ops) macro := op.Record(gtx.Ops)
gtx := gtx cgtx.Constraints = axisConstraints(f.Axis, flexSize, flexSize, crossMin, crossMax)
gtx.Constraints = axisConstraints(f.Axis, flexSize, flexSize, crossMin, crossMax) dims := child.widget(cgtx)
dims := child.widget(gtx)
c := macro.Stop() c := macro.Stop()
sz := axisMain(f.Axis, dims.Size) sz := axisMain(f.Axis, dims.Size)
size += sz size += sz