use crate::accessibility::AccessibilityProvider;
use accesskit::{Node, NodeClassSet, NodeId as AccessibilityId};
use std::{
num::NonZeroU128,
sync::{Arc, Mutex},
};
pub type SharedAccessibilityState = Arc<Mutex<AccessibilityState>>;
pub const ROOT_ID: AccessibilityId = AccessibilityId(unsafe { NonZeroU128::new_unchecked(1) });
#[derive(Default)]
pub struct AccessibilityState {
pub nodes: Vec<(AccessibilityId, Node)>,
pub node_classes: NodeClassSet,
pub focus: Option<AccessibilityId>,
}
impl AccessibilityState {
pub fn new() -> Self {
Self::default()
}
pub fn wrap(self) -> SharedAccessibilityState {
Arc::new(Mutex::new(self))
}
pub fn clear(&mut self) {
self.nodes.clear();
}
}
impl AccessibilityProvider for AccessibilityState {
fn node_classes(&mut self) -> &mut NodeClassSet {
&mut self.node_classes
}
fn nodes(&self) -> std::slice::Iter<(AccessibilityId, Node)> {
self.nodes.iter()
}
fn focus_id(&self) -> Option<AccessibilityId> {
self.focus
}
fn set_focus(&mut self, new_focus_id: Option<AccessibilityId>) {
self.focus = new_focus_id;
}
fn push_node(&mut self, id: AccessibilityId, node: Node) {
self.nodes.push((id, node))
}
}