-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathLcdMenu.h
132 lines (124 loc) · 4.28 KB
/
LcdMenu.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
LcdMenu.h - Main include file for the LcdMenu Library
MIT License
Copyright (c) 2020-2024 Forntoh Thomas
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include "MenuScreen.h"
#include "renderer/MenuRenderer.h"
#include "utils/constants.h"
#include <MenuItem.h>
#include <utils/utils.h>
/**
* @class LcdMenu
* @brief Represents the main menu object.
*
* The LcdMenu class is the main object that manages the menu system. It is
* responsible for displaying the menu on the screen, processing user input,
* and updating the display based on the user's actions.
*/
class LcdMenu {
private:
/**
* @brief The renderer used to display the menu on the screen.
*/
MenuRenderer& renderer;
/**
* @brief Currently visible menu screen.
*/
MenuScreen* screen = NULL;
/**
* @brief Enabled flag of menu.
* Determines whether the screen should be updated after an action. Set it
* to `false` when you want to display any other content on the screen then
* set it back to `true` to show the menu.
*/
bool enabled = true;
public:
/**
* Construct new instance of `LcdMenu`.
*/
LcdMenu(MenuRenderer& renderer) : renderer(renderer) {}
/**
* @brief Get the renderer.
* @return the renderer
*/
MenuRenderer* getRenderer();
/**
* @brief Get the screen that currently on display.
* @return currently active screen
*/
MenuScreen* getScreen();
/**
* @brief Set new screen to display.
* The only place that clears whole screen.
* Then it Will `draw` of new screen screen using the renderer.
* @param screen the new screen to display
*/
void setScreen(MenuScreen* screen);
/**
* @brief Process the input character.
* @param c the input character
* @return `true` if the input was processed successfully
*/
bool process(const unsigned char c);
/**
* @brief Reset current screen to initial state.
* Moves cursor and view positions to zero.
*/
void reset();
/**
* @brief Hide the menu.
* When you want to display any other content on the screen then
* call this function then display your content, later call
* `show()` to show the menu
*/
void hide();
/**
* @brief Show the menu.
*/
void show();
/**
* @brief Get the current cursor position of current screen.
* @return the 0-based `cursor` position
*/
uint8_t getCursor();
/**
* @brief Set the current cursor position
* @param cursor the 0-based `cursor` position
*/
void setCursor(uint8_t cursor);
/**
* @brief Get `MenuItem` at position on current screen.
* @return `MenuItem` item at `position`
*/
MenuItem* getItemAt(uint8_t position);
/**
* @brief Refresh the current screen.
*/
void refresh();
/**
* @brief Poll the menu for changes.
* This method is used to update the menu at regular intervals,
* for example, when a value bound to an item changes, the menu needs to be updated.
* This method should be called in the `loop` function of the sketch.
*
* @param pollInterval the interval to update the menu in milliseconds (default is 1000)
*/
void poll(uint16_t pollInterval = 1000);
};