From 5763ae213b8d80d764c3eaaae186f2cfea9e2be0 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Tue, 13 Aug 2024 16:05:03 +0800 Subject: [PATCH] =?utf8?q?=E6=B6=88=E6=81=AF=E8=AF=A6=E6=83=85=E7=95=8C?= =?utf8?q?=E9=9D=A2=E8=B0=83=E4=BC=98=20=E8=BF=98=E6=9C=89=E7=89=B9?= =?utf8?q?=E6=AE=8A=E6=83=85=E5=86=B5=E9=9C=80=E8=A6=81=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/message/src/MessageShowView.cpp | 42 +++++++++---------- .../nativeui/message/src/MessageView.cpp | 4 ++ 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageShowView.cpp b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageShowView.cpp index 904671d60..306d9a429 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageShowView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageShowView.cpp @@ -114,29 +114,27 @@ namespace OHOS } void MessageShowView::UpdateShowConfig() { - /* - 默认配置 : - 矩形长:60 - label长:40 - 通过字符串内容配置 - 一行最多显示 30 个字符 - 一行 矩形背景长加 40 - 一行 label长加 50 - */ - - const int maxCharsPerLine = 30; + // 默认配置: 矩形和标签的初始宽度 + const int maxCharsPerLine = 39; + const int baseRectWidth = defaultRectWidth; + const int baseLabelWidth = defaultLabelWidth; + const int extraRectWidthPerLine = 30; + const int extraLabelWidthPerLine = 50; // 计算行数 - int lines = (messageStr.size() / maxCharsPerLine) + (messageStr.size() % maxCharsPerLine ? 1 : 0); - - // 默认情况下,矩形宽度不变。如果有多行,则更新 - int updatedRectWidth = defaultRectWidth + (lines > 1 ? (lines * 10) : 0); - int updatedLabelWidth = defaultLabelWidth + (lines > 1 ? (lines * 50) : 0); + int totalChars = messageStr.size(); + int lines = (totalChars / maxCharsPerLine) + (totalChars % maxCharsPerLine ? 1 : 0); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UpdateShowConfig lines %d", lines); - /*小于2行不需要变化*/ + // 小于等于2行时,无需更新 if (lines <= 2) return; + // 计算更新后的宽度 + int additionalLines = lines - 1; // 增加一行预备 + int updatedRectWidth = baseRectWidth + (additionalLines * extraRectWidthPerLine); + int updatedLabelWidth = baseLabelWidth + (additionalLines * extraLabelWidthPerLine); + // 输出配置结果 messageButton->SetPosition(33, 157, 400, updatedRectWidth); deleteButton->SetPosition(43, 157 + updatedRectWidth + 20, 380, 100); @@ -186,7 +184,7 @@ namespace OHOS // messageButton->SetText(messageStr.c_str()); // messageButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); /* -------------------------------------------------------------------------- */ - InitUILabel(message, 68, 170, 320, 100, "message", messageStr.c_str(), DEFAULT_VECTOR_FONT_FILENAME, 30); + InitUILabel(message, 63, 165, 340, 100, "message", messageStr.c_str(), DEFAULT_VECTOR_FONT_FILENAME, 30); message->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); // 宽固定 高度变长! message->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); /*加载清除按键*/ @@ -236,10 +234,12 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "container_ new fail"); return; } - container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); - container_->SetScrollBlankSize(35); + container_->SetPosition(0, 0); + container_->Resize(VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION); + container_->SetScrollBlankSize(20); container_->SetReboundSize(50); - container_->SetDirection(1); + // container_->SetHorizontalScrollState(false); // 设置水平滚动失效 + // container_->SetDirection(1); container_->SetOnDragListener(presenter_); container_->SetTouchable(true); diff --git a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageView.cpp b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageView.cpp index 9e86c6b53..71d272d2f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageView.cpp @@ -228,9 +228,11 @@ namespace OHOS // SetContainerView(new UIScrollView()); container_ = new UIScrollView(); container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + container_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); container_->SetOnDragListener(presenter_); container_->SetTouchable(true); container_->SetDraggable(true); + // container_->SetFullScreenBlur(true); // 设置高斯模糊 ShowLackView(); ShowMessageView(); @@ -257,8 +259,10 @@ namespace OHOS { messageView->Add(MessageList); messageView->Add(DeleteButton); + // messageView->SetFullScreenBlur(true); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageList is add"); container_->Add(messageView); + // container_->SetFullScreenBlur(true); MessageList->SetAdapter(p_MessageListAdapter); } Draw(); -- 2.17.1