Browse Source

Fix menu history item selection

Scott Lahteine 5 years ago
parent
commit
10b9632bed
3 changed files with 13 additions and 16 deletions
  1. 10
    13
      Marlin/src/lcd/menu/menu.cpp
  2. 2
    2
      Marlin/src/lcd/menu/menu.h
  3. 1
    1
      Marlin/src/lcd/ultralcd.h

+ 10
- 13
Marlin/src/lcd/menu/menu.cpp View File

@@ -54,10 +54,12 @@
54 54
 ////////////////////////////////////////////
55 55
 
56 56
 // Menu Navigation
57
-int8_t encoderTopLine;
57
+int8_t encoderTopLine, encoderLine, screen_items;
58
+
58 59
 typedef struct {
59 60
   screenFunc_t menu_function;
60 61
   uint32_t encoder_position;
62
+  uint8_t top_line, items;
61 63
 } menuPosition;
62 64
 menuPosition screen_history[6];
63 65
 uint8_t screen_history_depth = 0;
@@ -80,20 +82,14 @@ bool no_reentry = false;
80 82
 void MarlinUI::return_to_status() { goto_screen(status_screen); }
81 83
 
82 84
 void MarlinUI::save_previous_screen() {
83
-  if (screen_history_depth < COUNT(screen_history)) {
84
-    screen_history[screen_history_depth].menu_function = currentScreen;
85
-    screen_history[screen_history_depth].encoder_position = encoderPosition;
86
-    ++screen_history_depth;
87
-  }
85
+  if (screen_history_depth < COUNT(screen_history))
86
+    screen_history[screen_history_depth++] = { currentScreen, encoderPosition, encoderTopLine, screen_items };
88 87
 }
89 88
 
90 89
 void MarlinUI::goto_previous_screen() {
91 90
   if (screen_history_depth > 0) {
92
-    --screen_history_depth;
93
-    goto_screen(
94
-      screen_history[screen_history_depth].menu_function,
95
-      screen_history[screen_history_depth].encoder_position
96
-    );
91
+    menuPosition &sh = screen_history[--screen_history_depth];
92
+    goto_screen(sh.menu_function, sh.encoder_position, sh.top_line, sh.items);
97 93
   }
98 94
   else
99 95
     return_to_status();
@@ -197,7 +193,7 @@ bool printer_busy() {
197 193
 /**
198 194
  * General function to go directly to a screen
199 195
  */
200
-void MarlinUI::goto_screen(screenFunc_t screen, const uint32_t encoder/*=0*/) {
196
+void MarlinUI::goto_screen(screenFunc_t screen, const uint32_t encoder/*=0*/, const uint8_t top/*=0*/, const uint8_t items/*=0*/) {
201 197
   if (currentScreen != screen) {
202 198
 
203 199
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
@@ -246,6 +242,8 @@ void MarlinUI::goto_screen(screenFunc_t screen, const uint32_t encoder/*=0*/) {
246 242
 
247 243
     currentScreen = screen;
248 244
     encoderPosition = encoder;
245
+    encoderTopLine = top;
246
+    screen_items = items;
249 247
     if (screen == status_screen) {
250 248
       defer_status_screen(false);
251 249
       #if ENABLED(AUTO_BED_LEVELING_UBL)
@@ -314,7 +312,6 @@ void MarlinUI::synchronize(PGM_P const msg/*=NULL*/) {
314 312
  *   _thisItemNr is the index of each MENU_ITEM or STATIC_ITEM
315 313
  *   screen_items is the total number of items in the menu (after one call)
316 314
  */
317
-int8_t encoderLine, screen_items;
318 315
 void scroll_screen(const uint8_t limit, const bool is_menu) {
319 316
   ui.encoder_direction_menus();
320 317
   ENCODER_RATE_MULTIPLY(false);

+ 2
- 2
Marlin/src/lcd/menu/menu.h View File

@@ -309,8 +309,8 @@ class MenuItem_bool {
309 309
 
310 310
 #define MENU_BACK(LABEL) MENU_ITEM(back, LABEL)
311 311
 #define MENU_ITEM_DUMMY() do { _thisItemNr++; }while(0)
312
-#define MENU_ITEM_P(TYPE, PLABEL, ...)                       _MENU_ITEM_VARIANT_P(TYPE,              , false, PLABEL,                   ## __VA_ARGS__)
313
-#define MENU_ITEM(TYPE, LABEL, ...)                          _MENU_ITEM_VARIANT_P(TYPE,              , false, PSTR(LABEL),              ## __VA_ARGS__)
312
+#define MENU_ITEM_P(TYPE, PLABEL, ...)                       _MENU_ITEM_VARIANT_P(TYPE,      , false, PLABEL,                   ## __VA_ARGS__)
313
+#define MENU_ITEM(TYPE, LABEL, ...)                          _MENU_ITEM_VARIANT_P(TYPE,      , false, PSTR(LABEL),              ## __VA_ARGS__)
314 314
 #define MENU_ITEM_EDIT(TYPE, LABEL, ...)                     _MENU_ITEM_VARIANT_P(TYPE, _edit, false, PSTR(LABEL), PSTR(LABEL), ## __VA_ARGS__)
315 315
 #define MENU_ITEM_EDIT_CALLBACK(TYPE, LABEL, ...)            _MENU_ITEM_VARIANT_P(TYPE, _edit, false, PSTR(LABEL), PSTR(LABEL), ## __VA_ARGS__)
316 316
 #define MENU_MULTIPLIER_ITEM_EDIT(TYPE, LABEL, ...)          _MENU_ITEM_VARIANT_P(TYPE, _edit,  true, PSTR(LABEL), PSTR(LABEL), ## __VA_ARGS__)

+ 1
- 1
Marlin/src/lcd/ultralcd.h View File

@@ -419,7 +419,7 @@ public:
419 419
     static void synchronize(PGM_P const msg=NULL);
420 420
 
421 421
     static screenFunc_t currentScreen;
422
-    static void goto_screen(const screenFunc_t screen, const uint32_t encoder=0);
422
+    static void goto_screen(const screenFunc_t screen, const uint32_t encoder=0, const uint8_t top=0, const uint8_t items=0);
423 423
     static void save_previous_screen();
424 424
     static void goto_previous_screen();
425 425
     static void return_to_status();

Loading…
Cancel
Save