pub struct HitTester<Id> { /* private fields */ }Expand description
A per-frame registry of (Rect, Id) pairs, queried by pointer position
to find the topmost widget under a point.
Standalone and headless: no Backend
dependency, so it’s usable (and unit-testable) without a
Terminal or any drawing at all, e.g. for
hand-rolled hit-testing outside of Interaction.
Registrations are draw-ordered: a later push means drawn
(and therefore visually on top) later, so topmost_at
scans back-to-front and returns the last match. This mirrors the
painter’s algorithm every widget in this crate already draws with.
A push_barriered rect additionally stops that scan: a point inside a
barrier’s rect never resolves to anything registered before the barrier, regardless of overlap
(an overlay region claims everything under it, not just what it happens to draw over), while a
point outside the barrier’s rect is unaffected by it and keeps scanning past it normally.
Implementations§
Source§impl<Id> HitTester<Id>
impl<Id> HitTester<Id>
Sourcepub fn push(&mut self, rect: Rect, id: Id)
pub fn push(&mut self, rect: Rect, id: Id)
Register id as occupying rect, on top of everything registered
so far this pass.
Sourcepub fn push_barrier(&mut self, rect: Rect)
pub fn push_barrier(&mut self, rect: Rect)
Register rect as a barrier, on top of everything registered so far this pass: see the
HitTester docs for what that does to topmost_at.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Discard all registrations, e.g. at the start of a new frame’s draw pass.
Source§impl<Id: Copy> HitTester<Id>
impl<Id: Copy> HitTester<Id>
Sourcepub fn topmost_at(&self, pos: Pos) -> Option<Id>
pub fn topmost_at(&self, pos: Pos) -> Option<Id>
The id of the topmost (most recently pushed)
registration whose rect contains pos, if any.
Stops at the first (most recently registered) push_barriered rect
that also contains pos: nothing registered earlier than that barrier can win at a
position the barrier covers.