From: Caisking <3449750381@qq.com> Date: Tue, 30 Jul 2024 11:49:54 +0000 (+0800) Subject: 优化组件函数 X-Git-Tag: release_V1.2.70_20241020_135402~730^2~9 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=ac7161a01d37336d21cf404863634107c08bfea8;p=mirrors%2FFD230.git 优化组件函数 --- diff --git a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp index 3c839e7eb..53429260b 100644 --- a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp +++ b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp @@ -31,10 +31,7 @@ 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) { // 检查标签指针是否为空 - if (label == nullptr) - { - label = new UILabel(); - } + label = new UILabel(); if (label == nullptr) { return false; // 内存分配失败,返回false @@ -49,12 +46,9 @@ namespace OHOS label->SetFont(fontName, fontSize); // 设置标签的文本和其他属性 label->SetText(text); - // label->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + 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; } /*** @@ -74,12 +68,11 @@ namespace OHOS bool InitLabel(UILabelExt *&label, int left, int top, int width, int height, const char *viewId, const char *text, const char *fontName, int fontSize) { // 检查标签指针是否为空 + + label = new UILabelExt(); if (label == nullptr) { - label = new UILabelExt(); - } - if (label == nullptr) - { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLabel is error"); return false; // 内存分配失败,返回false } // 设置标签的位置和大小 @@ -95,20 +88,16 @@ namespace OHOS 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) { // 检查标签指针是否为空 + label = new UILabelExt(); if (label == nullptr) { - label = new UILabelExt(); - } - if (label == nullptr) - { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLabelAdapt is error"); return false; // 内存分配失败,返回false } // 设置标签的位置和大小 @@ -124,9 +113,6 @@ namespace OHOS label->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); 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; } #ifdef FD230 @@ -147,12 +133,10 @@ namespace OHOS bool InitLabelExt(UILabelExt *&label, int left, int top, int width, int height, const char *viewId, UIResourceTextId id, const char *fontName, int fontSize) { // 检查标签指针是否为空 + label = new UILabelExt(); if (label == nullptr) { - label = new UILabelExt(); - } - if (label == nullptr) - { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLabelExt is error"); return false; // 内存分配失败,返回false } // 设置标签的位置和大小 @@ -165,13 +149,8 @@ namespace OHOS label->SetFont(fontName, fontSize); // 设置标签的文本和其他属性 label->SetTextId(id); - // label->SetFontId(); label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); label->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); - label->SetRollSpeed(100); - // 设置标签可见 - label->SetVisible(true); - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLabelExt is succeed"); return true; } @@ -194,6 +173,7 @@ namespace OHOS button = new UILabelButtonExt(); if (button == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitButtonExt is error"); return false; // 内存分配失败,返回false } button->SetPosition(left, top); @@ -302,12 +282,10 @@ namespace OHOS bool InitButton(UIButton *&button, int left, int top, int width, int height, const char *viewId) { // 创建新按钮(如果当前按钮为空) + button = new UIButton(); if (button == nullptr) { - button = new UIButton(); - } - if (button == nullptr) - { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new UIButton fail"); return false; // 内存分配失败,返回false } button->SetPosition(left, top); @@ -316,8 +294,6 @@ namespace OHOS 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); - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitButton is succeed"); return true; } @@ -335,21 +311,21 @@ namespace OHOS */ bool InitImageView(UIImageView *&imageView, int left, int top, int width, int height, const char *viewId, const char *imagePath) { + imageView = new UIImageView(); if (imageView == nullptr) { - imageView = new UIImageView(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "imagePath %s fail", imagePath); + return false; } - if (imageView == nullptr) + if (imagePath == nullptr) { - return false; // 内存分配失败,返回false + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "imagePath %s fail", imagePath); + return false; } imageView->SetPosition(left, top); imageView->SetAutoEnable(true); - // imageView->Resize(width, height); imageView->SetViewId(viewId); imageView->SetSrc(imagePath); - // imageView->SetVisible(true); - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitImageView is succeed"); return true; } /*带默认参数的初始化label*/ diff --git a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h index 4379cd419..3b0ea887f 100644 --- a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h +++ b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h @@ -1,7 +1,7 @@ -/*** +/*** * @Date: 2024-05-30 15:59:37 * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-07-12 10:42:20 + * @LastEditTime: 2024-07-29 14:19:44 * @FilePath: /FD230/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h */ /***