From 33103593a1b4cdd30f6601fd98db7bf922c379cf Mon Sep 17 00:00:00 2001 From: pierre Date: Mon, 28 Dec 2020 18:08:55 +0100 Subject: [PATCH] layout: updated comment, avoid copying whole context in Flex Signed-off-by: pierre --- layout/flex.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/layout/flex.go b/layout/flex.go index 2ccc4c25..b01e1931 100644 --- a/layout/flex.go +++ b/layout/flex.go @@ -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