Skip to main content

FocusGraph

Struct FocusGraph 

Source
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

Source

pub fn new() -> Self

Create an empty graph.

Source

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.

Source

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.

Source

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.

Source

pub fn disconnect(&mut self, from: FocusId, dir: NavDirection)

Disconnect an edge.

Source

pub fn navigate(&self, from: FocusId, dir: NavDirection) -> Option<FocusId>

Navigate from a node in a direction.

Returns the target node ID, or None if no edge exists.

Source

pub fn get(&self, id: FocusId) -> Option<&FocusNode>

Look up a node by ID.

Source

pub fn node_count(&self) -> usize

Number of nodes.

Source

pub fn edge_count(&self) -> usize

Number of edges.

Source

pub fn is_empty(&self) -> bool

Whether the graph is empty (no nodes).

Source

pub fn node_ids(&self) -> impl Iterator<Item = FocusId> + '_

All node IDs.

Source

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.

Source

pub fn group_tab_order(&self, group: u32) -> Vec<FocusId>

Nodes in a specific group, in tab order.

Source

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.

Source

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).

Source

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).

Source

pub fn clear(&mut self)

Clear all nodes and edges.

Trait Implementations§

Source§

impl Debug for FocusGraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FocusGraph

Source§

fn default() -> FocusGraph

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more