pub struct FocusGraph { /* private fields */ }Expand description
Directed graph for focus navigation.
Nodes are focusable widgets; edges encode directional navigation. The graph is sparse (most nodes have ≤6 outgoing edges).
Implementations§
Source§impl FocusGraph
impl FocusGraph
Sourcepub fn insert(&mut self, node: FocusNode) -> FocusId
pub fn insert(&mut self, node: FocusNode) -> FocusId
Insert a node. Returns the node’s ID.
If a node with the same ID exists, it is replaced.
Sourcepub fn remove(&mut self, id: FocusId) -> Option<FocusNode>
pub fn remove(&mut self, id: FocusId) -> Option<FocusNode>
Remove a node and all edges incident on it.
Returns the removed node, or None if not present.
Sourcepub fn connect(&mut self, from: FocusId, dir: NavDirection, to: FocusId)
pub fn connect(&mut self, from: FocusId, dir: NavDirection, to: FocusId)
Connect two nodes: navigating dir from from leads to to.
Both nodes must already exist. Silently no-ops if either is missing.
Sourcepub fn disconnect(&mut self, from: FocusId, dir: NavDirection)
pub fn disconnect(&mut self, from: FocusId, dir: NavDirection)
Disconnect an edge.
Navigate from a node in a direction.
Returns the target node ID, or None if no edge exists.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Number of nodes.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Number of edges.
Sourcepub fn tab_order(&self) -> Vec<FocusId> ⓘ
pub fn tab_order(&self) -> Vec<FocusId> ⓘ
Nodes in tab order (ascending tab_index, ties broken by ID).
Skips nodes with tab_index < 0 or !is_focusable.
Sourcepub fn group_tab_order(&self, group: u32) -> Vec<FocusId> ⓘ
pub fn group_tab_order(&self, group: u32) -> Vec<FocusId> ⓘ
Nodes in a specific group, in tab order.
Sourcepub fn find_cycle(&self, start: FocusId) -> Option<Vec<FocusId>>
pub fn find_cycle(&self, start: FocusId) -> Option<Vec<FocusId>>
Detect a cycle reachable from start following Next edges.
Returns Some(cycle) where cycle is the sequence of node IDs
forming the cycle (starting and ending at the same node), or None.
Uses tortoise-and-hare for O(V) time, O(1) extra space.
Sourcepub fn find_cycle_in_direction(
&self,
start: FocusId,
dir: NavDirection,
) -> Option<Vec<FocusId>>
pub fn find_cycle_in_direction( &self, start: FocusId, dir: NavDirection, ) -> Option<Vec<FocusId>>
Detect cycles reachable from start following any single direction.
More general than find_cycle (which only follows Next).
Sourcepub fn build_tab_chain(&mut self, wrap: bool)
pub fn build_tab_chain(&mut self, wrap: bool)
Build bidirectional Next/Prev chain from the current tab order.
Overwrites existing Next/Prev edges. If wrap is true, the
last node links back to the first (and vice versa).