Browse Source

🎨 Tweak custom menu item code

vanilla_fb_2.0.x
Scott Lahteine 3 years ago
parent
commit
6de25804eb
  1. 49
      Marlin/src/lcd/menu/menu_configuration.cpp
  2. 39
      Marlin/src/lcd/menu/menu_main.cpp

49
Marlin/src/lcd/menu/menu_configuration.cpp

@ -353,11 +353,6 @@ void menu_advanced_settings();
#define HAS_CUSTOM_ITEM_CONF(N) (defined(CONFIG_MENU_ITEM_##N##_DESC) && defined(CONFIG_MENU_ITEM_##N##_GCODE)) #define HAS_CUSTOM_ITEM_CONF(N) (defined(CONFIG_MENU_ITEM_##N##_DESC) && defined(CONFIG_MENU_ITEM_##N##_GCODE))
#define CUSTOM_TEST_CONF(N) do{ \
constexpr char c = CONFIG_MENU_ITEM_##N##_GCODE[strlen(CONFIG_MENU_ITEM_##N##_GCODE) - 1]; \
static_assert(c != '\n' && c != '\r', "CONFIG_MENU_ITEM_" STRINGIFY(N) "_GCODE cannot have a newline at the end. Please remove it."); \
}while(0)
#ifdef CUSTOM_MENU_CONFIG_SCRIPT_DONE #ifdef CUSTOM_MENU_CONFIG_SCRIPT_DONE
#define _DONE_SCRIPT "\n" CUSTOM_MENU_CONFIG_SCRIPT_DONE #define _DONE_SCRIPT "\n" CUSTOM_MENU_CONFIG_SCRIPT_DONE
#else #else
@ -365,115 +360,97 @@ void menu_advanced_settings();
#endif #endif
#define GCODE_LAMBDA_CONF(N) []{ _lcd_custom_menus_configuration_gcode(PSTR(CONFIG_MENU_ITEM_##N##_GCODE _DONE_SCRIPT)); } #define GCODE_LAMBDA_CONF(N) []{ _lcd_custom_menus_configuration_gcode(PSTR(CONFIG_MENU_ITEM_##N##_GCODE _DONE_SCRIPT)); }
#define _CUSTOM_ITEM_CONF(N) ACTION_ITEM_P(PSTR(CONFIG_MENU_ITEM_##N##_DESC), GCODE_LAMBDA_CONF(N)); #define _CUSTOM_ITEM_CONF(N) ACTION_ITEM_P(PSTR(CONFIG_MENU_ITEM_##N##_DESC), GCODE_LAMBDA_CONF(N));
#define _CUSTOM_ITEM_CONF_CONFIRM(N) \ #define _CUSTOM_ITEM_CONF_CONFIRM(N) \
SUBMENU_P(PSTR(CONFIG_MENU_ITEM_##N##_DESC), []{ \ SUBMENU_P(PSTR(CONFIG_MENU_ITEM_##N##_DESC), []{ \
MenuItem_confirm::confirm_screen( \ MenuItem_confirm::confirm_screen( \
GCODE_LAMBDA_CONF(N), \ GCODE_LAMBDA_CONF(N), \
ui.goto_previous_screen, \ ui.goto_previous_screen, \
PSTR(CONFIG_MENU_ITEM_##N##_DESC "?") \ PSTR(CONFIG_MENU_ITEM_##N##_DESC "?") \
); \ ); \
}) })
#define CUSTOM_ITEM_CONF(N) do{ if (ENABLED(CONFIG_MENU_ITEM_##N##_CONFIRM)) _CUSTOM_ITEM_CONF_CONFIRM(N); else _CUSTOM_ITEM_CONF(N); }while(0) #define CUSTOM_ITEM_CONF(N) do{ \
constexpr char c = CONFIG_MENU_ITEM_##N##_GCODE[strlen(CONFIG_MENU_ITEM_##N##_GCODE) - 1]; \
static_assert(c != '\n' && c != '\r', "CONFIG_MENU_ITEM_" STRINGIFY(N) "_GCODE cannot have a newline at the end. Please remove it."); \
if (ENABLED(CONFIG_MENU_ITEM_##N##_CONFIRM)) \
_CUSTOM_ITEM_CONF_CONFIRM(N); \
else \
_CUSTOM_ITEM_CONF(N); \
}while(0)
#if HAS_CUSTOM_ITEM_CONF(1) #if HAS_CUSTOM_ITEM_CONF(1)
CUSTOM_TEST_CONF(1);
CUSTOM_ITEM_CONF(1); CUSTOM_ITEM_CONF(1);
#endif #endif
#if HAS_CUSTOM_ITEM_CONF(2) #if HAS_CUSTOM_ITEM_CONF(2)
CUSTOM_TEST_CONF(2);
CUSTOM_ITEM_CONF(2); CUSTOM_ITEM_CONF(2);
#endif #endif
#if HAS_CUSTOM_ITEM_CONF(3) #if HAS_CUSTOM_ITEM_CONF(3)
CUSTOM_TEST_CONF(3);
CUSTOM_ITEM_CONF(3); CUSTOM_ITEM_CONF(3);
#endif #endif
#if HAS_CUSTOM_ITEM_CONF(4) #if HAS_CUSTOM_ITEM_CONF(4)
CUSTOM_TEST_CONF(4);
CUSTOM_ITEM_CONF(4); CUSTOM_ITEM_CONF(4);
#endif #endif
#if HAS_CUSTOM_ITEM_CONF(5) #if HAS_CUSTOM_ITEM_CONF(5)
CUSTOM_TEST_CONF(5);
CUSTOM_ITEM_CONF(5); CUSTOM_ITEM_CONF(5);
#endif #endif
#if HAS_CUSTOM_ITEM_CONF(6) #if HAS_CUSTOM_ITEM_CONF(6)
CUSTOM_TEST_CONF(6);
CUSTOM_ITEM_CONF(6); CUSTOM_ITEM_CONF(6);
#endif #endif
#if HAS_CUSTOM_ITEM_CONF(7) #if HAS_CUSTOM_ITEM_CONF(7)
CUSTOM_TEST_CONF(7);
CUSTOM_ITEM_CONF(7); CUSTOM_ITEM_CONF(7);
#endif #endif
#if HAS_CUSTOM_ITEM_CONF(8) #if HAS_CUSTOM_ITEM_CONF(8)
CUSTOM_TEST_CONF(8);
CUSTOM_ITEM_CONF(8); CUSTOM_ITEM_CONF(8);
#endif #endif
#if HAS_CUSTOM_ITEM_CONF(9) #if HAS_CUSTOM_ITEM_CONF(9)
CUSTOM_TEST_CONF(9);
CUSTOM_ITEM_CONF(9); CUSTOM_ITEM_CONF(9);
#endif #endif
#if HAS_CUSTOM_ITEM_CONF(10) #if HAS_CUSTOM_ITEM_CONF(10)
CUSTOM_TEST_CONF(10);
CUSTOM_ITEM_CONF(10); CUSTOM_ITEM_CONF(10);
#endif #endif
#if HAS_CUSTOM_ITEM_CONF(11) #if HAS_CUSTOM_ITEM_CONF(11)
CUSTOM_TEST_CONF(11);
CUSTOM_ITEM_CONF(11); CUSTOM_ITEM_CONF(11);
#endif #endif
#if HAS_CUSTOM_ITEM_CONF(12) #if HAS_CUSTOM_ITEM_CONF(12)
CUSTOM_TEST_CONF(12);
CUSTOM_ITEM_CONF(12); CUSTOM_ITEM_CONF(12);
#endif #endif
#if HAS_CUSTOM_ITEM_CONF(13) #if HAS_CUSTOM_ITEM_CONF(13)
CUSTOM_TEST_CONF(13);
CUSTOM_ITEM_CONF(13); CUSTOM_ITEM_CONF(13);
#endif #endif
#if HAS_CUSTOM_ITEM_CONF(14) #if HAS_CUSTOM_ITEM_CONF(14)
CUSTOM_TEST_CONF(14);
CUSTOM_ITEM_CONF(14); CUSTOM_ITEM_CONF(14);
#endif #endif
#if HAS_CUSTOM_ITEM_CONF(15) #if HAS_CUSTOM_ITEM_CONF(15)
CUSTOM_TEST_CONF(15);
CUSTOM_ITEM_CONF(15); CUSTOM_ITEM_CONF(15);
#endif #endif
#if HAS_CUSTOM_ITEM_CONF(16) #if HAS_CUSTOM_ITEM_CONF(16)
CUSTOM_TEST_CONF(16);
CUSTOM_ITEM_CONF(16); CUSTOM_ITEM_CONF(16);
#endif #endif
#if HAS_CUSTOM_ITEM_CONF(17) #if HAS_CUSTOM_ITEM_CONF(17)
CUSTOM_TEST_CONF(17);
CUSTOM_ITEM_CONF(17); CUSTOM_ITEM_CONF(17);
#endif #endif
#if HAS_CUSTOM_ITEM_CONF(18) #if HAS_CUSTOM_ITEM_CONF(18)
CUSTOM_TEST_CONF(18);
CUSTOM_ITEM_CONF(18); CUSTOM_ITEM_CONF(18);
#endif #endif
#if HAS_CUSTOM_ITEM_CONF(19) #if HAS_CUSTOM_ITEM_CONF(19)
CUSTOM_TEST_CONF(19);
CUSTOM_ITEM_CONF(19); CUSTOM_ITEM_CONF(19);
#endif #endif
#if HAS_CUSTOM_ITEM_CONF(20) #if HAS_CUSTOM_ITEM_CONF(20)
CUSTOM_TEST_CONF(20);
CUSTOM_ITEM_CONF(20); CUSTOM_ITEM_CONF(20);
#endif #endif
#if HAS_CUSTOM_ITEM_CONF(21) #if HAS_CUSTOM_ITEM_CONF(21)
CUSTOM_TEST_CONF(21);
CUSTOM_ITEM_CONF(21); CUSTOM_ITEM_CONF(21);
#endif #endif
#if HAS_CUSTOM_ITEM_CONF(22) #if HAS_CUSTOM_ITEM_CONF(22)
CUSTOM_TEST_CONF(22);
CUSTOM_ITEM_CONF(22); CUSTOM_ITEM_CONF(22);
#endif #endif
#if HAS_CUSTOM_ITEM_CONF(23) #if HAS_CUSTOM_ITEM_CONF(23)
CUSTOM_TEST_CONF(23);
CUSTOM_ITEM_CONF(23); CUSTOM_ITEM_CONF(23);
#endif #endif
#if HAS_CUSTOM_ITEM_CONF(24) #if HAS_CUSTOM_ITEM_CONF(24)
CUSTOM_TEST_CONF(24);
CUSTOM_ITEM_CONF(24); CUSTOM_ITEM_CONF(24);
#endif #endif
#if HAS_CUSTOM_ITEM_CONF(25) #if HAS_CUSTOM_ITEM_CONF(25)
CUSTOM_TEST_CONF(25);
CUSTOM_ITEM_CONF(25); CUSTOM_ITEM_CONF(25);
#endif #endif
END_MENU(); END_MENU();

39
Marlin/src/lcd/menu/menu_main.cpp

@ -118,11 +118,6 @@ void menu_configuration();
#define HAS_CUSTOM_ITEM_MAIN(N) (defined(MAIN_MENU_ITEM_##N##_DESC) && defined(MAIN_MENU_ITEM_##N##_GCODE)) #define HAS_CUSTOM_ITEM_MAIN(N) (defined(MAIN_MENU_ITEM_##N##_DESC) && defined(MAIN_MENU_ITEM_##N##_GCODE))
#define CUSTOM_TEST_MAIN(N) do{ \
constexpr char c = MAIN_MENU_ITEM_##N##_GCODE[strlen(MAIN_MENU_ITEM_##N##_GCODE) - 1]; \
static_assert(c != '\n' && c != '\r', "MAIN_MENU_ITEM_" STRINGIFY(N) "_GCODE cannot have a newline at the end. Please remove it."); \
}while(0)
#ifdef MAIN_MENU_ITEM_SCRIPT_DONE #ifdef MAIN_MENU_ITEM_SCRIPT_DONE
#define _DONE_SCRIPT "\n" MAIN_MENU_ITEM_SCRIPT_DONE #define _DONE_SCRIPT "\n" MAIN_MENU_ITEM_SCRIPT_DONE
#else #else
@ -139,106 +134,88 @@ void menu_configuration();
); \ ); \
}) })
#define CUSTOM_ITEM_MAIN(N) do{ if (ENABLED(MAIN_MENU_ITEM_##N##_CONFIRM)) _CUSTOM_ITEM_MAIN_CONFIRM(N); else _CUSTOM_ITEM_MAIN(N); }while(0) #define CUSTOM_ITEM_MAIN(N) do{ \
constexpr char c = MAIN_MENU_ITEM_##N##_GCODE[strlen(MAIN_MENU_ITEM_##N##_GCODE) - 1]; \
static_assert(c != '\n' && c != '\r', "MAIN_MENU_ITEM_" STRINGIFY(N) "_GCODE cannot have a newline at the end. Please remove it."); \
if (ENABLED(MAIN_MENU_ITEM_##N##_CONFIRM)) \
_CUSTOM_ITEM_MAIN_CONFIRM(N); \
else \
_CUSTOM_ITEM_MAIN(N); \
}while(0)
#if HAS_CUSTOM_ITEM_MAIN(1) #if HAS_CUSTOM_ITEM_MAIN(1)
CUSTOM_TEST_MAIN(1);
CUSTOM_ITEM_MAIN(1); CUSTOM_ITEM_MAIN(1);
#endif #endif
#if HAS_CUSTOM_ITEM_MAIN(2) #if HAS_CUSTOM_ITEM_MAIN(2)
CUSTOM_TEST_MAIN(2);
CUSTOM_ITEM_MAIN(2); CUSTOM_ITEM_MAIN(2);
#endif #endif
#if HAS_CUSTOM_ITEM_MAIN(3) #if HAS_CUSTOM_ITEM_MAIN(3)
CUSTOM_TEST_MAIN(3);
CUSTOM_ITEM_MAIN(3); CUSTOM_ITEM_MAIN(3);
#endif #endif
#if HAS_CUSTOM_ITEM_MAIN(4) #if HAS_CUSTOM_ITEM_MAIN(4)
CUSTOM_TEST_MAIN(4);
CUSTOM_ITEM_MAIN(4); CUSTOM_ITEM_MAIN(4);
#endif #endif
#if HAS_CUSTOM_ITEM_MAIN(5) #if HAS_CUSTOM_ITEM_MAIN(5)
CUSTOM_TEST_MAIN(5);
CUSTOM_ITEM_MAIN(5); CUSTOM_ITEM_MAIN(5);
#endif #endif
#if HAS_CUSTOM_ITEM_MAIN(6) #if HAS_CUSTOM_ITEM_MAIN(6)
CUSTOM_TEST_MAIN(6);
CUSTOM_ITEM_MAIN(6); CUSTOM_ITEM_MAIN(6);
#endif #endif
#if HAS_CUSTOM_ITEM_MAIN(7) #if HAS_CUSTOM_ITEM_MAIN(7)
CUSTOM_TEST_MAIN(7);
CUSTOM_ITEM_MAIN(7); CUSTOM_ITEM_MAIN(7);
#endif #endif
#if HAS_CUSTOM_ITEM_MAIN(8) #if HAS_CUSTOM_ITEM_MAIN(8)
CUSTOM_TEST_MAIN(8);
CUSTOM_ITEM_MAIN(8); CUSTOM_ITEM_MAIN(8);
#endif #endif
#if HAS_CUSTOM_ITEM_MAIN(9) #if HAS_CUSTOM_ITEM_MAIN(9)
CUSTOM_TEST_MAIN(9);
CUSTOM_ITEM_MAIN(9); CUSTOM_ITEM_MAIN(9);
#endif #endif
#if HAS_CUSTOM_ITEM_MAIN(10) #if HAS_CUSTOM_ITEM_MAIN(10)
CUSTOM_TEST_MAIN(10);
CUSTOM_ITEM_MAIN(10); CUSTOM_ITEM_MAIN(10);
#endif #endif
#if HAS_CUSTOM_ITEM_MAIN(11) #if HAS_CUSTOM_ITEM_MAIN(11)
CUSTOM_TEST_MAIN(11);
CUSTOM_ITEM_MAIN(11); CUSTOM_ITEM_MAIN(11);
#endif #endif
#if HAS_CUSTOM_ITEM_MAIN(12) #if HAS_CUSTOM_ITEM_MAIN(12)
CUSTOM_TEST_MAIN(12);
CUSTOM_ITEM_MAIN(12); CUSTOM_ITEM_MAIN(12);
#endif #endif
#if HAS_CUSTOM_ITEM_MAIN(13) #if HAS_CUSTOM_ITEM_MAIN(13)
CUSTOM_TEST_MAIN(13);
CUSTOM_ITEM_MAIN(13); CUSTOM_ITEM_MAIN(13);
#endif #endif
#if HAS_CUSTOM_ITEM_MAIN(14) #if HAS_CUSTOM_ITEM_MAIN(14)
CUSTOM_TEST_MAIN(14);
CUSTOM_ITEM_MAIN(14); CUSTOM_ITEM_MAIN(14);
#endif #endif
#if HAS_CUSTOM_ITEM_MAIN(15) #if HAS_CUSTOM_ITEM_MAIN(15)
CUSTOM_TEST_MAIN(15);
CUSTOM_ITEM_MAIN(15); CUSTOM_ITEM_MAIN(15);
#endif #endif
#if HAS_CUSTOM_ITEM_MAIN(16) #if HAS_CUSTOM_ITEM_MAIN(16)
CUSTOM_TEST_MAIN(16);
CUSTOM_ITEM_MAIN(16); CUSTOM_ITEM_MAIN(16);
#endif #endif
#if HAS_CUSTOM_ITEM_MAIN(17) #if HAS_CUSTOM_ITEM_MAIN(17)
CUSTOM_TEST_MAIN(17);
CUSTOM_ITEM_MAIN(17); CUSTOM_ITEM_MAIN(17);
#endif #endif
#if HAS_CUSTOM_ITEM_MAIN(18) #if HAS_CUSTOM_ITEM_MAIN(18)
CUSTOM_TEST_MAIN(18);
CUSTOM_ITEM_MAIN(18); CUSTOM_ITEM_MAIN(18);
#endif #endif
#if HAS_CUSTOM_ITEM_MAIN(19) #if HAS_CUSTOM_ITEM_MAIN(19)
CUSTOM_TEST_MAIN(19);
CUSTOM_ITEM_MAIN(19); CUSTOM_ITEM_MAIN(19);
#endif #endif
#if HAS_CUSTOM_ITEM_MAIN(20) #if HAS_CUSTOM_ITEM_MAIN(20)
CUSTOM_TEST_MAIN(20);
CUSTOM_ITEM_MAIN(20); CUSTOM_ITEM_MAIN(20);
#endif #endif
#if HAS_CUSTOM_ITEM_MAIN(21) #if HAS_CUSTOM_ITEM_MAIN(21)
CUSTOM_TEST_MAIN(21);
CUSTOM_ITEM_MAIN(21); CUSTOM_ITEM_MAIN(21);
#endif #endif
#if HAS_CUSTOM_ITEM_MAIN(22) #if HAS_CUSTOM_ITEM_MAIN(22)
CUSTOM_TEST_MAIN(22);
CUSTOM_ITEM_MAIN(22); CUSTOM_ITEM_MAIN(22);
#endif #endif
#if HAS_CUSTOM_ITEM_MAIN(23) #if HAS_CUSTOM_ITEM_MAIN(23)
CUSTOM_TEST_MAIN(23);
CUSTOM_ITEM_MAIN(23); CUSTOM_ITEM_MAIN(23);
#endif #endif
#if HAS_CUSTOM_ITEM_MAIN(24) #if HAS_CUSTOM_ITEM_MAIN(24)
CUSTOM_TEST_MAIN(24);
CUSTOM_ITEM_MAIN(24); CUSTOM_ITEM_MAIN(24);
#endif #endif
#if HAS_CUSTOM_ITEM_MAIN(25) #if HAS_CUSTOM_ITEM_MAIN(25)
CUSTOM_TEST_MAIN(25);
CUSTOM_ITEM_MAIN(25); CUSTOM_ITEM_MAIN(25);
#endif #endif
END_MENU(); END_MENU();

Loading…
Cancel
Save