diff --git a/crates/gpui/src/window/element_cx.rs b/crates/gpui/src/window/element_cx.rs index 4a334ea9dc..15758fb357 100644 --- a/crates/gpui/src/window/element_cx.rs +++ b/crates/gpui/src/window/element_cx.rs @@ -66,11 +66,13 @@ impl HitboxId { /// See [ElementContext::insert_hitbox] for more details. #[derive(Clone, Debug, Deref)] pub struct Hitbox { - /// A unique identifier for the hitbox + /// A unique identifier for the hitbox. pub id: HitboxId, - /// The bounds of the hitbox + /// The bounds of the hitbox. #[deref] pub bounds: Bounds, + /// The content mask when the hitbox was inserted. + pub content_mask: ContentMask, /// Whether the hitbox occludes other hitboxes inserted prior. pub opaque: bool, } @@ -201,7 +203,8 @@ impl Frame { pub(crate) fn hit_test(&self, position: Point) -> HitTest { let mut hit_test = HitTest::default(); for hitbox in self.hitboxes.iter().rev() { - if hitbox.bounds.contains(&position) { + let bounds = hitbox.bounds.intersect(&hitbox.content_mask.bounds); + if bounds.contains(&position) { hit_test.0.push(hitbox.id); if hitbox.opaque { break; @@ -1404,7 +1407,8 @@ impl<'a> ElementContext<'a> { window.next_hitbox_id.0 += 1; let hitbox = Hitbox { id, - bounds: bounds.intersect(&content_mask.bounds), + bounds, + content_mask, opaque, }; window.next_frame.hitboxes.push(hitbox.clone());