Move workspace overlay elements into an actual overlay in order to get proper stacking context depths

Co-Authored-By: Mikayla Maki <mikayla@zed.dev>
This commit is contained in:
K Simmons 2022-09-09 18:17:17 -07:00
parent 6b26965074
commit 444417203b
4 changed files with 50 additions and 41 deletions

View file

@ -2,7 +2,7 @@ use std::{any::Any, rc::Rc};
use collections::HashSet; use collections::HashSet;
use gpui::{ use gpui::{
elements::{Container, MouseEventHandler}, elements::{Container, MouseEventHandler, Overlay},
geometry::vector::Vector2F, geometry::vector::Vector2F,
scene::DragRegionEvent, scene::DragRegionEvent,
CursorStyle, Element, ElementBox, EventContext, MouseButton, MutableAppContext, RenderContext, CursorStyle, Element, ElementBox, EventContext, MouseButton, MutableAppContext, RenderContext,
@ -116,14 +116,9 @@ impl<V: View> DragAndDrop<V> {
enum DraggedElementHandler {} enum DraggedElementHandler {}
Some( Some(
Overlay::new(
MouseEventHandler::<DraggedElementHandler>::new(0, cx, |_, cx| { MouseEventHandler::<DraggedElementHandler>::new(0, cx, |_, cx| {
Container::new(render(payload, cx)) render(payload, cx)
.with_margin_left(position.x())
.with_margin_top(position.y())
.aligned()
.top()
.left()
.boxed()
}) })
.with_cursor_style(CursorStyle::Arrow) .with_cursor_style(CursorStyle::Arrow)
.on_up(MouseButton::Left, |_, cx| { .on_up(MouseButton::Left, |_, cx| {
@ -141,6 +136,9 @@ impl<V: View> DragAndDrop<V> {
.with_hoverable(false) .with_hoverable(false)
.boxed(), .boxed(),
) )
.with_anchor_position(position)
.boxed(),
)
}, },
) )
} }

View file

@ -12,8 +12,8 @@ use serde_json::json;
pub struct Overlay { pub struct Overlay {
child: ElementBox, child: ElementBox,
anchor_position: Option<Vector2F>, anchor_position: Option<Vector2F>,
fit_mode: OverlayFitMode,
anchor_corner: AnchorCorner, anchor_corner: AnchorCorner,
fit_mode: OverlayFitMode,
hoverable: bool, hoverable: bool,
} }
@ -71,8 +71,8 @@ impl Overlay {
Self { Self {
child, child,
anchor_position: None, anchor_position: None,
fit_mode: OverlayFitMode::None,
anchor_corner: AnchorCorner::TopLeft, anchor_corner: AnchorCorner::TopLeft,
fit_mode: OverlayFitMode::None,
hoverable: false, hoverable: false,
} }
} }
@ -183,14 +183,13 @@ impl Element for Overlay {
if self.hoverable { if self.hoverable {
enum OverlayHoverCapture {} enum OverlayHoverCapture {}
cx.scene.push_mouse_region( // Block hovers in lower stacking contexts
MouseRegion::new::<OverlayHoverCapture>( cx.scene
.push_mouse_region(MouseRegion::new::<OverlayHoverCapture>(
cx.current_view_id(), cx.current_view_id(),
cx.current_view_id(), cx.current_view_id(),
bounds, bounds,
) ));
.with_hoverable(true),
);
} }
self.child.paint(bounds.origin(), bounds, cx); self.child.paint(bounds.origin(), bounds, cx);

View file

@ -150,6 +150,7 @@ impl Dock {
cx: &mut RenderContext<Workspace>, cx: &mut RenderContext<Workspace>,
) -> Option<ElementBox> { ) -> Option<ElementBox> {
let style = &theme.workspace.dock; let style = &theme.workspace.dock;
self.position self.position
.visible() .visible()
.filter(|current_anchor| *current_anchor == anchor) .filter(|current_anchor| *current_anchor == anchor)

View file

@ -2618,7 +2618,14 @@ impl View for Workspace {
) )
.boxed() .boxed()
}) })
.with_children(self.dock.render(&theme, DockAnchor::Expanded, cx)) .with_child(
Overlay::new(
Stack::new()
.with_children(self.dock.render(
&theme,
DockAnchor::Expanded,
cx,
))
.with_children(self.modal.as_ref().map(|m| { .with_children(self.modal.as_ref().map(|m| {
ChildView::new(m) ChildView::new(m)
.contained() .contained()
@ -2628,6 +2635,10 @@ impl View for Workspace {
.boxed() .boxed()
})) }))
.with_children(self.render_notifications(&theme.workspace)) .with_children(self.render_notifications(&theme.workspace))
.boxed(),
)
.boxed(),
)
.flex(1.0, true) .flex(1.0, true)
.boxed(), .boxed(),
) )