1use cranpose_core::collections::rare::{RareProperties, rare, set_rare, update_rare};
2use cranpose_foundation::{
3 CanvasSemanticsNode, CollectionInfo, LiveRegionMode, ProgressBarRangeInfo, ScrollAxisRange,
4 SemanticsConfiguration, SemanticsCustomAction, SemanticsDismiss, SemanticsExpand,
5 SemanticsLongClick, SemanticsMagicTap, SemanticsScrollBy, SemanticsScrollToIndex,
6 SemanticsSetProgress, SemanticsSetSelection, SemanticsSetText, text::TextRange,
7};
8
9use super::SemanticsNode;
10
11#[derive(Clone, Debug, PartialEq)]
15pub struct SemanticsDetails {
16 pub state_description: Option<String>,
18 pub on_click_label: Option<String>,
20 pub on_long_click: Option<SemanticsLongClick>,
22 pub on_long_click_label: Option<String>,
24 pub on_magic_tap: Option<SemanticsMagicTap>,
26 pub on_magic_tap_label: Option<String>,
28 pub input_labels: Vec<String>,
30 pub language: Option<String>,
32 pub custom_actions: Vec<SemanticsCustomAction>,
34 pub canvas_children: Vec<CanvasSemanticsNode>,
37 pub editable_text: bool,
39 pub multiline: bool,
41 pub is_modal: bool,
43 pub selectable_group: bool,
45 pub pane_title: Option<String>,
47 pub error: Option<String>,
49 pub hint_text: Option<String>,
51 pub password: bool,
53 pub text_selection: Option<TextRange>,
56 pub live_region: Option<LiveRegionMode>,
59 pub progress: Option<ProgressBarRangeInfo>,
62 pub set_progress: Option<SemanticsSetProgress>,
64 pub set_text: Option<SemanticsSetText>,
66 pub set_selection: Option<SemanticsSetSelection>,
69 pub expand: Option<SemanticsExpand>,
71 pub collapse: Option<SemanticsExpand>,
73 pub dismiss: Option<SemanticsDismiss>,
75 pub vertical_scroll: Option<ScrollAxisRange>,
77 pub horizontal_scroll: Option<ScrollAxisRange>,
79 pub scroll_by: Option<SemanticsScrollBy>,
81 pub scroll_to_index: Option<SemanticsScrollToIndex>,
83 pub collection: Option<CollectionInfo>,
85 pub test_tag: Option<String>,
87 pub test_tags_as_resource_id: Option<bool>,
91}
92
93impl SemanticsDetails {
94 pub const NONE: Self = Self {
96 state_description: None,
97 on_click_label: None,
98 on_long_click: None,
99 on_long_click_label: None,
100 on_magic_tap: None,
101 on_magic_tap_label: None,
102 input_labels: Vec::new(),
103 language: None,
104 custom_actions: Vec::new(),
105 canvas_children: Vec::new(),
106 editable_text: false,
107 multiline: false,
108 is_modal: false,
109 selectable_group: false,
110 pane_title: None,
111 error: None,
112 hint_text: None,
113 password: false,
114 text_selection: None,
115 live_region: None,
116 progress: None,
117 set_progress: None,
118 set_text: None,
119 set_selection: None,
120 expand: None,
121 collapse: None,
122 dismiss: None,
123 vertical_scroll: None,
124 horizontal_scroll: None,
125 scroll_by: None,
126 scroll_to_index: None,
127 collection: None,
128 test_tag: None,
129 test_tags_as_resource_id: None,
130 };
131
132 pub(super) fn from_configuration(
133 config: SemanticsConfiguration,
134 on_click_label: Option<String>,
135 is_modal: bool,
136 ) -> Self {
137 Self {
138 state_description: config.state_description,
139 on_click_label,
140 on_long_click: config.on_long_click,
141 on_long_click_label: config.on_long_click_label,
142 on_magic_tap: config.on_magic_tap,
143 on_magic_tap_label: config.on_magic_tap_label,
144 input_labels: config.input_labels,
145 language: config.language,
146 custom_actions: config.custom_actions,
147 canvas_children: config.canvas_children,
148 editable_text: config.is_editable_text,
149 multiline: config.multiline,
150 is_modal,
151 selectable_group: config.selectable_group,
152 pane_title: config.pane_title,
153 error: config.error,
154 hint_text: config.hint_text,
155 password: config.password,
156 text_selection: config.text_selection,
157 live_region: config.live_region,
158 progress: config.progress,
159 set_progress: config.set_progress,
160 set_text: config.set_text,
161 set_selection: config.set_selection,
162 expand: config.expand,
163 collapse: config.collapse,
164 dismiss: config.dismiss,
165 vertical_scroll: config.vertical_scroll,
166 horizontal_scroll: config.horizontal_scroll,
167 scroll_by: config.scroll_by,
168 scroll_to_index: config.scroll_to_index,
169 collection: config.collection,
170 test_tag: config.test_tag,
171 test_tags_as_resource_id: config.test_tags_as_resource_id,
172 }
173 }
174}
175
176impl Default for SemanticsDetails {
177 fn default() -> Self {
178 Self::NONE
179 }
180}
181
182impl RareProperties for SemanticsDetails {
183 const EMPTY: &'static Self = &Self::NONE;
184}
185
186impl SemanticsNode {
187 pub fn details(&self) -> &SemanticsDetails {
190 rare(&self.details)
191 }
192
193 pub fn set_details(&mut self, details: SemanticsDetails) {
196 set_rare(&mut self.details, details);
197 }
198
199 pub fn update_details(&mut self, update: impl FnOnce(&mut SemanticsDetails)) {
202 update_rare(&mut self.details, update);
203 }
204}