forked from sle118/FreeTouchDeck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu.h
95 lines (91 loc) · 2.7 KB
/
Menu.h
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
95
#pragma once
#include <Arduino.h>
#include <map>
#include <list>
#include <vector>
#include "cJSON.h" // using cJSON for menu processing
#include <FS.h> // Filesystem support header
#include "FTButton.h"
#include "UserConfig.h"
#include "globals.hpp"
namespace FreeTouchDeck
{
enum class MenuTypes
{
NONE,
STANDARD,
OLDHOME,
SYSTEM,
HOME,
ROOT,
HOMESYSTEM,
EMPTY,
ENDLIST
};
class Menu
{
public:
static const char *JsonLabelName;
static const char *JsonLabelLabel;
static const char *JsonLabelRowsCount;
static const char *JsonLabelColsCount;
static const char *JsonLabelButtons;
static const char *JsonLabelBackgroundColor;
static const char *JsonLabelActions;
static const char *JsonLabelType;
static const char *JsonLabelIcon;
static const char *JsonLabelOutline;
static const char *JsonLabelTextColor;
std::string Name;
std::string Icon;
std::string Label;
uint8_t ColsCount = 0;
uint8_t RowsCount = 0;
uint8_t Spacing = 3;
uint32_t BackgroundColor = TFT_BLACK;
MenuTypes Type = MenuTypes::STANDARD;
bool Active = false;
bool Loaded = true;
std::vector<FTButton> buttons;
bool Pressed = false;
Menu(cJSON *menuJson);
Menu(MenuTypes menutype, const char *name, const char *label, const char *icon, uint8_t rowsCount, uint8_t colsCount, uint32_t backgroundColor, uint32_t outline, uint32_t textColor, uint8_t textSize);
void DrawShape(bool force = false);
void DrawImages(bool force = false);
~Menu();
void Touch(uint16_t x, uint16_t y);
void ReleaseAll();
void Activate();
// void Init(uint8_t rowsCount, uint8_t colsCount);
bool Button(FTAction *action);
FTButton &GetButton(const std::string &buttonName);
void Deactivate();
cJSON *ToJSON();
static Menu *FromJson(const char *jsonString);
uint16_t ButtonWidth = 0;
uint16_t ButtonHeight = 0;
void AddButton(FTButton &button);
ActionSequencesList Actions;
private:
uint32_t _outline = 0xFFFFFFFF;
uint8_t _textSize = KEY_TEXTSIZE;
uint32_t _textColor = 0xFFFFFFFF;
// bool LoadConfig(File *config);
// bool LoadConfig(const char *config);
void SetButtonWidth();
inline bool HasBackButton()
{
return Type != MenuTypes::EMPTY && Type != MenuTypes::ROOT && Type != MenuTypes::SYSTEM;
}
static FTAction *homeMenu;
};
inline MenuTypes &operator++(MenuTypes &state, int)
{
int i = static_cast<int>(state) + 1;
i = i >= (int)MenuTypes::ENDLIST ? (int)MenuTypes::NONE : i;
state = static_cast<MenuTypes>(i);
return state;
}
const char *enum_to_string(MenuTypes value);
bool parse(const char *value, MenuTypes *result);
}