• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef MYAPPLICATION_TYPEDARKUINODE_H
17 #define MYAPPLICATION_TYPEDARKUINODE_H
18 
19 #include "common/ArkUINode.h"
20 
21 namespace NativeModule {
22 class ArkUIScrollNode : public ArkUINode {
23 public:
ArkUIScrollNode()24     ArkUIScrollNode()
25         : ArkUINode(NativeModuleInstance::GetInstance()->GetNativeNodeAPI()->createNode(ARKUI_NODE_SCROLL)) {}
SetScrollDirection(ArkUI_Axis scrollDirection)26     void SetScrollDirection(ArkUI_Axis scrollDirection)
27     {
28         ArkUI_NumberValue dir_value[] = {{ .i32 = scrollDirection }};
29         ArkUI_AttributeItem dir_item = { dir_value, sizeof(dir_value) / sizeof(ArkUI_NumberValue) };
30         auto result = nativeModule_->setAttribute(handle_, NODE_SCROLL_SCROLL_DIRECTION, &dir_item);
31         if (result != ARKUI_ERROR_CODE_NO_ERROR) {
32             OH_LOG_ERROR(LOG_APP, "ArkUIScrollNode SetScrollDirection Failed %{public}d", result);
33         }
34     }
SetScrollBarDisplayMode(ArkUI_ScrollBarDisplayMode mode)35     void SetScrollBarDisplayMode(ArkUI_ScrollBarDisplayMode mode)
36     {
37         ArkUI_NumberValue mode_value[] = {{ .i32 = mode }};
38         ArkUI_AttributeItem mode_item = { mode_value, sizeof(mode_value) / sizeof(ArkUI_NumberValue) };
39         auto result = nativeModule_->setAttribute(handle_, NODE_SCROLL_BAR_DISPLAY_MODE, &mode_item);
40         if (result != ARKUI_ERROR_CODE_NO_ERROR) {
41             OH_LOG_ERROR(LOG_APP, "ArkUIScrollNode SetScrollDirection Failed %{public}d", result);
42         }
43     }
44 };
45 
46 class ArkUIRowNode : public ArkUINode {
47 public:
ArkUIRowNode()48     ArkUIRowNode()
49         : ArkUINode(NativeModuleInstance::GetInstance()->GetNativeNodeAPI()->createNode(ARKUI_NODE_ROW)) {}
50 };
51 
52 class ArkUIColumnNode : public ArkUINode {
53 public:
ArkUIColumnNode()54     ArkUIColumnNode()
55         : ArkUINode(NativeModuleInstance::GetInstance()->GetNativeNodeAPI()->createNode(ARKUI_NODE_COLUMN)) {}
56 };
57 
58 class ArkUIButtonNode : public ArkUINode {
59 public:
ArkUIButtonNode()60     ArkUIButtonNode()
61         : ArkUINode(NativeModuleInstance::GetInstance()->GetNativeNodeAPI()->createNode(ARKUI_NODE_BUTTON)) {}
SetLabel(const char * src)62     void SetLabel(const char* src)
63     {
64         ArkUI_AttributeItem label_item = { .string = src };
65         auto result = nativeModule_->setAttribute(handle_, NODE_BUTTON_LABEL, &label_item);
66         if (result != ARKUI_ERROR_CODE_NO_ERROR) {
67             OH_LOG_ERROR(LOG_APP, "ArkUIButtonNode SetLabel Failed %{public}d", result);
68         }
69     }
70 };
71 
72 class ArkUIImageNode : public ArkUINode {
73 public:
ArkUIImageNode()74     ArkUIImageNode()
75         : ArkUINode(NativeModuleInstance::GetInstance()->GetNativeNodeAPI()->createNode(ARKUI_NODE_IMAGE)) {}
SetSrc(const char * src)76     void SetSrc(const char* src)
77     {
78         ArkUI_AttributeItem image_src_item = {};
79         image_src_item.string = src;
80         auto result = nativeModule_->setAttribute(handle_, NODE_IMAGE_SRC, &image_src_item);
81         if (result != ARKUI_ERROR_CODE_NO_ERROR) {
82             OH_LOG_ERROR(LOG_APP, "ArkUIImageNode SetSrc Failed %{public}d", result);
83         }
84     }
SetAutoResize(bool autoResize)85     void SetAutoResize(bool autoResize)
86     {
87         ArkUI_NumberValue value[] = {{.i32 = autoResize} };
88         ArkUI_AttributeItem item = {value, 1};
89         auto result = nativeModule_->setAttribute(handle_, NODE_IMAGE_AUTO_RESIZE, &item);
90         if (result != ARKUI_ERROR_CODE_NO_ERROR) {
91             OH_LOG_ERROR(LOG_APP, "ArkUIImageNode SetAutoResize Failed %{public}d", result);
92         }
93     }
94 };
95 
96 class ArkUIRefreshNode : public ArkUINode {
97 public:
ArkUIRefreshNode()98     ArkUIRefreshNode()
99         : ArkUINode(NativeModuleInstance::GetInstance()->GetNativeNodeAPI()->createNode(ARKUI_NODE_REFRESH)) {}
SetRefreshing(bool refreshing)100     void SetRefreshing(bool refreshing)
101     {
102         ArkUI_NumberValue refreshing_value[] = {{ .i32 = refreshing }};
103         ArkUI_AttributeItem refreshing_item = {
104             refreshing_value, sizeof(refreshing_value) / sizeof(ArkUI_NumberValue) };
105         auto result = nativeModule_->setAttribute(handle_, NODE_REFRESH_REFRESHING, &refreshing_item);
106         if (result != ARKUI_ERROR_CODE_NO_ERROR) {
107             OH_LOG_ERROR(LOG_APP, "ArkUIRefreshNode SetRefreshing Failed %{public}d", result);
108         }
109     }
110 };
111 
112 class ArkUITextInputNode : public ArkUINode {
113 public:
ArkUITextInputNode()114     ArkUITextInputNode()
115         : ArkUINode(NativeModuleInstance::GetInstance()->GetNativeNodeAPI()->createNode(ARKUI_NODE_TEXT_INPUT)) {}
116 };
117 
118 class ArkUITextNode : public ArkUINode {
119 public:
ArkUITextNode()120     ArkUITextNode()
121         : ArkUINode(NativeModuleInstance::GetInstance()->GetNativeNodeAPI()->createNode(ARKUI_NODE_TEXT)) {}
SetContent(const char * content)122     void SetContent(const char* content)
123     {
124         ArkUI_AttributeItem content_item = { .string = content };
125         auto result = nativeModule_->setAttribute(handle_, NODE_TEXT_CONTENT, &content_item);
126         if (result != ARKUI_ERROR_CODE_NO_ERROR) {
127             OH_LOG_ERROR(LOG_APP, "ArkUITextNode SetContent Failed %{public}d", result);
128         }
129     }
SetFontSize(float size)130     void SetFontSize(float size)
131     {
132         ArkUI_NumberValue size_value[] = {{ .f32 = size }};
133         ArkUI_AttributeItem size_item = { size_value, sizeof(size_value) / sizeof(ArkUI_NumberValue) };
134         auto result = nativeModule_->setAttribute(handle_, NODE_FONT_SIZE, &size_item);
135         if (result != ARKUI_ERROR_CODE_NO_ERROR) {
136             OH_LOG_ERROR(LOG_APP, "ArkUIGridNode SetColumnGap Failed %{public}d", result);
137         }
138     }
139 };
140 
141 class ArkUIGridNode : public ArkUINode {
142 public:
ArkUIGridNode()143     ArkUIGridNode()
144         : ArkUINode(NativeModuleInstance::GetInstance()->GetNativeNodeAPI()->createNode(ARKUI_NODE_GRID)) {}
SetColumnTemplate(const char * columnTemplate)145     void SetColumnTemplate(const char* columnTemplate)
146     {
147         ArkUI_AttributeItem template_item = { .string = columnTemplate };
148         auto result = nativeModule_->setAttribute(handle_, NODE_GRID_COLUMN_TEMPLATE, &template_item);
149         if (result != ARKUI_ERROR_CODE_NO_ERROR) {
150             OH_LOG_ERROR(LOG_APP, "ArkUIGridNode SetColumnTemplate Failed %{public}d", result);
151         }
152     }
SetColumnGap(float gap)153     void SetColumnGap(float gap)
154     {
155         ArkUI_NumberValue gap_value[] = {{ .f32 = gap }};
156         ArkUI_AttributeItem gap_item = { gap_value, sizeof(gap_value) / sizeof(ArkUI_NumberValue) };
157         auto result = nativeModule_->setAttribute(handle_, NODE_GRID_COLUMN_GAP, &gap_item);
158         if (result != ARKUI_ERROR_CODE_NO_ERROR) {
159             OH_LOG_ERROR(LOG_APP, "ArkUIGridNode SetColumnGap Failed %{public}d", result);
160         }
161     }
SetRowGap(float gap)162     void SetRowGap(float gap)
163     {
164         ArkUI_NumberValue gap_value[] = {{ .f32 = gap }};
165         ArkUI_AttributeItem gap_item = { gap_value, sizeof(gap_value) / sizeof(ArkUI_NumberValue) };
166         auto result = nativeModule_->setAttribute(handle_, NODE_GRID_ROW_GAP, &gap_item);
167         if (result != ARKUI_ERROR_CODE_NO_ERROR) {
168             OH_LOG_ERROR(LOG_APP, "ArkUIGridNode SetRowGap Failed %{public}d", result);
169         }
170     }
171 };
172 
173 class ArkUIGridItemNode : public ArkUINode {
174 public:
ArkUIGridItemNode()175     ArkUIGridItemNode()
176         : ArkUINode(NativeModuleInstance::GetInstance()->GetNativeNodeAPI()->createNode(ARKUI_NODE_GRID_ITEM)) {}
177 };
178 
179 class ArkUIStackNode : public ArkUINode {
180 public:
ArkUIStackNode()181     ArkUIStackNode()
182         : ArkUINode(NativeModuleInstance::GetInstance()->GetNativeNodeAPI()->createNode(ARKUI_NODE_STACK)) {}
183 };
184 } // namespace NativeModule
185 
186 #endif //MYAPPLICATION_TYPEDARKUINODE_H
187