From: Caisking <3449750381@qq.com> Date: Thu, 22 Aug 2024 08:04:35 +0000 (+0800) Subject: 组件工具 增加UILabelButton的初始化函数 X-Git-Tag: release_V1.2.70_20241020_135402~606^2~14 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=08e9aadbf9ab44596eee6b0f9b6934efeb7a2302;p=mirrors%2FFD230.git 组件工具 增加UILabelButton的初始化函数 --- diff --git a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp index 6b8011647..d988e277a 100644 --- a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp +++ b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp @@ -229,6 +229,48 @@ namespace OHOS // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitButton is succeed"); return true; } + /*** + * @description: + * @param {UILabelButton} * + * @param {int} left + * @param {int} top + * @param {int} width + * @param {int} height + * @param {char} *viewId + * @param {UIResourceTextId} id + * @param {int} fontSize + * @return {*} + * @brief 初始化带label的button + */ + bool InitLabelButton(UILabelButton *&button, int left, int top, int width, int height, const char *viewId, const char *text, int fontSize) + { + // 创建新按钮(如果当前按钮为空) + if (button == nullptr) + { + button = new UILabelButton(); + if (button == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitButtonExt is error"); + return false; // 内存分配失败,返回false + } + } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UILabelButton UILabelButton is not nullptr"); + return false; // 内存分配失败,返回false + } + button->SetPosition(left, top); + button->Resize(width, height); + button->SetViewId(viewId); + button->SetText(text); + button->SetStyle(STYLE_TEXT_FONT, fontSize); + button->SetFont(DEFAULT_VECTOR_FONT_FILENAME, fontSize); + button->SetStyle(STYLE_BACKGROUND_COLOR, DEFAULT_BACKGROUND_COLOR); + button->SetStyleForState(STYLE_BACKGROUND_COLOR, DEFAULT_BACKGROUND_COLOR, UIButton::PRESSED); + button->SetStyleForState(STYLE_BORDER_COLOR, PRESSED_BORDER_COLOR, UIButton::PRESSED); + button->SetVisible(true); + return true; + } /* -------------------------------------------------------------------------- */ /*替换字符串中的变量*/ std::string UpdateLabelText(UILabelExt *&label, const std::string &newText, UIResourceTextId id) diff --git a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h index 3b0ea887f..a49674321 100644 --- a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h +++ b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-07-29 10:31:48 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-21 16:17:07 + * @FilePath: /FD230/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h + */ /*** * @Date: 2024-05-30 15:59:37 * @LastEditors: Caisking 3449750381@qq.com @@ -51,7 +57,8 @@ namespace OHOS bool InitUILabel(UILabel *&label, int left, int top, int width, int height, const char *viewId, const char *text, const char *fontName, int fontSize); /*初始化button*/ bool InitButton(UIButton *&button, int left, int top, int width, int height, const char *viewId); - /*初始化buttonExt*/ + /*初始化labelbutton*/ + bool InitLabelButton(UILabelButton *&button, int left, int top, int width, int height, const char *viewId, const char *text, int fontSize); /*初始化image*/ bool InitImageView(UIImageView *&imageView, int left, int top, int width, int height, const char *viewId, const char *imagePath); /*生成动画资源数组*/