ferroui_base/rendering/i_hit_tester.rs
1use crate::media::{Geometry, GeometryHitTestResult};
2use crate::{Point, Ref, Visual};
3
4/// An interface to allow hit testing of a visual tree.
5///
6/// Hit testing through this interface is low-level and does not respect
7/// input hit test visibility. Use the input hit testing methods of
8/// `InputElement` to perform input hit testing, or provide your own filter.
9pub trait IHitTester {
10 /// Hit tests a location to find the visuals at the specified point,
11 /// topmost first.
12 ///
13 /// `p` is the point in coordinates relative to `root`, the root of the
14 /// subtree to search. If `filter` returns false for a visual then the
15 /// visual and all its descendants are excluded from the results.
16 fn hit_test(&self, p: Point, root: &Visual, filter: Option<&dyn Fn(&Visual) -> bool>) -> Vec<Ref<Visual>>;
17
18 /// Hit tests a geometry to find the visuals intersecting a region,
19 /// topmost first.
20 ///
21 /// `geometry` is in coordinates relative to `root`, the root of the
22 /// subtree to search. If `filter` returns false for a visual then the
23 /// visual and all its descendants are excluded from the results.
24 fn hit_test_geometry(
25 &self,
26 geometry: &Geometry,
27 root: &Visual,
28 filter: Option<&dyn Fn(&Visual) -> bool>,
29 ) -> Vec<GeometryHitTestResult>;
30
31 /// Hit tests a location to find the first (topmost) visual at the
32 /// specified point.
33 ///
34 /// See [`hit_test`](Self::hit_test) for the parameters.
35 fn hit_test_first(&self, p: Point, root: &Visual, filter: Option<&dyn Fn(&Visual) -> bool>)
36 -> Option<Ref<Visual>>;
37
38 /// Hit tests a geometry to find the first (topmost) visual intersecting
39 /// a region.
40 ///
41 /// See [`hit_test_geometry`](Self::hit_test_geometry) for the
42 /// parameters.
43 fn hit_test_first_geometry(
44 &self,
45 geometry: &Geometry,
46 root: &Visual,
47 filter: Option<&dyn Fn(&Visual) -> bool>,
48 ) -> Option<GeometryHitTestResult>;
49}