♻️ Refactor status screen timeout

This commit is contained in:
Scott Lahteine
2021-06-27 00:33:44 -05:00
parent e3ae76d76d
commit 2b37a71eba
9 changed files with 56 additions and 54 deletions

View File

@ -50,9 +50,12 @@
int8_t encoderTopLine, encoderLine, screen_items;
typedef struct {
screenFunc_t menu_function;
uint32_t encoder_position;
int8_t top_line, items;
screenFunc_t menu_function; // The screen's function
uint32_t encoder_position; // The position of the encoder
int8_t top_line, items; // The amount of scroll, and the number of items
#if SCREENS_CAN_TIME_OUT
bool sticky; // The screen is sticky
#endif
} menuPosition;
menuPosition screen_history[6];
uint8_t screen_history_depth = 0;
@ -75,9 +78,9 @@ bool MenuEditItemBase::liveEdit;
void MarlinUI::return_to_status() { goto_screen(status_screen); }
void MarlinUI::save_previous_screen() {
void MarlinUI::push_current_screen() {
if (screen_history_depth < COUNT(screen_history))
screen_history[screen_history_depth++] = { currentScreen, encoderPosition, encoderTopLine, screen_items };
screen_history[screen_history_depth++] = { currentScreen, encoderPosition, encoderTopLine, screen_items OPTARG(SCREENS_CAN_TIME_OUT, screen_is_sticky()) };
}
void MarlinUI::_goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_back/*=false*/)) {
@ -90,6 +93,7 @@ void MarlinUI::_goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_b
is_back ? 0 : sh.top_line,
sh.items
);
defer_status_screen(TERN_(SCREENS_CAN_TIME_OUT, sh.sticky));
}
else
return_to_status();
@ -147,7 +151,7 @@ void MenuEditItemBase::goto_edit_screen(
) {
TERN_(HAS_TOUCH_BUTTONS, ui.on_edit_screen = true);
ui.screen_changed = true;
ui.save_previous_screen();
ui.push_current_screen();
ui.refresh();
editLabel = el;
editValue = ev;
@ -237,7 +241,7 @@ void MarlinUI::goto_screen(screenFunc_t screen, const uint16_t encoder/*=0*/, co
//
void MarlinUI::synchronize(PGM_P const msg/*=nullptr*/) {
static PGM_P sync_message = msg ?: GET_TEXT(MSG_MOVING);
save_previous_screen();
push_current_screen();
goto_screen([]{
if (should_draw()) MenuItem_static::draw(LCD_HEIGHT >= 4, sync_message);
});
@ -371,6 +375,7 @@ void MenuItem_confirm::select_screen(
selectFunc_t yesFunc, selectFunc_t noFunc,
PGM_P const pref, const char * const string/*=nullptr*/, PGM_P const suff/*=nullptr*/
) {
ui.defer_status_screen();
const bool ui_selection = ui.update_selection(), got_click = ui.use_click();
if (got_click || ui.should_draw()) {
draw_select_screen(yes, no, ui_selection, pref, string, suff);
@ -378,7 +383,6 @@ void MenuItem_confirm::select_screen(
selectFunc_t callFunc = ui_selection ? yesFunc : noFunc;
if (callFunc) callFunc(); else ui.goto_previous_screen();
}
ui.defer_status_screen();
}
}

View File

@ -39,7 +39,7 @@ class MenuItem_submenu : public MenuItemBase {
FORCE_INLINE static void draw(const bool sel, const uint8_t row, PGM_P const pstr, ...) {
_draw(sel, row, pstr, '>', LCD_STR_ARROW_RIGHT[0]);
}
static inline void action(PGM_P const, const screenFunc_t func) { ui.save_previous_screen(); ui.goto_screen(func); }
static inline void action(PGM_P const, const screenFunc_t func) { ui.push_current_screen(); ui.goto_screen(func); }
};
// Any menu item that invokes an immediate action
@ -406,7 +406,7 @@ class MenuItem_bool : public MenuEditItemBase {
#define _CONFIRM_ITEM_INNER_P(PLABEL, V...) do { \
if (encoderLine == _thisItemNr && ui.use_click()) { \
ui.save_previous_screen(); \
ui.push_current_screen(); \
ui.goto_screen([]{MenuItem_confirm::select_screen(V);}); \
return; \
} \

View File

@ -177,7 +177,7 @@ void Password::menu_password() {
START_MENU();
BACK_ITEM(MSG_ADVANCED_SETTINGS);
SUBMENU(MSG_CHANGE_PASSWORD, screen_set_password);
ACTION_ITEM(MSG_REMOVE_PASSWORD, []{ ui.save_previous_screen(); remove_password(); } );
ACTION_ITEM(MSG_REMOVE_PASSWORD, []{ ui.push_current_screen(); remove_password(); } );
#if ENABLED(EEPROM_SETTINGS)
ACTION_ITEM(MSG_STORE_EEPROM, ui.store_settings);
#endif