Interface IHitTestable<TElement>
Interface for components that support hit testing.
Contract: Implementations MUST document and enforce the coordinate space specified by HitTestCoordinateSpace. Callers MUST provide positions in the declared coordinate space.
Inspired by:
- Konva.js: Stage.getIntersection(pos) returning the topmost Shape
- react-diagrams: DiagramEngine.getModelAtPosition()
- WPF/Avalonia: VisualTreeHelper.HitTest() pattern
public interface IHitTestable<TElement>
Type Parameters
TElementThe type of element this tests against.
Properties
HitTestCoordinateSpace
The coordinate space expected for the hit test position parameter.
Implementation guidance:
- Most hit testers should expect Canvas coordinates
- Direct renderers that manage their own transforms may expect Screen
- The caller is responsible for converting coordinates before calling HitTest(Point, double)
CoordinateSpace HitTestCoordinateSpace { get; }
Property Value
Methods
HitTest(Point, double)
Performs a hit test at the specified position.
HitTestResult<TElement> HitTest(Point position, double tolerance = 0)
Parameters
positionPointPosition to test. MUST be in the coordinate space specified by HitTestCoordinateSpace. Passing coordinates in the wrong space will produce incorrect results.
tolerancedoubleOptional tolerance/margin for the hit test, in the same coordinate space. Use this for edge hit testing or touch-friendly targets.
Returns
- HitTestResult<TElement>
The hit test result containing the hit element (if any) and positions.