summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-02-27 16:49:25 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-02-27 16:54:28 +0100
commit9e815cb749f1bf6bce0232e870be266aca0c0742 (patch)
treea8947e78efcd14435e47f4b2db89d2c58e4471ec /native
parent5f93437285c4451a8b5ffac1b3c9e1b91e8a5918 (diff)
downloadiced-9e815cb749f1bf6bce0232e870be266aca0c0742.tar.gz
iced-9e815cb749f1bf6bce0232e870be266aca0c0742.tar.bz2
iced-9e815cb749f1bf6bce0232e870be266aca0c0742.zip
Remove `Fill` variant for `Alignment`
Implementing this generically in our `flex` logic has an exponential cost. Let's explore other options!
Diffstat (limited to '')
-rw-r--r--native/src/layout/flex.rs67
-rw-r--r--native/src/layout/node.rs6
2 files changed, 8 insertions, 65 deletions
diff --git a/native/src/layout/flex.rs b/native/src/layout/flex.rs
index 5d70c2fc..8b967849 100644
--- a/native/src/layout/flex.rs
+++ b/native/src/layout/flex.rs
@@ -81,32 +81,6 @@ where
let mut nodes: Vec<Node> = Vec::with_capacity(items.len());
nodes.resize(items.len(), Node::default());
- if align_items == Alignment::Fill {
- let mut fill_cross = axis.cross(limits.min());
-
- items.iter().for_each(|child| {
- let cross_fill_factor = match axis {
- Axis::Horizontal => child.as_widget().height(),
- Axis::Vertical => child.as_widget().width(),
- }
- .fill_factor();
-
- if cross_fill_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(renderer, &child_limits);
- let size = layout.size();
-
- fill_cross = fill_cross.max(axis.cross(size));
- }
- });
-
- cross = fill_cross;
- }
-
for (i, child) in items.iter().enumerate() {
let fill_factor = match axis {
Axis::Horizontal => child.as_widget().width(),
@@ -115,31 +89,16 @@ where
.fill_factor();
if fill_factor == 0 {
- let (min_width, min_height) = if align_items == Alignment::Fill {
- axis.pack(0.0, cross)
- } else {
- axis.pack(0.0, 0.0)
- };
+ let (max_width, max_height) = axis.pack(available, max_cross);
- let (max_width, max_height) = if align_items == Alignment::Fill {
- axis.pack(available, cross)
- } else {
- axis.pack(available, max_cross)
- };
-
- let child_limits = Limits::new(
- Size::new(min_width, min_height),
- Size::new(max_width, max_height),
- );
+ let child_limits =
+ Limits::new(Size::ZERO, Size::new(max_width, max_height));
let layout = child.as_widget().layout(renderer, &child_limits);
let size = layout.size();
available -= axis.main(size);
-
- if align_items != Alignment::Fill {
- cross = cross.max(axis.cross(size));
- }
+ cross = cross.max(axis.cross(size));
nodes[i] = layout;
} else {
@@ -164,17 +123,10 @@ where
max_main
};
- let (min_width, min_height) = if align_items == Alignment::Fill {
- axis.pack(min_main, cross)
- } else {
- axis.pack(min_main, axis.cross(limits.min()))
- };
+ let (min_width, min_height) =
+ axis.pack(min_main, axis.cross(limits.min()));
- let (max_width, max_height) = if align_items == Alignment::Fill {
- axis.pack(max_main, cross)
- } else {
- axis.pack(max_main, max_cross)
- };
+ let (max_width, max_height) = axis.pack(max_main, max_cross);
let child_limits = Limits::new(
Size::new(min_width, min_height),
@@ -182,10 +134,7 @@ where
);
let layout = child.as_widget().layout(renderer, &child_limits);
-
- if align_items != Alignment::Fill {
- cross = cross.max(axis.cross(layout.size()));
- }
+ cross = cross.max(axis.cross(layout.size()));
nodes[i] = layout;
}
diff --git a/native/src/layout/node.rs b/native/src/layout/node.rs
index e0c7dcb2..2b44a7d5 100644
--- a/native/src/layout/node.rs
+++ b/native/src/layout/node.rs
@@ -56,9 +56,6 @@ impl Node {
Alignment::End => {
self.bounds.x += space.width - self.bounds.width;
}
- Alignment::Fill => {
- self.bounds.width = space.width;
- }
}
match vertical_alignment {
@@ -69,9 +66,6 @@ impl Node {
Alignment::End => {
self.bounds.y += space.height - self.bounds.height;
}
- Alignment::Fill => {
- self.bounds.height = space.height;
- }
}
}