From fffb30ac6d57e3974f2b12a6f97ea71dfe7da71b Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 20 Dec 2023 11:02:47 -0700 Subject: [PATCH] Add InteractiveElement::block_mouse which renders an "opaque" layer Co-Authored-By: Antonio Co-Authored-By: Max Brunsfeld --- crates/gpui2/src/elements/div.rs | 20 ++++++++++++++++---- crates/workspace2/src/dock.rs | 3 ++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/crates/gpui2/src/elements/div.rs b/crates/gpui2/src/elements/div.rs index 54c0884870f64079ef16d1215d20b1e099646c4a..0c67d1648e8500718afb1a86516734dbf91cd156 100644 --- a/crates/gpui2/src/elements/div.rs +++ b/crates/gpui2/src/elements/div.rs @@ -345,6 +345,10 @@ impl Interactivity { ); self.tooltip_builder = Some(Rc::new(build_tooltip)); } + + pub fn block_mouse(&mut self) { + self.block_mouse = true; + } } pub trait InteractiveElement: Sized { @@ -564,6 +568,11 @@ pub trait InteractiveElement: Sized { self.interactivity().on_drop(listener); self } + + fn block_mouse(mut self) -> Self { + self.interactivity().block_mouse(); + self + } } pub trait StatefulInteractiveElement: InteractiveElement { @@ -888,6 +897,7 @@ pub struct Interactivity { pub drag_listener: Option<(Box, DragListener)>, pub hover_listener: Option>, pub tooltip_builder: Option, + pub block_mouse: bool, #[cfg(debug_assertions)] pub location: Option>, @@ -1076,10 +1086,11 @@ impl Interactivity { }); } - if style - .background - .as_ref() - .is_some_and(|fill| fill.color().is_some_and(|color| !color.is_transparent())) + if self.block_mouse + || style + .background + .as_ref() + .is_some_and(|fill| fill.color().is_some_and(|color| !color.is_transparent())) { cx.add_opaque_layer(bounds) } @@ -1642,6 +1653,7 @@ impl Default for Interactivity { drag_listener: None, hover_listener: None, tooltip_builder: None, + block_mouse: false, #[cfg(debug_assertions)] location: None, diff --git a/crates/workspace2/src/dock.rs b/crates/workspace2/src/dock.rs index d0aba998b97895ae62359714f19522de6b2dadba..82f00da6f9b436d6f398dc5ebc553c9d2e7f2c87 100644 --- a/crates/workspace2/src/dock.rs +++ b/crates/workspace2/src/dock.rs @@ -499,7 +499,8 @@ impl Render for Dock { cx.stop_propagation(); } })) - .z_index(1); + .z_index(1) + .block_mouse(); const HANDLE_SIZE: Pixels = Pixels(6.);