summaryrefslogtreecommitdiffstats
path: root/native/src/layout/flex.rs
diff options
context:
space:
mode:
Diffstat (limited to 'native/src/layout/flex.rs')
-rw-r--r--native/src/layout/flex.rs28
1 files changed, 14 insertions, 14 deletions
diff --git a/native/src/layout/flex.rs b/native/src/layout/flex.rs
index bc90553e..2f65f1c1 100644
--- a/native/src/layout/flex.rs
+++ b/native/src/layout/flex.rs
@@ -18,7 +18,7 @@
// limitations under the License.
use crate::{
layout::{Limits, Node},
- Align, Element, Size,
+ Align, Element, Point, Size,
};
/// The main axis of a flex layout.
@@ -73,11 +73,12 @@ where
Renderer: crate::Renderer,
{
let limits = limits.pad(padding);
+ let total_spacing = spacing * items.len().saturating_sub(1) as f32;
+ let max_cross = axis.cross(limits.max());
- let mut total_non_fill =
- spacing as f32 * (items.len() as i32 - 1).max(0) as f32;
let mut fill_sum = 0;
- let mut cross = axis.cross(limits.min());
+ let mut cross = axis.cross(limits.min()).max(axis.cross(limits.fill()));
+ let mut available = axis.main(limits.max()) - total_spacing;
let mut nodes: Vec<Node> = Vec::with_capacity(items.len());
nodes.resize(items.len(), Node::default());
@@ -90,12 +91,15 @@ where
.fill_factor();
if fill_factor == 0 {
- let child_limits = Limits::new(Size::ZERO, limits.max());
+ 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.layout(renderer, &child_limits);
let size = layout.size();
- total_non_fill += axis.main(size);
+ available -= axis.main(size);
cross = cross.max(axis.cross(size));
nodes[i] = layout;
@@ -104,8 +108,7 @@ where
}
}
- let available = axis.main(limits.max());
- let remaining = (available - total_non_fill).max(0.0);
+ let remaining = available.max(0.0);
for (i, child) in items.iter().enumerate() {
let fill_factor = match axis {
@@ -149,8 +152,7 @@ where
let (x, y) = axis.pack(main, padding);
- node.bounds.x = x;
- node.bounds.y = y;
+ node.move_to(Point::new(x, y));
match axis {
Axis::Horizontal => {
@@ -166,13 +168,11 @@ where
main += axis.main(size);
}
- let (width, height) = axis.pack(main, cross);
+ let (width, height) = axis.pack(main - padding, cross);
let size = limits.resolve(Size::new(width, height));
- let (padding_x, padding_y) = axis.pack(padding, padding * 2.0);
-
Node::with_children(
- Size::new(size.width + padding_x, size.height + padding_y),
+ Size::new(size.width + padding * 2.0, size.height + padding * 2.0),
nodes,
)
}