Honor max constraint in Flex even if children overflow

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra
2021-09-03 17:47:45 +02:00
co-authored by Nathan Sobo
parent 0ae70b62cb
commit 2f0f6e210d
+19 -4
View File
@@ -82,7 +82,7 @@ impl Extend<ElementBox> for Flex {
}
impl Element for Flex {
type LayoutState = ();
type LayoutState = bool;
type PaintState = ();
fn layout(
@@ -153,21 +153,33 @@ impl Element for Flex {
if constraint.min.x().is_finite() {
size.set_x(size.x().max(constraint.min.x()));
}
if constraint.min.y().is_finite() {
size.set_y(size.y().max(constraint.min.y()));
}
(size, ())
let mut overflowing = false;
if size.x() > constraint.max.x() {
size.set_x(constraint.max.x());
overflowing = true;
}
if size.y() > constraint.max.y() {
size.set_y(constraint.max.y());
overflowing = true;
}
(size, overflowing)
}
fn paint(
&mut self,
bounds: RectF,
visible_bounds: RectF,
_: &mut Self::LayoutState,
overflowing: &mut Self::LayoutState,
cx: &mut PaintContext,
) -> Self::PaintState {
if *overflowing {
cx.scene.push_layer(Some(bounds));
}
let mut child_origin = bounds.origin();
for child in &mut self.children {
child.paint(child_origin, visible_bounds, cx);
@@ -176,6 +188,9 @@ impl Element for Flex {
Axis::Vertical => child_origin += vec2f(0.0, child.size().y()),
}
}
if *overflowing {
cx.scene.pop_layer();
}
}
fn dispatch_event(