Avoid setting constrain min to infinity in Flex layout
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
f5752969ab
commit
36699dc095
1 changed files with 12 additions and 4 deletions
|
@ -64,8 +64,16 @@ impl Element for Flex {
|
||||||
if let Some(flex) = Self::child_flex(&child) {
|
if let Some(flex) = Self::child_flex(&child) {
|
||||||
total_flex += flex;
|
total_flex += flex;
|
||||||
} else {
|
} else {
|
||||||
let child_constraint =
|
let child_constraint = match self.axis {
|
||||||
SizeConstraint::strict_along(cross_axis, constraint.max_along(cross_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);
|
let size = child.layout(child_constraint, ctx);
|
||||||
fixed_space += size.along(self.axis);
|
fixed_space += size.along(self.axis);
|
||||||
cross_axis_max = cross_axis_max.max(size.along(cross_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_max = space_per_flex * flex;
|
||||||
let child_constraint = match self.axis {
|
let child_constraint = match self.axis {
|
||||||
Axis::Horizontal => SizeConstraint::new(
|
Axis::Horizontal => SizeConstraint::new(
|
||||||
vec2f(0.0, constraint.max.y()),
|
vec2f(0.0, constraint.min.y()),
|
||||||
vec2f(child_max, constraint.max.y()),
|
vec2f(child_max, constraint.max.y()),
|
||||||
),
|
),
|
||||||
Axis::Vertical => SizeConstraint::new(
|
Axis::Vertical => SizeConstraint::new(
|
||||||
vec2f(constraint.max.x(), 0.0),
|
vec2f(constraint.min.x(), 0.0),
|
||||||
vec2f(constraint.max.x(), child_max),
|
vec2f(constraint.max.x(), child_max),
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue