Streamline menu item logic (#17664)

This commit is contained in:
Scott Lahteine
2020-04-27 23:52:11 -05:00
committed by GitHub
parent f709c565a1
commit 4f003fc7a7
17 changed files with 303 additions and 251 deletions

View File

@@ -319,7 +319,33 @@ class MenuItem_bool : public MenuEditItemBase {
////////////////////////////////////////////
/**
* SCREEN_OR_MENU_LOOP generates init code for a screen or menu
* Marlin's native menu screens work by running a loop from the top visible line index
* to the bottom visible line index (according to how much the screen has been scrolled).
* This complete loop is done on every menu screen call.
*
* The menu system is highly dynamic, so it doesn't know ahead of any menu loop which
* items will be visible or hidden, so menu items don't have a fixed index number.
*
* During the loop, each menu item checks to see if its line is the current one. If it is,
* then it checks to see if a click has arrived so it can run its action. If the action
* doesn't redirect to another screen then the menu item calls its draw method.
*
* Menu item add-ons can do whatever they like.
*
* This mixture of drawing and processing inside a loop has the advantage that a single
* line can be used to represent a menu item, and that is the rationale for this design.
*
* One of the pitfalls of this method is that DOGM displays call the screen handler 2x,
* 4x, or 8x per screen update to draw just one segment of the screen. As a result, any
* menu item that exists in two screen segments is drawn and processed twice per screen
* update. With each item processed 5, 10, 20, or 40 times the logic has to be simple.
*
* To keep performance optimal, use the MENU_ITEM_IF/ELSE/ELIF macros. If function calls
* are needed to test conditions, they should come before START_MENU / START_SCREEN.
*/
/**
* SCREEN_OR_MENU_LOOP generates header code for a screen or menu
*
* encoderTopLine is the top menu line to display
* _lcdLineNr is the index of the LCD line (e.g., 0-3)
@@ -510,6 +536,17 @@ class MenuItem_bool : public MenuEditItemBase {
#define YESNO_ITEM_N_P(N,PLABEL, V...) _CONFIRM_ITEM_N_P(N, PLABEL, ##V)
#define YESNO_ITEM_N(N,LABEL, V...) YESNO_ITEM_N_P(N, GET_TEXT(LABEL), ##V)
/**
* MENU_ITEM_IF/ELSE/ELIF
*
* Apply a condition for a menu item to exist.
* When the condition passes, NEXT_ITEM updates _thisItemNr.
* This cannot be used to wrap multiple menu items.
*/
#define MENU_ITEM_IF(COND) if ((_menuLineNr == _thisItemNr) && (COND))
#define MENU_ITEM_ELIF(COND) else if ((_menuLineNr == _thisItemNr) && (COND))
#define MENU_ITEM_ELSE else if (_menuLineNr == _thisItemNr)
////////////////////////////////////////////
/////////////// Menu Screens ///////////////
////////////////////////////////////////////