mod tree_builder;
use accesskit::{Action, NodeId as AccessKitNodeId, Role, Toggled};
pub(crate) use tree_builder::{build_tree_update, dispatch_action};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct AccessibilityId(pub u64);
impl AccessibilityId {
pub fn new(id: u64) -> Self {
Self(id)
}
pub fn to_accesskit_id(self) -> AccessKitNodeId {
AccessKitNodeId(self.0)
}
pub fn from_accesskit_id(id: AccessKitNodeId) -> Self {
Self(id.0)
}
pub fn from_component_node_id(node_id: indextree::NodeId) -> Self {
let index: usize = node_id.into();
Self(index as u64)
}
}
#[derive(Debug, Clone, Default)]
pub struct AccessibilityNode {
pub role: Option<Role>,
pub label: Option<String>,
pub description: Option<String>,
pub value: Option<String>,
pub numeric_value: Option<f64>,
pub min_numeric_value: Option<f64>,
pub max_numeric_value: Option<f64>,
pub focusable: bool,
pub focused: bool,
pub toggled: Option<Toggled>,
pub disabled: bool,
pub hidden: bool,
pub actions: Vec<Action>,
pub key: Option<String>,
}
impl AccessibilityNode {
pub fn new() -> Self {
Self::default()
}
pub fn with_role(mut self, role: Role) -> Self {
self.role = Some(role);
self
}
pub fn with_label(mut self, label: impl Into<String>) -> Self {
self.label = Some(label.into());
self
}
pub fn with_description(mut self, description: impl Into<String>) -> Self {
self.description = Some(description.into());
self
}
pub fn with_value(mut self, value: impl Into<String>) -> Self {
self.value = Some(value.into());
self
}
pub fn with_numeric_value(mut self, value: f64) -> Self {
self.numeric_value = Some(value);
self
}
pub fn with_numeric_range(mut self, min: f64, max: f64) -> Self {
self.min_numeric_value = Some(min);
self.max_numeric_value = Some(max);
self
}
pub fn focusable(mut self) -> Self {
self.focusable = true;
self
}
pub fn focused(mut self) -> Self {
self.focused = true;
self
}
pub fn with_toggled(mut self, toggled: Toggled) -> Self {
self.toggled = Some(toggled);
self
}
pub fn disabled(mut self) -> Self {
self.disabled = true;
self
}
pub fn hidden(mut self) -> Self {
self.hidden = true;
self
}
pub fn with_action(mut self, action: Action) -> Self {
self.actions.push(action);
self
}
pub fn with_actions(mut self, actions: impl IntoIterator<Item = Action>) -> Self {
self.actions.extend(actions);
self
}
pub fn with_key(mut self, key: impl Into<String>) -> Self {
self.key = Some(key.into());
self
}
}
pub type AccessibilityActionHandler = Box<dyn Fn(Action) + Send + Sync>;