Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
gpui: Add `Hitbox::is_hovered_at` (#63696)
Cameron Mcloughlin3ce72bab201a
diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rsindex 9997ac6d0c9..cf8eded704c 100644--- a/crates/gpui/src/window.rs+++ b/crates/gpui/src/window.rs@@ -853,6 +853,17 @@ impl Hitbox {self.id.is_hovered(window)}+ /// Checks whether this hitbox would be hovered at `position`, regardless of the current input+ /// modality or mouse position.+ pub fn is_hovered_at(&self, position: Point<Pixels>, window: &Window) -> bool {+ let hit_test = window.rendered_frame.hit_test(position);+ hit_test+ .ids+ .iter()+ .take(hit_test.hover_hitbox_count)+ .any(|id| self.id == *id)+ }+/// Checks if the hitbox contains the mouse and should handle scroll events. Typically this/// should only be used when handling `ScrollWheelEvent`, and otherwise `is_hovered` should be/// used. See the documentation of `Hitbox::is_hovered` for details about this distinction.