From 84dd538fa9d47c1ef24ebc76bfd55f50282a42af Mon Sep 17 00:00:00 2001 From: Mateusz Piesta Date: Mon, 1 Aug 2022 09:18:14 +0200 Subject: [PATCH] [BH-1538] Stats info widget Created statistics info widget. --- .../widgets/SummaryListItem.cpp | 83 ++++++++++++------- .../widgets/SummaryListItem.hpp | 19 ++--- 2 files changed, 58 insertions(+), 44 deletions(-) diff --git a/products/BellHybrid/apps/application-bell-meditation-timer/widgets/SummaryListItem.cpp b/products/BellHybrid/apps/application-bell-meditation-timer/widgets/SummaryListItem.cpp index 01f3b64f93733237a91901418b7da3fdb2c49220..3bf110910ee8fd6236d19aea1a53c6d243ccbc86 100644 --- a/products/BellHybrid/apps/application-bell-meditation-timer/widgets/SummaryListItem.cpp +++ b/products/BellHybrid/apps/application-bell-meditation-timer/widgets/SummaryListItem.cpp @@ -1,46 +1,67 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "SummaryListItem.hpp" -#include -#include +#include +#include +#include namespace { - constexpr auto width = style::window::default_body_width; - constexpr auto height = 66; - constexpr auto title_height = 33; - constexpr auto value_height = 33; + std::string format(const std::chrono::minutes minutes) + { + using namespace std::chrono; + const auto hoursPart = duration_cast(minutes); + const auto minutesPart = minutes - hoursPart; + + std::string ret; + if (hoursPart.count() > 0) { + ret = std::to_string(hoursPart.count()) + std::string{" h "}; + } + ret += std::to_string(minutesPart.count()) + std::string{" "} + utils::translate("common_minute_short"); + + return ret; + } + } // namespace namespace app::meditation { using namespace gui; - SummaryListItem::SummaryListItem(const std::string &titleText, const std::string &valueText) + SummaryListItem::SummaryListItem(const std::string &topDescription, + const std::chrono::minutes total, + const std::chrono::minutes average) + : BellSideListItemWithCallbacks(topDescription) { - setMinimumSize(width, height); - setMargins(Margins(0, style::margins::big, 0, style::margins::huge)); - activeItem = false; - - body = new VBox(this, 0, 0, 0, 0); - body->setEdges(RectangleEdge::None); - - title = new Text(body, 0, 0, 0, 0); - title->setMinimumSize(width, title_height); - title->setFont(style::window::font::bigbold); - title->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Top)); - title->setText(titleText); - - value = new Text(body, 0, 0, 0, 0); - value->setMinimumSize(width, value_height); - value->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Bottom)); - value->setFont(style::window::font::big); - value->setText(valueText); - - dimensionChangedCallback = [&]([[maybe_unused]] Item &item, const BoundingBox &newDim) -> bool { - body->setArea({0, 0, newDim.w, newDim.h}); - return true; - }; + + auto duoBox = new VBox(body->getCenterBox()); + duoBox->setEdges(RectangleEdge::None); + duoBox->setAlignment(Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center)); + duoBox->setMaximumSize(::style::bell_base_layout::w, ::style::bell_base_layout::h); + + auto centerText = new TextFixedSize(duoBox); + centerText->setMinimumSize(style::bell_base_layout::w, 2 * (style::bell_base_layout::center_layout_h / 3)); + centerText->setFont(style::bell_sidelist_item::title_font); + centerText->setEdges(RectangleEdge::None); + centerText->activeItem = false; + centerText->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Top)); + centerText->setRichText(utils::translate("app_meditation_summary_total"), + text::RichTextParser::TokenMap({{"$VALUE", format(total)}})); + centerText->drawUnderline(false); + + auto centerText2 = new TextFixedSize(duoBox); + centerText2->setFont(style::bell_sidelist_item::title_font); + centerText2->setMinimumSize(style::bell_base_layout::w, style::bell_base_layout::center_layout_h / 3); + centerText2->setEdges(RectangleEdge::None); + centerText2->activeItem = false; + centerText2->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Bottom)); + centerText2->setRichText(utils::translate("app_meditation_summary_average")); + centerText2->drawUnderline(false); + + setupBottomDescription(format(average)); + bottomText->setFont(style::bell_sidelist_item::title_font); + bottomText->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Top)); + bottomText->setEdges(RectangleEdge::None); } } // namespace app::meditation diff --git a/products/BellHybrid/apps/application-bell-meditation-timer/widgets/SummaryListItem.hpp b/products/BellHybrid/apps/application-bell-meditation-timer/widgets/SummaryListItem.hpp index 861460cfe2d4f214657d941e9072e40682a425b7..6e451d3787beb26fab3cf8cd949c83b554854988 100644 --- a/products/BellHybrid/apps/application-bell-meditation-timer/widgets/SummaryListItem.hpp +++ b/products/BellHybrid/apps/application-bell-meditation-timer/widgets/SummaryListItem.hpp @@ -3,24 +3,17 @@ #pragma once -#include +#include -namespace gui -{ - class Text; - class VBox; -} // namespace gui +#include namespace app::meditation { - class SummaryListItem : public gui::ListItem + class SummaryListItem : public gui::BellSideListItemWithCallbacks { public: - SummaryListItem(const std::string &title, const std::string &value); - - private: - gui::VBox *body{}; - gui::Text *title{}; - gui::Text *value{}; + SummaryListItem(const std::string &topDescription, + std::chrono::minutes total, + std::chrono::minutes average); }; } // namespace app::meditation