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
// of the space left over from Rigid children. The fraction is weight
// divided by the weight sum of all Flexed children.
// Flexed returns a Flex child forced to take up weight fraction of the
// space left over from Rigid children. The fraction is weight
// divided by either the weight sum of all Flexed children or the Flex
// WeightSum if non zero.
func Flexed(weight float32, widget Widget) FlexChild {
return FlexChild{
flex: true,
@@ -86,6 +87,7 @@ func (f Flex) Layout(gtx Context, children ...FlexChild) Dimensions {
crossMin, crossMax := axisCrossConstraint(f.Axis, cs)
remaining := mainMax
var totalWeight float32
cgtx := gtx
// Lay out Rigid children.
for i, child := range children {
if child.flex {
@@ -93,9 +95,8 @@ func (f Flex) Layout(gtx Context, children ...FlexChild) Dimensions {
continue
}
macro := op.Record(gtx.Ops)
gtx := gtx
gtx.Constraints = axisConstraints(f.Axis, 0, remaining, crossMin, crossMax)
dims := child.widget(gtx)
cgtx.Constraints = axisConstraints(f.Axis, 0, remaining, crossMin, crossMax)
dims := child.widget(cgtx)
c := macro.Stop()
sz := axisMain(f.Axis, dims.Size)
size += sz
@@ -129,9 +130,8 @@ func (f Flex) Layout(gtx Context, children ...FlexChild) Dimensions {
}
}
macro := op.Record(gtx.Ops)
gtx := gtx
gtx.Constraints = axisConstraints(f.Axis, flexSize, flexSize, crossMin, crossMax)
dims := child.widget(gtx)
cgtx.Constraints = axisConstraints(f.Axis, flexSize, flexSize, crossMin, crossMax)
dims := child.widget(cgtx)
c := macro.Stop()
sz := axisMain(f.Axis, dims.Size)
size += sz