diff --git a/crates/gpui/src/elements/flex.rs b/crates/gpui/src/elements/flex.rs index f7d60e409bd3581bcb1c4bd85e2106650be3641f..1ae9c591c89c1b5de838b18612696e4a9e6990cb 100644 --- a/crates/gpui/src/elements/flex.rs +++ b/crates/gpui/src/elements/flex.rs @@ -270,6 +270,12 @@ impl Element for Flex { _: &mut Self::PaintState, cx: &mut EventContext, ) -> bool { + if let Some(position) = event.position() { + if !bounds.contains_point(position) { + return false; + } + } + let mut handled = false; for child in &mut self.children { handled = child.dispatch_event(event, cx) || handled; diff --git a/crates/gpui/src/platform/event.rs b/crates/gpui/src/platform/event.rs index 72e1c24d6b2d157825b115bb8a3c9122fe72a97d..fe353fed4c9be36df5b74aa474be07d5123f3ad1 100644 --- a/crates/gpui/src/platform/event.rs +++ b/crates/gpui/src/platform/event.rs @@ -61,3 +61,20 @@ pub enum Event { left_mouse_down: bool, }, } + +impl Event { + pub fn position(&self) -> Option { + match self { + Event::KeyDown { .. } => None, + Event::ScrollWheel { position, .. } + | Event::LeftMouseDown { position, .. } + | Event::LeftMouseUp { position } + | Event::LeftMouseDragged { position } + | Event::RightMouseDown { position, .. } + | Event::RightMouseUp { position } + | Event::NavigateMouseDown { position, .. } + | Event::NavigateMouseUp { position, .. } + | Event::MouseMoved { position, .. } => Some(*position), + } + } +}