-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXUI_ScreenMenu.cpp
More file actions
81 lines (66 loc) · 1.89 KB
/
XUI_ScreenMenu.cpp
File metadata and controls
81 lines (66 loc) · 1.89 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
#include <sys/types.h>
#include "XUI_Engine.h"
XUI_ScreenMenu::XUI_ScreenMenu(string title, uint8_t displayLines)
: XUI_Screen(title)
{
this->displayLines = displayLines;
_draw = true;
uint8_t animationFrames = (displayLines == 3) ? 8 : 4;
xuiScroller = new XUI_Scroller(animationFrames, dynamic_cast<XUI_EventListener*> (this));
}
void XUI_ScreenMenu::bttn_event(uint8_t button){
_draw = true;
switch (button){
case BTTN_UP:
xuiScroller->scrollDown();
_draw = true;
break;
case BTTN_DOWN:
xuiScroller->scrollUp();
_draw = true;
break;
case BTTN_LEFT:
xuiEngine->nav(prevScreen);
break;
case BTTN_RIGHT:
if (xuiScreens.size() > menuIndex) xuiEngine->nav(xuiScreens[menuIndex]);
break;
}
}
void XUI_ScreenMenu::run(){
if (childrenCount == 0 && _draw){ // avoid drawing when we have no items to draw
xuiDisplay->clear();
} else if (_draw){ // avoid drawing when nothing has changed
_draw = xuiScroller->scrolling();
xuiDisplay->clear();
xuiDisplay->drawList(dynamic_cast<XUI_List*> (this), displayLines, menuIndex, xuiScroller->getOffset());
if (displayLines == DISPLAY_LINES_3){
xuiDisplay->drawBoxItemSelector(displayLines);
}else{
xuiDisplay->drawLineItemSelector(displayLines);
}
xuiDisplay->drawScrollIndicator(menuIndex, childrenCount);
xuiDisplay->display();
}
}
string XUI_ScreenMenu::getElement(uint8_t index){
return xuiScreens[index]->xuiTitle;
};
size_t XUI_ScreenMenu::getSize(){
return childrenCount;
}
void XUI_ScreenMenu::event(uint8_t event){
switch (event) {
case EVT_SCROLL_UP_END:
menuIndex++;
if (menuIndex == childrenCount) menuIndex = 0;
break;
case EVT_SCROLL_DOWN_END:
if (menuIndex == 0) {
menuIndex = childrenCount-1;
}else{
menuIndex--;
}
break;
}
};