Avoid setting constrain min to infinity in Flex layout

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld 2021-04-14 15:11:56 -07:00
parent f5752969ab
commit 36699dc095

View File

@ -64,8 +64,16 @@ impl Element for Flex {
if let Some(flex) = Self::child_flex(&child) {
total_flex += flex;
} else {
let child_constraint =
SizeConstraint::strict_along(cross_axis, constraint.max_along(cross_axis));
let child_constraint = match self.axis {
Axis::Horizontal => SizeConstraint::new(
vec2f(0.0, constraint.min.y()),
vec2f(INFINITY, constraint.max.y()),
),
Axis::Vertical => SizeConstraint::new(
vec2f(constraint.min.x(), 0.0),
vec2f(constraint.max.x(), INFINITY),
),
};
let size = child.layout(child_constraint, ctx);
fixed_space += size.along(self.axis);
cross_axis_max = cross_axis_max.max(size.along(cross_axis));
@ -85,11 +93,11 @@ impl Element for Flex {
let child_max = space_per_flex * flex;
let child_constraint = match self.axis {
Axis::Horizontal => SizeConstraint::new(
vec2f(0.0, constraint.max.y()),
vec2f(0.0, constraint.min.y()),
vec2f(child_max, constraint.max.y()),
),
Axis::Vertical => SizeConstraint::new(
vec2f(constraint.max.x(), 0.0),
vec2f(constraint.min.x(), 0.0),
vec2f(constraint.max.x(), child_max),
),
};