优化组件
authorCaisking <3449750381@qq.com>
Thu, 27 Jun 2024 07:23:51 +0000 (15:23 +0800)
committerCaisking <3449750381@qq.com>
Thu, 27 Jun 2024 07:23:51 +0000 (15:23 +0800)
code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp
code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h
code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepTimeView.cpp

index eefda14..fb7b1a0 100644 (file)
@@ -29,6 +29,35 @@ namespace OHOS
      * @brief 初始化标签
      */
     bool InitLabel(UILabelExt *&label, int left, int top, int width, int height, const char *viewId, const char *text, const char *fontName, int fontSize)
+    {
+        // 检查标签指针是否为空
+        if (label == nullptr)
+        {
+            label = new UILabelExt();
+        }
+        if (label == nullptr)
+        {
+            return false; // 内存分配失败,返回false
+        }
+        // 设置标签的位置和大小
+        label->SetPosition(left, top);
+        label->Resize(width, height);
+        // 设置标签的视图 ID
+        label->SetViewId(viewId);
+        // 设置标签的样式
+        label->SetStyle(STYLE_TEXT_FONT, fontSize);
+        label->SetFont(fontName, fontSize);
+        // 设置标签的文本和其他属性
+        label->SetText(text);
+        label->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
+        label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+        label->SetRollSpeed(0);
+        // 设置标签可见
+        label->SetVisible(true);
+        // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLabelExt is succeed");
+        return true;
+    }
+    bool InitLabelAdapt(UILabelExt *&label, int left, int top, int width, int height, const char *viewId, const char *text, const char *fontName, int fontSize)
     {
         // 检查标签指针是否为空
         if (label == nullptr)
index 869e038..597ed1b 100644 (file)
@@ -1,3 +1,9 @@
+/***
+ * @Date: 2024-05-30 15:59:37
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-06-27 15:04:48
+ * @FilePath: /FD230/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h
+ */
 /***
  * @Date: 2024-05-10 10:27:30
  * @LastEditors: Caisking 3449750381@qq.com
@@ -43,6 +49,8 @@ namespace OHOS
     bool InitImageView(UIImageView *&imageView, int left, int top, int width, int height, const char *viewId, const char *imagePath);
     /*生成动画资源数组*/
     const char **CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages);
+    /*自适应label*/
+    bool InitLabelAdapt(UILabelExt *&label, int left, int top, int width, int height, const char *viewId, const char *text, const char *fontName, int fontSize);
     /*初始化动画资源*/
     void InitImageAnimatorSource(UIImageAnimatorView *&imageAnimator, const char **imagePaths, int numFrames, int left, int top, int width, int height, const char *viewId, int time);
     /*InitLabel[默认参数]*/
index 8289c5d..7f234e0 100644 (file)
@@ -141,13 +141,13 @@ namespace OHOS
         apptitle->SetTextColor(Color::Gray());
         /* ------------------------------- 数据label初始化 ------------------------------- */
         restStr = "--";
-        InitLabel(rest, 211, 95, 230, 47, "restlabel", restStr.c_str(), DEFAULT_VECTOR_FONT_FILENAME, 30);
+        InitLabelAdapt(rest, 211, 95, 230, 47, "restlabel", restStr.c_str(), DEFAULT_VECTOR_FONT_FILENAME, 30);
         rest->SetTextColor(Color::Gray());
         sleepStr = "--";
-        InitLabel(sleep, 99, 238, 230, 47, "sleeplabel", sleepStr.c_str(), DEFAULT_VECTOR_FONT_FILENAME, 30);
+        InitLabelAdapt(sleep, 99, 238, 230, 47, "sleeplabel", sleepStr.c_str(), DEFAULT_VECTOR_FONT_FILENAME, 30);
         sleep->SetTextColor(Color::Purple());
         walkStr = "--";
-        InitLabel(walk, 321, 238, 230, 47, "walklabel", walkStr.c_str(), DEFAULT_VECTOR_FONT_FILENAME, 30);
+        InitLabelAdapt(walk, 321, 238, 230, 47, "walklabel", walkStr.c_str(), DEFAULT_VECTOR_FONT_FILENAME, 30);
         walk->SetTextColor(Color::Purple());
         /* -------------------------------- 将组件添加到根视图 ------------------------------- */
         Add(resttitle);