-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathmain_menu.cpp
More file actions
96 lines (88 loc) · 2.87 KB
/
main_menu.cpp
File metadata and controls
96 lines (88 loc) · 2.87 KB
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
96
#include "main_menu.h"
#include "display.h"
#include "utils.h"
#include <globals.h>
MainMenu::MainMenu() {
_menuItems = {
&wifiMenu,
&bw16Menu,
&bleMenu,
#if !defined(LITE_VERSION)
ðernetMenu,
#endif
&rfMenu,
&rfidMenu,
&irMenu,
#if defined(FM_SI4713) && !defined(LITE_VERSION)
&fmMenu,
#endif
&fileMenu,
&gpsMenu,
&nrf24Menu,
#if !defined(LITE_VERSION)
#if !defined(DISABLE_INTERPRETER)
&scriptsMenu,
#endif
&loraMenu,
#endif
&othersMenu,
&clockMenu,
#if !defined(LITE_VERSION)
&connectMenu,
#endif
&configMenu,
};
_totalItems = _menuItems.size();
}
MainMenu::~MainMenu() {}
void MainMenu::begin(void) {
returnToMenu = false;
options = {};
std::vector<String> l = bruceConfig.disabledMenus;
for (int i = 0; i < _totalItems; i++) {
String itemName = _menuItems[i]->getName();
if (find(l.begin(), l.end(), itemName) == l.end()) { // If menu item is not disabled
options.push_back(
{// selected lambda
_menuItems[i]->getName(),
[this, i]() { _menuItems[i]->optionsMenu(); },
false, // selected = false
[](void *menuItem, bool shouldRender) { // render lambda
if (!shouldRender) return false;
drawMainBorder(false);
MenuItemInterface *obj = static_cast<MenuItemInterface *>(menuItem);
float scale = float((float)tftWidth / (float)240);
if (bruceConfigPins.rotation & 0b01) scale = float((float)tftHeight / (float)135);
obj->draw(scale);
#if defined(HAS_TOUCH)
TouchFooter();
#endif
return true;
},
_menuItems[i]
}
);
}
}
_currentIndex = loopOptions(options, MENU_TYPE_MAIN, "Main Menu", _currentIndex);
};
/*********************************************************************
** Function: hideAppsMenu
** Menu to Hide or show menus
**********************************************************************/
void MainMenu::hideAppsMenu() {
auto items = this->getItems();
RESTART: // using gotos to avoid stackoverflow after many choices
options.clear();
for (auto item : items) {
String label = item->getName();
std::vector<String> l = bruceConfig.disabledMenus;
bool enabled = find(l.begin(), l.end(), label) == l.end();
options.push_back({label, [this, label]() { bruceConfig.addDisabledMenu(label); }, enabled});
}
options.push_back({"Show All", [=]() { bruceConfig.disabledMenus.clear(); }, true});
addOptionToMainMenu();
loopOptions(options);
bruceConfig.saveFile();
if (!returnToMenu) goto RESTART;
}