hitTest method
Performs hit testing at a point.
Tests in priority order matching visual z-order (top to bottom): foreground nodes (CommentNode) → ports → middle nodes → connections → background nodes (GroupNode) → canvas
This order ensures that elements visually on top receive hit priority. Foreground nodes (comments) are above everything except the interaction layer. Background nodes (groups) are behind regular nodes and connections.
Implementation
HitTestResult hitTest(Offset point) {
// 1. Foreground nodes (CommentNode - highest priority, visually on top)
final foregroundResult = _hitTestNodesByLayer(
point,
layer: NodeRenderLayer.foreground,
);
if (foregroundResult != null) return foregroundResult;
// 2. Ports
final portResult = _hitTestPorts(point);
if (portResult != null) return portResult;
// 3. Middle layer nodes (regular nodes)
final nodeResult = _hitTestNodesByLayer(
point,
layer: NodeRenderLayer.middle,
);
if (nodeResult != null) return nodeResult;
// 4. Connections
final connectionResult = _hitTestConnections(point);
if (connectionResult != null) return connectionResult;
// 5. Background nodes (GroupNode - behind regular nodes/connections)
final backgroundResult = _hitTestNodesByLayer(
point,
layer: NodeRenderLayer.background,
);
if (backgroundResult != null) return backgroundResult;
// 6. Canvas (background)
return const HitTestResult(hitType: HitTarget.canvas);
}