vizia_core/context/
access.rs1use accesskit::{Node, NodeId, Rect, TextDirection, TextSelection};
2
3use crate::{cache::CachedData, prelude::*, text::TextContext};
4
5pub struct AccessContext<'a> {
7 pub(crate) current: Entity,
8 pub(crate) tree: &'a Tree<Entity>,
9 pub(crate) style: &'a Style,
10 pub(crate) cache: &'a CachedData,
11 pub(crate) text_context: &'a mut TextContext,
12}
13
14impl AccessContext<'_> {
15 pub fn bounds(&self) -> BoundingBox {
17 self.cache.get_bounds(self.current)
18 }
19}
20
21#[derive(Debug)]
23pub struct AccessNode {
24 pub(crate) node_id: NodeId,
25 pub(crate) node_builder: Node,
26 pub(crate) children: Vec<AccessNode>,
27}
28
29impl AccessNode {
30 pub fn new_from_parent(parent_id: NodeId, index: usize) -> Self {
32 let mut node_id = parent_id.0 << 32;
34 node_id |= index as u64;
35 let node_id: NodeId = NodeId(node_id);
36
37 Self { node_id, node_builder: Node::default(), children: Vec::new() }
38 }
39
40 pub(crate) fn node_id(&self) -> NodeId {
42 self.node_id
43 }
44
45 pub fn add_child(&mut self, child: AccessNode) {
47 self.children.push(child);
48 }
49
50 pub fn set_role(&mut self, role: Role) {
52 self.node_builder.set_role(role);
53 }
54
55 pub fn set_text_direction(&mut self, text_direction: TextDirection) {
57 self.node_builder.set_text_direction(text_direction);
58 }
59
60 pub fn set_text_selection(&mut self, text_selection: TextSelection) {
62 self.node_builder.set_text_selection(text_selection);
63 }
64
65 pub fn set_bounds(&mut self, bounds: BoundingBox) {
67 self.node_builder.set_bounds(Rect {
68 x0: bounds.left() as f64,
69 y0: bounds.top() as f64,
70 x1: bounds.right() as f64,
71 y1: bounds.bottom() as f64,
72 });
73 }
74
75 pub fn set_value(&mut self, value: impl Into<Box<str>>) {
77 self.node_builder.set_value(value);
78 }
79
80 pub fn set_character_lengths(&mut self, character_lengths: impl Into<Box<[u8]>>) {
82 self.node_builder.set_character_lengths(character_lengths);
83 }
84
85 pub fn set_character_positions(&mut self, character_positions: impl Into<Box<[f32]>>) {
87 self.node_builder.set_character_positions(character_positions);
88 }
89
90 pub fn set_character_widths(&mut self, character_widths: impl Into<Box<[f32]>>) {
92 self.node_builder.set_character_widths(character_widths);
93 }
94
95 pub fn set_word_lengths(&mut self, word_lengths: impl Into<Box<[u8]>>) {
97 self.node_builder.set_word_lengths(word_lengths);
98 }
99
100 pub fn set_numeric_value_step(&mut self, value: f64) {
102 self.node_builder.set_numeric_value_step(value);
103 }
104
105 pub fn set_numeric_value(&mut self, value: f64) {
107 self.node_builder.set_numeric_value(value);
108 }
109
110 pub fn set_numeric_value_jump(&mut self, value: f64) {
112 self.node_builder.set_numeric_value_jump(value);
113 }
114
115 pub fn set_min_numeric_value(&mut self, value: f64) {
117 self.node_builder.set_min_numeric_value(value);
118 }
119
120 pub fn set_max_numeric_value(&mut self, value: f64) {
122 self.node_builder.set_max_numeric_value(value);
123 }
124}