Fix cross calculation in layout::flex

This commit is contained in:
Héctor Ramón Jiménez 2024-01-09 07:15:57 +01:00
parent 025064c9e0
commit 88f8c343fa
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
3 changed files with 16 additions and 22 deletions

View file

@ -79,7 +79,17 @@ where
let max_cross = axis.cross(limits.max());
let mut fill_main_sum = 0;
let mut cross = 0.0f32;
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,
},
};
let mut available = axis.main(limits.max()) - total_spacing;
let mut nodes: Vec<Node> = Vec::with_capacity(items.len());
@ -113,17 +123,6 @@ where
}
}
let intrinsic_cross = match axis {
Axis::Horizontal => match height {
Length::Shrink => cross,
_ => max_cross,
},
Axis::Vertical => match width {
Length::Shrink => cross,
_ => max_cross,
},
};
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();
@ -132,7 +131,7 @@ where
};
if fill_main_factor == 0 && fill_cross_factor != 0 {
let (max_width, max_height) = axis.pack(available, intrinsic_cross);
let (max_width, max_height) = axis.pack(available, cross);
let child_limits =
Limits::new(Size::ZERO, Size::new(max_width, max_height));
@ -182,7 +181,7 @@ where
let max_cross = if fill_cross_factor == 0 {
max_cross
} else {
intrinsic_cross
cross
};
let (min_width, min_height) =

View file

@ -1,4 +1,4 @@
use iced::widget::{column, container, pick_list, scrollable, vertical_space};
use iced::widget::{column, pick_list, scrollable, vertical_space};
use iced::{Alignment, Element, Length, Sandbox, Settings};
pub fn main() -> iced::Result {
@ -48,15 +48,11 @@ impl Sandbox for Example {
pick_list,
vertical_space(600),
]
.width(Length::Fill)
.align_items(Alignment::Center)
.spacing(10);
container(scrollable(content))
.width(Length::Fill)
.height(Length::Fill)
.center_x()
.center_y()
.into()
scrollable(content).into()
}
}

View file

@ -451,7 +451,6 @@ where
limits
.width(width)
.height(Length::Shrink)
.shrink(padding)
.resolve(width, Length::Shrink, intrinsic)
.expand(padding)