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
Revision 11:6814cbc83ae0, committed 2016-01-13
- Comitter:
- charly
- Date:
- Wed Jan 13 19:59:21 2016 +0000
- Parent:
- 10:2b6ddf53b05e
- Commit message:
- added show_longtext() to display a long text. With scrollbars.
Changed in this revision
diff -r 2b6ddf53b05e -r 6814cbc83ae0 MenuItem.h --- a/MenuItem.h Mon Mar 16 21:05:37 2015 +0000 +++ b/MenuItem.h Wed Jan 13 19:59:21 2016 +0000 @@ -17,15 +17,20 @@ /** default mode: just display the Menu-Text an perform user_action */ mode_default = 0, + /** wait_select: Call user_action and then only accept a select * use for displaying text, values,... * the menu is paused until select is pressed */ mode_wait_select = 1, + /** mode_yes_no: show text and ask user for yes/no * */ - mode_yes_no = 2 + mode_yes_no = 2, + + //** mode_long_text: show a long text with scrollbars and wait for select() + mode_show_longtext = 3 }; /** structure to pass data to menu and back @@ -33,6 +38,7 @@ struct menu_data{ // Longer text to display. // For Yes/No-Question + // or show_longtext char * text; //Yes/No Value In and Out bool yes_no;
diff -r 2b6ddf53b05e -r 6814cbc83ae0 Navigator.cpp --- a/Navigator.cpp Mon Mar 16 21:05:37 2015 +0000 +++ b/Navigator.cpp Wed Jan 13 19:59:21 2016 +0000 @@ -13,6 +13,8 @@ _wait_for_select = false; _wait_for_yesno = false; + _start_line = 0; + printMenu(); printCursor(); } @@ -52,10 +54,6 @@ } } -void Navigator::poll() -{ -// no longer needed -} void Navigator::show_yes_no(bool yesorno) { @@ -76,8 +74,27 @@ } } +void Navigator::show_longtext(void) +{ + int maxchunksize = _display_cols - 1; // one column for "Scrollbar" + // MenuItem is a long_text + // show the text , support scrolling up/down, wait for select + lcd->cls(); + if (activeMenu->selections[_cursorPos].menu_parameter->text != NULL) { + //show text starting a correct position + for (int row=0; row< _display_rows; row++) { + lcd->locate(0,row); + lcd->printf("%-*.*s", maxchunksize,maxchunksize, activeMenu->selections[_cursorPos].menu_parameter->text + ((_start_line+row)*(_display_cols - 1))); + if ((row == 0)&& (_start_line > 0)) lcd->printf("^"); + else if (row == _display_rows-1) lcd->printf("v"); + else lcd->printf("|"); + } + } +} + void Navigator::select() { + // user ressed the select button Menu *lastMenu; // are we waiting for a Select()? @@ -96,6 +113,9 @@ } else if(activeMenu->selections[_cursorPos].itemMode == MenuItem::mode_yes_no) { show_yes_no(activeMenu->selections[_cursorPos].menu_parameter->yes_no); _wait_for_yesno = true; + } else if(activeMenu->selections[_cursorPos].itemMode == MenuItem::mode_show_longtext) { + show_longtext(); + _wait_for_select = true; } else { // normal mneuItem if(activeMenu->selections[_cursorPos].userAction != NULL) { @@ -126,7 +146,8 @@ printCursor(); } // only accept select after showing this menu/user_action ? - if(activeMenu->selections[_cursorPos].itemMode == MenuItem::mode_wait_select) { + if ((activeMenu->selections[_cursorPos].itemMode == MenuItem::mode_wait_select) || + (activeMenu->selections[_cursorPos].itemMode == MenuItem::mode_show_longtext)) { _wait_for_select = true; } } @@ -134,28 +155,36 @@ void Navigator::moveUp() { - if (_wait_for_yesno) { + if (_wait_for_yesno) { // change Yes/no Selection show_yes_no( ! activeMenu->selections[_cursorPos].menu_parameter->yes_no); - }else - // only if we don't wait for a select() - if (! _wait_for_select) { - // Show the MenuItems - // allready on TOP of Display? - if(_cursorLine > 1) { - // scroll up cursor one line - _cursorLine--; - } - if(_cursorPos > 0) { - //scroll up one item - _cursorPos--; - activeMenu->CurrentSelection = _cursorPos; + } else if(activeMenu->selections[_cursorPos].itemMode == MenuItem::mode_show_longtext) { + // show a long text + // can we scoll further up? + if (_start_line >= 1) { + _start_line--; + show_longtext(); + } + } else + // only if we don't wait for a select() + if (! _wait_for_select) { + // Show the MenuItems + // allready on TOP of Display? + if(_cursorLine > 1) { + // scroll up cursor one line + _cursorLine--; + } + if(_cursorPos > 0) { + //scroll up one item + _cursorPos--; + activeMenu->CurrentSelection = _cursorPos; + + } + printMenu(); + printCursor(); } - printMenu(); - printCursor(); - } } void Navigator::moveDown() @@ -163,29 +192,36 @@ if (_wait_for_yesno) { // change Yes/no Selection show_yes_no( ! activeMenu->selections[_cursorPos].menu_parameter->yes_no); - }else - // only if we don't wait for a select() - if (! _wait_for_select) { - //Show the menuItem - // allready on last line of display? - if (_cursorPos == activeMenu->selections.size()-1) { - //stay on this line - } else { - // move down - if(_cursorLine < _display_rows) { - // Only move down cursor - _cursorLine++; - _cursorPos++; + } else if(activeMenu->selections[_cursorPos].itemMode == MenuItem::mode_show_longtext) { + // show a long text + // can we scoll further down? + if ((_start_line+_display_rows)*(_display_cols-1) < strlen(activeMenu->selections[_cursorPos].menu_parameter->text)) { + _start_line++; + show_longtext(); + } + } else + // only if we don't wait for a select() + if (! _wait_for_select) { + //Show the menuItem + // allready on last line of display? + if (_cursorPos == activeMenu->selections.size()-1) { + //stay on this line } else { - // on last Display-Line scroll down Menu - _cursorPos++; - } - // save currentPosition in Menu - activeMenu->CurrentSelection = _cursorPos; + // move down + if(_cursorLine < _display_rows) { + // Only move down cursor + _cursorLine++; + _cursorPos++; + } else { + // on last Display-Line scroll down Menu + _cursorPos++; + } + // save currentPosition in Menu + activeMenu->CurrentSelection = _cursorPos; - } + } - printMenu(); - printCursor(); - } + printMenu(); + printCursor(); + } }
diff -r 2b6ddf53b05e -r 6814cbc83ae0 Navigator.h --- a/Navigator.h Mon Mar 16 21:05:37 2015 +0000 +++ b/Navigator.h Wed Jan 13 19:59:21 2016 +0000 @@ -46,11 +46,6 @@ TextLCD_Base *lcd; - /** no longer used! - * - */ - void poll(); // no longer needed! - /** Move up one line in menu. * call this method when user moves up one line. * can be triggered by RPG or Button (PinDetect) or otherwise. @@ -81,11 +76,15 @@ /** Show Yes/No Dialog and wait fo Selection */ void show_yes_no(bool yesorno); + /** Show a long Text and wait for Select. Scroll Up/Down in Text + */ + void show_longtext(void); int _display_rows; // number of rows the LCD can display int _display_cols; // number of lines of LCD 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 _start_line; // display a long text starting from this line bool _wait_for_select; // only accept Select Button to go Back bool _wait_for_yesno; // up/don change selection ; Select accepts