1use std::{
4 collections::HashMap,
5 ffi::{CStr, CString},
6 os::raw::{c_char, c_void},
7 ptr::NonNull,
8};
9
10use ohos_arkui_input_binding::ArkUIErrorCode;
11use ohos_arkui_sys::*;
12
13use crate::check_arkui_status;
14use crate::{ArkUIError, ArkUIResult};
15
16pub(in crate::api::attribute_option) fn non_null_or_panic<T>(
17 ptr: *mut T,
18 name: &'static str,
19) -> NonNull<T> {
20 NonNull::new(ptr).unwrap_or_else(|| panic!("{name} pointer is null"))
21}
22
23pub(in crate::api::attribute_option) fn c_char_ptr_to_string(ptr: *const c_char) -> Option<String> {
24 if ptr.is_null() {
25 None
26 } else {
27 Some(unsafe { CStr::from_ptr(ptr).to_string_lossy().into_owned() })
28 }
29}
30
31pub(in crate::api::attribute_option) fn with_optional_cstring<F>(
32 value: Option<&str>,
33 f: F,
34) -> ArkUIResult<()>
35where
36 F: FnOnce(*const c_char),
37{
38 let owned = if let Some(v) = value {
39 Some(CString::new(v).map_err(|_| {
40 ArkUIError::new(
41 ArkUIErrorCode::ParamInvalid,
42 "string contains interior NUL bytes",
43 )
44 })?)
45 } else {
46 None
47 };
48 let ptr = owned
49 .as_ref()
50 .map_or(std::ptr::null::<c_char>(), |v| v.as_ptr());
51 f(ptr);
52 Ok(())
53}
54
55pub(in crate::api::attribute_option) fn with_cstring<F>(value: &str, f: F) -> ArkUIResult<()>
56where
57 F: FnOnce(*const c_char),
58{
59 let value = CString::new(value).map_err(|_| {
60 ArkUIError::new(
61 ArkUIErrorCode::ParamInvalid,
62 "string contains interior NUL bytes",
63 )
64 })?;
65 f(value.as_ptr());
66 Ok(())
67}
68
69#[derive(Clone, Copy, Debug, Default, PartialEq)]
70pub struct Margin {
72 pub top: f32,
73 pub right: f32,
74 pub bottom: f32,
75 pub left: f32,
76}
77
78impl From<ArkUI_Margin> for Margin {
79 fn from(value: ArkUI_Margin) -> Self {
80 Self {
81 top: value.top,
82 right: value.right,
83 bottom: value.bottom,
84 left: value.left,
85 }
86 }
87}
88
89impl From<Margin> for ArkUI_Margin {
90 fn from(value: Margin) -> Self {
91 Self {
92 top: value.top,
93 right: value.right,
94 bottom: value.bottom,
95 left: value.left,
96 }
97 }
98}
99
100pub struct LayoutConstraint {
102 raw: NonNull<ArkUI_LayoutConstraint>,
103}
104
105impl LayoutConstraint {
106 pub fn new() -> ArkUIResult<Self> {
107 let constraint = unsafe { OH_ArkUI_LayoutConstraint_Create() };
108 NonNull::new(constraint)
109 .map(|raw| Self::from_raw(raw.as_ptr()))
110 .ok_or_else(|| {
111 ArkUIError::new(
112 ArkUIErrorCode::ParamInvalid,
113 "OH_ArkUI_LayoutConstraint_Create returned null",
114 )
115 })
116 }
117
118 pub fn copy(&self) -> ArkUIResult<Self> {
119 let copied = unsafe { OH_ArkUI_LayoutConstraint_Copy(self.raw()) };
120 NonNull::new(copied)
121 .map(|raw| Self::from_raw(raw.as_ptr()))
122 .ok_or_else(|| {
123 ArkUIError::new(
124 ArkUIErrorCode::ParamInvalid,
125 "OH_ArkUI_LayoutConstraint_Copy returned null",
126 )
127 })
128 }
129
130 pub(crate) fn raw(&self) -> *mut ArkUI_LayoutConstraint {
131 self.raw.as_ptr()
132 }
133
134 pub(crate) fn from_raw(raw: *mut ArkUI_LayoutConstraint) -> Self {
135 Self {
136 raw: non_null_or_panic(raw, "ArkUI_LayoutConstraint"),
137 }
138 }
139
140 pub(crate) fn into_raw(self) -> *mut ArkUI_LayoutConstraint {
141 self.raw.as_ptr()
142 }
143
144 pub fn dispose(self) {
145 let _ = unsafe { OH_ArkUI_LayoutConstraint_Dispose(self.raw()) };
146 }
147
148 pub fn get_max_width(&self) -> i32 {
149 unsafe { OH_ArkUI_LayoutConstraint_GetMaxWidth(self.raw()) }
150 }
151
152 pub fn get_min_width(&self) -> i32 {
153 unsafe { OH_ArkUI_LayoutConstraint_GetMinWidth(self.raw()) }
154 }
155
156 pub fn get_max_height(&self) -> i32 {
157 unsafe { OH_ArkUI_LayoutConstraint_GetMaxHeight(self.raw()) }
158 }
159
160 pub fn get_min_height(&self) -> i32 {
161 unsafe { OH_ArkUI_LayoutConstraint_GetMinHeight(self.raw()) }
162 }
163
164 pub fn get_percent_reference_width(&self) -> i32 {
165 unsafe { OH_ArkUI_LayoutConstraint_GetPercentReferenceWidth(self.raw()) }
166 }
167
168 pub fn get_percent_reference_height(&self) -> i32 {
169 unsafe { OH_ArkUI_LayoutConstraint_GetPercentReferenceHeight(self.raw()) }
170 }
171
172 pub fn set_max_width(&mut self, value: i32) {
173 unsafe { OH_ArkUI_LayoutConstraint_SetMaxWidth(self.raw(), value) }
174 }
175
176 pub fn set_min_width(&mut self, value: i32) {
177 unsafe { OH_ArkUI_LayoutConstraint_SetMinWidth(self.raw(), value) }
178 }
179
180 pub fn set_max_height(&mut self, value: i32) {
181 unsafe { OH_ArkUI_LayoutConstraint_SetMaxHeight(self.raw(), value) }
182 }
183
184 pub fn set_min_height(&mut self, value: i32) {
185 unsafe { OH_ArkUI_LayoutConstraint_SetMinHeight(self.raw(), value) }
186 }
187
188 pub fn set_percent_reference_width(&mut self, value: i32) {
189 unsafe { OH_ArkUI_LayoutConstraint_SetPercentReferenceWidth(self.raw(), value) }
190 }
191
192 pub fn set_percent_reference_height(&mut self, value: i32) {
193 unsafe { OH_ArkUI_LayoutConstraint_SetPercentReferenceHeight(self.raw(), value) }
194 }
195}
196
197pub struct AlignmentRuleOption {
199 raw: NonNull<ArkUI_AlignmentRuleOption>,
200}
201
202impl AlignmentRuleOption {
203 pub fn new() -> ArkUIResult<Self> {
204 let option = unsafe { OH_ArkUI_AlignmentRuleOption_Create() };
205 NonNull::new(option)
206 .map(|raw| Self::from_raw(raw.as_ptr()))
207 .ok_or_else(|| {
208 ArkUIError::new(
209 ArkUIErrorCode::ParamInvalid,
210 "OH_ArkUI_AlignmentRuleOption_Create returned null",
211 )
212 })
213 }
214
215 pub(crate) fn raw(&self) -> *mut ArkUI_AlignmentRuleOption {
216 self.raw.as_ptr()
217 }
218
219 pub(crate) fn from_raw(raw: *mut ArkUI_AlignmentRuleOption) -> Self {
220 Self {
221 raw: non_null_or_panic(raw, "ArkUI_AlignmentRuleOption"),
222 }
223 }
224
225 pub(crate) fn into_raw(self) -> *mut ArkUI_AlignmentRuleOption {
226 self.raw.as_ptr()
227 }
228
229 pub fn dispose(self) {
230 unsafe { OH_ArkUI_AlignmentRuleOption_Dispose(self.raw()) }
231 }
232
233 pub fn set_start(
234 &mut self,
235 id: Option<&str>,
236 alignment: crate::HorizontalAlignment,
237 ) -> ArkUIResult<()> {
238 with_optional_cstring(id, |id_ptr| unsafe {
239 OH_ArkUI_AlignmentRuleOption_SetStart(self.raw(), id_ptr, alignment.into())
240 })
241 }
242
243 pub fn set_end(
244 &mut self,
245 id: Option<&str>,
246 alignment: crate::HorizontalAlignment,
247 ) -> ArkUIResult<()> {
248 with_optional_cstring(id, |id_ptr| unsafe {
249 OH_ArkUI_AlignmentRuleOption_SetEnd(self.raw(), id_ptr, alignment.into())
250 })
251 }
252
253 pub fn set_center_horizontal(
254 &mut self,
255 id: Option<&str>,
256 alignment: crate::HorizontalAlignment,
257 ) -> ArkUIResult<()> {
258 with_optional_cstring(id, |id_ptr| unsafe {
259 OH_ArkUI_AlignmentRuleOption_SetCenterHorizontal(self.raw(), id_ptr, alignment.into())
260 })
261 }
262
263 pub fn set_top(
264 &mut self,
265 id: Option<&str>,
266 alignment: crate::VerticalAlignment,
267 ) -> ArkUIResult<()> {
268 with_optional_cstring(id, |id_ptr| unsafe {
269 OH_ArkUI_AlignmentRuleOption_SetTop(self.raw(), id_ptr, alignment.into())
270 })
271 }
272
273 pub fn set_bottom(
274 &mut self,
275 id: Option<&str>,
276 alignment: crate::VerticalAlignment,
277 ) -> ArkUIResult<()> {
278 with_optional_cstring(id, |id_ptr| unsafe {
279 OH_ArkUI_AlignmentRuleOption_SetBottom(self.raw(), id_ptr, alignment.into())
280 })
281 }
282
283 pub fn set_center_vertical(
284 &mut self,
285 id: Option<&str>,
286 alignment: crate::VerticalAlignment,
287 ) -> ArkUIResult<()> {
288 with_optional_cstring(id, |id_ptr| unsafe {
289 OH_ArkUI_AlignmentRuleOption_SetCenterVertical(self.raw(), id_ptr, alignment.into())
290 })
291 }
292
293 pub fn set_bias_horizontal(&mut self, bias: f32) {
294 unsafe { OH_ArkUI_AlignmentRuleOption_SetBiasHorizontal(self.raw(), bias) }
295 }
296
297 pub fn set_bias_vertical(&mut self, bias: f32) {
298 unsafe { OH_ArkUI_AlignmentRuleOption_SetBiasVertical(self.raw(), bias) }
299 }
300
301 pub fn get_start_id(&self) -> Option<String> {
302 c_char_ptr_to_string(unsafe { OH_ArkUI_AlignmentRuleOption_GetStartId(self.raw()) })
303 }
304
305 pub fn get_start_alignment(&self) -> crate::HorizontalAlignment {
306 unsafe { OH_ArkUI_AlignmentRuleOption_GetStartAlignment(self.raw()).into() }
307 }
308
309 pub fn get_end_id(&self) -> Option<String> {
310 c_char_ptr_to_string(unsafe { OH_ArkUI_AlignmentRuleOption_GetEndId(self.raw()) })
311 }
312
313 pub fn get_end_alignment(&self) -> crate::HorizontalAlignment {
314 unsafe { OH_ArkUI_AlignmentRuleOption_GetEndAlignment(self.raw()).into() }
315 }
316
317 pub fn get_center_id_horizontal(&self) -> Option<String> {
318 c_char_ptr_to_string(unsafe {
319 OH_ArkUI_AlignmentRuleOption_GetCenterIdHorizontal(self.raw())
320 })
321 }
322
323 pub fn get_center_alignment_horizontal(&self) -> crate::HorizontalAlignment {
324 unsafe { OH_ArkUI_AlignmentRuleOption_GetCenterAlignmentHorizontal(self.raw()).into() }
325 }
326
327 pub fn get_top_id(&self) -> Option<String> {
328 c_char_ptr_to_string(unsafe { OH_ArkUI_AlignmentRuleOption_GetTopId(self.raw()) })
329 }
330
331 pub fn get_top_alignment(&self) -> crate::VerticalAlignment {
332 unsafe { OH_ArkUI_AlignmentRuleOption_GetTopAlignment(self.raw()).into() }
333 }
334
335 pub fn get_bottom_id(&self) -> Option<String> {
336 c_char_ptr_to_string(unsafe { OH_ArkUI_AlignmentRuleOption_GetBottomId(self.raw()) })
337 }
338
339 pub fn get_bottom_alignment(&self) -> crate::VerticalAlignment {
340 unsafe { OH_ArkUI_AlignmentRuleOption_GetBottomAlignment(self.raw()).into() }
341 }
342
343 pub fn get_center_id_vertical(&self) -> Option<String> {
344 c_char_ptr_to_string(unsafe {
345 OH_ArkUI_AlignmentRuleOption_GetCenterIdVertical(self.raw())
346 })
347 }
348
349 pub fn get_center_alignment_vertical(&self) -> crate::VerticalAlignment {
350 unsafe { OH_ArkUI_AlignmentRuleOption_GetCenterAlignmentVertical(self.raw()).into() }
351 }
352
353 pub fn get_bias_horizontal(&self) -> f32 {
354 unsafe { OH_ArkUI_AlignmentRuleOption_GetBiasHorizontal(self.raw()) }
355 }
356
357 pub fn get_bias_vertical(&self) -> f32 {
358 unsafe { OH_ArkUI_AlignmentRuleOption_GetBiasVertical(self.raw()) }
359 }
360}
361
362pub struct AccessibilityValue {
364 raw: NonNull<ArkUI_AccessibilityValue>,
365}
366
367impl AccessibilityValue {
368 pub fn new() -> ArkUIResult<Self> {
369 let value = unsafe { OH_ArkUI_AccessibilityValue_Create() };
370 NonNull::new(value)
371 .map(|raw| Self::from_raw(raw.as_ptr()))
372 .ok_or_else(|| {
373 ArkUIError::new(
374 ArkUIErrorCode::ParamInvalid,
375 "OH_ArkUI_AccessibilityValue_Create returned null",
376 )
377 })
378 }
379
380 pub(crate) fn raw(&self) -> *mut ArkUI_AccessibilityValue {
381 self.raw.as_ptr()
382 }
383
384 pub(crate) fn from_raw(raw: *mut ArkUI_AccessibilityValue) -> Self {
385 Self {
386 raw: non_null_or_panic(raw, "ArkUI_AccessibilityValue"),
387 }
388 }
389
390 pub(crate) fn into_raw(self) -> *mut ArkUI_AccessibilityValue {
391 self.raw.as_ptr()
392 }
393
394 pub fn dispose(self) {
395 unsafe { OH_ArkUI_AccessibilityValue_Dispose(self.raw()) }
396 }
397
398 pub fn set_min(&mut self, min: i32) {
399 unsafe { OH_ArkUI_AccessibilityValue_SetMin(self.raw(), min) }
400 }
401
402 pub fn get_min(&self) -> i32 {
403 unsafe { OH_ArkUI_AccessibilityValue_GetMin(self.raw()) }
404 }
405
406 pub fn set_max(&mut self, max: i32) {
407 unsafe { OH_ArkUI_AccessibilityValue_SetMax(self.raw(), max) }
408 }
409
410 pub fn get_max(&self) -> i32 {
411 unsafe { OH_ArkUI_AccessibilityValue_GetMax(self.raw()) }
412 }
413
414 pub fn set_current(&mut self, current: i32) {
415 unsafe { OH_ArkUI_AccessibilityValue_SetCurrent(self.raw(), current) }
416 }
417
418 pub fn get_current(&self) -> i32 {
419 unsafe { OH_ArkUI_AccessibilityValue_GetCurrent(self.raw()) }
420 }
421
422 #[cfg(feature = "api-18")]
423 pub fn set_range_min(&mut self, range_min: i32) {
424 unsafe { OH_ArkUI_AccessibilityValue_SetRangeMin(self.raw(), range_min) }
425 }
426
427 #[cfg(feature = "api-18")]
428 pub fn get_range_min(&self) -> i32 {
429 unsafe { OH_ArkUI_AccessibilityValue_GetRangeMin(self.raw()) }
430 }
431
432 #[cfg(feature = "api-18")]
433 pub fn set_range_max(&mut self, range_max: i32) {
434 unsafe { OH_ArkUI_AccessibilityValue_SetRangeMax(self.raw(), range_max) }
435 }
436
437 #[cfg(feature = "api-18")]
438 pub fn get_range_max(&self) -> i32 {
439 unsafe { OH_ArkUI_AccessibilityValue_GetRangeMax(self.raw()) }
440 }
441
442 #[cfg(feature = "api-18")]
443 pub fn set_range_current(&mut self, range_current: i32) {
444 unsafe { OH_ArkUI_AccessibilityValue_SetRangeCurrent(self.raw(), range_current) }
445 }
446
447 #[cfg(feature = "api-18")]
448 pub fn get_range_current(&self) -> i32 {
449 unsafe { OH_ArkUI_AccessibilityValue_GetRangeCurrent(self.raw()) }
450 }
451
452 pub fn set_text(&mut self, text: &str) -> ArkUIResult<()> {
453 with_cstring(text, |text_ptr| unsafe {
454 OH_ArkUI_AccessibilityValue_SetText(self.raw(), text_ptr)
455 })
456 }
457
458 pub fn get_text(&self) -> Option<String> {
459 c_char_ptr_to_string(unsafe { OH_ArkUI_AccessibilityValue_GetText(self.raw()) })
460 }
461}
462
463struct WaterFlowMainSizeCallbackContext {
464 callback: Box<dyn Fn(i32) -> f32>,
465}
466
467pub struct WaterFlowSectionOption {
469 raw: NonNull<ArkUI_WaterFlowSectionOption>,
470 main_size_callbacks: HashMap<i32, *mut WaterFlowMainSizeCallbackContext>,
471}
472
473impl WaterFlowSectionOption {
474 pub fn new() -> ArkUIResult<Self> {
475 let option = unsafe { OH_ArkUI_WaterFlowSectionOption_Create() };
476 NonNull::new(option)
477 .map(|raw| Self::from_raw(raw.as_ptr()))
478 .ok_or_else(|| {
479 ArkUIError::new(
480 ArkUIErrorCode::ParamInvalid,
481 "OH_ArkUI_WaterFlowSectionOption_Create returned null",
482 )
483 })
484 }
485
486 pub(crate) fn raw(&self) -> *mut ArkUI_WaterFlowSectionOption {
487 self.raw.as_ptr()
488 }
489
490 pub(crate) fn from_raw(raw: *mut ArkUI_WaterFlowSectionOption) -> Self {
491 Self {
492 raw: non_null_or_panic(raw, "ArkUI_WaterFlowSectionOption"),
493 main_size_callbacks: HashMap::new(),
494 }
495 }
496
497 pub(crate) fn into_raw(self) -> *mut ArkUI_WaterFlowSectionOption {
498 self.raw.as_ptr()
499 }
500
501 pub fn dispose(mut self) {
502 self.clear_get_item_main_size_callback_by_index_all();
503 unsafe { OH_ArkUI_WaterFlowSectionOption_Dispose(self.raw()) }
504 }
505
506 pub fn set_size(&mut self, size: i32) {
507 unsafe { OH_ArkUI_WaterFlowSectionOption_SetSize(self.raw(), size) }
508 }
509
510 pub fn get_size(&self) -> i32 {
511 unsafe { OH_ArkUI_WaterFlowSectionOption_GetSize(self.raw()) }
512 }
513
514 pub fn set_item_count(&mut self, index: i32, item_count: i32) {
515 unsafe { OH_ArkUI_WaterFlowSectionOption_SetItemCount(self.raw(), index, item_count) }
516 }
517
518 pub fn get_item_count(&self, index: i32) -> i32 {
519 unsafe { OH_ArkUI_WaterFlowSectionOption_GetItemCount(self.raw(), index) }
520 }
521
522 pub fn register_get_item_main_size_callback_by_index<T: Fn(i32) -> f32 + 'static>(
523 &mut self,
524 index: i32,
525 callback: T,
526 ) {
527 self.clear_get_item_main_size_callback_by_index(index);
528 let callback = Box::into_raw(Box::new(WaterFlowMainSizeCallbackContext {
529 callback: Box::new(callback),
530 }));
531 unsafe {
532 OH_ArkUI_WaterFlowSectionOption_RegisterGetItemMainSizeCallbackByIndexWithUserData(
533 self.raw(),
534 index,
535 callback.cast(),
536 Some(water_flow_main_size_callback_trampoline),
537 );
538 }
539 self.main_size_callbacks.insert(index, callback);
540 }
541
542 pub fn clear_get_item_main_size_callback_by_index(&mut self, index: i32) {
543 unsafe {
544 OH_ArkUI_WaterFlowSectionOption_RegisterGetItemMainSizeCallbackByIndexWithUserData(
545 self.raw(),
546 index,
547 std::ptr::null_mut(),
548 None,
549 );
550 }
551 if let Some(callback) = self.main_size_callbacks.remove(&index) {
552 unsafe {
553 drop(Box::from_raw(callback));
554 }
555 }
556 }
557
558 pub fn clear_get_item_main_size_callback_by_index_all(&mut self) {
559 let indexes: Vec<i32> = self.main_size_callbacks.keys().copied().collect();
560 for index in indexes {
561 self.clear_get_item_main_size_callback_by_index(index);
562 }
563 }
564
565 pub fn set_cross_count(&mut self, index: i32, cross_count: i32) {
566 unsafe { OH_ArkUI_WaterFlowSectionOption_SetCrossCount(self.raw(), index, cross_count) }
567 }
568
569 pub fn get_cross_count(&self, index: i32) -> i32 {
570 unsafe { OH_ArkUI_WaterFlowSectionOption_GetCrossCount(self.raw(), index) }
571 }
572
573 pub fn set_column_gap(&mut self, index: i32, column_gap: f32) {
574 unsafe { OH_ArkUI_WaterFlowSectionOption_SetColumnGap(self.raw(), index, column_gap) }
575 }
576
577 pub fn get_column_gap(&self, index: i32) -> f32 {
578 unsafe { OH_ArkUI_WaterFlowSectionOption_GetColumnGap(self.raw(), index) }
579 }
580
581 pub fn set_row_gap(&mut self, index: i32, row_gap: f32) {
582 unsafe { OH_ArkUI_WaterFlowSectionOption_SetRowGap(self.raw(), index, row_gap) }
583 }
584
585 pub fn get_row_gap(&self, index: i32) -> f32 {
586 unsafe { OH_ArkUI_WaterFlowSectionOption_GetRowGap(self.raw(), index) }
587 }
588
589 pub fn set_margin(
590 &mut self,
591 index: i32,
592 margin_top: f32,
593 margin_right: f32,
594 margin_bottom: f32,
595 margin_left: f32,
596 ) {
597 unsafe {
598 OH_ArkUI_WaterFlowSectionOption_SetMargin(
599 self.raw(),
600 index,
601 margin_top,
602 margin_right,
603 margin_bottom,
604 margin_left,
605 )
606 }
607 }
608
609 pub fn get_margin(&self, index: i32) -> Margin {
610 unsafe { OH_ArkUI_WaterFlowSectionOption_GetMargin(self.raw(), index) }.into()
611 }
612}
613
614unsafe extern "C" fn water_flow_main_size_callback_trampoline(
615 item_index: i32,
616 user_data: *mut c_void,
617) -> f32 {
618 if user_data.is_null() {
619 return 0.0;
620 }
621
622 let callback = unsafe { &*(user_data as *mut WaterFlowMainSizeCallbackContext) };
623 (callback.callback)(item_index)
624}
625
626#[cfg(feature = "image")]
627pub use ohos_image_native_binding::PixelMapNativeHandle;
628
629#[cfg(feature = "image")]
631pub struct DrawableDescriptor {
632 raw: NonNull<ArkUI_DrawableDescriptor>,
633}
634
635#[cfg(feature = "image")]
636impl DrawableDescriptor {
637 pub fn from_pixel_map(pixel_map: PixelMapNativeHandle) -> ArkUIResult<Self> {
638 let descriptor =
639 unsafe { OH_ArkUI_DrawableDescriptor_CreateFromPixelMap(pixel_map.as_raw().cast()) };
640 NonNull::new(descriptor)
641 .map(|raw| Self::from_raw(raw.as_ptr()))
642 .ok_or_else(|| {
643 ArkUIError::new(
644 ArkUIErrorCode::ParamInvalid,
645 "OH_ArkUI_DrawableDescriptor_CreateFromPixelMap returned null",
646 )
647 })
648 }
649
650 pub fn from_animated_pixel_map(pixel_map_array: &[PixelMapNativeHandle]) -> ArkUIResult<Self> {
651 let mut raw_pixel_map_array: Vec<_> = pixel_map_array
652 .iter()
653 .map(|pixel_map| pixel_map.as_raw().cast())
654 .collect();
655 let array_ptr = if raw_pixel_map_array.is_empty() {
656 std::ptr::null_mut()
657 } else {
658 raw_pixel_map_array.as_mut_ptr()
659 };
660 let descriptor = unsafe {
661 OH_ArkUI_DrawableDescriptor_CreateFromAnimatedPixelMap(
662 array_ptr,
663 raw_pixel_map_array.len() as i32,
664 )
665 };
666 NonNull::new(descriptor)
667 .map(|raw| Self::from_raw(raw.as_ptr()))
668 .ok_or_else(|| {
669 ArkUIError::new(
670 ArkUIErrorCode::ParamInvalid,
671 "OH_ArkUI_DrawableDescriptor_CreateFromAnimatedPixelMap returned null",
672 )
673 })
674 }
675
676 pub(crate) fn raw(&self) -> *mut ArkUI_DrawableDescriptor {
677 self.raw.as_ptr()
678 }
679
680 pub(crate) fn from_raw(raw: *mut ArkUI_DrawableDescriptor) -> Self {
681 Self {
682 raw: non_null_or_panic(raw, "ArkUI_DrawableDescriptor"),
683 }
684 }
685
686 pub(crate) fn into_raw(self) -> *mut ArkUI_DrawableDescriptor {
687 self.raw.as_ptr()
688 }
689
690 pub fn dispose(self) {
691 unsafe { OH_ArkUI_DrawableDescriptor_Dispose(self.raw()) }
692 }
693
694 pub fn get_static_pixel_map(&self) -> Option<PixelMapNativeHandle> {
695 PixelMapNativeHandle::from_raw(
696 unsafe { OH_ArkUI_DrawableDescriptor_GetStaticPixelMap(self.raw()) }.cast(),
697 )
698 }
699
700 pub fn get_animated_pixel_maps(&self) -> Vec<PixelMapNativeHandle> {
701 let size = self.get_animated_pixel_map_array_size();
702 if size <= 0 {
703 return Vec::new();
704 }
705 let ptr = unsafe { OH_ArkUI_DrawableDescriptor_GetAnimatedPixelMapArray(self.raw()) };
706 if ptr.is_null() {
707 return Vec::new();
708 }
709 let size = size as usize;
710 unsafe { std::slice::from_raw_parts(ptr, size) }
711 .iter()
712 .filter_map(|pixel_map| PixelMapNativeHandle::from_raw((*pixel_map).cast()))
713 .collect()
714 }
715
716 pub fn get_animated_pixel_map_array_size(&self) -> i32 {
717 unsafe { OH_ArkUI_DrawableDescriptor_GetAnimatedPixelMapArraySize(self.raw()) }
718 }
719
720 pub fn set_animation_duration(&mut self, duration: i32) {
721 unsafe { OH_ArkUI_DrawableDescriptor_SetAnimationDuration(self.raw(), duration) }
722 }
723
724 pub fn get_animation_duration(&self) -> i32 {
725 unsafe { OH_ArkUI_DrawableDescriptor_GetAnimationDuration(self.raw()) }
726 }
727
728 pub fn set_animation_iteration(&mut self, iteration: i32) {
729 unsafe { OH_ArkUI_DrawableDescriptor_SetAnimationIteration(self.raw(), iteration) }
730 }
731
732 pub fn get_animation_iteration(&self) -> i32 {
733 unsafe { OH_ArkUI_DrawableDescriptor_GetAnimationIteration(self.raw()) }
734 }
735
736 #[cfg(feature = "api-22")]
737 pub fn set_animation_frame_durations(&mut self, durations: &mut [u32]) -> ArkUIResult<()> {
738 unsafe {
739 check_arkui_status!(OH_ArkUI_DrawableDescriptor_SetAnimationFrameDurations(
740 self.raw(),
741 durations.as_mut_ptr(),
742 durations.len()
743 ))
744 }
745 }
746
747 #[cfg(feature = "api-22")]
748 pub fn get_animation_frame_durations(&self, durations: &mut [u32]) -> ArkUIResult<usize> {
749 let mut size = durations.len();
750 unsafe {
751 check_arkui_status!(OH_ArkUI_DrawableDescriptor_GetAnimationFrameDurations(
752 self.raw(),
753 durations.as_mut_ptr(),
754 &mut size
755 ))
756 }?;
757 Ok(size)
758 }
759
760 #[cfg(feature = "api-22")]
761 pub fn set_animation_auto_play(&mut self, auto_play: u32) -> ArkUIResult<()> {
762 unsafe {
763 check_arkui_status!(OH_ArkUI_DrawableDescriptor_SetAnimationAutoPlay(
764 self.raw(),
765 auto_play
766 ))
767 }
768 }
769
770 #[cfg(feature = "api-22")]
771 pub fn get_animation_auto_play(&self) -> ArkUIResult<u32> {
772 let mut auto_play = 0;
773 unsafe {
774 check_arkui_status!(OH_ArkUI_DrawableDescriptor_GetAnimationAutoPlay(
775 self.raw(),
776 &mut auto_play
777 ))
778 }?;
779 Ok(auto_play)
780 }
781
782 #[cfg(feature = "api-22")]
783 pub fn create_animation_controller(
784 &self,
785 node: &crate::ArkUINode,
786 ) -> ArkUIResult<DrawableDescriptorAnimationController> {
787 let mut controller = std::ptr::null_mut();
788 unsafe {
789 check_arkui_status!(OH_ArkUI_DrawableDescriptor_CreateAnimationController(
790 self.raw(),
791 node.raw(),
792 &mut controller
793 ))
794 }?;
795 NonNull::new(controller)
796 .map(|raw| DrawableDescriptorAnimationController::from_raw(raw.as_ptr()))
797 .ok_or_else(|| {
798 ArkUIError::new(
799 ArkUIErrorCode::ParamInvalid,
800 "OH_ArkUI_DrawableDescriptor_CreateAnimationController returned null",
801 )
802 })
803 }
804}
805
806#[cfg(all(feature = "api-22", feature = "image"))]
807pub struct DrawableDescriptorAnimationController {
809 raw: NonNull<ArkUI_DrawableDescriptor_AnimationController>,
810}
811
812#[cfg(all(feature = "api-22", feature = "image"))]
813impl DrawableDescriptorAnimationController {
814 pub(crate) fn raw(&self) -> *mut ArkUI_DrawableDescriptor_AnimationController {
815 self.raw.as_ptr()
816 }
817
818 pub(crate) fn from_raw(raw: *mut ArkUI_DrawableDescriptor_AnimationController) -> Self {
819 Self {
820 raw: non_null_or_panic(raw, "ArkUI_DrawableDescriptor_AnimationController"),
821 }
822 }
823
824 pub(crate) fn into_raw(self) -> *mut ArkUI_DrawableDescriptor_AnimationController {
825 self.raw.as_ptr()
826 }
827
828 pub fn dispose(self) {
829 unsafe { OH_ArkUI_DrawableDescriptor_DisposeAnimationController(self.raw()) }
830 }
831
832 pub fn start_animation(&self) -> ArkUIResult<()> {
833 unsafe { check_arkui_status!(OH_ArkUI_DrawableDescriptor_StartAnimation(self.raw())) }
834 }
835
836 pub fn stop_animation(&self) -> ArkUIResult<()> {
837 unsafe { check_arkui_status!(OH_ArkUI_DrawableDescriptor_StopAnimation(self.raw())) }
838 }
839
840 pub fn resume_animation(&self) -> ArkUIResult<()> {
841 unsafe { check_arkui_status!(OH_ArkUI_DrawableDescriptor_ResumeAnimation(self.raw())) }
842 }
843
844 pub fn pause_animation(&self) -> ArkUIResult<()> {
845 unsafe { check_arkui_status!(OH_ArkUI_DrawableDescriptor_PauseAnimation(self.raw())) }
846 }
847
848 pub fn get_animation_status(&self) -> ArkUIResult<DrawableDescriptor_AnimationStatus> {
849 let mut status =
850 DrawableDescriptor_AnimationStatus_DRAWABLE_DESCRIPTOR_ANIMATION_STATUS_INITIAL;
851 unsafe {
852 check_arkui_status!(OH_ArkUI_DrawableDescriptor_GetAnimationStatus(
853 self.raw(),
854 &mut status
855 ))
856 }?;
857 Ok(status)
858 }
859}
860
861pub struct SwiperIndicator {
863 raw: NonNull<ArkUI_SwiperIndicator>,
864}
865
866impl SwiperIndicator {
867 pub fn new(type_: crate::SwiperIndicatorType) -> ArkUIResult<Self> {
868 let indicator = unsafe { OH_ArkUI_SwiperIndicator_Create(type_.into()) };
869 NonNull::new(indicator)
870 .map(|raw| Self::from_raw(raw.as_ptr()))
871 .ok_or_else(|| {
872 ArkUIError::new(
873 ArkUIErrorCode::ParamInvalid,
874 "OH_ArkUI_SwiperIndicator_Create returned null",
875 )
876 })
877 }
878
879 pub(crate) fn raw(&self) -> *mut ArkUI_SwiperIndicator {
880 self.raw.as_ptr()
881 }
882
883 pub(crate) fn from_raw(raw: *mut ArkUI_SwiperIndicator) -> Self {
884 Self {
885 raw: non_null_or_panic(raw, "ArkUI_SwiperIndicator"),
886 }
887 }
888
889 pub(crate) fn into_raw(self) -> *mut ArkUI_SwiperIndicator {
890 self.raw.as_ptr()
891 }
892
893 pub fn dispose(self) {
894 unsafe { OH_ArkUI_SwiperIndicator_Dispose(self.raw()) }
895 }
896
897 pub fn set_start_position(&mut self, value: f32) {
898 unsafe { OH_ArkUI_SwiperIndicator_SetStartPosition(self.raw(), value) }
899 }
900
901 pub fn get_start_position(&self) -> f32 {
902 unsafe { OH_ArkUI_SwiperIndicator_GetStartPosition(self.raw()) }
903 }
904
905 pub fn set_top_position(&mut self, value: f32) {
906 unsafe { OH_ArkUI_SwiperIndicator_SetTopPosition(self.raw(), value) }
907 }
908
909 pub fn get_top_position(&self) -> f32 {
910 unsafe { OH_ArkUI_SwiperIndicator_GetTopPosition(self.raw()) }
911 }
912
913 pub fn set_end_position(&mut self, value: f32) {
914 unsafe { OH_ArkUI_SwiperIndicator_SetEndPosition(self.raw(), value) }
915 }
916
917 pub fn get_end_position(&self) -> f32 {
918 unsafe { OH_ArkUI_SwiperIndicator_GetEndPosition(self.raw()) }
919 }
920
921 pub fn set_bottom_position(&mut self, value: f32) {
922 unsafe { OH_ArkUI_SwiperIndicator_SetBottomPosition(self.raw(), value) }
923 }
924
925 pub fn get_bottom_position(&self) -> f32 {
926 unsafe { OH_ArkUI_SwiperIndicator_GetBottomPosition(self.raw()) }
927 }
928
929 pub fn set_item_width(&mut self, value: f32) {
930 unsafe { OH_ArkUI_SwiperIndicator_SetItemWidth(self.raw(), value) }
931 }
932
933 pub fn get_item_width(&self) -> f32 {
934 unsafe { OH_ArkUI_SwiperIndicator_GetItemWidth(self.raw()) }
935 }
936
937 pub fn set_item_height(&mut self, value: f32) {
938 unsafe { OH_ArkUI_SwiperIndicator_SetItemHeight(self.raw(), value) }
939 }
940
941 pub fn get_item_height(&self) -> f32 {
942 unsafe { OH_ArkUI_SwiperIndicator_GetItemHeight(self.raw()) }
943 }
944
945 pub fn set_selected_item_width(&mut self, value: f32) {
946 unsafe { OH_ArkUI_SwiperIndicator_SetSelectedItemWidth(self.raw(), value) }
947 }
948
949 pub fn get_selected_item_width(&self) -> f32 {
950 unsafe { OH_ArkUI_SwiperIndicator_GetSelectedItemWidth(self.raw()) }
951 }
952
953 pub fn set_selected_item_height(&mut self, value: f32) {
954 unsafe { OH_ArkUI_SwiperIndicator_SetSelectedItemHeight(self.raw(), value) }
955 }
956
957 pub fn get_selected_item_height(&self) -> f32 {
958 unsafe { OH_ArkUI_SwiperIndicator_GetSelectedItemHeight(self.raw()) }
959 }
960
961 pub fn set_mask(&mut self, mask: i32) {
962 unsafe { OH_ArkUI_SwiperIndicator_SetMask(self.raw(), mask) }
963 }
964
965 pub fn get_mask(&self) -> i32 {
966 unsafe { OH_ArkUI_SwiperIndicator_GetMask(self.raw()) }
967 }
968
969 pub fn set_color(&mut self, color: u32) {
970 unsafe { OH_ArkUI_SwiperIndicator_SetColor(self.raw(), color) }
971 }
972
973 pub fn get_color(&self) -> u32 {
974 unsafe { OH_ArkUI_SwiperIndicator_GetColor(self.raw()) }
975 }
976
977 pub fn set_selected_color(&mut self, color: u32) {
978 unsafe { OH_ArkUI_SwiperIndicator_SetSelectedColor(self.raw(), color) }
979 }
980
981 pub fn get_selected_color(&self) -> u32 {
982 unsafe { OH_ArkUI_SwiperIndicator_GetSelectedColor(self.raw()) }
983 }
984
985 pub fn set_max_display_count(&mut self, max_display_count: i32) -> ArkUIResult<()> {
986 unsafe {
987 check_arkui_status!(OH_ArkUI_SwiperIndicator_SetMaxDisplayCount(
988 self.raw(),
989 max_display_count
990 ))
991 }
992 }
993
994 pub fn get_max_display_count(&self) -> i32 {
995 unsafe { OH_ArkUI_SwiperIndicator_GetMaxDisplayCount(self.raw()) }
996 }
997
998 #[cfg(feature = "api-19")]
999 pub fn set_ignore_size_of_bottom(&mut self, ignore_size: i32) {
1000 unsafe { OH_ArkUI_SwiperIndicator_SetIgnoreSizeOfBottom(self.raw(), ignore_size) }
1001 }
1002
1003 #[cfg(feature = "api-19")]
1004 pub fn get_ignore_size_of_bottom(&self) -> i32 {
1005 unsafe { OH_ArkUI_SwiperIndicator_GetIgnoreSizeOfBottom(self.raw()) }
1006 }
1007
1008 #[cfg(feature = "api-19")]
1009 pub fn set_space(&mut self, space: f32) {
1010 unsafe { OH_ArkUI_SwiperIndicator_SetSpace(self.raw(), space) }
1011 }
1012
1013 #[cfg(feature = "api-19")]
1014 pub fn get_space(&self) -> f32 {
1015 unsafe { OH_ArkUI_SwiperIndicator_GetSpace(self.raw()) }
1016 }
1017}
1018
1019#[cfg(feature = "api-19")]
1020pub struct SwiperDigitIndicator {
1022 raw: NonNull<ArkUI_SwiperDigitIndicator>,
1023}
1024
1025#[cfg(feature = "api-19")]
1026impl SwiperDigitIndicator {
1027 pub fn new() -> ArkUIResult<Self> {
1028 let indicator = unsafe { OH_ArkUI_SwiperDigitIndicator_Create() };
1029 NonNull::new(indicator)
1030 .map(|raw| Self::from_raw(raw.as_ptr()))
1031 .ok_or_else(|| {
1032 ArkUIError::new(
1033 ArkUIErrorCode::ParamInvalid,
1034 "OH_ArkUI_SwiperDigitIndicator_Create returned null",
1035 )
1036 })
1037 }
1038
1039 pub(crate) fn raw(&self) -> *mut ArkUI_SwiperDigitIndicator {
1040 self.raw.as_ptr()
1041 }
1042
1043 pub(crate) fn from_raw(raw: *mut ArkUI_SwiperDigitIndicator) -> Self {
1044 Self {
1045 raw: non_null_or_panic(raw, "ArkUI_SwiperDigitIndicator"),
1046 }
1047 }
1048
1049 pub(crate) fn into_raw(self) -> *mut ArkUI_SwiperDigitIndicator {
1050 self.raw.as_ptr()
1051 }
1052
1053 pub fn destroy(self) {
1054 unsafe { OH_ArkUI_SwiperDigitIndicator_Destroy(self.raw()) }
1055 }
1056
1057 pub fn set_start_position(&mut self, value: f32) {
1058 unsafe { OH_ArkUI_SwiperDigitIndicator_SetStartPosition(self.raw(), value) }
1059 }
1060
1061 pub fn get_start_position(&self) -> f32 {
1062 unsafe { OH_ArkUI_SwiperDigitIndicator_GetStartPosition(self.raw()) }
1063 }
1064
1065 pub fn set_top_position(&mut self, value: f32) {
1066 unsafe { OH_ArkUI_SwiperDigitIndicator_SetTopPosition(self.raw(), value) }
1067 }
1068
1069 pub fn get_top_position(&self) -> f32 {
1070 unsafe { OH_ArkUI_SwiperDigitIndicator_GetTopPosition(self.raw()) }
1071 }
1072
1073 pub fn set_end_position(&mut self, value: f32) {
1074 unsafe { OH_ArkUI_SwiperDigitIndicator_SetEndPosition(self.raw(), value) }
1075 }
1076
1077 pub fn get_end_position(&self) -> f32 {
1078 unsafe { OH_ArkUI_SwiperDigitIndicator_GetEndPosition(self.raw()) }
1079 }
1080
1081 pub fn set_bottom_position(&mut self, value: f32) {
1082 unsafe { OH_ArkUI_SwiperDigitIndicator_SetBottomPosition(self.raw(), value) }
1083 }
1084
1085 pub fn get_bottom_position(&self) -> f32 {
1086 unsafe { OH_ArkUI_SwiperDigitIndicator_GetBottomPosition(self.raw()) }
1087 }
1088
1089 pub fn set_font_color(&mut self, color: u32) {
1090 unsafe { OH_ArkUI_SwiperDigitIndicator_SetFontColor(self.raw(), color) }
1091 }
1092
1093 pub fn get_font_color(&self) -> u32 {
1094 unsafe { OH_ArkUI_SwiperDigitIndicator_GetFontColor(self.raw()) }
1095 }
1096
1097 pub fn set_selected_font_color(&mut self, color: u32) {
1098 unsafe { OH_ArkUI_SwiperDigitIndicator_SetSelectedFontColor(self.raw(), color) }
1099 }
1100
1101 pub fn get_selected_font_color(&self) -> u32 {
1102 unsafe { OH_ArkUI_SwiperDigitIndicator_GetSelectedFontColor(self.raw()) }
1103 }
1104
1105 pub fn set_font_size(&mut self, size: f32) {
1106 unsafe { OH_ArkUI_SwiperDigitIndicator_SetFontSize(self.raw(), size) }
1107 }
1108
1109 pub fn get_font_size(&self) -> f32 {
1110 unsafe { OH_ArkUI_SwiperDigitIndicator_GetFontSize(self.raw()) }
1111 }
1112
1113 pub fn set_selected_font_size(&mut self, size: f32) {
1114 unsafe { OH_ArkUI_SwiperDigitIndicator_SetSelectedFontSize(self.raw(), size) }
1115 }
1116
1117 pub fn get_selected_font_size(&self) -> f32 {
1118 unsafe { OH_ArkUI_SwiperDigitIndicator_GetSelectedFontSize(self.raw()) }
1119 }
1120
1121 pub fn set_font_weight(&mut self, weight: crate::FontWeight) {
1122 unsafe { OH_ArkUI_SwiperDigitIndicator_SetFontWeight(self.raw(), weight.into()) }
1123 }
1124
1125 pub fn get_font_weight(&self) -> crate::FontWeight {
1126 unsafe { OH_ArkUI_SwiperDigitIndicator_GetFontWeight(self.raw()).into() }
1127 }
1128
1129 pub fn set_selected_font_weight(&mut self, weight: crate::FontWeight) {
1130 unsafe { OH_ArkUI_SwiperDigitIndicator_SetSelectedFontWeight(self.raw(), weight.into()) }
1131 }
1132
1133 pub fn get_selected_font_weight(&self) -> crate::FontWeight {
1134 unsafe { OH_ArkUI_SwiperDigitIndicator_GetSelectedFontWeight(self.raw()).into() }
1135 }
1136
1137 pub fn set_ignore_size_of_bottom(&mut self, ignore_size: i32) {
1138 unsafe { OH_ArkUI_SwiperDigitIndicator_SetIgnoreSizeOfBottom(self.raw(), ignore_size) }
1139 }
1140
1141 pub fn get_ignore_size_of_bottom(&self) -> i32 {
1142 unsafe { OH_ArkUI_SwiperDigitIndicator_GetIgnoreSizeOfBottom(self.raw()) }
1143 }
1144}
1145
1146#[cfg(feature = "api-19")]
1147pub struct SwiperArrowStyle {
1149 raw: NonNull<ArkUI_SwiperArrowStyle>,
1150}
1151
1152#[cfg(feature = "api-19")]
1153impl SwiperArrowStyle {
1154 pub fn new() -> ArkUIResult<Self> {
1155 let style = unsafe { OH_ArkUI_SwiperArrowStyle_Create() };
1156 NonNull::new(style)
1157 .map(|raw| Self::from_raw(raw.as_ptr()))
1158 .ok_or_else(|| {
1159 ArkUIError::new(
1160 ArkUIErrorCode::ParamInvalid,
1161 "OH_ArkUI_SwiperArrowStyle_Create returned null",
1162 )
1163 })
1164 }
1165
1166 pub(crate) fn raw(&self) -> *mut ArkUI_SwiperArrowStyle {
1167 self.raw.as_ptr()
1168 }
1169
1170 pub(crate) fn from_raw(raw: *mut ArkUI_SwiperArrowStyle) -> Self {
1171 Self {
1172 raw: non_null_or_panic(raw, "ArkUI_SwiperArrowStyle"),
1173 }
1174 }
1175
1176 pub(crate) fn into_raw(self) -> *mut ArkUI_SwiperArrowStyle {
1177 self.raw.as_ptr()
1178 }
1179
1180 pub fn destroy(self) {
1181 unsafe { OH_ArkUI_SwiperArrowStyle_Destroy(self.raw()) }
1182 }
1183
1184 pub fn set_show_background(&mut self, show: i32) {
1185 unsafe { OH_ArkUI_SwiperArrowStyle_SetShowBackground(self.raw(), show) }
1186 }
1187
1188 pub fn get_show_background(&self) -> i32 {
1189 unsafe { OH_ArkUI_SwiperArrowStyle_GetShowBackground(self.raw()) }
1190 }
1191
1192 pub fn set_show_sidebar_middle(&mut self, show: i32) {
1193 unsafe { OH_ArkUI_SwiperArrowStyle_SetShowSidebarMiddle(self.raw(), show) }
1194 }
1195
1196 pub fn get_show_sidebar_middle(&self) -> i32 {
1197 unsafe { OH_ArkUI_SwiperArrowStyle_GetShowSidebarMiddle(self.raw()) }
1198 }
1199
1200 pub fn set_background_size(&mut self, size: f32) {
1201 unsafe { OH_ArkUI_SwiperArrowStyle_SetBackgroundSize(self.raw(), size) }
1202 }
1203
1204 pub fn get_background_size(&self) -> f32 {
1205 unsafe { OH_ArkUI_SwiperArrowStyle_GetBackgroundSize(self.raw()) }
1206 }
1207
1208 pub fn set_background_color(&mut self, color: u32) {
1209 unsafe { OH_ArkUI_SwiperArrowStyle_SetBackgroundColor(self.raw(), color) }
1210 }
1211
1212 pub fn get_background_color(&self) -> u32 {
1213 unsafe { OH_ArkUI_SwiperArrowStyle_GetBackgroundColor(self.raw()) }
1214 }
1215
1216 pub fn set_arrow_size(&mut self, size: f32) {
1217 unsafe { OH_ArkUI_SwiperArrowStyle_SetArrowSize(self.raw(), size) }
1218 }
1219
1220 pub fn get_arrow_size(&self) -> f32 {
1221 unsafe { OH_ArkUI_SwiperArrowStyle_GetArrowSize(self.raw()) }
1222 }
1223
1224 pub fn set_arrow_color(&mut self, color: u32) {
1225 unsafe { OH_ArkUI_SwiperArrowStyle_SetArrowColor(self.raw(), color) }
1226 }
1227
1228 pub fn get_arrow_color(&self) -> u32 {
1229 unsafe { OH_ArkUI_SwiperArrowStyle_GetArrowColor(self.raw()) }
1230 }
1231}
1232
1233pub struct ImageAnimatorFrameInfo {
1235 raw: NonNull<ArkUI_ImageAnimatorFrameInfo>,
1236}
1237
1238impl ImageAnimatorFrameInfo {
1239 pub fn from_string(src: &str) -> ArkUIResult<Self> {
1240 let src = CString::new(src).map_err(|_| {
1241 ArkUIError::new(
1242 ArkUIErrorCode::ParamInvalid,
1243 "string contains interior NUL bytes",
1244 )
1245 })?;
1246 let info = unsafe {
1247 OH_ArkUI_ImageAnimatorFrameInfo_CreateFromString(src.as_ptr() as *mut c_char)
1248 };
1249 NonNull::new(info)
1250 .map(|raw| Self::from_raw(raw.as_ptr()))
1251 .ok_or_else(|| {
1252 ArkUIError::new(
1253 ArkUIErrorCode::ParamInvalid,
1254 "OH_ArkUI_ImageAnimatorFrameInfo_CreateFromString returned null",
1255 )
1256 })
1257 }
1258
1259 #[cfg(feature = "image")]
1260 pub fn from_drawable_descriptor(drawable: &DrawableDescriptor) -> ArkUIResult<Self> {
1261 let info =
1262 unsafe { OH_ArkUI_ImageAnimatorFrameInfo_CreateFromDrawableDescriptor(drawable.raw()) };
1263 NonNull::new(info)
1264 .map(|raw| Self::from_raw(raw.as_ptr()))
1265 .ok_or_else(|| {
1266 ArkUIError::new(
1267 ArkUIErrorCode::ParamInvalid,
1268 "OH_ArkUI_ImageAnimatorFrameInfo_CreateFromDrawableDescriptor returned null",
1269 )
1270 })
1271 }
1272
1273 pub(crate) fn raw(&self) -> *mut ArkUI_ImageAnimatorFrameInfo {
1274 self.raw.as_ptr()
1275 }
1276
1277 pub(crate) fn from_raw(raw: *mut ArkUI_ImageAnimatorFrameInfo) -> Self {
1278 Self {
1279 raw: non_null_or_panic(raw, "ArkUI_ImageAnimatorFrameInfo"),
1280 }
1281 }
1282
1283 pub(crate) fn into_raw(self) -> *mut ArkUI_ImageAnimatorFrameInfo {
1284 self.raw.as_ptr()
1285 }
1286
1287 pub fn dispose(self) {
1288 unsafe { OH_ArkUI_ImageAnimatorFrameInfo_Dispose(self.raw()) }
1289 }
1290
1291 pub fn set_width(&mut self, width: i32) {
1292 unsafe { OH_ArkUI_ImageAnimatorFrameInfo_SetWidth(self.raw(), width) }
1293 }
1294
1295 pub fn get_width(&self) -> i32 {
1296 unsafe { OH_ArkUI_ImageAnimatorFrameInfo_GetWidth(self.raw()) }
1297 }
1298
1299 pub fn set_height(&mut self, height: i32) {
1300 unsafe { OH_ArkUI_ImageAnimatorFrameInfo_SetHeight(self.raw(), height) }
1301 }
1302
1303 pub fn get_height(&self) -> i32 {
1304 unsafe { OH_ArkUI_ImageAnimatorFrameInfo_GetHeight(self.raw()) }
1305 }
1306
1307 pub fn set_top(&mut self, top: i32) {
1308 unsafe { OH_ArkUI_ImageAnimatorFrameInfo_SetTop(self.raw(), top) }
1309 }
1310
1311 pub fn get_top(&self) -> i32 {
1312 unsafe { OH_ArkUI_ImageAnimatorFrameInfo_GetTop(self.raw()) }
1313 }
1314
1315 pub fn set_left(&mut self, left: i32) {
1316 unsafe { OH_ArkUI_ImageAnimatorFrameInfo_SetLeft(self.raw(), left) }
1317 }
1318
1319 pub fn get_left(&self) -> i32 {
1320 unsafe { OH_ArkUI_ImageAnimatorFrameInfo_GetLeft(self.raw()) }
1321 }
1322
1323 pub fn set_duration(&mut self, duration: i32) {
1324 unsafe { OH_ArkUI_ImageAnimatorFrameInfo_SetDuration(self.raw(), duration) }
1325 }
1326
1327 pub fn get_duration(&self) -> i32 {
1328 unsafe { OH_ArkUI_ImageAnimatorFrameInfo_GetDuration(self.raw()) }
1329 }
1330}