layout: add WeightSum to Flex for overriding the Flexed total weight

Updates gio#139

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-06-17 09:43:11 +02:00
parent a3f7eaae08
commit 3b54c665ca
2 changed files with 8 additions and 4 deletions
+7
View File
@@ -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