Skip to main content

ohos_arkui_binding/component/built_in_component/
xcomponent.rs

1//! Module component::built_in_component::xcomponent wrappers and related types.
2
3#[cfg(feature = "xcomponent")]
4use crate::{
5    ArkUIAttributeBasic, ArkUINodeAttributeItem, ArkUINodeAttributeType, ARK_UI_NATIVE_NODE_API_1,
6};
7
8#[cfg(feature = "xcomponent")]
9use ohos_xcomponent_binding::NativeXComponent as XC;
10#[cfg(feature = "xcomponent")]
11use ohos_xcomponent_sys::OH_NativeXComponent_GetNativeXComponent;
12
13impl Clone for super::XComponent {
14    fn clone(&self) -> Self {
15        Self(self.0.clone())
16    }
17}
18
19impl super::XComponent {
20    #[cfg(feature = "xcomponent")]
21    pub fn native_xcomponent(&self) -> XC {
22        use ohos_xcomponent_binding::XComponentRaw;
23
24        let handle = unsafe { OH_NativeXComponent_GetNativeXComponent(self.raw().raw()) };
25        let id = ARK_UI_NATIVE_NODE_API_1
26            .with(|api| api.get_attribute(self.raw(), ArkUINodeAttributeType::XComponentId))
27            .ok()
28            .and_then(|attr| {
29                if let ArkUINodeAttributeItem::String(xcomponent_id) = attr {
30                    Some(xcomponent_id)
31                } else {
32                    None
33                }
34            });
35        match id {
36            Some(id) => XC::with_id(XComponentRaw(handle), id),
37            None => XC::new(XComponentRaw(handle)),
38        }
39    }
40}
41
42// BEGIN_GENERATED_COMPONENT_METHODS_XComponent
43impl super::XComponent {
44    pub fn set_x_component_id<T: Into<crate::ArkUINodeAttributeItem>>(
45        &self,
46        value: T,
47    ) -> crate::ArkUIResult<()> {
48        <Self as crate::ArkUICommonAttribute>::set_attribute(
49            self,
50            crate::ArkUINodeAttributeType::XComponentId,
51            value.into(),
52        )
53    }
54
55    pub fn get_x_component_id(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
56        <Self as crate::ArkUICommonAttribute>::get_attribute(
57            self,
58            crate::ArkUINodeAttributeType::XComponentId,
59        )
60    }
61
62    pub fn set_x_component_type<T: Into<crate::ArkUINodeAttributeItem>>(
63        &self,
64        value: T,
65    ) -> crate::ArkUIResult<()> {
66        <Self as crate::ArkUICommonAttribute>::set_attribute(
67            self,
68            crate::ArkUINodeAttributeType::XComponentType,
69            value.into(),
70        )
71    }
72
73    pub fn get_x_component_type(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
74        <Self as crate::ArkUICommonAttribute>::get_attribute(
75            self,
76            crate::ArkUINodeAttributeType::XComponentType,
77        )
78    }
79
80    pub fn set_x_component_surface_size<T: Into<crate::ArkUINodeAttributeItem>>(
81        &self,
82        value: T,
83    ) -> crate::ArkUIResult<()> {
84        <Self as crate::ArkUICommonAttribute>::set_attribute(
85            self,
86            crate::ArkUINodeAttributeType::XComponentSurfaceSize,
87            value.into(),
88        )
89    }
90
91    pub fn get_x_component_surface_size(
92        &self,
93    ) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
94        <Self as crate::ArkUICommonAttribute>::get_attribute(
95            self,
96            crate::ArkUINodeAttributeType::XComponentSurfaceSize,
97        )
98    }
99
100    #[cfg(feature = "api-18")]
101    pub fn set_x_component_enable_analyzer<T: Into<crate::ArkUINodeAttributeItem>>(
102        &self,
103        value: T,
104    ) -> crate::ArkUIResult<()> {
105        <Self as crate::ArkUICommonAttribute>::set_attribute(
106            self,
107            crate::ArkUINodeAttributeType::XComponentEnableAnalyzer,
108            value.into(),
109        )
110    }
111
112    #[cfg(feature = "api-18")]
113    pub fn get_x_component_enable_analyzer(
114        &self,
115    ) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
116        <Self as crate::ArkUICommonAttribute>::get_attribute(
117            self,
118            crate::ArkUINodeAttributeType::XComponentEnableAnalyzer,
119        )
120    }
121
122    #[cfg(feature = "api-18")]
123    pub fn set_x_component_surface_rect<T: Into<crate::ArkUINodeAttributeItem>>(
124        &self,
125        value: T,
126    ) -> crate::ArkUIResult<()> {
127        <Self as crate::ArkUICommonAttribute>::set_attribute(
128            self,
129            crate::ArkUINodeAttributeType::XComponentSurfaceRect,
130            value.into(),
131        )
132    }
133
134    #[cfg(feature = "api-18")]
135    pub fn get_x_component_surface_rect(
136        &self,
137    ) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
138        <Self as crate::ArkUICommonAttribute>::get_attribute(
139            self,
140            crate::ArkUINodeAttributeType::XComponentSurfaceRect,
141        )
142    }
143}
144// END_GENERATED_COMPONENT_METHODS_XComponent