~aleteoryx/muditaos

0e8b4c848e3f87f3bbb1f64ef7460cf56017b87f — Lefucjusz 3 months ago e1d2330
[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.
M harmony_changelog.md => harmony_changelog.md +1 -0
@@ 3,6 3,7 @@
## Unreleased

### Fixed
* Fixed misaligned charging symbol on battery state screen

### Added
* Added custom quotations feature

M module-gui/gui/widgets/Rect.cpp => module-gui/gui/widgets/Rect.cpp +3 -1
@@ 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;

M products/BellHybrid/apps/common/include/common/data/BatteryUtils.hpp => products/BellHybrid/apps/common/include/common/data/BatteryUtils.hpp +1 -2
@@ 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

M products/BellHybrid/apps/common/include/common/windows/BellBatteryStatusWindow.hpp => products/BellHybrid/apps/common/include/common/windows/BellBatteryStatusWindow.hpp +6 -6
@@ 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

M products/BellHybrid/apps/common/src/windows/BellBatteryStatusWindow.cpp => products/BellHybrid/apps/common/src/windows/BellBatteryStatusWindow.cpp +45 -38
@@ 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<battery_utils::BatteryLevelEntry, 6>{{{{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();