Expand description
Spatial navigation: arrow-key focus movement based on widget geometry.
Given a set of focusable nodes with bounding rectangles, finds the best candidate in a given direction using a quadrant-based search with weighted distance scoring.
§Algorithm
- Check for explicit edge override in the graph (takes precedence).
- Filter candidates to the correct quadrant relative to the current node.
- Score each candidate:
primary_distance + 0.3 × orthogonal_distance. - Return the candidate with the lowest score.
§Invariants
- Explicit graph edges always take precedence over spatial search.
- Only focusable nodes are considered.
- If no candidate exists in the direction,
Noneis returned. - The algorithm is deterministic: same layout → same navigation path.
Functions§
- build_
spatial_ edges - Build spatial edges for all nodes in the graph.
- spatial_
navigate - Find the best spatial navigation target from
originindir.