diff --git a/gpui/src/elements/flex.rs b/gpui/src/elements/flex.rs index a71407cc2562eff46cbe12cca48a54e3ab001a5d..73f3a863730a8a07a3542cf44bffbad637a2cc73 100644 --- a/gpui/src/elements/flex.rs +++ b/gpui/src/elements/flex.rs @@ -82,7 +82,7 @@ impl Extend 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(