Fix the handling of `Flex::gap` (#560)

Fixes https://github.com/linebender/xilem/issues/559

See comment on the fix for an explanation. Essentially, the `major`
value was used for multiple purposes, and this corrects into the
expected "direction".
This commit is contained in:
Daniel McNab 2024-08-28 15:49:12 +01:00 committed by GitHub
parent 923c0fb8ca
commit 251f42ae87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 0 deletions

View File

@ -847,6 +847,13 @@ impl Widget for Flex {
tracing::warn!("A child of Flex is flex, but Flex is unbounded.");
}
if !self.children.is_empty() {
// If we have at least one child, the last child added `gap` to `major`, which means that `major` is
// not the total size of the flex in the major axis, it's instead where the "next widget" will be placed.
// However, for the rest of this value, we need the total size of the widget in the major axis.
major -= gap;
}
if flex_sum > 0.0 {
major = total_major;
}