vizia_core/context/
access.rs1use accesskit::{Node, NodeId, Rect, TextDirection, TextSelection};
2use hashbrown::HashMap;
3
4use crate::{cache::CachedData, prelude::*, text::TextContext};
5
6pub struct AccessContext<'a> {
8 pub(crate) current: Entity,
9 pub(crate) tree: &'a Tree<Entity>,
10 pub(crate) entity_identifiers: &'a HashMap<String, Entity>,
11 pub(crate) style: &'a Style,
12 pub(crate) cache: &'a CachedData,
13 pub(crate) text_context: &'a mut TextContext,
14}
15
16impl AccessContext<'_> {
17 pub fn bounds(&self) -> BoundingBox {
19 self.cache.get_bounds(self.current)
20 }
21
22 pub fn resolve_entity_identifier(&self, identity: &str) -> Option<Entity> {
24 self.entity_identifiers.get(identity).copied()
25 }
26}
27
28#[derive(Debug)]
30pub struct AccessNode {
31 pub(crate) node_id: NodeId,
32 pub(crate) node_builder: Node,
33 pub(crate) children: Vec<AccessNode>,
34}
35
36impl AccessNode {
37 pub fn new_from_parent(parent_id: NodeId, index: usize) -> Self {
39 let mut node_id = parent_id.0 << 32;
41 node_id |= index as u64;
42 let node_id: NodeId = NodeId(node_id);
43
44 Self { node_id, node_builder: Node::default(), children: Vec::new() }
45 }
46
47 pub(crate) fn node_id(&self) -> NodeId {
49 self.node_id
50 }
51
52 pub fn add_child(&mut self, child: AccessNode) {
54 self.children.push(child);
55 }
56
57 pub fn set_role(&mut self, role: Role) {
59 self.node_builder.set_role(role);
60 }
61
62 pub fn set_text_direction(&mut self, text_direction: TextDirection) {
64 self.node_builder.set_text_direction(text_direction);
65 }
66
67 pub fn set_text_selection(&mut self, text_selection: TextSelection) {
69 self.node_builder.set_text_selection(text_selection);
70 }
71
72 pub fn set_bounds(&mut self, bounds: BoundingBox) {
74 self.node_builder.set_bounds(Rect {
75 x0: bounds.left() as f64,
76 y0: bounds.top() as f64,
77 x1: bounds.right() as f64,
78 y1: bounds.bottom() as f64,
79 });
80 }
81
82 pub fn set_value(&mut self, value: impl Into<Box<str>>) {
84 self.node_builder.set_value(value);
85 }
86
87 pub fn set_character_lengths(&mut self, character_lengths: impl Into<Box<[u8]>>) {
89 self.node_builder.set_character_lengths(character_lengths);
90 }
91
92 pub fn set_character_positions(&mut self, character_positions: impl Into<Box<[f32]>>) {
94 self.node_builder.set_character_positions(character_positions);
95 }
96
97 pub fn set_character_widths(&mut self, character_widths: impl Into<Box<[f32]>>) {
99 self.node_builder.set_character_widths(character_widths);
100 }
101
102 pub fn set_word_starts(&mut self, word_starts: impl Into<Box<[u8]>>) {
104 self.node_builder.set_word_starts(word_starts);
105 }
106
107 pub fn set_placeholder(&mut self, placeholder: impl Into<Box<str>>) {
109 self.node_builder.set_placeholder(placeholder);
110 }
111
112 pub fn set_numeric_value_step(&mut self, value: f64) {
114 self.node_builder.set_numeric_value_step(value);
115 }
116
117 pub fn set_numeric_value(&mut self, value: f64) {
119 self.node_builder.set_numeric_value(value);
120 }
121
122 pub fn set_numeric_value_jump(&mut self, value: f64) {
124 self.node_builder.set_numeric_value_jump(value);
125 }
126
127 pub fn set_min_numeric_value(&mut self, value: f64) {
129 self.node_builder.set_min_numeric_value(value);
130 }
131
132 pub fn set_max_numeric_value(&mut self, value: f64) {
134 self.node_builder.set_max_numeric_value(value);
135 }
136}