Library to display menus on TextLCDs. Interaction with functions Up,Down and Select (Buttons or RPG) Based on menu-library from pyeh9
Fork of Menu by
Library to display menus on TextLCDs. Interaction with functions Up,Down and Select (Buttons or RPG) Based on menu-library from pyeh9
Diff: Navigator.cpp
- Revision:
- 8:fbaeab73fe1a
- Parent:
- 7:12f2b3b7975f
- Child:
- 9:c9df0b33d176
--- a/Navigator.cpp Mon Jan 12 19:37:51 2015 +0000
+++ b/Navigator.cpp Fri Jan 16 22:23:34 2015 +0000
@@ -6,6 +6,8 @@
_cursorPos = 0;
_cursorLine = 1;
_display_rows = lcd->rows();
+
+ activeMenu->CurrentSelection = _cursorPos;
printMenu();
printCursor();
@@ -53,6 +55,8 @@
void Navigator::select()
{
+ Menu *lastMenu;
+
if(activeMenu->selections[_cursorPos].fun != NULL) {
//execute function
(activeMenu->selections[_cursorPos].fun)();
@@ -60,9 +64,22 @@
//printMenu();
//printCursor();
}
+ //change the menu?
if(activeMenu->selections[_cursorPos].childMenu != NULL) {
+ lastMenu = activeMenu;
+
+ //change to childMenu
activeMenu = activeMenu->selections[_cursorPos].childMenu;
- _cursorPos = 0;
+
+ // if we went up one level, set CurrectSelection of SubMenu to zero, if we come back again
+ if (activeMenu->selections[activeMenu->CurrentSelection].childMenu == lastMenu) {
+ //reset menuposition of submenu to zero
+ lastMenu->CurrentSelection = 0;
+ }
+
+ // return to last position from that menu, if we went up on level
+ _cursorPos = activeMenu->CurrentSelection;
+
_cursorLine = 1;
printMenu();
printCursor();
@@ -79,6 +96,7 @@
if(_cursorPos > 0) {
//scroll up one item
_cursorPos--;
+ activeMenu->CurrentSelection = _cursorPos;
}
printMenu();
@@ -101,6 +119,8 @@
// on last Display-Line scroll down Menu
_cursorPos++;
}
+ // save currentPosition in Menu
+ activeMenu->CurrentSelection = _cursorPos;
}
