~aleteoryx/muditaos

ref: d3173ad555cd1b5f097c06ca08fde90a57ba331c muditaos/module-apps/apps-common/widgets/TimeSetSpinner.hpp -rw-r--r-- 2.2 KiB
d3173ad5 — Lukasz Skrzypczak [BH-972] Fixed battery charging 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
// 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 "Rect.hpp"
#include <gui/widgets/Spinner.hpp>
#include <gui/widgets/Style.hpp>
#include <gui/widgets/TextConstants.hpp>

#include <string>

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

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

        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 updateColon(const std::string &fontName) noexcept -> void;
        auto setEditMode(EditMode editMode) noexcept -> void;
        auto setHourMax(std::uint32_t newMax) noexcept -> void;
        auto setHourMin(std::uint32_t newMin) noexcept -> void;
        [[nodiscard]] auto getHour() const noexcept -> int;
        [[nodiscard]] auto getMinute() const noexcept -> int;

      private:
        Spinner *hour        = nullptr;
        Label *colon         = nullptr;
        Spinner *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 onInput(const InputEvent &inputEvent) -> bool override;
        [[nodiscard]] auto getFontHeight(const std::string &fontName) const noexcept -> uint16_t;
        [[nodiscard]] auto getWidestDigitWidth(const std::string &fontName) const noexcept -> uint32_t;
        [[nodiscard]] auto getColonWidth(const std::string &fontName) const noexcept -> uint32_t;
    };
} /* namespace gui */