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 Peihsun Yeh

Library to display menus on TextLCDs. Interaction with functions Up,Down and Select (Buttons or RPG) Based on menu-library from pyeh9

Files at this revision

API Documentation at this revision

Comitter:
charly
Date:
Fri Jan 16 22:23:34 2015 +0000
Parent:
7:12f2b3b7975f
Child:
9:c9df0b33d176
Commit message:
Save CurrentSelection of Menu to get back to the correct position.

Changed in this revision

Menu.cpp Show annotated file Show diff for this revision Revisions of this file
Menu.h Show annotated file Show diff for this revision Revisions of this file
Navigator.cpp Show annotated file Show diff for this revision Revisions of this file
Navigator.h Show annotated file Show diff for this revision Revisions of this file
--- a/Menu.cpp	Mon Jan 12 19:37:51 2015 +0000
+++ b/Menu.cpp	Fri Jan 16 22:23:34 2015 +0000
@@ -5,6 +5,7 @@
 Menu::Menu(char *id) : menuID(id)
 {
     selections.clear();
+    CurrentSelection = 0;
 }
 
 void Menu::add(const Selection &toAdd)
--- a/Menu.h	Mon Jan 12 19:37:51 2015 +0000
+++ b/Menu.h	Fri Jan 16 22:23:34 2015 +0000
@@ -9,10 +9,12 @@
 
 class Menu {
     private:
-               
     public:
         vector<Selection> selections;
         char *menuID;
+
+        // currently selected Item in Menu (used to return to this point from submenu)
+        int  CurrentSelection;       
         
         Menu(char *);
         
--- 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;
 
     }
 
--- a/Navigator.h	Mon Jan 12 19:37:51 2015 +0000
+++ b/Navigator.h	Fri Jan 16 22:23:34 2015 +0000
@@ -79,8 +79,8 @@
     
 private:
     int _display_rows; // number of rows the LCD can display
-    int _cursorPos;  // what selection the cursor points to
-    int _cursorLine; // what line of the lcd the cursor is on. 1 = first line, 2 = second line
+    int _cursorPos;    // what selection the cursor points to
+    int _cursorLine;   // what line of the lcd the cursor is on. 1 = first line, 2 = second line
     
     
 };