1#[derive(Clone, Debug, PartialEq)]
4pub struct TextPickerTextStyleObject {
6 pub font_color: String,
7 pub font_size: f32,
8 pub font_weight: String,
9 pub font_family: String,
10 pub font_style: String,
11}
12
13impl TextPickerTextStyleObject {
14 pub fn new<C, W, F, S>(
15 font_color: C,
16 font_size: f32,
17 font_weight: W,
18 font_family: F,
19 font_style: S,
20 ) -> Self
21 where
22 C: Into<String>,
23 W: Into<String>,
24 F: Into<String>,
25 S: Into<String>,
26 {
27 Self {
28 font_color: font_color.into(),
29 font_size,
30 font_weight: font_weight.into(),
31 font_family: font_family.into(),
32 font_style: font_style.into(),
33 }
34 }
35
36 pub fn to_attribute_string(&self) -> String {
37 format!(
38 "{};{};{};{};{}",
39 self.font_color, self.font_size, self.font_weight, self.font_family, self.font_style
40 )
41 }
42
43 pub fn from_attribute_string(raw: &str) -> Option<Self> {
44 let mut parts = raw.splitn(5, ';');
45 let font_color = parts.next()?.to_string();
46 let font_size = parts.next()?.parse::<f32>().ok()?;
47 let font_weight = parts.next()?.to_string();
48 let font_family = parts.next()?.to_string();
49 let font_style = parts.next()?.to_string();
50 Some(Self {
51 font_color,
52 font_size,
53 font_weight,
54 font_family,
55 font_style,
56 })
57 }
58}
59
60impl super::TextPicker {
61 pub fn set_text_picker_disappear_text_style_object(
62 &self,
63 style: &TextPickerTextStyleObject,
64 ) -> crate::ArkUIResult<()> {
65 <Self as crate::ArkUICommonAttribute>::set_attribute(
66 self,
67 crate::ArkUINodeAttributeType::TextPickerDisappearTextStyle,
68 crate::ArkUINodeAttributeItem::String(style.to_attribute_string()),
69 )
70 }
71
72 pub fn get_text_picker_disappear_text_style_object(
73 &self,
74 ) -> crate::ArkUIResult<Option<TextPickerTextStyleObject>> {
75 match <Self as crate::ArkUICommonAttribute>::get_attribute(
76 self,
77 crate::ArkUINodeAttributeType::TextPickerDisappearTextStyle,
78 )? {
79 crate::ArkUINodeAttributeItem::String(raw) => {
80 Ok(TextPickerTextStyleObject::from_attribute_string(&raw))
81 }
82 _ => Ok(None),
83 }
84 }
85
86 pub fn set_text_picker_text_style_object(
87 &self,
88 style: &TextPickerTextStyleObject,
89 ) -> crate::ArkUIResult<()> {
90 <Self as crate::ArkUICommonAttribute>::set_attribute(
91 self,
92 crate::ArkUINodeAttributeType::TextPickerTextStyle,
93 crate::ArkUINodeAttributeItem::String(style.to_attribute_string()),
94 )
95 }
96
97 pub fn get_text_picker_text_style_object(
98 &self,
99 ) -> crate::ArkUIResult<Option<TextPickerTextStyleObject>> {
100 match <Self as crate::ArkUICommonAttribute>::get_attribute(
101 self,
102 crate::ArkUINodeAttributeType::TextPickerTextStyle,
103 )? {
104 crate::ArkUINodeAttributeItem::String(raw) => {
105 Ok(TextPickerTextStyleObject::from_attribute_string(&raw))
106 }
107 _ => Ok(None),
108 }
109 }
110
111 pub fn set_text_picker_selected_text_style_object(
112 &self,
113 style: &TextPickerTextStyleObject,
114 ) -> crate::ArkUIResult<()> {
115 <Self as crate::ArkUICommonAttribute>::set_attribute(
116 self,
117 crate::ArkUINodeAttributeType::TextPickerSelectedTextStyle,
118 crate::ArkUINodeAttributeItem::String(style.to_attribute_string()),
119 )
120 }
121
122 pub fn get_text_picker_selected_text_style_object(
123 &self,
124 ) -> crate::ArkUIResult<Option<TextPickerTextStyleObject>> {
125 match <Self as crate::ArkUICommonAttribute>::get_attribute(
126 self,
127 crate::ArkUINodeAttributeType::TextPickerSelectedTextStyle,
128 )? {
129 crate::ArkUINodeAttributeItem::String(raw) => {
130 Ok(TextPickerTextStyleObject::from_attribute_string(&raw))
131 }
132 _ => Ok(None),
133 }
134 }
135
136 #[cfg(feature = "api-19")]
137 pub fn set_text_picker_option_range_array(
138 &self,
139 range: &crate::TextPickerRangeContentArray,
140 ) -> crate::ArkUIResult<()> {
141 <Self as crate::ArkUICommonAttribute>::set_attribute(
142 self,
143 crate::ArkUINodeAttributeType::TextPickerOptionRange,
144 crate::ArkUINodeAttributeItem::Object(range.raw().cast()),
145 )
146 }
147
148 #[cfg(feature = "api-19")]
149 pub fn set_text_picker_option_range_cascade_array(
150 &self,
151 range: &crate::TextCascadePickerRangeContentArray,
152 ) -> crate::ArkUIResult<()> {
153 <Self as crate::ArkUICommonAttribute>::set_attribute(
154 self,
155 crate::ArkUINodeAttributeType::TextPickerOptionRange,
156 crate::ArkUINodeAttributeItem::Object(range.raw().cast()),
157 )
158 }
159}
160
161impl super::TextPicker {
163 pub fn set_text_picker_option_range<T: Into<crate::ArkUINodeAttributeItem>>(
164 &self,
165 value: T,
166 ) -> crate::ArkUIResult<()> {
167 <Self as crate::ArkUICommonAttribute>::set_attribute(
168 self,
169 crate::ArkUINodeAttributeType::TextPickerOptionRange,
170 value.into(),
171 )
172 }
173
174 pub fn get_text_picker_option_range(
175 &self,
176 ) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
177 <Self as crate::ArkUICommonAttribute>::get_attribute(
178 self,
179 crate::ArkUINodeAttributeType::TextPickerOptionRange,
180 )
181 }
182
183 pub fn set_text_picker_option_selected<T: Into<crate::ArkUINodeAttributeItem>>(
184 &self,
185 value: T,
186 ) -> crate::ArkUIResult<()> {
187 <Self as crate::ArkUICommonAttribute>::set_attribute(
188 self,
189 crate::ArkUINodeAttributeType::TextPickerOptionSelected,
190 value.into(),
191 )
192 }
193
194 pub fn get_text_picker_option_selected(
195 &self,
196 ) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
197 <Self as crate::ArkUICommonAttribute>::get_attribute(
198 self,
199 crate::ArkUINodeAttributeType::TextPickerOptionSelected,
200 )
201 }
202
203 pub fn set_text_picker_option_value<T: Into<crate::ArkUINodeAttributeItem>>(
204 &self,
205 value: T,
206 ) -> crate::ArkUIResult<()> {
207 <Self as crate::ArkUICommonAttribute>::set_attribute(
208 self,
209 crate::ArkUINodeAttributeType::TextPickerOptionValue,
210 value.into(),
211 )
212 }
213
214 pub fn get_text_picker_option_value(
215 &self,
216 ) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
217 <Self as crate::ArkUICommonAttribute>::get_attribute(
218 self,
219 crate::ArkUINodeAttributeType::TextPickerOptionValue,
220 )
221 }
222
223 pub fn set_text_picker_disappear_text_style<T: Into<crate::ArkUINodeAttributeItem>>(
224 &self,
225 value: T,
226 ) -> crate::ArkUIResult<()> {
227 <Self as crate::ArkUICommonAttribute>::set_attribute(
228 self,
229 crate::ArkUINodeAttributeType::TextPickerDisappearTextStyle,
230 value.into(),
231 )
232 }
233
234 pub fn get_text_picker_disappear_text_style(
235 &self,
236 ) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
237 <Self as crate::ArkUICommonAttribute>::get_attribute(
238 self,
239 crate::ArkUINodeAttributeType::TextPickerDisappearTextStyle,
240 )
241 }
242
243 pub fn set_text_picker_text_style<T: Into<crate::ArkUINodeAttributeItem>>(
244 &self,
245 value: T,
246 ) -> crate::ArkUIResult<()> {
247 <Self as crate::ArkUICommonAttribute>::set_attribute(
248 self,
249 crate::ArkUINodeAttributeType::TextPickerTextStyle,
250 value.into(),
251 )
252 }
253
254 pub fn get_text_picker_text_style(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
255 <Self as crate::ArkUICommonAttribute>::get_attribute(
256 self,
257 crate::ArkUINodeAttributeType::TextPickerTextStyle,
258 )
259 }
260
261 pub fn set_text_picker_selected_text_style<T: Into<crate::ArkUINodeAttributeItem>>(
262 &self,
263 value: T,
264 ) -> crate::ArkUIResult<()> {
265 <Self as crate::ArkUICommonAttribute>::set_attribute(
266 self,
267 crate::ArkUINodeAttributeType::TextPickerSelectedTextStyle,
268 value.into(),
269 )
270 }
271
272 pub fn get_text_picker_selected_text_style(
273 &self,
274 ) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
275 <Self as crate::ArkUICommonAttribute>::get_attribute(
276 self,
277 crate::ArkUINodeAttributeType::TextPickerSelectedTextStyle,
278 )
279 }
280
281 pub fn set_text_picker_selected_index<T: Into<crate::ArkUINodeAttributeItem>>(
282 &self,
283 value: T,
284 ) -> crate::ArkUIResult<()> {
285 <Self as crate::ArkUICommonAttribute>::set_attribute(
286 self,
287 crate::ArkUINodeAttributeType::TextPickerSelectedIndex,
288 value.into(),
289 )
290 }
291
292 pub fn get_text_picker_selected_index(
293 &self,
294 ) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
295 <Self as crate::ArkUICommonAttribute>::get_attribute(
296 self,
297 crate::ArkUINodeAttributeType::TextPickerSelectedIndex,
298 )
299 }
300
301 pub fn set_text_picker_can_loop<T: Into<crate::ArkUINodeAttributeItem>>(
302 &self,
303 value: T,
304 ) -> crate::ArkUIResult<()> {
305 <Self as crate::ArkUICommonAttribute>::set_attribute(
306 self,
307 crate::ArkUINodeAttributeType::TextPickerCanLoop,
308 value.into(),
309 )
310 }
311
312 pub fn get_text_picker_can_loop(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
313 <Self as crate::ArkUICommonAttribute>::get_attribute(
314 self,
315 crate::ArkUINodeAttributeType::TextPickerCanLoop,
316 )
317 }
318
319 pub fn set_text_picker_default_picker_item_height<T: Into<crate::ArkUINodeAttributeItem>>(
320 &self,
321 value: T,
322 ) -> crate::ArkUIResult<()> {
323 <Self as crate::ArkUICommonAttribute>::set_attribute(
324 self,
325 crate::ArkUINodeAttributeType::TextPickerDefaultPickerItemHeight,
326 value.into(),
327 )
328 }
329
330 pub fn get_text_picker_default_picker_item_height(
331 &self,
332 ) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
333 <Self as crate::ArkUICommonAttribute>::get_attribute(
334 self,
335 crate::ArkUINodeAttributeType::TextPickerDefaultPickerItemHeight,
336 )
337 }
338
339 #[cfg(feature = "api-18")]
340 pub fn set_text_picker_column_widths<T: Into<crate::ArkUINodeAttributeItem>>(
341 &self,
342 value: T,
343 ) -> crate::ArkUIResult<()> {
344 <Self as crate::ArkUICommonAttribute>::set_attribute(
345 self,
346 crate::ArkUINodeAttributeType::TextPickerColumnWidths,
347 value.into(),
348 )
349 }
350
351 #[cfg(feature = "api-18")]
352 pub fn get_text_picker_column_widths(
353 &self,
354 ) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
355 <Self as crate::ArkUICommonAttribute>::get_attribute(
356 self,
357 crate::ArkUINodeAttributeType::TextPickerColumnWidths,
358 )
359 }
360
361 #[cfg(feature = "api-18")]
362 pub fn set_text_picker_enable_haptic_feedback<T: Into<crate::ArkUINodeAttributeItem>>(
363 &self,
364 value: T,
365 ) -> crate::ArkUIResult<()> {
366 <Self as crate::ArkUICommonAttribute>::set_attribute(
367 self,
368 crate::ArkUINodeAttributeType::TextPickerEnableHapticFeedback,
369 value.into(),
370 )
371 }
372
373 #[cfg(feature = "api-18")]
374 pub fn get_text_picker_enable_haptic_feedback(
375 &self,
376 ) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
377 <Self as crate::ArkUICommonAttribute>::get_attribute(
378 self,
379 crate::ArkUINodeAttributeType::TextPickerEnableHapticFeedback,
380 )
381 }
382
383 #[cfg(feature = "api-20")]
384 pub fn set_text_picker_selected_background_style<T: Into<crate::ArkUINodeAttributeItem>>(
385 &self,
386 value: T,
387 ) -> crate::ArkUIResult<()> {
388 <Self as crate::ArkUICommonAttribute>::set_attribute(
389 self,
390 crate::ArkUINodeAttributeType::TextPickerSelectedBackgroundStyle,
391 value.into(),
392 )
393 }
394
395 #[cfg(feature = "api-20")]
396 pub fn get_text_picker_selected_background_style(
397 &self,
398 ) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
399 <Self as crate::ArkUICommonAttribute>::get_attribute(
400 self,
401 crate::ArkUINodeAttributeType::TextPickerSelectedBackgroundStyle,
402 )
403 }
404}
405impl super::TextPicker {
408 pub fn on_text_picker_change<T: Fn(Vec<i32>) + 'static>(&mut self, cb: T) {
409 crate::ArkUIEvent::on_event(
410 self,
411 crate::NodeEventType::TextPickerEventOnChange,
412 move |event| {
413 let mut values = Vec::new();
414 for i in 0..12 {
415 let Some(value) = event.i32_value(i) else {
416 break;
417 };
418 values.push(value);
419 }
420 cb(values);
421 },
422 );
423 }
424
425 #[cfg(feature = "api-14")]
426 pub fn on_text_picker_scroll_stop<T: Fn(Vec<i32>) + 'static>(&mut self, cb: T) {
427 crate::ArkUIEvent::on_event(
428 self,
429 crate::NodeEventType::TextPickerEventOnScrollStop,
430 move |event| {
431 let mut values = Vec::new();
432 for i in 0..12 {
433 let Some(value) = event.i32_value(i) else {
434 break;
435 };
436 values.push(value);
437 }
438 cb(values);
439 },
440 );
441 }
442}