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_ARKUITEXTNODE_H 17 #define MYAPPLICATION_ARKUITEXTNODE_H 18 19 #include "ArkUINode.h" 20 21 #include <string> 22 23 namespace NativeModule { 24 class ArkUITextNode : public ArkUINode { 25 public: ArkUITextNode()26 ArkUITextNode() 27 : ArkUINode((NativeModuleInstance::GetInstance()->GetNativeNodeAPI())->createNode(ARKUI_NODE_TEXT)) {} 28 // 文本属性NDK接口封装。 SetFontSize(float fontSize)29 void SetFontSize(float fontSize) { 30 assert(handle_); 31 ArkUI_NumberValue value[] = {{.f32 = fontSize}}; 32 ArkUI_AttributeItem item = {value, 1}; 33 nativeModule_->setAttribute(handle_, NODE_FONT_SIZE, &item); 34 } SetFontColor(uint32_t color)35 void SetFontColor(uint32_t color) { 36 assert(handle_); 37 ArkUI_NumberValue value[] = {{.u32 = color}}; 38 ArkUI_AttributeItem item = {value, 1}; 39 nativeModule_->setAttribute(handle_, NODE_FONT_COLOR, &item); 40 } SetTextContent(const std::string & content)41 void SetTextContent(const std::string &content) { 42 assert(handle_); 43 ArkUI_AttributeItem item = {nullptr, 0, content.c_str()}; 44 nativeModule_->setAttribute(handle_, NODE_TEXT_CONTENT, &item); 45 } SetTextAlign(ArkUI_TextAlignment align)46 void SetTextAlign(ArkUI_TextAlignment align) { 47 assert(handle_); 48 ArkUI_NumberValue value[] = {{.i32 = align}}; 49 ArkUI_AttributeItem item = {value, 1}; 50 nativeModule_->setAttribute(handle_, NODE_TEXT_ALIGN, &item); 51 } 52 }; 53 } // namespace NativeModule 54 55 #endif // MYAPPLICATION_ARKUITEXTNODE_H