M module-gui/gui/widgets/CMakeLists.txt => module-gui/gui/widgets/CMakeLists.txt +3 -2
@@ 22,7 22,9 @@ target_sources( ${PROJECT_NAME}
"${CMAKE_CURRENT_LIST_DIR}/BoxLayoutSizeStore.cpp"
"${CMAKE_CURRENT_LIST_DIR}/TopBar.cpp"
"${CMAKE_CURRENT_LIST_DIR}/TopBar/SIM.cpp"
- "${CMAKE_CURRENT_LIST_DIR}/TopBar/BatteryWidget.cpp"
+ "${CMAKE_CURRENT_LIST_DIR}/TopBar/BatteryWidgetBase.cpp"
+ "${CMAKE_CURRENT_LIST_DIR}/TopBar/BatteryWidgetBar.cpp"
+ "${CMAKE_CURRENT_LIST_DIR}/TopBar/BatteryWidgetText.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Text.cpp"
"${CMAKE_CURRENT_LIST_DIR}/TextBlock.cpp"
"${CMAKE_CURRENT_LIST_DIR}/TextDocument.cpp"
@@ 72,4 74,3 @@ target_sources( ${PROJECT_NAME}
"${CMAKE_CURRENT_LIST_DIR}/visitor/ItemTree.hpp"
"${CMAKE_CURRENT_LIST_DIR}/visitor/DepthFirstItemTree.hpp"
)
-
M module-gui/gui/widgets/TopBar.cpp => module-gui/gui/widgets/TopBar.cpp +11 -7
@@ 8,11 8,15 @@
#include "TopBar.hpp"
#include <time/time_conversion.hpp>
#include "Style.hpp"
-
+#include "TopBar/BatteryWidgetBar.hpp"
+#include "TopBar/BatteryWidgetText.hpp"
#include "common_data/EventStore.hpp"
namespace gui::top_bar
{
+ constexpr auto batteryWidgetAsText = false;
+ using BatteryWidgetType = std::conditional<batteryWidgetAsText, BatteryWidgetText, BatteryWidgetBar>::type;
+
namespace networkTechnology
{
constexpr uint32_t x = 80;
@@ 24,8 28,8 @@ namespace gui::top_bar
static constexpr uint32_t signalOffset = 35;
static constexpr uint32_t batteryOffset = 413;
- TopBar::TimeMode TopBar::timeMode = TimeMode::TIME_24H;
- uint32_t TopBar::time = 0;
+ TopBar::TimeMode TopBar::timeMode = TimeMode::TIME_24H;
+ uint32_t TopBar::time = 0;
void Configuration::enable(Indicator indicator)
{
@@ 84,7 88,7 @@ namespace gui::top_bar
signal[5] = new gui::Image(this, signalOffset, 17, 0, 0, "signal5");
updateSignalStrength();
- batteryWidget = new BatteryWidget(this, batteryOffset, 15);
+ batteryWidget = new BatteryWidgetType(this, batteryOffset, 15, 60, 24);
const auto design_sim_offset = 376; // this offset is not final, but it is pixel Purefect
sim = new SIM(this, design_sim_offset, 12);
@@ 229,8 233,8 @@ namespace gui::top_bar
void TopBar::setTime(uint32_t value, bool mode24H)
{
setTime(utils::time::Time());
- timeMode = (mode24H ? TimeMode::TIME_24H : TimeMode::TIME_12H);
- time = value;
+ timeMode = (mode24H ? TimeMode::TIME_24H : TimeMode::TIME_12H);
+ time = value;
}
UTF8 TopBar::getTimeString()
@@ 256,4 260,4 @@ namespace gui::top_bar
{
visitor.visit(*this);
}
-} /* namespace gui */
+} // namespace gui::top_bar
M module-gui/gui/widgets/TopBar.hpp => module-gui/gui/widgets/TopBar.hpp +2 -2
@@ 7,7 7,7 @@
#include "Label.hpp"
#include "Rect.hpp"
#include "TopBar/SIM.hpp"
-#include "TopBar/BatteryWidget.hpp"
+#include "TopBar/BatteryWidgetBase.hpp"
#include <common_data/EventStore.hpp>
#include <vector>
@@ 83,7 83,7 @@ namespace gui::top_bar
std::map<const Store::Battery::State, Image *> batteryChargings = {
{Store::Battery::State::Charging, nullptr}, {Store::Battery::State::PluggedNotCharging, nullptr}};
gui::SIM *sim = nullptr;
- gui::BatteryWidget *batteryWidget = nullptr;
+ gui::BatteryWidgetBase *batteryWidget = nullptr;
Configuration configuration;
static TimeMode timeMode;
R module-gui/gui/widgets/TopBar/BatteryWidget.cpp => module-gui/gui/widgets/TopBar/BatteryWidgetBar.cpp +30 -30
@@ 1,7 1,10 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
-#include "BatteryWidget.hpp"
+#include "BatteryWidgetBar.hpp"
+#include "Style.hpp"
+#include "Utils.hpp"
+#include "visitor/GuiVisitor.hpp"
namespace gui
{
@@ 23,45 26,42 @@ namespace gui
constexpr auto level5Threshold = 95;
} // namespace
- BatteryWidget::BatteryWidget(Item *parent, uint32_t x, uint32_t y) : Image(parent, x, y, 0, 0)
+ BatteryWidgetBar::BatteryWidgetBar(Item *parent, uint32_t x, uint32_t y, uint32_t w, uint32_t h)
+ : BatteryWidgetBase(parent, x, y, w, h)
{
- set(battery1);
+ img = new Image(this, battery1);
}
- void BatteryWidget::show(const Store::Battery batteryContext, bool shown)
+ void BatteryWidgetBar::showBatteryLevel(std::uint32_t percentage)
{
- if (shown) {
- switch (batteryContext.state) {
- case Store::Battery::State::Discharging:
- showBatteryBars(batteryContext.level);
- break;
- case Store::Battery::State::Charging:
- set(batteryCharging);
- break;
- case Store::Battery::State::PluggedNotCharging:
- set(batteryChargingReady);
- break;
- }
+ if (percentage <= level1Threshold) {
+ img->set(batteryLow);
+ }
+ else if (percentage <= level2Threshold) {
+ img->set(battery1);
+ }
+ else if (percentage <= level3Threshold) {
+ img->set(battery2);
+ }
+ else if (percentage <= level4Threshold) {
+ img->set(battery3);
+ }
+ else if (percentage <= level5Threshold) {
+ img->set(battery4);
}
else {
- setVisible(false);
+ img->set(battery5);
}
}
- void BatteryWidget::showBatteryBars(std::uint32_t percentage)
+ void BatteryWidgetBar::showBatteryCharging()
+ {
+ img->set(batteryCharging);
+ }
+
+ void BatteryWidgetBar::showBatteryPluggedNotCharging()
{
- if (percentage <= level1Threshold)
- set(batteryLow);
- else if (percentage <= level2Threshold)
- set(battery1);
- else if (percentage <= level3Threshold)
- set(battery2);
- else if (percentage <= level4Threshold)
- set(battery3);
- else if (percentage <= level5Threshold)
- set(battery4);
- else
- set(battery5);
+ img->set(batteryChargingReady);
}
} // namespace gui
R module-gui/gui/widgets/TopBar/BatteryWidget.hpp => module-gui/gui/widgets/TopBar/BatteryWidgetBar.hpp +9 -6
@@ 3,18 3,21 @@
#pragma once
-#include "../Image.hpp"
-#include <common_data/EventStore.hpp>
+#include "BatteryWidgetBase.hpp"
+#include "Image.hpp"
namespace gui
{
- class BatteryWidget : public Image
+ class BatteryWidgetBar : public BatteryWidgetBase
{
public:
- BatteryWidget(Item *parent, uint32_t x, uint32_t y);
- void show(const Store::Battery batteryContext, bool shown);
+ BatteryWidgetBar(Item *parent, uint32_t x, uint32_t y, uint32_t w, uint32_t h);
private:
- void showBatteryBars(std::uint32_t percentage);
+ void showBatteryLevel(std::uint32_t percentage) override;
+ void showBatteryPluggedNotCharging() override;
+ void showBatteryCharging() override;
+
+ Image *img = nullptr;
};
} // namespace gui
A module-gui/gui/widgets/TopBar/BatteryWidgetBase.cpp => module-gui/gui/widgets/TopBar/BatteryWidgetBase.cpp +35 -0
@@ 0,0 1,35 @@
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
+// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
+
+#include "BatteryWidgetBase.hpp"
+#include "BoxLayout.hpp"
+
+namespace gui
+{
+ BatteryWidgetBase::BatteryWidgetBase(Item *parent, uint32_t x, uint32_t y, uint32_t w, uint32_t h)
+ : HBox(parent, x, y, w, h)
+ {
+ setBorderColor(gui::ColorNoColor);
+ }
+
+ void BatteryWidgetBase::show(const Store::Battery batteryContext, bool shown)
+ {
+ if (shown) {
+ setVisible(true);
+ switch (batteryContext.state) {
+ case Store::Battery::State::Discharging:
+ showBatteryLevel(batteryContext.level);
+ break;
+ case Store::Battery::State::Charging:
+ showBatteryCharging();
+ break;
+ case Store::Battery::State::PluggedNotCharging:
+ showBatteryPluggedNotCharging();
+ break;
+ }
+ }
+ else {
+ setVisible(false);
+ }
+ }
+} // namespace gui
A module-gui/gui/widgets/TopBar/BatteryWidgetBase.hpp => module-gui/gui/widgets/TopBar/BatteryWidgetBase.hpp +23 -0
@@ 0,0 1,23 @@
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
+// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
+
+#pragma once
+
+#include "BoxLayout.hpp"
+#include <common_data/EventStore.hpp>
+
+namespace gui
+{
+ class HBox;
+
+ class BatteryWidgetBase : public HBox
+ {
+ virtual void showBatteryLevel(std::uint32_t percentage) = 0;
+ virtual void showBatteryPluggedNotCharging() = 0;
+ virtual void showBatteryCharging() = 0;
+
+ public:
+ BatteryWidgetBase(Item *parent, uint32_t x, uint32_t y, uint32_t w, uint32_t h);
+ void show(const Store::Battery batteryContext, bool shown);
+ };
+} // namespace gui
A module-gui/gui/widgets/TopBar/BatteryWidgetText.cpp => module-gui/gui/widgets/TopBar/BatteryWidgetText.cpp +37 -0
@@ 0,0 1,37 @@
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
+// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
+
+#include "BatteryWidgetText.hpp"
+#include "Label.hpp"
+#include <Utils.hpp>
+#include <Style.hpp>
+
+namespace gui
+{
+ BatteryWidgetText::BatteryWidgetText(Item *parent, uint32_t x, uint32_t y, uint32_t w, uint32_t h)
+ : BatteryWidgetBase(parent, x, y, w, h)
+ {
+ label = new Label(this, 0, 0, 0, 0);
+ label->setFilled(false);
+ label->setBorderColor(gui::ColorNoColor);
+ label->setFont(style::header::font::modes);
+ label->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Center));
+ label->setMaximumSize(this->getWidth(), this->getHeight());
+ }
+
+ void BatteryWidgetText::showBatteryLevel(std::uint32_t percentage)
+ {
+ label->setText(utils::to_string(percentage) + " %");
+ }
+
+ void BatteryWidgetText::showBatteryCharging()
+ {
+ label->setText(utils::localize.get("topbar_battery_charging"));
+ }
+
+ void BatteryWidgetText::showBatteryPluggedNotCharging()
+ {
+ label->setText(utils::localize.get("topbar_battery_plugged"));
+ }
+
+} // namespace gui
A module-gui/gui/widgets/TopBar/BatteryWidgetText.hpp => module-gui/gui/widgets/TopBar/BatteryWidgetText.hpp +22 -0
@@ 0,0 1,22 @@
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
+// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
+
+#pragma once
+
+#include "BatteryWidgetBase.hpp"
+
+namespace gui
+{
+ class Label;
+ class BatteryWidgetText : public BatteryWidgetBase
+ {
+ public:
+ BatteryWidgetText(Item *parent, uint32_t x, uint32_t y, uint32_t w, uint32_t h);
+
+ private:
+ void showBatteryLevel(std::uint32_t percentage) override;
+ void showBatteryPluggedNotCharging() override;
+ void showBatteryCharging() override;
+ Label *label = nullptr;
+ };
+} // namespace gui