Skip to main content

ohos_arkui_binding/component/built_in_component/
common_component.rs

1//! Module component::built_in_component::common_component wrappers and related types.
2
3use crate::{
4    ArkUIAttributeBasic, ArkUICommonAttribute, ArkUIEvent, ArkUIGesture, ArkUINode, ArkUINodeType,
5    ArkUIResult, ARK_UI_NATIVE_NODE_API_1,
6};
7
8macro_rules! define_common_component {
9    ($name:ident, $tag:ident) => {
10        pub struct $name(pub(crate) ArkUINode);
11
12        impl $name {
13            pub fn new() -> ArkUIResult<Self> {
14                let node =
15                    ARK_UI_NATIVE_NODE_API_1.with(|api| api.create_node(ArkUINodeType::$tag))?;
16                Ok(Self(ArkUINode {
17                    raw: node,
18                    tag: ArkUINodeType::$tag,
19                    ..Default::default()
20                }))
21            }
22        }
23
24        impl From<$name> for ArkUINode {
25            fn from(node: $name) -> Self {
26                node.0
27            }
28        }
29
30        impl ArkUIAttributeBasic for $name {
31            fn raw(&self) -> &ArkUINode {
32                &self.0
33            }
34
35            fn borrow_mut(&mut self) -> &mut ArkUINode {
36                &mut self.0
37            }
38        }
39
40        impl ArkUICommonAttribute for $name {}
41        impl ArkUIEvent for $name {}
42        impl ArkUIGesture for $name {}
43    };
44}
45
46define_common_component!(Custom, Custom);
47define_common_component!(Text, Text);
48define_common_component!(TextInput, TextInput);
49define_common_component!(XComponent, XComponent);
50define_common_component!(Span, Span);
51define_common_component!(ImageSpan, ImageSpan);
52define_common_component!(Image, Image);
53define_common_component!(Toggle, Toggle);
54define_common_component!(LoadingProgress, LoadingProgress);
55define_common_component!(TextArea, TextArea);
56define_common_component!(Button, Button);
57define_common_component!(Progress, Progress);
58define_common_component!(Checkbox, Checkbox);
59define_common_component!(DatePicker, DatePicker);
60define_common_component!(TimePicker, TimePicker);
61define_common_component!(TextPicker, TextPicker);
62define_common_component!(CalendarPicker, CalendarPicker);
63define_common_component!(Slider, Slider);
64define_common_component!(Radio, Radio);
65define_common_component!(ImageAnimator, ImageAnimator);
66#[cfg(feature = "api-18")]
67define_common_component!(XComponentTexture, XComponentTexture);
68#[cfg(feature = "api-15")]
69define_common_component!(CheckboxGroup, CheckboxGroup);
70define_common_component!(Stack, Stack);
71define_common_component!(Swiper, Swiper);
72define_common_component!(Scroll, Scroll);
73define_common_component!(ListItemGroup, ListItemGroup);
74define_common_component!(List, List);
75define_common_component!(ListItem, ListItem);
76define_common_component!(Column, Column);
77define_common_component!(Row, Row);
78define_common_component!(Flex, Flex);
79define_common_component!(Refresh, Refresh);
80define_common_component!(WaterFlow, WaterFlow);
81define_common_component!(FlowItem, FlowItem);
82define_common_component!(RelativeContainer, RelativeContainer);
83define_common_component!(Grid, Grid);
84define_common_component!(GridItem, GridItem);
85define_common_component!(CustomSpan, CustomSpan);
86#[cfg(feature = "api-20")]
87define_common_component!(EmbeddedComponent, EmbeddedComponent);
88#[cfg(feature = "api-20")]
89define_common_component!(Undefined, Undefined);