From: Caisking <3449750381@qq.com> Date: Thu, 27 Jun 2024 07:23:51 +0000 (+0800) Subject: 优化组件 X-Git-Tag: release_V1.2.70_20241020_135402~946 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=c4a53f01b84f64504107636039a214cb18b447e5;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 eefda1419..fb7b1a0dc 100644 --- a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp +++ b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp @@ -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) diff --git a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h index 869e038ce..597ed1b3c 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-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[默认参数]*/ diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepTimeView.cpp b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepTimeView.cpp index 8289c5d3c..7f234e0e1 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepTimeView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepTimeView.cpp @@ -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);