Browse Source

Reduce redundancy in MENU_ITEM code

pull/1/head
Scott Lahteine 8 years ago
parent
commit
4fb8013be1
  1. 34
      Marlin/ultralcd.cpp

34
Marlin/ultralcd.cpp

@ -199,19 +199,25 @@ static void lcd_status_screen();
* menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999) * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999)
* *
*/ */
#define MENU_ITEM(type, label, args...) do { \ #define _MENU_ITEM_PART_1(type, label, args...) \
if (_menuItemNr == _lineNr) { \ if (_menuItemNr == _lineNr) { \
itemSelected = encoderLine == _menuItemNr; \ itemSelected = encoderLine == _menuItemNr; \
if (lcdDrawUpdate) \ if (lcdDrawUpdate) \
lcd_implementation_drawmenu_ ## type(itemSelected, _drawLineNr, PSTR(label), ## args); \ lcd_implementation_drawmenu_ ## type(itemSelected, _drawLineNr, PSTR(label), ## args); \
if (wasClicked && itemSelected) { \ if (wasClicked && itemSelected) { \
lcd_quick_feedback(); \ lcd_quick_feedback()
#define _MENU_ITEM_PART_2(type, args...) \
menu_action_ ## type(args); \ menu_action_ ## type(args); \
return; \ return; \
} \ } \
} \ } \
_menuItemNr++; \ _menuItemNr++
} while(0)
#define MENU_ITEM(type, label, args...) do { \
_MENU_ITEM_PART_1(type, label, ## args); \
_MENU_ITEM_PART_2(type, ## args); \
} while(0)
#if ENABLED(ENCODER_RATE_MULTIPLIER) #if ENABLED(ENCODER_RATE_MULTIPLIER)
@ -221,20 +227,12 @@ static void lcd_status_screen();
* MENU_MULTIPLIER_ITEM generates drawing and handling code for a multiplier menu item * MENU_MULTIPLIER_ITEM generates drawing and handling code for a multiplier menu item
*/ */
#define MENU_MULTIPLIER_ITEM(type, label, args...) do { \ #define MENU_MULTIPLIER_ITEM(type, label, args...) do { \
if (_menuItemNr == _lineNr) { \ _MENU_ITEM_PART_1(type, label, ## args); \
itemSelected = encoderLine == _menuItemNr; \ encoderRateMultiplierEnabled = true; \
if (lcdDrawUpdate) \ lastEncoderMovementMillis = 0; \
lcd_implementation_drawmenu_ ## type(itemSelected, _drawLineNr, PSTR(label), ## args); \ _MENU_ITEM_PART_2(type, ## args); \
if (wasClicked && itemSelected) { \ } while(0)
lcd_quick_feedback(); \
encoderRateMultiplierEnabled = true; \
lastEncoderMovementMillis = 0; \
menu_action_ ## type(args); \
return; \
} \
} \
_menuItemNr++; \
} while(0)
#endif //ENCODER_RATE_MULTIPLIER #endif //ENCODER_RATE_MULTIPLIER
#define MENU_ITEM_DUMMY() do { _menuItemNr++; } while(0) #define MENU_ITEM_DUMMY() do { _menuItemNr++; } while(0)

Loading…
Cancel
Save