From 444417203b2dbc7d2330ffe33d245c30147600c5 Mon Sep 17 00:00:00 2001 From: K Simmons Date: Fri, 9 Sep 2022 18:17:17 -0700 Subject: [PATCH] Move workspace overlay elements into an actual overlay in order to get proper stacking context depths Co-Authored-By: Mikayla Maki --- crates/drag_and_drop/src/drag_and_drop.rs | 46 +++++++++++------------ crates/gpui/src/elements/overlay.rs | 13 +++---- crates/workspace/src/dock.rs | 1 + crates/workspace/src/workspace.rs | 31 ++++++++++----- 4 files changed, 50 insertions(+), 41 deletions(-) diff --git a/crates/drag_and_drop/src/drag_and_drop.rs b/crates/drag_and_drop/src/drag_and_drop.rs index 2c7cf94ea7..8fa0e19c66 100644 --- a/crates/drag_and_drop/src/drag_and_drop.rs +++ b/crates/drag_and_drop/src/drag_and_drop.rs @@ -2,7 +2,7 @@ use std::{any::Any, rc::Rc}; use collections::HashSet; use gpui::{ - elements::{Container, MouseEventHandler}, + elements::{Container, MouseEventHandler, Overlay}, geometry::vector::Vector2F, scene::DragRegionEvent, CursorStyle, Element, ElementBox, EventContext, MouseButton, MutableAppContext, RenderContext, @@ -116,29 +116,27 @@ impl DragAndDrop { enum DraggedElementHandler {} Some( - MouseEventHandler::::new(0, cx, |_, cx| { - Container::new(render(payload, cx)) - .with_margin_left(position.x()) - .with_margin_top(position.y()) - .aligned() - .top() - .left() - .boxed() - }) - .with_cursor_style(CursorStyle::Arrow) - .on_up(MouseButton::Left, |_, cx| { - cx.defer(|cx| { - cx.update_global::(|this, cx| this.stop_dragging(cx)); - }); - cx.propogate_event(); - }) - .on_up_out(MouseButton::Left, |_, cx| { - cx.defer(|cx| { - cx.update_global::(|this, cx| this.stop_dragging(cx)); - }); - }) - // Don't block hover events or invalidations - .with_hoverable(false) + Overlay::new( + MouseEventHandler::::new(0, cx, |_, cx| { + render(payload, cx) + }) + .with_cursor_style(CursorStyle::Arrow) + .on_up(MouseButton::Left, |_, cx| { + cx.defer(|cx| { + cx.update_global::(|this, cx| this.stop_dragging(cx)); + }); + cx.propogate_event(); + }) + .on_up_out(MouseButton::Left, |_, cx| { + cx.defer(|cx| { + cx.update_global::(|this, cx| this.stop_dragging(cx)); + }); + }) + // Don't block hover events or invalidations + .with_hoverable(false) + .boxed(), + ) + .with_anchor_position(position) .boxed(), ) }, diff --git a/crates/gpui/src/elements/overlay.rs b/crates/gpui/src/elements/overlay.rs index 211fc2e418..20b6c75c8f 100644 --- a/crates/gpui/src/elements/overlay.rs +++ b/crates/gpui/src/elements/overlay.rs @@ -12,8 +12,8 @@ use serde_json::json; pub struct Overlay { child: ElementBox, anchor_position: Option, - fit_mode: OverlayFitMode, anchor_corner: AnchorCorner, + fit_mode: OverlayFitMode, hoverable: bool, } @@ -71,8 +71,8 @@ impl Overlay { Self { child, anchor_position: None, - fit_mode: OverlayFitMode::None, anchor_corner: AnchorCorner::TopLeft, + fit_mode: OverlayFitMode::None, hoverable: false, } } @@ -183,14 +183,13 @@ impl Element for Overlay { if self.hoverable { enum OverlayHoverCapture {} - cx.scene.push_mouse_region( - MouseRegion::new::( + // Block hovers in lower stacking contexts + cx.scene + .push_mouse_region(MouseRegion::new::( cx.current_view_id(), cx.current_view_id(), bounds, - ) - .with_hoverable(true), - ); + )); } self.child.paint(bounds.origin(), bounds, cx); diff --git a/crates/workspace/src/dock.rs b/crates/workspace/src/dock.rs index 9e1c523096..70e73ef33d 100644 --- a/crates/workspace/src/dock.rs +++ b/crates/workspace/src/dock.rs @@ -150,6 +150,7 @@ impl Dock { cx: &mut RenderContext, ) -> Option { let style = &theme.workspace.dock; + self.position .visible() .filter(|current_anchor| *current_anchor == anchor) diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 98293e25d8..636449ee36 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -2618,16 +2618,27 @@ impl View for Workspace { ) .boxed() }) - .with_children(self.dock.render(&theme, DockAnchor::Expanded, cx)) - .with_children(self.modal.as_ref().map(|m| { - ChildView::new(m) - .contained() - .with_style(theme.workspace.modal) - .aligned() - .top() - .boxed() - })) - .with_children(self.render_notifications(&theme.workspace)) + .with_child( + Overlay::new( + Stack::new() + .with_children(self.dock.render( + &theme, + DockAnchor::Expanded, + cx, + )) + .with_children(self.modal.as_ref().map(|m| { + ChildView::new(m) + .contained() + .with_style(theme.workspace.modal) + .aligned() + .top() + .boxed() + })) + .with_children(self.render_notifications(&theme.workspace)) + .boxed(), + ) + .boxed(), + ) .flex(1.0, true) .boxed(), )