From 0e8b4c848e3f87f3bbb1f64ef7460cf56017b87f Mon Sep 17 00:00:00 2001 From: Lefucjusz Date: Fri, 22 Aug 2025 13:36:09 +0200 Subject: [PATCH] [BH-2108] Fix misaligned charging symbol * Fixed misaligned charging symbol on battery popup, shown after holding back button. * Fixed improper handling of string_view storing battery image name. --- harmony_changelog.md | 1 + module-gui/gui/widgets/Rect.cpp | 4 +- .../include/common/data/BatteryUtils.hpp | 3 +- .../windows/BellBatteryStatusWindow.hpp | 12 +-- .../src/windows/BellBatteryStatusWindow.cpp | 83 ++++++++++--------- 5 files changed, 56 insertions(+), 47 deletions(-) diff --git a/harmony_changelog.md b/harmony_changelog.md index 3d53c433505e714307ffa504af0ffa68ab4b1e43..f63e237df82127494e23e7501b30adde1040637c 100644 --- a/harmony_changelog.md +++ b/harmony_changelog.md @@ -3,6 +3,7 @@ ## Unreleased ### Fixed +* Fixed misaligned charging symbol on battery state screen ### Added * Added custom quotations feature diff --git a/module-gui/gui/widgets/Rect.cpp b/module-gui/gui/widgets/Rect.cpp index 68a71b29928c7a9c9de316780973df01a3299d40..d9eaa62c9875e16b248521052cfe6b3c41197779 100644 --- a/module-gui/gui/widgets/Rect.cpp +++ b/module-gui/gui/widgets/Rect.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2025, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md /* @@ -43,10 +43,12 @@ namespace gui { borderColor = color; } + void Rect::setPenWidth(uint8_t width) { penWidth = width; } + void Rect::setPenFocusWidth(uint8_t width) { penFocusWidth = width; diff --git a/products/BellHybrid/apps/common/include/common/data/BatteryUtils.hpp b/products/BellHybrid/apps/common/include/common/data/BatteryUtils.hpp index ef8dd6b5b038404f8dd312d3a4b95e04107e4f3a..dfc358c1db65adb5174cc1512c7207ce1183bb31 100644 --- a/products/BellHybrid/apps/common/include/common/data/BatteryUtils.hpp +++ b/products/BellHybrid/apps/common/include/common/data/BatteryUtils.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2025, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md #pragma once @@ -33,5 +33,4 @@ namespace battery_utils return {}; } - } // namespace battery_utils diff --git a/products/BellHybrid/apps/common/include/common/windows/BellBatteryStatusWindow.hpp b/products/BellHybrid/apps/common/include/common/windows/BellBatteryStatusWindow.hpp index 64365925451b82647bc1e990eb857da7fccad8cf..35abe814c9a888042e7ef3f846da241ebc7f6919 100644 --- a/products/BellHybrid/apps/common/include/common/windows/BellBatteryStatusWindow.hpp +++ b/products/BellHybrid/apps/common/include/common/windows/BellBatteryStatusWindow.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2025, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md #pragma once @@ -8,7 +8,7 @@ namespace gui { - class TextFixedSize; + class Text; class ImageBox; class Image; @@ -17,7 +17,7 @@ namespace gui public: static constexpr auto windowName = "BellBatteryStatusWindow"; - BellBatteryStatusWindow(app::ApplicationCommon *app, const std::string &name = windowName); + explicit BellBatteryStatusWindow(app::ApplicationCommon *app, const std::string &name = windowName); private: void buildInterface() override; @@ -26,13 +26,13 @@ namespace gui void onClose(CloseReason reason) override; BellBaseLayout *body{}; - TextFixedSize *topDescription{}; + Text *topDescription{}; - TextFixedSize *bottomDescription{}; + Text *bottomDescription{}; ImageBox *chargingIcon{}; HBox *hbox{}; - ImageBox *center{}; + ImageBox *batteryImage{}; }; } // namespace gui diff --git a/products/BellHybrid/apps/common/src/windows/BellBatteryStatusWindow.cpp b/products/BellHybrid/apps/common/src/windows/BellBatteryStatusWindow.cpp index 1e285ebf0e60431c38ab46e9e65bcce5f1dee513..81d9577795fed1ed59e3c5c064a3ef2f4ffc3a78 100644 --- a/products/BellHybrid/apps/common/src/windows/BellBatteryStatusWindow.cpp +++ b/products/BellHybrid/apps/common/src/windows/BellBatteryStatusWindow.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2025, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md #include "windows/BellBatteryStatusWindow.hpp" @@ -15,11 +15,14 @@ namespace { using namespace std::chrono_literals; - constexpr auto top_description_font = style::window::font::largelight; - constexpr auto bottom_description_font = style::window::font::verybiglight; - constexpr auto bottom_description_max_size_w = style::bell_base_layout::outer_layouts_w; - constexpr auto bottom_description_max_size_h = 85U; - constexpr auto imageType = gui::ImageTypeSpecifier::W_G; + constexpr auto topDescriptionFont = style::window::font::largelight; + constexpr auto bottomDescriptionFont = style::window::font::verybiglight; + + constexpr auto bottomDescriptionMaxSizeW = style::bell_base_layout::outer_layouts_w; + constexpr auto bottomDescriptionMaxSizeH = 85U; + constexpr auto bottomDescriptionRightMargin = 8U; + constexpr auto chargingIconRightMargin = 12U; + constexpr auto batteryEntries = std::array{{{{0, 9}, "bell_status_battery_lvl0"}, {{10, 19}, "bell_status_battery_lvl1"}, @@ -27,12 +30,10 @@ namespace {{40, 69}, "bell_status_battery_lvl3"}, {{70, 95}, "bell_status_battery_lvl4"}, {{96, 100}, "bell_status_battery_lvl5"}}}; - // this time must be longer than the long press time (10s) to turn off the system - constexpr auto windowLongTimeout{12s}; - // default screen timeout - constexpr auto windowDefaultTimeout{3s}; - // default screen timeout for low battery warning - constexpr auto windowDefaultTimeoutForLowBatteryWarning{6s}; + + constexpr auto windowLongTimeout = 12s; // Must be longer than the long press time (10s) to turn off the system + constexpr auto windowDefaultTimeout = 3s; + constexpr auto windowLowBatteryTimeout = 6s; } // namespace namespace gui @@ -42,6 +43,7 @@ namespace gui { buildInterface(); } + void BellBatteryStatusWindow::buildInterface() { WindowWithTimer::buildInterface(); @@ -55,44 +57,46 @@ namespace gui topDescription = new TextFixedSize(body->firstBox); topDescription->setMinimumSize(style::bell_base_layout::outer_layouts_w, style::bell_base_layout::outer_layouts_h); - topDescription->setFont(top_description_font); + topDescription->setFont(topDescriptionFont); topDescription->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center)); topDescription->setEdges(RectangleEdge::None); - topDescription->activeItem = false; topDescription->drawUnderline(false); + topDescription->activeItem = false; hbox = new HBox(body->lastBox); hbox->setMinimumSize(style::bell_base_layout::outer_layouts_w, style::bell_base_layout::outer_layouts_h); hbox->setEdges(RectangleEdge::None); hbox->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center)); - chargingIcon = new ImageBox(hbox, 0, 0, 0, 0, new Image("bell_lightning", imageType)); - chargingIcon->setMargins(gui::Margins(0, 0, 8, 0)); + chargingIcon = new ImageBox(hbox, 0, 0, 0, 0, new Image("bell_lightning", gui::ImageTypeSpecifier::W_G)); chargingIcon->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center)); chargingIcon->setMinimumSizeToFitImage(); + chargingIcon->setMargins(gui::Margins(0, 0, chargingIconRightMargin, 0)); chargingIcon->activeItem = false; - bottomDescription = new TextFixedSize(hbox); - bottomDescription->setMaximumSize(bottom_description_max_size_w, bottom_description_max_size_h); - bottomDescription->setFont(bottom_description_font); + batteryImage = new ImageBox(body->centerBox, + 0, + 0, + style::bell_base_layout::w, + style::bell_base_layout::h, + new Image("bell_status_battery_lvl0", gui::ImageTypeSpecifier::W_G)); + batteryImage->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center)); + batteryImage->setEdges(RectangleEdge::None); + batteryImage->setMinimumSizeToFitImage(); + batteryImage->activeItem = false; + + bottomDescription = new Text(hbox); + bottomDescription->setMaximumSize(bottomDescriptionMaxSizeW, bottomDescriptionMaxSizeH); + bottomDescription->setFont(bottomDescriptionFont); bottomDescription->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center)); bottomDescription->setEdges(RectangleEdge::None); - bottomDescription->activeItem = false; + bottomDescription->setMargins(gui::Margins(0, 0, bottomDescriptionRightMargin, 0)); bottomDescription->drawUnderline(false); - - center = new ImageBox(body->centerBox, - 0, - 0, - style::bell_base_layout::w, - style::bell_base_layout::h, - new Image("bell_status_battery_lvl0", imageType)); - center->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center)); - center->setEdges(RectangleEdge::None); - center->setMinimumSizeToFitImage(); - center->activeItem = false; + bottomDescription->activeItem = false; body->resize(); } + bool BellBatteryStatusWindow::onInput(const InputEvent &inputEvent) { if (inputEvent.isShortRelease(KeyCode::KEY_ENTER) || inputEvent.isShortRelease(KeyCode::KEY_RF)) { @@ -100,7 +104,8 @@ namespace gui application->returnToPreviousWindow(); return true; } - else if (inputEvent.getKeyCode() == KeyCode::KEY_RF) { + + if (inputEvent.getKeyCode() == KeyCode::KEY_RF) { if (inputEvent.isLongRelease()) { // here the "back" button is held all the time, so we set the screen timeout to a long time // to stay on this screen until the system shutdown popup is displayed @@ -115,6 +120,7 @@ namespace gui return false; } + void BellBatteryStatusWindow::onBeforeShow(ShowMode mode, SwitchData *data) { if (data != nullptr) { @@ -125,28 +131,29 @@ namespace gui } const auto soc = batteryData->getBatteryLevel(); const bool isCharging = batteryData->isCharging(); - const bool isLowBatteryWarning = batteryData->isLowBatteryWarning(); - const auto image = battery_utils::getBatteryLevelImage(batteryEntries, soc); - if (isLowBatteryWarning) { + if (batteryData->isLowBatteryWarning()) { topDescription->setText(utils::translate("battery_low")); auto tokenMap = text::RichTextParser::TokenMap({{"$BATTERY", std::to_string(soc)}}); bottomDescription->setRichText(utils::translate("battery_remaining"), std::move(tokenMap)); chargingIcon->setVisible(false); - resetTimer(windowDefaultTimeoutForLowBatteryWarning); + resetTimer(windowLowBatteryTimeout); } else { topDescription->setText(utils::translate("app_settings_tech_info_battery")); bottomDescription->setText(std::to_string(soc) + "%"); chargingIcon->setVisible(isCharging); } - if (image) { - center->setImage(image->data(), imageType); + + const auto &image = battery_utils::getBatteryLevelImage(batteryEntries, soc); + if (image.has_value()) { + batteryImage->setImage(std::string{image.value()}, gui::ImageTypeSpecifier::W_G); hbox->resizeItems(); body->resize(); } } WindowWithTimer::onBeforeShow(mode, data); } + void BellBatteryStatusWindow::onClose(CloseReason reason) { application->popCurrentWindow();