🎨 Tweak custom menu item code

This commit is contained in:
Scott Lahteine 2021-09-12 21:21:35 -05:00
parent ded8ee0a1d
commit 6de25804eb
2 changed files with 21 additions and 67 deletions

View File

@ -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 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
#define _DONE_SCRIPT "\n" CUSTOM_MENU_CONFIG_SCRIPT_DONE
#else
@ -365,115 +360,97 @@ void menu_advanced_settings();
#endif
#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_CONFIRM(N) \
#define _CUSTOM_ITEM_CONF_CONFIRM(N) \
SUBMENU_P(PSTR(CONFIG_MENU_ITEM_##N##_DESC), []{ \
MenuItem_confirm::confirm_screen( \
GCODE_LAMBDA_CONF(N), \
ui.goto_previous_screen, \
MenuItem_confirm::confirm_screen( \
GCODE_LAMBDA_CONF(N), \
ui.goto_previous_screen, \
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)
CUSTOM_TEST_CONF(1);
CUSTOM_ITEM_CONF(1);
#endif
#if HAS_CUSTOM_ITEM_CONF(2)
CUSTOM_TEST_CONF(2);
CUSTOM_ITEM_CONF(2);
#endif
#if HAS_CUSTOM_ITEM_CONF(3)
CUSTOM_TEST_CONF(3);
CUSTOM_ITEM_CONF(3);
#endif
#if HAS_CUSTOM_ITEM_CONF(4)
CUSTOM_TEST_CONF(4);
CUSTOM_ITEM_CONF(4);
#endif
#if HAS_CUSTOM_ITEM_CONF(5)
CUSTOM_TEST_CONF(5);
CUSTOM_ITEM_CONF(5);
#endif
#if HAS_CUSTOM_ITEM_CONF(6)
CUSTOM_TEST_CONF(6);
CUSTOM_ITEM_CONF(6);
#endif
#if HAS_CUSTOM_ITEM_CONF(7)
CUSTOM_TEST_CONF(7);
CUSTOM_ITEM_CONF(7);
#endif
#if HAS_CUSTOM_ITEM_CONF(8)
CUSTOM_TEST_CONF(8);
CUSTOM_ITEM_CONF(8);
#endif
#if HAS_CUSTOM_ITEM_CONF(9)
CUSTOM_TEST_CONF(9);
CUSTOM_ITEM_CONF(9);
#endif
#if HAS_CUSTOM_ITEM_CONF(10)
CUSTOM_TEST_CONF(10);
CUSTOM_ITEM_CONF(10);
#endif
#if HAS_CUSTOM_ITEM_CONF(11)
CUSTOM_TEST_CONF(11);
CUSTOM_ITEM_CONF(11);
#endif
#if HAS_CUSTOM_ITEM_CONF(12)
CUSTOM_TEST_CONF(12);
CUSTOM_ITEM_CONF(12);
#endif
#if HAS_CUSTOM_ITEM_CONF(13)
CUSTOM_TEST_CONF(13);
CUSTOM_ITEM_CONF(13);
#endif
#if HAS_CUSTOM_ITEM_CONF(14)
CUSTOM_TEST_CONF(14);
CUSTOM_ITEM_CONF(14);
#endif
#if HAS_CUSTOM_ITEM_CONF(15)
CUSTOM_TEST_CONF(15);
CUSTOM_ITEM_CONF(15);
#endif
#if HAS_CUSTOM_ITEM_CONF(16)
CUSTOM_TEST_CONF(16);
CUSTOM_ITEM_CONF(16);
#endif
#if HAS_CUSTOM_ITEM_CONF(17)
CUSTOM_TEST_CONF(17);
CUSTOM_ITEM_CONF(17);
#endif
#if HAS_CUSTOM_ITEM_CONF(18)
CUSTOM_TEST_CONF(18);
CUSTOM_ITEM_CONF(18);
#endif
#if HAS_CUSTOM_ITEM_CONF(19)
CUSTOM_TEST_CONF(19);
CUSTOM_ITEM_CONF(19);
#endif
#if HAS_CUSTOM_ITEM_CONF(20)
CUSTOM_TEST_CONF(20);
CUSTOM_ITEM_CONF(20);
#endif
#if HAS_CUSTOM_ITEM_CONF(21)
CUSTOM_TEST_CONF(21);
CUSTOM_ITEM_CONF(21);
#endif
#if HAS_CUSTOM_ITEM_CONF(22)
CUSTOM_TEST_CONF(22);
CUSTOM_ITEM_CONF(22);
#endif
#if HAS_CUSTOM_ITEM_CONF(23)
CUSTOM_TEST_CONF(23);
CUSTOM_ITEM_CONF(23);
#endif
#if HAS_CUSTOM_ITEM_CONF(24)
CUSTOM_TEST_CONF(24);
CUSTOM_ITEM_CONF(24);
#endif
#if HAS_CUSTOM_ITEM_CONF(25)
CUSTOM_TEST_CONF(25);
CUSTOM_ITEM_CONF(25);
#endif
END_MENU();

View File

@ -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 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
#define _DONE_SCRIPT "\n" MAIN_MENU_ITEM_SCRIPT_DONE
#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)
CUSTOM_TEST_MAIN(1);
CUSTOM_ITEM_MAIN(1);
#endif
#if HAS_CUSTOM_ITEM_MAIN(2)
CUSTOM_TEST_MAIN(2);
CUSTOM_ITEM_MAIN(2);
#endif
#if HAS_CUSTOM_ITEM_MAIN(3)
CUSTOM_TEST_MAIN(3);
CUSTOM_ITEM_MAIN(3);
#endif
#if HAS_CUSTOM_ITEM_MAIN(4)
CUSTOM_TEST_MAIN(4);
CUSTOM_ITEM_MAIN(4);
#endif
#if HAS_CUSTOM_ITEM_MAIN(5)
CUSTOM_TEST_MAIN(5);
CUSTOM_ITEM_MAIN(5);
#endif
#if HAS_CUSTOM_ITEM_MAIN(6)
CUSTOM_TEST_MAIN(6);
CUSTOM_ITEM_MAIN(6);
#endif
#if HAS_CUSTOM_ITEM_MAIN(7)
CUSTOM_TEST_MAIN(7);
CUSTOM_ITEM_MAIN(7);
#endif
#if HAS_CUSTOM_ITEM_MAIN(8)
CUSTOM_TEST_MAIN(8);
CUSTOM_ITEM_MAIN(8);
#endif
#if HAS_CUSTOM_ITEM_MAIN(9)
CUSTOM_TEST_MAIN(9);
CUSTOM_ITEM_MAIN(9);
#endif
#if HAS_CUSTOM_ITEM_MAIN(10)
CUSTOM_TEST_MAIN(10);
CUSTOM_ITEM_MAIN(10);
#endif
#if HAS_CUSTOM_ITEM_MAIN(11)
CUSTOM_TEST_MAIN(11);
CUSTOM_ITEM_MAIN(11);
#endif
#if HAS_CUSTOM_ITEM_MAIN(12)
CUSTOM_TEST_MAIN(12);
CUSTOM_ITEM_MAIN(12);
#endif
#if HAS_CUSTOM_ITEM_MAIN(13)
CUSTOM_TEST_MAIN(13);
CUSTOM_ITEM_MAIN(13);
#endif
#if HAS_CUSTOM_ITEM_MAIN(14)
CUSTOM_TEST_MAIN(14);
CUSTOM_ITEM_MAIN(14);
#endif
#if HAS_CUSTOM_ITEM_MAIN(15)
CUSTOM_TEST_MAIN(15);
CUSTOM_ITEM_MAIN(15);
#endif
#if HAS_CUSTOM_ITEM_MAIN(16)
CUSTOM_TEST_MAIN(16);
CUSTOM_ITEM_MAIN(16);
#endif
#if HAS_CUSTOM_ITEM_MAIN(17)
CUSTOM_TEST_MAIN(17);
CUSTOM_ITEM_MAIN(17);
#endif
#if HAS_CUSTOM_ITEM_MAIN(18)
CUSTOM_TEST_MAIN(18);
CUSTOM_ITEM_MAIN(18);
#endif
#if HAS_CUSTOM_ITEM_MAIN(19)
CUSTOM_TEST_MAIN(19);
CUSTOM_ITEM_MAIN(19);
#endif
#if HAS_CUSTOM_ITEM_MAIN(20)
CUSTOM_TEST_MAIN(20);
CUSTOM_ITEM_MAIN(20);
#endif
#if HAS_CUSTOM_ITEM_MAIN(21)
CUSTOM_TEST_MAIN(21);
CUSTOM_ITEM_MAIN(21);
#endif
#if HAS_CUSTOM_ITEM_MAIN(22)
CUSTOM_TEST_MAIN(22);
CUSTOM_ITEM_MAIN(22);
#endif
#if HAS_CUSTOM_ITEM_MAIN(23)
CUSTOM_TEST_MAIN(23);
CUSTOM_ITEM_MAIN(23);
#endif
#if HAS_CUSTOM_ITEM_MAIN(24)
CUSTOM_TEST_MAIN(24);
CUSTOM_ITEM_MAIN(24);
#endif
#if HAS_CUSTOM_ITEM_MAIN(25)
CUSTOM_TEST_MAIN(25);
CUSTOM_ITEM_MAIN(25);
#endif
END_MENU();