static constexpr const int kTimeHeight = 33;
static constexpr const int kTimeFontSize = 28;
static constexpr const char *kTimeViewId = "time";
+
+ // 配置默认值
+ static constexpr const int defaultRectWidth = 100;
+ static constexpr const int defaultLabelWidth = 40;
// static constexpr const Color kTimeTextColor = Color::Gray();
#if 0
std::string titleStr = "12306中国高速铁路";
std::string timeStr = "2023.12.26 17:23";
- std::string messageStr = "【铁路12306】系统已自动为您生成订单EC09828333,04月23日G2231次,深圳北站13:31开。请您在2小时内完成支付。您可通过以下链接进行支付。https://www.12306.cn/index/";
+ std::string messageStr = "【铁路12306】系统已自动为您生成订单EC09828333,04月23日G2231次,深圳北站13:31开。请您在2小时内完成支付。您可通过以下链接进行支付。https://www.12306.cn/index/";
#endif
MessageShowView::MessageShowView()
label = new UILabel();
if (label == nullptr)
{
- return; // 内存分配失败,返回
+ return; // 内存分配失败,返回
}
label->SetPosition(posX, posY);
label->Resize(width, height);
button = new UILabelButton();
if (button == nullptr)
{
- return; // 内存分配失败,返回
+ return; // 内存分配失败,返回
}
button->SetPosition(left, top);
button->Resize(width, height);
button->SetStyleForState(STYLE_BORDER_COLOR, PRESSED_BORDER_COLOR, UIButton::PRESSED);
button->SetVisible(true);
}
+ void MessageShowView::UpdateShowConfig()
+ {
+ /*
+ 默认配置 :
+ 矩形长:60
+ label长:40
+ 通过字符串内容配置
+ 一行最多显示 30 个字符
+ 一行 矩形背景长加 40
+ 一行 label长加 50
+ */
+
+ const int maxCharsPerLine = 30;
+
+ // 计算行数
+ 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);
+
+ /*小于2行不需要变化*/
+ if (lines <= 2)
+ return;
+
+ // 输出配置结果
+ messageButton->SetPosition(33, 157, 400, updatedRectWidth);
+ deleteButton->SetPosition(43, 157 + updatedRectWidth + 20, 380, 100);
+
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "updatedRectWidth %d updatedLabelWidth %d lines %d \r\n", updatedRectWidth, updatedLabelWidth, lines);
+ }
void MessageShowView::InitView()
{
- // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitView");
/* -------------------------------------------------------------------------- */
title = new UILabel();
if (title == nullptr)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "title:: new UILabel fail");
- return; // 内存分配失败,返回
+ return; // 内存分配失败,返回
}
title->SetPosition(83, 60, 300, 35);
title->SetText(titleStr.c_str());
title->SetStyle(STYLE_TEXT_FONT, 30);
- title->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ title->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); // 来回滚动属性
+ title->SetRollSpeed(70);
title->SetVisible(true);
/* -------------------------------------------------------------------------- */
time = new UILabel();
if (time == nullptr)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "time:: new UILabel fail");
- return; // 内存分配失败,返回
+ return; // 内存分配失败,返回
}
time->SetPosition(73, 104, 320, 33);
time->SetViewId("time");
time->SetVisible(true);
/* -------------------------------------------------------------------------- */
/*初始化消息内容*/
- InitializeButton(messageButton, 33, 157, 380, 350, "message");
+ InitializeButton(messageButton, 33, 157, 400, defaultRectWidth, "message");
messageButton->SetStyle(STYLE_BORDER_RADIUS, 30);
- messageButton->SetText(messageStr.c_str());
+ messageButton->SetAlign(TEXT_ALIGNMENT_LEFT);
messageButton->SetTextColor(Color::Gray());
messageButton->SetTouchable(false);
- messageButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ // 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);
+ message->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); // 宽固定 高度变长!
+ message->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER);
/*加载清除按键*/
- InitButtonExt(deleteButton, 43, 527, 380, 100, DELETEBUTTON, STR_CLEAN, 30);
+ InitButtonExt(deleteButton, 43, 157 + defaultRectWidth + 20, 380, 100, DELETEBUTTON, STR_CLEAN, 30);
deleteButton->SetOnClickListener(static_cast<UIView::OnClickListener *>(MessageShowPresenter::GetInstance()));
/* -------------------------------------------------------------------------- */
container_->Add(title);
container_->Add(time);
container_->Add(messageButton);
+ container_->Add(message);
container_->Add(deleteButton);
/* -------------------------------------------------------------------------- */
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitView is ok!");
View<MessageShowPresenter>::OnStart();
container_ = new UIScrollView();
- container_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
+ if (container_ == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "container_ new fail");
+ return;
+ }
+ container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
container_->SetScrollBlankSize(35);
container_->SetReboundSize(50);
+ container_->SetDirection(1);
container_->SetOnDragListener(presenter_);
container_->SetTouchable(true);
container_->SetDraggable(true);
+ // container_->SetStyle(STYLE_BACKGROUND_COLOR, BACK_GROUND_COLOR);
+ container_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
PreLoad();
+ UpdateShowConfig();
SetContainerView(container_);
RootView::GetInstance()->SetOnKeyActListener(presenter_);