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}
88
89impl SemanticsDetails {
90 pub const NONE: Self = Self {
92 state_description: None,
93 on_click_label: None,
94 on_long_click: None,
95 on_long_click_label: None,
96 on_magic_tap: None,
97 on_magic_tap_label: None,
98 input_labels: Vec::new(),
99 language: None,
100 custom_actions: Vec::new(),
101 canvas_children: Vec::new(),
102 editable_text: false,
103 multiline: false,
104 is_modal: false,
105 selectable_group: false,
106 pane_title: None,
107 error: None,
108 hint_text: None,
109 password: false,
110 text_selection: None,
111 live_region: None,
112 progress: None,
113 set_progress: None,
114 set_text: None,
115 set_selection: None,
116 expand: None,
117 collapse: None,
118 dismiss: None,
119 vertical_scroll: None,
120 horizontal_scroll: None,
121 scroll_by: None,
122 scroll_to_index: None,
123 collection: None,
124 test_tag: None,
125 };
126
127 pub(super) fn from_configuration(
128 config: SemanticsConfiguration,
129 on_click_label: Option<String>,
130 is_modal: bool,
131 ) -> Self {
132 Self {
133 state_description: config.state_description,
134 on_click_label,
135 on_long_click: config.on_long_click,
136 on_long_click_label: config.on_long_click_label,
137 on_magic_tap: config.on_magic_tap,
138 on_magic_tap_label: config.on_magic_tap_label,
139 input_labels: config.input_labels,
140 language: config.language,
141 custom_actions: config.custom_actions,
142 canvas_children: config.canvas_children,
143 editable_text: config.is_editable_text,
144 multiline: config.multiline,
145 is_modal,
146 selectable_group: config.selectable_group,
147 pane_title: config.pane_title,
148 error: config.error,
149 hint_text: config.hint_text,
150 password: config.password,
151 text_selection: config.text_selection,
152 live_region: config.live_region,
153 progress: config.progress,
154 set_progress: config.set_progress,
155 set_text: config.set_text,
156 set_selection: config.set_selection,
157 expand: config.expand,
158 collapse: config.collapse,
159 dismiss: config.dismiss,
160 vertical_scroll: config.vertical_scroll,
161 horizontal_scroll: config.horizontal_scroll,
162 scroll_by: config.scroll_by,
163 scroll_to_index: config.scroll_to_index,
164 collection: config.collection,
165 test_tag: config.test_tag,
166 }
167 }
168}
169
170impl Default for SemanticsDetails {
171 fn default() -> Self {
172 Self::NONE
173 }
174}
175
176impl RareProperties for SemanticsDetails {
177 const EMPTY: &'static Self = &Self::NONE;
178}
179
180impl SemanticsNode {
181 pub fn details(&self) -> &SemanticsDetails {
184 rare(&self.details)
185 }
186
187 pub fn set_details(&mut self, details: SemanticsDetails) {
190 set_rare(&mut self.details, details);
191 }
192
193 pub fn update_details(&mut self, update: impl FnOnce(&mut SemanticsDetails)) {
196 update_rare(&mut self.details, update);
197 }
198}