From 95d848fe1e038a652a8331028cff249df920fd18 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 6 May 2022 10:20:03 +0200 Subject: [PATCH] Ensure `flex_float` works even when re-painting without layout Previously, we were mutating the remaining space stored on the layout state, which would cause re-paints to always have a `remaining_space` of 0 and therefore not align `flex_float` elements to the right/bottom. --- crates/gpui/src/elements/flex.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/gpui/src/elements/flex.rs b/crates/gpui/src/elements/flex.rs index 4f930dfb46..3384b20019 100644 --- a/crates/gpui/src/elements/flex.rs +++ b/crates/gpui/src/elements/flex.rs @@ -225,7 +225,9 @@ impl Element for Flex { remaining_space: &mut Self::LayoutState, cx: &mut PaintContext, ) -> Self::PaintState { - let overflowing = *remaining_space < 0.; + let mut remaining_space = *remaining_space; + + let overflowing = remaining_space < 0.; if overflowing { cx.scene.push_layer(Some(bounds)); } @@ -240,14 +242,14 @@ impl Element for Flex { } for child in &mut self.children { - if *remaining_space > 0. { + if remaining_space > 0. { if let Some(metadata) = child.metadata::() { if metadata.float { match self.axis { - Axis::Horizontal => child_origin += vec2f(*remaining_space, 0.0), - Axis::Vertical => child_origin += vec2f(0.0, *remaining_space), + Axis::Horizontal => child_origin += vec2f(remaining_space, 0.0), + Axis::Vertical => child_origin += vec2f(0.0, remaining_space), } - *remaining_space = 0.; + remaining_space = 0.; } } } @@ -257,6 +259,7 @@ impl Element for Flex { Axis::Vertical => child_origin += vec2f(0.0, child.size().y()), } } + if overflowing { cx.scene.pop_layer(); }