~aleteoryx/muditaos

ref: efef3c368c389fc9f9eb4318b474be6aef655080 muditaos/module-gui/gui/widgets/TopBar/BatteryBar.cpp -rw-r--r-- 2.1 KiB
efef3c36 — Alek Rudnik [EGD-6043] Change status bar layout 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "BatteryBar.hpp"
#include "Style.hpp"
#include "Utils.hpp"
#include "visitor/GuiVisitor.hpp"
#include <Image.hpp>

namespace gui::top_bar
{
    namespace
    {
        constexpr auto batteryLow           = "battery_low_W_M";
        constexpr auto batteryCharging      = "battery_charging_W_M";
        constexpr auto batteryChargingReady = "battery_charging_ready_W_M";
        constexpr auto battery1             = "battery1_W_M";
        constexpr auto battery2             = "battery2_W_M";
        constexpr auto battery3             = "battery3_W_M";
        constexpr auto battery4             = "battery4_W_M";
        constexpr auto battery5             = "battery5_W_M";

        constexpr auto level1Threshold = 5;
        constexpr auto level2Threshold = 27;
        constexpr auto level3Threshold = 50;
        constexpr auto level4Threshold = 73;
        constexpr auto level5Threshold = 95;
    } // namespace

    BatteryBar::BatteryBar(Item *parent, uint32_t x, uint32_t y, uint32_t w, uint32_t h)
        : BatteryBase(parent, x, y, w, h)
    {
        img = new Image(this, battery1);

        setMinimumSize(img->getWidth(), style::header::status_bar::height);
    }

    void BatteryBar::showBatteryLevel(std::uint32_t percentage)
    {
        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 {
            img->set(battery5);
        }
    }

    void BatteryBar::showBatteryCharging()
    {
        img->set(batteryCharging);
    }

    void BatteryBar::showBatteryChargingDone()
    {
        img->set(batteryChargingReady);
    }

} // namespace gui::top_bar