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 password: bool,
51 pub text_selection: Option<TextRange>,
54 pub live_region: Option<LiveRegionMode>,
57 pub progress: Option<ProgressBarRangeInfo>,
60 pub set_progress: Option<SemanticsSetProgress>,
62 pub set_text: Option<SemanticsSetText>,
64 pub set_selection: Option<SemanticsSetSelection>,
67 pub expand: Option<SemanticsExpand>,
69 pub collapse: Option<SemanticsExpand>,
71 pub dismiss: Option<SemanticsDismiss>,
73 pub vertical_scroll: Option<ScrollAxisRange>,
75 pub horizontal_scroll: Option<ScrollAxisRange>,
77 pub scroll_by: Option<SemanticsScrollBy>,
79 pub scroll_to_index: Option<SemanticsScrollToIndex>,
81 pub collection: Option<CollectionInfo>,
83 pub test_tag: Option<String>,
85}
86
87impl SemanticsDetails {
88 pub const NONE: Self = Self {
90 state_description: None,
91 on_click_label: None,
92 on_long_click: None,
93 on_long_click_label: None,
94 on_magic_tap: None,
95 on_magic_tap_label: None,
96 input_labels: Vec::new(),
97 language: None,
98 custom_actions: Vec::new(),
99 canvas_children: Vec::new(),
100 editable_text: false,
101 multiline: false,
102 is_modal: false,
103 selectable_group: false,
104 pane_title: None,
105 error: None,
106 password: false,
107 text_selection: None,
108 live_region: None,
109 progress: None,
110 set_progress: None,
111 set_text: None,
112 set_selection: None,
113 expand: None,
114 collapse: None,
115 dismiss: None,
116 vertical_scroll: None,
117 horizontal_scroll: None,
118 scroll_by: None,
119 scroll_to_index: None,
120 collection: None,
121 test_tag: None,
122 };
123
124 pub(super) fn from_configuration(
125 config: SemanticsConfiguration,
126 on_click_label: Option<String>,
127 is_modal: bool,
128 ) -> Self {
129 Self {
130 state_description: config.state_description,
131 on_click_label,
132 on_long_click: config.on_long_click,
133 on_long_click_label: config.on_long_click_label,
134 on_magic_tap: config.on_magic_tap,
135 on_magic_tap_label: config.on_magic_tap_label,
136 input_labels: config.input_labels,
137 language: config.language,
138 custom_actions: config.custom_actions,
139 canvas_children: config.canvas_children,
140 editable_text: config.is_editable_text,
141 multiline: config.multiline,
142 is_modal,
143 selectable_group: config.selectable_group,
144 pane_title: config.pane_title,
145 error: config.error,
146 password: config.password,
147 text_selection: config.text_selection,
148 live_region: config.live_region,
149 progress: config.progress,
150 set_progress: config.set_progress,
151 set_text: config.set_text,
152 set_selection: config.set_selection,
153 expand: config.expand,
154 collapse: config.collapse,
155 dismiss: config.dismiss,
156 vertical_scroll: config.vertical_scroll,
157 horizontal_scroll: config.horizontal_scroll,
158 scroll_by: config.scroll_by,
159 scroll_to_index: config.scroll_to_index,
160 collection: config.collection,
161 test_tag: config.test_tag,
162 }
163 }
164}
165
166impl Default for SemanticsDetails {
167 fn default() -> Self {
168 Self::NONE
169 }
170}
171
172impl RareProperties for SemanticsDetails {
173 const EMPTY: &'static Self = &Self::NONE;
174}
175
176impl SemanticsNode {
177 pub fn details(&self) -> &SemanticsDetails {
180 rare(&self.details)
181 }
182
183 pub fn set_details(&mut self, details: SemanticsDetails) {
186 set_rare(&mut self.details, details);
187 }
188
189 pub fn update_details(&mut self, update: impl FnOnce(&mut SemanticsDetails)) {
192 update_rare(&mut self.details, update);
193 }
194}