Browse Source

Reduce redundancy in MENU_ITEM code

Scott Lahteine 8 years ago
parent
commit
4fb8013be1
1 changed files with 16 additions and 18 deletions
  1. 16
    18
      Marlin/ultralcd.cpp

+ 16
- 18
Marlin/ultralcd.cpp View File

199
    *     menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999)
199
    *     menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999)
200
    *
200
    *
201
    */
201
    */
202
-  #define MENU_ITEM(type, label, args...) do { \
202
+  #define _MENU_ITEM_PART_1(type, label, args...) \
203
     if (_menuItemNr == _lineNr) { \
203
     if (_menuItemNr == _lineNr) { \
204
       itemSelected = encoderLine == _menuItemNr; \
204
       itemSelected = encoderLine == _menuItemNr; \
205
       if (lcdDrawUpdate) \
205
       if (lcdDrawUpdate) \
206
         lcd_implementation_drawmenu_ ## type(itemSelected, _drawLineNr, PSTR(label), ## args); \
206
         lcd_implementation_drawmenu_ ## type(itemSelected, _drawLineNr, PSTR(label), ## args); \
207
       if (wasClicked && itemSelected) { \
207
       if (wasClicked && itemSelected) { \
208
-        lcd_quick_feedback(); \
208
+        lcd_quick_feedback()
209
+
210
+  #define _MENU_ITEM_PART_2(type, args...) \
209
         menu_action_ ## type(args); \
211
         menu_action_ ## type(args); \
210
         return; \
212
         return; \
211
       } \
213
       } \
212
     } \
214
     } \
213
-    _menuItemNr++; \
214
-  } while(0)
215
+    _menuItemNr++
216
+
217
+  #define MENU_ITEM(type, label, args...) do { \
218
+      _MENU_ITEM_PART_1(type, label, ## args); \
219
+      _MENU_ITEM_PART_2(type, ## args); \
220
+    } while(0)
215
 
221
 
216
   #if ENABLED(ENCODER_RATE_MULTIPLIER)
222
   #if ENABLED(ENCODER_RATE_MULTIPLIER)
217
 
223
 
221
      * MENU_MULTIPLIER_ITEM generates drawing and handling code for a multiplier menu item
227
      * MENU_MULTIPLIER_ITEM generates drawing and handling code for a multiplier menu item
222
      */
228
      */
223
     #define MENU_MULTIPLIER_ITEM(type, label, args...) do { \
229
     #define MENU_MULTIPLIER_ITEM(type, label, args...) do { \
224
-      if (_menuItemNr == _lineNr) { \
225
-        itemSelected = encoderLine == _menuItemNr; \
226
-        if (lcdDrawUpdate) \
227
-          lcd_implementation_drawmenu_ ## type(itemSelected, _drawLineNr, PSTR(label), ## args); \
228
-        if (wasClicked && itemSelected) { \
229
-          lcd_quick_feedback(); \
230
-          encoderRateMultiplierEnabled = true; \
231
-          lastEncoderMovementMillis = 0; \
232
-          menu_action_ ## type(args); \
233
-          return; \
234
-        } \
235
-      } \
236
-      _menuItemNr++; \
237
-    } while(0)
230
+        _MENU_ITEM_PART_1(type, label, ## args); \
231
+        encoderRateMultiplierEnabled = true; \
232
+        lastEncoderMovementMillis = 0; \
233
+        _MENU_ITEM_PART_2(type, ## args); \
234
+      } while(0)
235
+
238
   #endif //ENCODER_RATE_MULTIPLIER
236
   #endif //ENCODER_RATE_MULTIPLIER
239
 
237
 
240
   #define MENU_ITEM_DUMMY() do { _menuItemNr++; } while(0)
238
   #define MENU_ITEM_DUMMY() do { _menuItemNr++; } while(0)

Loading…
Cancel
Save