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