Skip to main content

Accessible

Trait Accessible 

Source
pub trait Accessible {
    // Required method
    fn accessibility_nodes(&self, area: Rect) -> Vec<A11yNodeInfo>;
}
Expand description

Trait for widgets that provide accessibility metadata.

Implementing this trait is opt-in. Widgets that do not implement it are invisible to screen readers (treated as presentational / decorative).

§Contract

  • accessibility_nodes must return at least one node for the widget.
  • The first node in the returned Vec is the widget’s “primary” node; additional nodes represent internal structure (e.g. a table widget returns the table node plus row/cell nodes).
  • Node IDs must be unique within a single render pass. Use a deterministic scheme (e.g. widget identity hash) to keep IDs stable across frames for efficient diffing.
  • area is the bounding rectangle the widget was laid out into.

§Example

use ftui_core::geometry::Rect;
use ftui_a11y::Accessible;
use ftui_a11y::node::{A11yNodeInfo, A11yRole};

struct MyButton {
    label: String,
    id: u64,
}

impl Accessible for MyButton {
    fn accessibility_nodes(&self, area: Rect) -> Vec<A11yNodeInfo> {
        vec![
            A11yNodeInfo::new(self.id, A11yRole::Button, area)
                .with_name(&self.label)
        ]
    }
}

Required Methods§

Source

fn accessibility_nodes(&self, area: Rect) -> Vec<A11yNodeInfo>

Return accessibility node(s) for this widget at the given bounds.

Container widgets should return a parent node with children IDs, plus the child nodes themselves.

Implementors§