-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathILI9341_t3_Menu.h
316 lines (215 loc) · 9.53 KB
/
ILI9341_t3_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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/*
The MIT License (MIT)
library writen by Kris Kasprzak
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.
On a personal note, if you develop an application or product using this library
and make millions of dollars, I'm happy for you!
rev date author change
1.0 1/2022 kasprzak initial code
2.0 1/2022 kasprzak added touch support
4.0 8/21/2024 kasprzak fixed a nast bug if number of menu items = MAX_OPT in the .h
// Website for generating icons
// https://javl.github.io/image2cpp/
*/
#ifndef ILI9341_MENU_H
#define ILI9341_MENU_H
#define ILI9341_MENU_VER 4.0
#if ARDUINO >= 100
#include "Arduino.h"
#include "Print.h"
#else
#endif
#ifdef __cplusplus
#endif
#include <ILI9341_t3.h>
#define MAX_OPT+1 15 // max elements in a menu, increase as needed
#define MAX_CHAR_LEN 30 // max chars in menus, increase as needed
#define TRIANGLE_H 3.7
#define TRIANGLE_W 2.5
#define MENU_C_DKGREY 0x4A49 // used for disable color, method to change
#define EXIT_TEXT "Exit" // default text for menu exit text, change here or use a method
#define EDIT_TEXT "Edit" // default text for menu exit text, change here or use a method
#define ICON_NONE 0
#define ICON_MONO 1
#define ICON_565 2
#define BUTTON_PRESSED 1
#define BUTTON_NOTPRESSED 0
class EditMenu {
public:
EditMenu(ILI9341_t3 *Display,bool EnableTouch = false);
void init(uint16_t TextColor, uint16_t BackgroundColor,
uint16_t HighlightTextColor, uint16_t HighlightColor,
uint16_t SelectedTextColor, uint16_t SelectedColor,
uint16_t MenuColumn, uint16_t ItemRowHeight,uint16_t MaxRow,
const char *TitleText, const ILI9341_t3_font_t &ItemFont, const ILI9341_t3_font_t &TitleFont);
int addNI(const char *ItemText, float Data, float LowLimit, float HighLimit,
float Increment, byte DecimalPlaces = 0, const char **ItemMenuText = NULL);
int addMono(const char *ItemText, float Data, float LowLimit, float HighLimit,
float Increment, byte DecimalPlaces = 0,const char **ItemMenuText = NULL,
const unsigned char *Bitmap = nullptr, uint8_t BitmapWidth = 0, uint8_t BitmapHeight = 0);
int add565(const char *ItemText, float Data, float LowLimit, float HighLimit,
float Increment, byte DecimalPlaces = 0, const char **ItemMenuText = NULL,
const uint16_t *Bitmap = nullptr, uint8_t BitmapWidth = 0, uint8_t BitmapHeight = 0);
int selectRow();
void draw();
void MoveUp();
void MoveDown();
void setTitleColors(uint16_t TitleTextColor, uint16_t TitleFillColor);
void setTitleBarSize(uint16_t TitleTop, uint16_t TitleLeft, uint16_t TitleWith, uint16_t TitleHeight);
void setTitleText( char *TitleText, char *ExitText);
void setTitleText( char *TitleText, char *ExitText, char *EditText);
void setTitleTextMargins(uint16_t LeftMargin, uint16_t TopMargin);
void setIncrementDelay(uint16_t Delay);
void setMenuBarMargins(uint16_t LeftMargin, uint16_t Width, uint16_t BorderRadius, uint16_t BorderThickness);
void setItemColors( uint16_t DisableTextColor, uint16_t BorderColor, uint16_t EditModeBorderColor = 0);
void setItemTextMargins(uint16_t LeftMargin, uint16_t TopMargin, uint16_t MenuMargin);
void setItemText(int ItemID, const char *ItemText);
void setIconMargins(uint16_t LeftMargin, uint16_t TopMargin);
void SetItemValue(int ItemID, float ItemValue);
void SetAllColors(uint16_t TextColor, uint16_t BackgroundColor,
uint16_t HighlightTextColor, uint16_t HighlightColor, uint16_t HighlightBorderColor,
uint16_t SelectedTextColor, uint16_t SelectedColor, uint16_t SelectBorderColor,
uint16_t DisableTextColor , uint16_t TitleTextColor, uint16_t TitleFillColor);
void disable(int ID);
void enable(int ID);
bool getEnableState(int ID);
int press(int16_t ScreenX, int16_t ScreenY);
void drawRow(int ID);
float value[MAX_OPT+1];
int item;
private:
void drawHeader(bool ShowEdit);
void up();
void down();
void incrementUp();
void incrementDown();
void drawItems();
void drawMonoBitmap(int16_t x, int16_t y, const unsigned char *bitmap, uint8_t w, uint8_t h, uint16_t color);
void draw565Bitmap(int16_t x, int16_t y, const uint16_t *bitmap, uint8_t w, uint8_t h);
ILI9341_t3 *d;
char itemlabel[MAX_OPT+1][MAX_CHAR_LEN];
char ttx[MAX_CHAR_LEN];
char etx[MAX_CHAR_LEN];
char dtx[MAX_CHAR_LEN];
ILI9341_t3_font_t itemf;
ILI9341_t3_font_t titlef;
uint16_t itc, ibc, ihtc, ihbc, istc, isbc; // item variables
uint16_t tbl, tbt, tbw, tbh, ttc, tfc, tox, toy; // title variables
// margins
uint16_t imr, isx, itx, isy, irh, irw, ioy, iox, mm,icox, icoy;
int i;
int totalID;
int MaxRow;
int currentID;
int cr;
byte debounce;
int sr, pr;
uint16_t col;
float data[MAX_OPT+1];
float low[MAX_OPT+1];
float high[MAX_OPT+1];
float inc[MAX_OPT+1];
byte dec[MAX_OPT+1];
char **itemtext[MAX_OPT+1];
bool rowselected = false;
bool haslist[MAX_OPT+1];
bool enablestate[MAX_OPT+1];
bool drawTitleFlag = true;
bool redraw = false;
uint16_t ditc = 0;
uint16_t temptColor = 0, bcolor, sbcolor;
const unsigned char *itemBitmap[MAX_OPT+1];
const uint16_t *item565Bitmap[MAX_OPT+1];
uint8_t bmp_w[MAX_OPT+1];
uint8_t bmp_h[MAX_OPT+1];
byte IconType[MAX_OPT+1];
uint16_t radius = 0;
uint16_t thick = 0;
uint16_t incdelay = 50;
bool InputFromTouch = false;
bool dh = true;
};
class ItemMenu {
public:
ItemMenu(ILI9341_t3 *Display, bool EnableTouch = false);
void init(uint16_t TextColor, uint16_t BackgroundColor,
uint16_t HighlightTextColor, uint16_t HighlightColor,
uint16_t ItemRowHeight,uint16_t MaxRow,
const char *TitleText, const ILI9341_t3_font_t &ItemFont, const ILI9341_t3_font_t &TitleFont);
int addNI(const char *ItemLabel);
int addMono(const char *ItemLabel, const unsigned char *Bitmap, uint8_t BitmapWidth, uint8_t BitmapHeight );
int add565(const char *ItemLabel, const uint16_t *Bitmap, uint8_t BitmapWidth, uint8_t BitmapHeight);
void draw();
void MoveUp();
void MoveDown();
int selectRow();
void setTitleColors(uint16_t TitleTextColor, uint16_t TitleFillColor);
void setTitleBarSize(uint16_t TitleTop, uint16_t TitleLeft, uint16_t TitleWith, uint16_t TitleHeight);
void setTitleText( char *TitleText, char *ExitText);
void setTitleText(char *TitleText, char *ExitText, char *EditText);
void setTitleTextMargins(uint16_t LeftMargin, uint16_t TopMargin);
void setMenuBarMargins(uint16_t LeftMargin, uint16_t Width, byte BorderRadius, byte BorderThickness);
void setItemColors( uint16_t DisableTextColor, uint16_t BorderColor);
void setItemTextMargins(uint16_t LeftMargin, uint16_t TopMargin, uint16_t MenuMargin);
void setItemText(int ItemID, const char *ItemText);
void setIconMargins(uint16_t LeftMargin, uint16_t TopMargin);
void SetAllColors(uint16_t TextColor, uint16_t BackgroundColor, uint16_t HighlightTextColor, uint16_t HighlightColor,
uint16_t HighLightBorderColor, uint16_t DisableTextColor, uint16_t TitleTextColor, uint16_t TitleFillColor);
void disable(int ID);
void enable(int ID);
bool getEnableState(int ID);
int press(int16_t ScreenX, int16_t ScreenY);
void drawRow(int ID, uint8_t style);
float value[MAX_OPT+1];
int item;
private:
void drawHeader(bool ShowEdit);
void drawItems();
void drawMonoBitmap(int16_t x, int16_t y, const unsigned char *bitmap, uint8_t w, uint8_t h, uint16_t color);
void draw565Bitmap(int16_t x, int16_t y, const uint16_t *Bitmap , uint8_t w, uint8_t h);
ILI9341_t3 *d;
//bool enabletouch;
char itemlabel[MAX_OPT+1][MAX_CHAR_LEN];
char ttx[MAX_CHAR_LEN];
char etx[MAX_CHAR_LEN];
char dtx[MAX_CHAR_LEN];
ILI9341_t3_font_t itemf;
ILI9341_t3_font_t titlef;
uint16_t bkgr, isx, itx, isy, irh, itc, ibc, ihbc, ihtc, isc, imr, irw, ioy, iox; // item variables
uint16_t tbl, tbt, tbw, tbh, ttc, tfc, tox, toy, icox, icoy, di, mm; // title variables
uint16_t ditc, difc, temptColor, bcolor;
bool hasIcon = false, moreup = false, moredown = false;
int i;
int totalID;
int MaxRow;
int currentID;
int cr;
byte debounce;
int sr, pr;
const unsigned char *itemBitmap[MAX_OPT+1];
const uint16_t *item565Bitmap[MAX_OPT+1];
bool rowselected = false;
bool drawTitleFlag = true;
bool redraw = false;
bool enablestate[MAX_OPT+1];
uint8_t bmp_w[MAX_OPT+1];
uint8_t bmp_h[MAX_OPT+1];
byte IconType[MAX_OPT+1];
byte radius, thick;
bool InputFromTouch = false;
bool dh = true; // draw header
};
#endif