diff --git a/layout/example_test.go b/layout/example_test.go index 03ba44df..4be88fbb 100644 --- a/layout/example_test.go +++ b/layout/example_test.go @@ -62,7 +62,7 @@ func ExampleFlex() { Constraints: layout.Exact(image.Point{X: 100, Y: 100}), } - layout.Flex{}.Layout(gtx, + layout.Flex{WeightSum: 2}.Layout(gtx, // Rigid 10x10 widget. layout.Rigid(func(gtx layout.Context) layout.Dimensions { fmt.Printf("Rigid: %v\n", gtx.Constraints) @@ -73,9 +73,6 @@ func ExampleFlex() { fmt.Printf("50%%: %v\n", gtx.Constraints) return layoutWidget(gtx, 10, 10) }), - layout.Flexed(1, func(gtx layout.Context) layout.Dimensions { - return layout.Dimensions{} - }), ) // Output: diff --git a/layout/flex.go b/layout/flex.go index 76a018d9..77b3d49d 100644 --- a/layout/flex.go +++ b/layout/flex.go @@ -18,6 +18,10 @@ type Flex struct { Spacing Spacing // Alignment is the alignment in the cross axis. Alignment Alignment + // WeightSum is the sum of weights used for the weighted + // size of Flexed children. If WeightSum is zero, the sum + // of all Flexed weights is used. + WeightSum float32 } // FlexChild is the descriptor for a Flex child. @@ -102,6 +106,9 @@ func (f Flex) Layout(gtx Context, children ...FlexChild) Dimensions { children[i].call = c children[i].dims = dims } + if w := f.WeightSum; w != 0 { + totalWeight = w + } // fraction is the rounding error from a Flex weighting. var fraction float32 flexTotal := remaining