hitTest method

NodeLayoutEntry? hitTest(
  1. double px,
  2. double py
)

Hit-test: find the deepest (smallest area) node at canvas coordinates (px, py).

Implementation

NodeLayoutEntry? hitTest(double px, double py) {
  NodeLayoutEntry? best;
  double bestArea = double.maxFinite;

  for (final entry in _entries) {
    if (px >= entry.relX &&
        px <= entry.relX + entry.width &&
        py >= entry.relY &&
        py <= entry.relY + entry.height) {
      final area = entry.width * entry.height;
      if (area < bestArea) {
        bestArea = area;
        best = entry;
      }
    }
  }
  return best;
}