From dfe2fd03861a19430176e2ee589e24fd9fba5b52 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 25 Oct 2022 13:41:47 +0200 Subject: [PATCH] Allow specifying a custom height for stacking contexts --- crates/editor/src/element.rs | 4 ++-- crates/gpui/src/elements/overlay.rs | 9 ++++++++- crates/gpui/src/elements/resizable.rs | 2 +- crates/gpui/src/presenter.rs | 10 +++++++--- crates/gpui/src/scene.rs | 4 ++-- crates/workspace/src/pane/dragged_item_receiver.rs | 2 +- 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 424351ebfc1fc40ff75636879fb14699800b0e3a..d80b4ea844433b9fd75e0b13f3395899304ed85b 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -791,7 +791,7 @@ impl EditorElement { cx.scene.pop_layer(); if let Some((position, context_menu)) = layout.context_menu.as_mut() { - cx.scene.push_stacking_context(None); + cx.scene.push_stacking_context(None, None); let cursor_row_layout = &layout.position_map.line_layouts[(position.row() - start_row) as usize]; let x = cursor_row_layout.x_for_index(position.column() as usize) - scroll_left; @@ -820,7 +820,7 @@ impl EditorElement { } if let Some((position, hover_popovers)) = layout.hover_popovers.as_mut() { - cx.scene.push_stacking_context(None); + cx.scene.push_stacking_context(None, None); // This is safe because we check on layout whether the required row is available let hovered_row_layout = diff --git a/crates/gpui/src/elements/overlay.rs b/crates/gpui/src/elements/overlay.rs index 15d3d764f2a626d9a2b4e2530e284e44f85ec9f4..b63b488b19977312d619ec540ca9ae48c549acf1 100644 --- a/crates/gpui/src/elements/overlay.rs +++ b/crates/gpui/src/elements/overlay.rs @@ -16,6 +16,7 @@ pub struct Overlay { fit_mode: OverlayFitMode, position_mode: OverlayPositionMode, hoverable: bool, + height: Option, } #[derive(Copy, Clone)] @@ -82,6 +83,7 @@ impl Overlay { fit_mode: OverlayFitMode::None, position_mode: OverlayPositionMode::Window, hoverable: false, + height: None, } } @@ -109,6 +111,11 @@ impl Overlay { self.hoverable = hoverable; self } + + pub fn with_height(mut self, height: usize) -> Self { + self.height = Some(height); + self + } } impl Element for Overlay { @@ -204,7 +211,7 @@ impl Element for Overlay { OverlayFitMode::None => {} } - cx.paint_stacking_context(None, |cx| { + cx.paint_stacking_context(None, self.height, |cx| { if self.hoverable { enum OverlayHoverCapture {} // Block hovers in lower stacking contexts diff --git a/crates/gpui/src/elements/resizable.rs b/crates/gpui/src/elements/resizable.rs index fb5bfa4a11643dbb351a9f7138b7fdb683f43ddb..b84ea57f54bdd62d65080220a7180f3b94bb329d 100644 --- a/crates/gpui/src/elements/resizable.rs +++ b/crates/gpui/src/elements/resizable.rs @@ -149,7 +149,7 @@ impl Element for Resizable { _child_size: &mut Self::LayoutState, cx: &mut crate::PaintContext, ) -> Self::PaintState { - cx.scene.push_stacking_context(None); + cx.scene.push_stacking_context(None, None); let handle_region = self.side.of_rect(bounds, self.handle_size); diff --git a/crates/gpui/src/presenter.rs b/crates/gpui/src/presenter.rs index 7628edee0354d2d1a7878d2b03c3649cdfc45d9d..4b2f7676697d83eed717f28e1ac426cc02085ee5 100644 --- a/crates/gpui/src/presenter.rs +++ b/crates/gpui/src/presenter.rs @@ -709,11 +709,15 @@ impl<'a> PaintContext<'a> { } #[inline] - pub fn paint_stacking_context(&mut self, clip_bounds: Option, f: F) - where + pub fn paint_stacking_context( + &mut self, + clip_bounds: Option, + height: Option, + f: F, + ) where F: FnOnce(&mut Self), { - self.scene.push_stacking_context(clip_bounds); + self.scene.push_stacking_context(clip_bounds, height); f(self); self.scene.pop_stacking_context(); } diff --git a/crates/gpui/src/scene.rs b/crates/gpui/src/scene.rs index fbed606ff86d0a5248f14538bfc1ef48c66b5277..079073fbd950535953a2f82bcec054bcbc09e9e4 100644 --- a/crates/gpui/src/scene.rs +++ b/crates/gpui/src/scene.rs @@ -235,8 +235,8 @@ impl SceneBuilder { self.scale_factor } - pub fn push_stacking_context(&mut self, clip_bounds: Option) { - let height = self.active_stacking_context().height + 1; + pub fn push_stacking_context(&mut self, clip_bounds: Option, height: Option) { + let height = height.unwrap_or_else(|| self.active_stacking_context().height + 1); self.active_stacking_context_stack .push(self.stacking_contexts.len()); self.stacking_contexts diff --git a/crates/workspace/src/pane/dragged_item_receiver.rs b/crates/workspace/src/pane/dragged_item_receiver.rs index a3f1285e51303feb4961e522a4deb3a051ee6ae7..6b69b94094da508d09fb87db89a05076e7703639 100644 --- a/crates/workspace/src/pane/dragged_item_receiver.rs +++ b/crates/workspace/src/pane/dragged_item_receiver.rs @@ -48,7 +48,7 @@ where .map(|(dir, margin)| dir.along_edge(bounds, margin)) .unwrap_or(bounds); - cx.paint_stacking_context(None, |cx| { + cx.paint_stacking_context(None, None, |cx| { cx.scene.push_quad(Quad { bounds: overlay_region, background: Some(overlay_color(cx)),