Browse Source

Fix menu history item selection

pull/1/head
Scott Lahteine 6 years ago
parent
commit
10b9632bed
  1. 23
      Marlin/src/lcd/menu/menu.cpp
  2. 4
      Marlin/src/lcd/menu/menu.h
  3. 2
      Marlin/src/lcd/ultralcd.h

23
Marlin/src/lcd/menu/menu.cpp

@ -54,10 +54,12 @@
//////////////////////////////////////////// ////////////////////////////////////////////
// Menu Navigation // Menu Navigation
int8_t encoderTopLine; int8_t encoderTopLine, encoderLine, screen_items;
typedef struct { typedef struct {
screenFunc_t menu_function; screenFunc_t menu_function;
uint32_t encoder_position; uint32_t encoder_position;
uint8_t top_line, items;
} menuPosition; } menuPosition;
menuPosition screen_history[6]; menuPosition screen_history[6];
uint8_t screen_history_depth = 0; uint8_t screen_history_depth = 0;
@ -80,20 +82,14 @@ bool no_reentry = false;
void MarlinUI::return_to_status() { goto_screen(status_screen); } void MarlinUI::return_to_status() { goto_screen(status_screen); }
void MarlinUI::save_previous_screen() { void MarlinUI::save_previous_screen() {
if (screen_history_depth < COUNT(screen_history)) { if (screen_history_depth < COUNT(screen_history))
screen_history[screen_history_depth].menu_function = currentScreen; screen_history[screen_history_depth++] = { currentScreen, encoderPosition, encoderTopLine, screen_items };
screen_history[screen_history_depth].encoder_position = encoderPosition;
++screen_history_depth;
}
} }
void MarlinUI::goto_previous_screen() { void MarlinUI::goto_previous_screen() {
if (screen_history_depth > 0) { if (screen_history_depth > 0) {
--screen_history_depth; menuPosition &sh = screen_history[--screen_history_depth];
goto_screen( goto_screen(sh.menu_function, sh.encoder_position, sh.top_line, sh.items);
screen_history[screen_history_depth].menu_function,
screen_history[screen_history_depth].encoder_position
);
} }
else else
return_to_status(); return_to_status();
@ -197,7 +193,7 @@ bool printer_busy() {
/** /**
* General function to go directly to a screen * General function to go directly to a screen
*/ */
void MarlinUI::goto_screen(screenFunc_t screen, const uint32_t encoder/*=0*/) { void MarlinUI::goto_screen(screenFunc_t screen, const uint32_t encoder/*=0*/, const uint8_t top/*=0*/, const uint8_t items/*=0*/) {
if (currentScreen != screen) { if (currentScreen != screen) {
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
@ -246,6 +242,8 @@ void MarlinUI::goto_screen(screenFunc_t screen, const uint32_t encoder/*=0*/) {
currentScreen = screen; currentScreen = screen;
encoderPosition = encoder; encoderPosition = encoder;
encoderTopLine = top;
screen_items = items;
if (screen == status_screen) { if (screen == status_screen) {
defer_status_screen(false); defer_status_screen(false);
#if ENABLED(AUTO_BED_LEVELING_UBL) #if ENABLED(AUTO_BED_LEVELING_UBL)
@ -314,7 +312,6 @@ void MarlinUI::synchronize(PGM_P const msg/*=NULL*/) {
* _thisItemNr is the index of each MENU_ITEM or STATIC_ITEM * _thisItemNr is the index of each MENU_ITEM or STATIC_ITEM
* screen_items is the total number of items in the menu (after one call) * screen_items is the total number of items in the menu (after one call)
*/ */
int8_t encoderLine, screen_items;
void scroll_screen(const uint8_t limit, const bool is_menu) { void scroll_screen(const uint8_t limit, const bool is_menu) {
ui.encoder_direction_menus(); ui.encoder_direction_menus();
ENCODER_RATE_MULTIPLY(false); ENCODER_RATE_MULTIPLY(false);

4
Marlin/src/lcd/menu/menu.h

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

2
Marlin/src/lcd/ultralcd.h

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

Loading…
Cancel
Save