~aleteoryx/muditaos

ref: 028229a9177e91be0798edeac6a0f12fa27d96fc muditaos/module-gui/gui/widgets/text/modes/InputMode.hpp -rw-r--r-- 1.5 KiB
028229a9 — Maciej-Mudita [MOS-924] Fix redundant logs about CSQ reporting mode 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
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <functional>
#include <list>
#include <utf8/UTF8.hpp>

/// this element has one goal - nicely change input parsing which is done in application in it's widgets
class InputMode
{
  public:
    /// ! when adding modes please update next method and input_mode (in cpp file)
    enum Mode
    {
        digit,
        Abc,
        abc,
        ABC,
        phone,
    };

  private:
    InputMode() = delete;
    // list of enabled input modes
    std::list<Mode> input_mode_list                    = {};
    uint32_t input_mode_list_pos                       = 0;
    std::function<void(const UTF8 &text)> show_type_cb = nullptr;
    std::function<void()> restore_after_show_type_cb   = nullptr;
    std::function<void()> show_special_char_selector   = nullptr;
    Mode modeNow() const;

    void show_input_type();

  public:
    void show_restore();
    InputMode(std::list<InputMode::Mode> mode_list,
              std::function<void(const UTF8 &text)> show_type_cb = nullptr,
              std::function<void()> restore_after_show_type_cb   = nullptr,
              std::function<void()> show_special_char_selector   = nullptr);

    void next();
    const std::string &get();
    const std::string &get(Mode mode);
    void select_special_char();
    [[nodiscard]] bool is(Mode mode) const
    {
        return mode == modeNow();
    }
};