~aleteoryx/muditaos

ref: 993c2c4f3f8922ccc748a1e7328a68c54c2240cf muditaos/module-apps/apps-common/widgets/TimeSetSpinner.hpp -rw-r--r-- 4.3 KiB
993c2c4f — rrandomsky [BH-1843] Add progress bar for volume adjustment windows 2 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <widgets/spinners/Spinners.hpp>
#include <gui/widgets/Style.hpp>
#include <gui/widgets/text/TextConstants.hpp>

#include <string>

namespace style::time_set_spinner
{
    namespace focus
    {
        inline constexpr auto size = 6U;
    } // namespace focus

    inline constexpr auto very_small_margin       = 3U;
    inline constexpr auto small_margin = 6U;
    inline constexpr auto big_margin   = 6U;
    inline constexpr auto gargantuan_margin_left  = 14U;
    inline constexpr auto gargantuan_margin_right = 7U;
} // namespace style::time_set_spinner

namespace gui
{
    class ImageBox;

    class TimeSetSpinner : public HBox
    {
      public:
        explicit TimeSetSpinner(Item *parent);
        TimeSetSpinner(Item *parent, Length x, Length y, Length w, Length h);

        auto setTime(std::time_t time) noexcept -> void;
        auto setTime(int hourValue, int minuteValue) noexcept -> void;
        auto setHour(int value) noexcept -> void;
        auto setMinute(int value) noexcept -> void;
        auto setFont(const std::string &newFontName) noexcept -> void;
        auto setFont(std::string newFocusFontName, std::string newNoFocusFontName) noexcept -> void;
        auto updateFont(TextFixedSize *elem, const std::string &fontName) noexcept -> void;
        auto setEditMode(EditMode editMode) noexcept -> void;
        auto setHourRange(std::uint32_t min, std::uint32_t max) -> void;
        [[nodiscard]] auto getHour() const noexcept -> int;
        [[nodiscard]] auto getMinute() const noexcept -> int;

      private:
        std::map<std::string, std::string> colonFontMap = {
            {style::window::font::verybiglight, "alarm_colon_W_M"},
            {style::window::font::veryverybiglight, "alarm_colon_W_M"},
            {style::window::font::largelight, "alarm_colon_W_M"},
            {style::window::font::supersizeme, "alarm_colon_select_W_M"},
            {style::window::font::supersizemelight, "alarm_colon_select_W_M"},
            {style::window::font::huge, "alarm_colon_clock_W_M"},
            {style::window::font::gargantuan, "alarm_colon_clock_W_M"}};

        std::map<std::string, Margins> colonMarginsMap = {
            {style::window::font::verybiglight,
             {style::time_set_spinner::very_small_margin, 0, style::time_set_spinner::very_small_margin, 0}},
            {style::window::font::veryverybiglight,
             {style::time_set_spinner::very_small_margin, 0, style::time_set_spinner::very_small_margin, 0}},
            {style::window::font::largelight,
             {style::time_set_spinner::small_margin, 0, style::time_set_spinner::small_margin, 0}},
            {style::window::font::supersizeme,
             {style::time_set_spinner::big_margin, 0, style::time_set_spinner::big_margin, 0}},
            {style::window::font::supersizemelight,
             {style::time_set_spinner::big_margin, 0, style::time_set_spinner::big_margin, 0}},
            {style::window::font::huge,
             {style::time_set_spinner::big_margin, 0, style::time_set_spinner::big_margin, 0}},
            {style::window::font::gargantuan,
             {style::time_set_spinner::gargantuan_margin_left,
              0,
              style::time_set_spinner::gargantuan_margin_right,
              0}}};

        U8IntegerSpinner *hour        = nullptr;
        ImageBox *colon              = nullptr;
        U8IntegerSpinnerFixed *minute = nullptr;
        EditMode editMode            = EditMode::Edit;
        Item *lastFocus              = nullptr;
        std::string focusFontName    = style::window::font::supersizeme;
        std::string noFocusFontName  = style::window::font::supersizemelight;

        void updateFocus(Item *newFocus);
        auto handleEnterKey() -> bool;
        auto handleRightFunctionKey() -> bool;
        auto applySizeRestrictions() -> void;
        auto onInput(const InputEvent &inputEvent) -> bool override;
        [[nodiscard]] auto getFontHeight(const std::string &fontName) const noexcept -> uint16_t;
        [[nodiscard]] auto getColonImage(const std::string &colonFont) const noexcept -> std::string;
        [[nodiscard]] auto getColonMargins(const std::string &colonFont) const noexcept -> Margins;
    };
} /* namespace gui */