-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWidgets.ino
38 lines (30 loc) · 834 Bytes
/
Widgets.ino
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
boolean button(int16_t x, int16_t y, int16_t w, int16_t h, boolean sel, char *text) {
int16_t tpx = tp.y();
int16_t tpy = fb.getHeight() - tp.x();
boolean hover = (
tpx >= x && tpx < (x + w) &&
tpy >= y && tpy < (y + h)
);
uint16_t fg = MenuFG;
uint16_t bg = MenuBG;
if (sel) {
fg = MenuBG;
bg = MenuFG;
}
if (hover) {
bg = MenuHI;
}
fb.fillRoundRect(x, y, w, h, 8, bg);
fb.drawRoundRect(x, y, w, h, 8, fg);
fb.setFont(Fonts::Topaz);
fb.setTextColor(fg, fg);
uint16_t tw = fb.stringWidth(text);
fb.setCursor(x + (w/2) - (tw/2), y + (h/2) - 4);
fb.print(text);
return hover;
}
void hbar(int16_t x, int16_t y, int16_t w, int16_t h, float mval, float cval, uint16_t color) {
fb.drawRectangle(x, y, w, h, color);
float pct = cval / mval * (float)(w - 4);
fb.fillRect(x+2, y+2, pct, h-4, color);
}