Skip to main content

ohos_arkui_binding/component/built_in_component/
image.rs

1//! Module component::built_in_component::image wrappers and related types.
2
3// BEGIN_GENERATED_COMPONENT_METHODS_Image
4impl super::Image {
5    pub fn set_image_src<T: Into<crate::ArkUINodeAttributeItem>>(
6        &self,
7        value: T,
8    ) -> crate::ArkUIResult<()> {
9        <Self as crate::ArkUICommonAttribute>::set_attribute(
10            self,
11            crate::ArkUINodeAttributeType::ImageSrc,
12            value.into(),
13        )
14    }
15
16    pub fn get_image_src(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
17        <Self as crate::ArkUICommonAttribute>::get_attribute(
18            self,
19            crate::ArkUINodeAttributeType::ImageSrc,
20        )
21    }
22
23    pub fn set_image_object_fit<T: Into<crate::ArkUINodeAttributeItem>>(
24        &self,
25        value: T,
26    ) -> crate::ArkUIResult<()> {
27        <Self as crate::ArkUICommonAttribute>::set_attribute(
28            self,
29            crate::ArkUINodeAttributeType::ImageObjectFit,
30            value.into(),
31        )
32    }
33
34    pub fn get_image_object_fit(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
35        <Self as crate::ArkUICommonAttribute>::get_attribute(
36            self,
37            crate::ArkUINodeAttributeType::ImageObjectFit,
38        )
39    }
40
41    pub fn set_image_interpolation<T: Into<crate::ArkUINodeAttributeItem>>(
42        &self,
43        value: T,
44    ) -> crate::ArkUIResult<()> {
45        <Self as crate::ArkUICommonAttribute>::set_attribute(
46            self,
47            crate::ArkUINodeAttributeType::ImageInterpolation,
48            value.into(),
49        )
50    }
51
52    pub fn get_image_interpolation(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
53        <Self as crate::ArkUICommonAttribute>::get_attribute(
54            self,
55            crate::ArkUINodeAttributeType::ImageInterpolation,
56        )
57    }
58
59    pub fn set_image_object_repeat<T: Into<crate::ArkUINodeAttributeItem>>(
60        &self,
61        value: T,
62    ) -> crate::ArkUIResult<()> {
63        <Self as crate::ArkUICommonAttribute>::set_attribute(
64            self,
65            crate::ArkUINodeAttributeType::ImageObjectRepeat,
66            value.into(),
67        )
68    }
69
70    pub fn get_image_object_repeat(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
71        <Self as crate::ArkUICommonAttribute>::get_attribute(
72            self,
73            crate::ArkUINodeAttributeType::ImageObjectRepeat,
74        )
75    }
76
77    pub fn set_image_color_filter<T: Into<crate::ArkUINodeAttributeItem>>(
78        &self,
79        value: T,
80    ) -> crate::ArkUIResult<()> {
81        <Self as crate::ArkUICommonAttribute>::set_attribute(
82            self,
83            crate::ArkUINodeAttributeType::ImageColorFilter,
84            value.into(),
85        )
86    }
87
88    pub fn get_image_color_filter(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
89        <Self as crate::ArkUICommonAttribute>::get_attribute(
90            self,
91            crate::ArkUINodeAttributeType::ImageColorFilter,
92        )
93    }
94
95    pub fn set_image_auto_resize<T: Into<crate::ArkUINodeAttributeItem>>(
96        &self,
97        value: T,
98    ) -> crate::ArkUIResult<()> {
99        <Self as crate::ArkUICommonAttribute>::set_attribute(
100            self,
101            crate::ArkUINodeAttributeType::ImageAutoResize,
102            value.into(),
103        )
104    }
105
106    pub fn get_image_auto_resize(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
107        <Self as crate::ArkUICommonAttribute>::get_attribute(
108            self,
109            crate::ArkUINodeAttributeType::ImageAutoResize,
110        )
111    }
112
113    pub fn set_image_alt<T: Into<crate::ArkUINodeAttributeItem>>(
114        &self,
115        value: T,
116    ) -> crate::ArkUIResult<()> {
117        <Self as crate::ArkUICommonAttribute>::set_attribute(
118            self,
119            crate::ArkUINodeAttributeType::ImageAlt,
120            value.into(),
121        )
122    }
123
124    pub fn get_image_alt(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
125        <Self as crate::ArkUICommonAttribute>::get_attribute(
126            self,
127            crate::ArkUINodeAttributeType::ImageAlt,
128        )
129    }
130
131    pub fn set_image_draggable<T: Into<crate::ArkUINodeAttributeItem>>(
132        &self,
133        value: T,
134    ) -> crate::ArkUIResult<()> {
135        <Self as crate::ArkUICommonAttribute>::set_attribute(
136            self,
137            crate::ArkUINodeAttributeType::ImageDraggable,
138            value.into(),
139        )
140    }
141
142    pub fn get_image_draggable(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
143        <Self as crate::ArkUICommonAttribute>::get_attribute(
144            self,
145            crate::ArkUINodeAttributeType::ImageDraggable,
146        )
147    }
148
149    pub fn set_image_render_mode<T: Into<crate::ArkUINodeAttributeItem>>(
150        &self,
151        value: T,
152    ) -> crate::ArkUIResult<()> {
153        <Self as crate::ArkUICommonAttribute>::set_attribute(
154            self,
155            crate::ArkUINodeAttributeType::ImageRenderMode,
156            value.into(),
157        )
158    }
159
160    pub fn get_image_render_mode(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
161        <Self as crate::ArkUICommonAttribute>::get_attribute(
162            self,
163            crate::ArkUINodeAttributeType::ImageRenderMode,
164        )
165    }
166
167    pub fn set_image_fit_original_size<T: Into<crate::ArkUINodeAttributeItem>>(
168        &self,
169        value: T,
170    ) -> crate::ArkUIResult<()> {
171        <Self as crate::ArkUICommonAttribute>::set_attribute(
172            self,
173            crate::ArkUINodeAttributeType::ImageFitOriginalSize,
174            value.into(),
175        )
176    }
177
178    pub fn get_image_fit_original_size(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
179        <Self as crate::ArkUICommonAttribute>::get_attribute(
180            self,
181            crate::ArkUINodeAttributeType::ImageFitOriginalSize,
182        )
183    }
184
185    pub fn set_image_fill_color<T: Into<crate::ArkUINodeAttributeItem>>(
186        &self,
187        value: T,
188    ) -> crate::ArkUIResult<()> {
189        <Self as crate::ArkUICommonAttribute>::set_attribute(
190            self,
191            crate::ArkUINodeAttributeType::ImageFillColor,
192            value.into(),
193        )
194    }
195
196    pub fn get_image_fill_color(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
197        <Self as crate::ArkUICommonAttribute>::get_attribute(
198            self,
199            crate::ArkUINodeAttributeType::ImageFillColor,
200        )
201    }
202
203    pub fn set_image_resizable<T: Into<crate::ArkUINodeAttributeItem>>(
204        &self,
205        value: T,
206    ) -> crate::ArkUIResult<()> {
207        <Self as crate::ArkUICommonAttribute>::set_attribute(
208            self,
209            crate::ArkUINodeAttributeType::ImageResizable,
210            value.into(),
211        )
212    }
213
214    pub fn get_image_resizable(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
215        <Self as crate::ArkUICommonAttribute>::get_attribute(
216            self,
217            crate::ArkUINodeAttributeType::ImageResizable,
218        )
219    }
220
221    #[cfg(feature = "api-22")]
222    pub fn set_image_alt_error<T: Into<crate::ArkUINodeAttributeItem>>(
223        &self,
224        value: T,
225    ) -> crate::ArkUIResult<()> {
226        <Self as crate::ArkUICommonAttribute>::set_attribute(
227            self,
228            crate::ArkUINodeAttributeType::ImageAltError,
229            value.into(),
230        )
231    }
232
233    #[cfg(feature = "api-22")]
234    pub fn get_image_alt_error(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
235        <Self as crate::ArkUICommonAttribute>::get_attribute(
236            self,
237            crate::ArkUINodeAttributeType::ImageAltError,
238        )
239    }
240
241    #[cfg(feature = "api-22")]
242    pub fn set_image_alt_placeholder<T: Into<crate::ArkUINodeAttributeItem>>(
243        &self,
244        value: T,
245    ) -> crate::ArkUIResult<()> {
246        <Self as crate::ArkUICommonAttribute>::set_attribute(
247            self,
248            crate::ArkUINodeAttributeType::ImageAltPlaceholder,
249            value.into(),
250        )
251    }
252
253    #[cfg(feature = "api-22")]
254    pub fn get_image_alt_placeholder(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
255        <Self as crate::ArkUICommonAttribute>::get_attribute(
256            self,
257            crate::ArkUINodeAttributeType::ImageAltPlaceholder,
258        )
259    }
260
261    #[cfg(feature = "api-21")]
262    pub fn set_image_content_transition<T: Into<crate::ArkUINodeAttributeItem>>(
263        &self,
264        value: T,
265    ) -> crate::ArkUIResult<()> {
266        <Self as crate::ArkUICommonAttribute>::set_attribute(
267            self,
268            crate::ArkUINodeAttributeType::ImageContentTransition,
269            value.into(),
270        )
271    }
272
273    #[cfg(feature = "api-21")]
274    pub fn get_image_content_transition(
275        &self,
276    ) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
277        <Self as crate::ArkUICommonAttribute>::get_attribute(
278            self,
279            crate::ArkUINodeAttributeType::ImageContentTransition,
280        )
281    }
282
283    #[cfg(feature = "api-21")]
284    pub fn set_image_copy_option<T: Into<crate::ArkUINodeAttributeItem>>(
285        &self,
286        value: T,
287    ) -> crate::ArkUIResult<()> {
288        <Self as crate::ArkUICommonAttribute>::set_attribute(
289            self,
290            crate::ArkUINodeAttributeType::ImageCopyOption,
291            value.into(),
292        )
293    }
294
295    #[cfg(feature = "api-21")]
296    pub fn get_image_copy_option(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
297        <Self as crate::ArkUICommonAttribute>::get_attribute(
298            self,
299            crate::ArkUINodeAttributeType::ImageCopyOption,
300        )
301    }
302
303    #[cfg(feature = "api-21")]
304    pub fn set_image_dynamic_range_mode<T: Into<crate::ArkUINodeAttributeItem>>(
305        &self,
306        value: T,
307    ) -> crate::ArkUIResult<()> {
308        <Self as crate::ArkUICommonAttribute>::set_attribute(
309            self,
310            crate::ArkUINodeAttributeType::ImageDynamicRangeMode,
311            value.into(),
312        )
313    }
314
315    #[cfg(feature = "api-21")]
316    pub fn get_image_dynamic_range_mode(
317        &self,
318    ) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
319        <Self as crate::ArkUICommonAttribute>::get_attribute(
320            self,
321            crate::ArkUINodeAttributeType::ImageDynamicRangeMode,
322        )
323    }
324
325    #[cfg(feature = "api-21")]
326    pub fn set_image_enable_analyzer<T: Into<crate::ArkUINodeAttributeItem>>(
327        &self,
328        value: T,
329    ) -> crate::ArkUIResult<()> {
330        <Self as crate::ArkUICommonAttribute>::set_attribute(
331            self,
332            crate::ArkUINodeAttributeType::ImageEnableAnalyzer,
333            value.into(),
334        )
335    }
336
337    #[cfg(feature = "api-21")]
338    pub fn get_image_enable_analyzer(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
339        <Self as crate::ArkUICommonAttribute>::get_attribute(
340            self,
341            crate::ArkUINodeAttributeType::ImageEnableAnalyzer,
342        )
343    }
344
345    #[cfg(feature = "api-21")]
346    pub fn set_image_hdr_brightness<T: Into<crate::ArkUINodeAttributeItem>>(
347        &self,
348        value: T,
349    ) -> crate::ArkUIResult<()> {
350        <Self as crate::ArkUICommonAttribute>::set_attribute(
351            self,
352            crate::ArkUINodeAttributeType::ImageHdrBrightness,
353            value.into(),
354        )
355    }
356
357    #[cfg(feature = "api-21")]
358    pub fn get_image_hdr_brightness(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
359        <Self as crate::ArkUICommonAttribute>::get_attribute(
360            self,
361            crate::ArkUINodeAttributeType::ImageHdrBrightness,
362        )
363    }
364
365    #[cfg(feature = "api-21")]
366    pub fn set_image_image_matrix<T: Into<crate::ArkUINodeAttributeItem>>(
367        &self,
368        value: T,
369    ) -> crate::ArkUIResult<()> {
370        <Self as crate::ArkUICommonAttribute>::set_attribute(
371            self,
372            crate::ArkUINodeAttributeType::ImageImageMatrix,
373            value.into(),
374        )
375    }
376
377    #[cfg(feature = "api-21")]
378    pub fn get_image_image_matrix(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
379        <Self as crate::ArkUICommonAttribute>::get_attribute(
380            self,
381            crate::ArkUINodeAttributeType::ImageImageMatrix,
382        )
383    }
384
385    #[cfg(feature = "api-21")]
386    pub fn set_image_match_text_direction<T: Into<crate::ArkUINodeAttributeItem>>(
387        &self,
388        value: T,
389    ) -> crate::ArkUIResult<()> {
390        <Self as crate::ArkUICommonAttribute>::set_attribute(
391            self,
392            crate::ArkUINodeAttributeType::ImageMatchTextDirection,
393            value.into(),
394        )
395    }
396
397    #[cfg(feature = "api-21")]
398    pub fn get_image_match_text_direction(
399        &self,
400    ) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
401        <Self as crate::ArkUICommonAttribute>::get_attribute(
402            self,
403            crate::ArkUINodeAttributeType::ImageMatchTextDirection,
404        )
405    }
406
407    #[cfg(feature = "api-21")]
408    pub fn set_image_orientation<T: Into<crate::ArkUINodeAttributeItem>>(
409        &self,
410        value: T,
411    ) -> crate::ArkUIResult<()> {
412        <Self as crate::ArkUICommonAttribute>::set_attribute(
413            self,
414            crate::ArkUINodeAttributeType::ImageOrientation,
415            value.into(),
416        )
417    }
418
419    #[cfg(feature = "api-21")]
420    pub fn get_image_orientation(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
421        <Self as crate::ArkUICommonAttribute>::get_attribute(
422            self,
423            crate::ArkUINodeAttributeType::ImageOrientation,
424        )
425    }
426
427    #[cfg(feature = "api-21")]
428    pub fn set_image_source_size<T: Into<crate::ArkUINodeAttributeItem>>(
429        &self,
430        value: T,
431    ) -> crate::ArkUIResult<()> {
432        <Self as crate::ArkUICommonAttribute>::set_attribute(
433            self,
434            crate::ArkUINodeAttributeType::ImageSourceSize,
435            value.into(),
436        )
437    }
438
439    #[cfg(feature = "api-21")]
440    pub fn get_image_source_size(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
441        <Self as crate::ArkUICommonAttribute>::get_attribute(
442            self,
443            crate::ArkUINodeAttributeType::ImageSourceSize,
444        )
445    }
446
447    #[cfg(feature = "api-21")]
448    pub fn set_image_support_svg2<T: Into<crate::ArkUINodeAttributeItem>>(
449        &self,
450        value: T,
451    ) -> crate::ArkUIResult<()> {
452        <Self as crate::ArkUICommonAttribute>::set_attribute(
453            self,
454            crate::ArkUINodeAttributeType::ImageSupportSvg2,
455            value.into(),
456        )
457    }
458
459    #[cfg(feature = "api-21")]
460    pub fn get_image_support_svg2(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
461        <Self as crate::ArkUICommonAttribute>::get_attribute(
462            self,
463            crate::ArkUINodeAttributeType::ImageSupportSvg2,
464        )
465    }
466
467    #[cfg(feature = "api-20")]
468    pub fn set_image_sync_load<T: Into<crate::ArkUINodeAttributeItem>>(
469        &self,
470        value: T,
471    ) -> crate::ArkUIResult<()> {
472        <Self as crate::ArkUICommonAttribute>::set_attribute(
473            self,
474            crate::ArkUINodeAttributeType::ImageSyncLoad,
475            value.into(),
476        )
477    }
478
479    #[cfg(feature = "api-20")]
480    pub fn get_image_sync_load(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
481        <Self as crate::ArkUICommonAttribute>::get_attribute(
482            self,
483            crate::ArkUINodeAttributeType::ImageSyncLoad,
484        )
485    }
486}
487// END_GENERATED_COMPONENT_METHODS_Image
488
489#[derive(Clone, Copy, Debug, PartialEq)]
490/// Event payload emitted when image loading/decoding completes.
491pub struct ImageCompleteEvent {
492    pub loading_status: i32,
493    pub width: f32,
494    pub height: f32,
495    pub component_width: f32,
496    pub component_height: f32,
497    pub content_offset_x: f32,
498    pub content_offset_y: f32,
499    pub content_width: f32,
500    pub content_height: f32,
501}
502
503impl super::Image {
504    pub fn on_image_complete<T: Fn(ImageCompleteEvent) + 'static>(&mut self, cb: T) {
505        crate::ArkUIEvent::on_event(self, crate::NodeEventType::ImageOnComplete, move |event| {
506            cb(ImageCompleteEvent {
507                loading_status: event.i32_value(0).unwrap_or_default(),
508                width: event.f32_value(1).unwrap_or_default(),
509                height: event.f32_value(2).unwrap_or_default(),
510                component_width: event.f32_value(3).unwrap_or_default(),
511                component_height: event.f32_value(4).unwrap_or_default(),
512                content_offset_x: event.f32_value(5).unwrap_or_default(),
513                content_offset_y: event.f32_value(6).unwrap_or_default(),
514                content_width: event.f32_value(7).unwrap_or_default(),
515                content_height: event.f32_value(8).unwrap_or_default(),
516            });
517        });
518    }
519
520    pub fn on_image_error<T: Fn(i32) + 'static>(&mut self, cb: T) {
521        crate::ArkUIEvent::on_event(self, crate::NodeEventType::ImageOnError, move |event| {
522            cb(event.i32_value(0).unwrap_or_default());
523        });
524    }
525
526    pub fn on_image_svg_play_finish<T: Fn() + 'static>(&mut self, cb: T) {
527        crate::ArkUIEvent::on_event_no_param(self, crate::NodeEventType::ImageOnSvgPlayFinish, cb);
528    }
529
530    pub fn on_image_download_progress<T: Fn(u32, u32) + 'static>(&mut self, cb: T) {
531        crate::ArkUIEvent::on_event(
532            self,
533            crate::NodeEventType::ImageOnDownloadProgress,
534            move |event| {
535                cb(
536                    event.u32_value(0).unwrap_or_default(),
537                    event.u32_value(1).unwrap_or_default(),
538                );
539            },
540        );
541    }
542}