组件工具 增加UILabelButton的初始化函数
authorCaisking <3449750381@qq.com>
Thu, 22 Aug 2024 08:04:35 +0000 (16:04 +0800)
committerCaisking <3449750381@qq.com>
Thu, 22 Aug 2024 08:04:35 +0000 (16:04 +0800)
code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp
code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h

index 6b80116..d988e27 100644 (file)
@@ -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)
index 3b0ea88..a496743 100644 (file)
@@ -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);
     /*生成动画资源数组*/