Fix cross calculation in layout::flex
This commit is contained in:
parent
025064c9e0
commit
88f8c343fa
3 changed files with 16 additions and 22 deletions
|
|
@ -79,7 +79,17 @@ where
|
||||||
let max_cross = axis.cross(limits.max());
|
let max_cross = axis.cross(limits.max());
|
||||||
|
|
||||||
let mut fill_main_sum = 0;
|
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 available = axis.main(limits.max()) - total_spacing;
|
||||||
|
|
||||||
let mut nodes: Vec<Node> = Vec::with_capacity(items.len());
|
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() {
|
for (i, (child, tree)) in items.iter().zip(trees.iter_mut()).enumerate() {
|
||||||
let (fill_main_factor, fill_cross_factor) = {
|
let (fill_main_factor, fill_cross_factor) = {
|
||||||
let size = child.as_widget().size();
|
let size = child.as_widget().size();
|
||||||
|
|
@ -132,7 +131,7 @@ where
|
||||||
};
|
};
|
||||||
|
|
||||||
if fill_main_factor == 0 && fill_cross_factor != 0 {
|
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 =
|
let child_limits =
|
||||||
Limits::new(Size::ZERO, Size::new(max_width, max_height));
|
Limits::new(Size::ZERO, Size::new(max_width, max_height));
|
||||||
|
|
@ -182,7 +181,7 @@ where
|
||||||
let max_cross = if fill_cross_factor == 0 {
|
let max_cross = if fill_cross_factor == 0 {
|
||||||
max_cross
|
max_cross
|
||||||
} else {
|
} else {
|
||||||
intrinsic_cross
|
cross
|
||||||
};
|
};
|
||||||
|
|
||||||
let (min_width, min_height) =
|
let (min_width, min_height) =
|
||||||
|
|
|
||||||
|
|
@ -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};
|
use iced::{Alignment, Element, Length, Sandbox, Settings};
|
||||||
|
|
||||||
pub fn main() -> iced::Result {
|
pub fn main() -> iced::Result {
|
||||||
|
|
@ -48,15 +48,11 @@ impl Sandbox for Example {
|
||||||
pick_list,
|
pick_list,
|
||||||
vertical_space(600),
|
vertical_space(600),
|
||||||
]
|
]
|
||||||
|
.width(Length::Fill)
|
||||||
.align_items(Alignment::Center)
|
.align_items(Alignment::Center)
|
||||||
.spacing(10);
|
.spacing(10);
|
||||||
|
|
||||||
container(scrollable(content))
|
scrollable(content).into()
|
||||||
.width(Length::Fill)
|
|
||||||
.height(Length::Fill)
|
|
||||||
.center_x()
|
|
||||||
.center_y()
|
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -451,7 +451,6 @@ where
|
||||||
|
|
||||||
limits
|
limits
|
||||||
.width(width)
|
.width(width)
|
||||||
.height(Length::Shrink)
|
|
||||||
.shrink(padding)
|
.shrink(padding)
|
||||||
.resolve(width, Length::Shrink, intrinsic)
|
.resolve(width, Length::Shrink, intrinsic)
|
||||||
.expand(padding)
|
.expand(padding)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue