summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-01-09 07:15:57 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-01-10 10:01:50 +0100
commit88f8c343fa7d69203ab98bb7abc85fe002014422 (patch)
tree59252dca047ee6dcd2da1602ea4698851a731e47
parent025064c9e028ea65cc0c6ff236d42e9861efdda9 (diff)
downloadiced-88f8c343fa7d69203ab98bb7abc85fe002014422.tar.gz
iced-88f8c343fa7d69203ab98bb7abc85fe002014422.tar.bz2
iced-88f8c343fa7d69203ab98bb7abc85fe002014422.zip
Fix `cross` calculation in `layout::flex`
-rw-r--r--core/src/layout/flex.rs27
-rw-r--r--examples/pick_list/src/main.rs10
-rw-r--r--widget/src/pick_list.rs1
3 files changed, 16 insertions, 22 deletions
diff --git a/core/src/layout/flex.rs b/core/src/layout/flex.rs
index cf3e1340..47cd7112 100644
--- a/core/src/layout/flex.rs
+++ b/core/src/layout/flex.rs
@@ -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) =
diff --git a/examples/pick_list/src/main.rs b/examples/pick_list/src/main.rs
index bfd642f5..e4d96dc8 100644
--- a/examples/pick_list/src/main.rs
+++ b/examples/pick_list/src/main.rs
@@ -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()
}
}
diff --git a/widget/src/pick_list.rs b/widget/src/pick_list.rs
index 2576a1e8..9f6a371a 100644
--- a/widget/src/pick_list.rs
+++ b/widget/src/pick_list.rs
@@ -451,7 +451,6 @@ where
limits
.width(width)
- .height(Length::Shrink)
.shrink(padding)
.resolve(width, Length::Shrink, intrinsic)
.expand(padding)