Add InteractiveElement::block_mouse which renders an "opaque" layer

Co-Authored-By: Antonio <antonio@zed.dev>
Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
Nathan Sobo 2023-12-20 11:02:47 -07:00
parent dc047437c6
commit fffb30ac6d
2 changed files with 18 additions and 5 deletions

View file

@ -345,6 +345,10 @@ impl Interactivity {
); );
self.tooltip_builder = Some(Rc::new(build_tooltip)); self.tooltip_builder = Some(Rc::new(build_tooltip));
} }
pub fn block_mouse(&mut self) {
self.block_mouse = true;
}
} }
pub trait InteractiveElement: Sized { pub trait InteractiveElement: Sized {
@ -564,6 +568,11 @@ pub trait InteractiveElement: Sized {
self.interactivity().on_drop(listener); self.interactivity().on_drop(listener);
self self
} }
fn block_mouse(mut self) -> Self {
self.interactivity().block_mouse();
self
}
} }
pub trait StatefulInteractiveElement: InteractiveElement { pub trait StatefulInteractiveElement: InteractiveElement {
@ -888,6 +897,7 @@ pub struct Interactivity {
pub drag_listener: Option<(Box<dyn Any>, DragListener)>, pub drag_listener: Option<(Box<dyn Any>, DragListener)>,
pub hover_listener: Option<Box<dyn Fn(&bool, &mut WindowContext)>>, pub hover_listener: Option<Box<dyn Fn(&bool, &mut WindowContext)>>,
pub tooltip_builder: Option<TooltipBuilder>, pub tooltip_builder: Option<TooltipBuilder>,
pub block_mouse: bool,
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
pub location: Option<core::panic::Location<'static>>, pub location: Option<core::panic::Location<'static>>,
@ -1076,10 +1086,11 @@ impl Interactivity {
}); });
} }
if style if self.block_mouse
.background || style
.as_ref() .background
.is_some_and(|fill| fill.color().is_some_and(|color| !color.is_transparent())) .as_ref()
.is_some_and(|fill| fill.color().is_some_and(|color| !color.is_transparent()))
{ {
cx.add_opaque_layer(bounds) cx.add_opaque_layer(bounds)
} }
@ -1642,6 +1653,7 @@ impl Default for Interactivity {
drag_listener: None, drag_listener: None,
hover_listener: None, hover_listener: None,
tooltip_builder: None, tooltip_builder: None,
block_mouse: false,
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
location: None, location: None,

View file

@ -499,7 +499,8 @@ impl Render for Dock {
cx.stop_propagation(); cx.stop_propagation();
} }
})) }))
.z_index(1); .z_index(1)
.block_mouse();
const HANDLE_SIZE: Pixels = Pixels(6.); const HANDLE_SIZE: Pixels = Pixels(6.);