use accesskit::{NodeBuilder, NodeId, Rect, TextDirection, TextSelection};
use crate::{cache::CachedData, prelude::*, text::TextContext};
pub struct AccessContext<'a> {
pub(crate) current: Entity,
pub(crate) tree: &'a Tree<Entity>,
pub(crate) style: &'a Style,
pub(crate) cache: &'a CachedData,
pub(crate) text_context: &'a mut TextContext,
}
impl<'a> AccessContext<'a> {
pub fn bounds(&self) -> BoundingBox {
self.cache.get_bounds(self.current)
}
}
#[derive(Debug)]
pub struct AccessNode {
pub(crate) node_id: NodeId,
pub(crate) node_builder: NodeBuilder,
pub(crate) children: Vec<AccessNode>,
}
impl AccessNode {
pub fn new_from_parent(parent_id: NodeId, index: usize) -> Self {
let mut node_id = parent_id.0 << 32;
node_id |= index as u64;
let node_id: NodeId = NodeId(node_id);
Self { node_id, node_builder: NodeBuilder::default(), children: Vec::new() }
}
pub(crate) fn node_id(&self) -> NodeId {
self.node_id
}
pub fn add_child(&mut self, child: AccessNode) {
self.children.push(child);
}
pub fn set_role(&mut self, role: Role) {
self.node_builder.set_role(role);
}
pub fn set_text_direction(&mut self, text_direction: TextDirection) {
self.node_builder.set_text_direction(text_direction);
}
pub fn set_text_selection(&mut self, text_selection: TextSelection) {
self.node_builder.set_text_selection(text_selection);
}
pub fn set_bounds(&mut self, bounds: BoundingBox) {
self.node_builder.set_bounds(Rect {
x0: bounds.left() as f64,
y0: bounds.top() as f64,
x1: bounds.right() as f64,
y1: bounds.bottom() as f64,
});
}
pub fn set_value(&mut self, value: impl Into<Box<str>>) {
self.node_builder.set_value(value);
}
pub fn set_character_lengths(&mut self, character_lengths: impl Into<Box<[u8]>>) {
self.node_builder.set_character_lengths(character_lengths);
}
pub fn set_character_positions(&mut self, character_positions: impl Into<Box<[f32]>>) {
self.node_builder.set_character_positions(character_positions);
}
pub fn set_character_widths(&mut self, character_widths: impl Into<Box<[f32]>>) {
self.node_builder.set_character_widths(character_widths);
}
pub fn set_word_lengths(&mut self, word_lengths: impl Into<Box<[u8]>>) {
self.node_builder.set_word_lengths(word_lengths);
}
pub fn set_numeric_value_step(&mut self, value: f64) {
self.node_builder.set_numeric_value_step(value);
}
pub fn set_numeric_value(&mut self, value: f64) {
self.node_builder.set_numeric_value(value);
}
pub fn set_numeric_value_jump(&mut self, value: f64) {
self.node_builder.set_numeric_value_jump(value);
}
pub fn set_min_numeric_value(&mut self, value: f64) {
self.node_builder.set_min_numeric_value(value);
}
pub fn set_max_numeric_value(&mut self, value: f64) {
self.node_builder.set_max_numeric_value(value);
}
}