diff options
author | 2024-03-03 01:02:23 +0100 | |
---|---|---|
committer | 2024-03-03 01:08:11 +0100 | |
commit | cbe4603579c6af55c35254257981e14cd4a67897 (patch) | |
tree | 23fa181e9a5a8aad983d9e623e14fa8524592691 /core | |
parent | af9fb367f361a564aa2a9fc11333816566eb5d55 (diff) | |
download | iced-cbe4603579c6af55c35254257981e14cd4a67897.tar.gz iced-cbe4603579c6af55c35254257981e14cd4a67897.tar.bz2 iced-cbe4603579c6af55c35254257981e14cd4a67897.zip |
Remove complex cross-axis layout logic from `Column` and `Row`
Diffstat (limited to 'core')
-rw-r--r-- | core/src/layout/flex.rs | 67 |
1 files changed, 22 insertions, 45 deletions
diff --git a/core/src/layout/flex.rs b/core/src/layout/flex.rs index 40bd7123..dcb4d8de 100644 --- a/core/src/layout/flex.rs +++ b/core/src/layout/flex.rs @@ -80,14 +80,9 @@ where let mut fill_main_sum = 0; let mut cross = match axis { - Axis::Horizontal => match height { - Length::Shrink => 0.0, - _ => max_cross, - }, - Axis::Vertical => match width { - Length::Shrink => 0.0, - _ => max_cross, - }, + Axis::Vertical if width == Length::Shrink => 0.0, + Axis::Horizontal if height == Length::Shrink => 0.0, + _ => max_cross, }; let mut available = axis.main(limits.max()) - total_spacing; @@ -103,35 +98,14 @@ where }; if fill_main_factor == 0 { - if fill_cross_factor == 0 { - let (max_width, max_height) = axis.pack(available, max_cross); - - let child_limits = - Limits::new(Size::ZERO, Size::new(max_width, max_height)); - - let layout = - child.as_widget().layout(tree, renderer, &child_limits); - let size = layout.size(); - - available -= axis.main(size); - cross = cross.max(axis.cross(size)); - - nodes[i] = layout; - } - } else { - fill_main_sum += fill_main_factor; - } - } - - for (i, (child, tree)) in items.iter().zip(trees.iter_mut()).enumerate() { - let (fill_main_factor, fill_cross_factor) = { - let size = child.as_widget().size(); - - axis.pack(size.width.fill_factor(), size.height.fill_factor()) - }; - - if fill_main_factor == 0 && fill_cross_factor != 0 { - let (max_width, max_height) = axis.pack(available, cross); + let (max_width, max_height) = axis.pack( + available, + if fill_cross_factor == 0 { + max_cross + } else { + cross + }, + ); let child_limits = Limits::new(Size::ZERO, Size::new(max_width, max_height)); @@ -141,9 +115,11 @@ where let size = layout.size(); available -= axis.main(size); - cross = cross.max(axis.cross(layout.size())); + cross = cross.max(axis.cross(size)); nodes[i] = layout; + } else { + fill_main_sum += fill_main_factor; } } @@ -175,14 +151,15 @@ where max_main }; - let max_cross = if fill_cross_factor == 0 { - max_cross - } else { - cross - }; - let (min_width, min_height) = axis.pack(min_main, 0.0); - let (max_width, max_height) = axis.pack(max_main, max_cross); + let (max_width, max_height) = axis.pack( + max_main, + if fill_cross_factor == 0 { + max_cross + } else { + cross + }, + ); let child_limits = Limits::new( Size::new(min_width, min_height), |