@@ 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 <Text.hpp>
-#include <BoxLayout.hpp>
+#include <gui/widgets/text/TextFixedSize.hpp>
+#include <i18n/i18n.hpp>
+#include <string>
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<hours>(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
@@ 3,24 3,17 @@
#pragma once
-#include <ListItem.hpp>
+#include <common/widgets/BellSideListItemWithCallbacks.hpp>
-namespace gui
-{
- class Text;
- class VBox;
-} // namespace gui
+#include <chrono>
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