diff --git a/CYD-Klipper/src/conf/global_config.h b/CYD-Klipper/src/conf/global_config.h index 545735d..31c16c8 100644 --- a/CYD-Klipper/src/conf/global_config.h +++ b/CYD-Klipper/src/conf/global_config.h @@ -68,6 +68,7 @@ typedef struct _GLOBAL_CONFIG { bool on_during_print : 1; bool display_mode : 1; // Driver specifc usage. Currently only used on ESP32-2432S028R to fix the screen on the usb-c model bool disable_m117_messaging : 1; + bool sort_macros : 1; }; }; diff --git a/CYD-Klipper/src/core/macros_query.cpp b/CYD-Klipper/src/core/macros_query.cpp index c1d5fa8..958b3e7 100644 --- a/CYD-Klipper/src/core/macros_query.cpp +++ b/CYD-Klipper/src/core/macros_query.cpp @@ -45,6 +45,13 @@ MACROSQUERY macros_query(PRINTER_CONFIG * config) } } + if (global_config.sort_macros) + { + std::sort(macros, macros + macros_count, [](const char* a, const char* b) { + return strcmp(a, b) < 0; + }); + } + return {(const char**)macros, (unsigned int)macros_count}; } else { diff --git a/CYD-Klipper/src/ui/panels/settings_panel.cpp b/CYD-Klipper/src/ui/panels/settings_panel.cpp index 48787a2..2e88b41 100644 --- a/CYD-Klipper/src/ui/panels/settings_panel.cpp +++ b/CYD-Klipper/src/ui/panels/settings_panel.cpp @@ -110,6 +110,13 @@ static void disable_m117_messaging_switch(lv_event_t* e){ write_global_config(); } +static void sort_macros_switch(lv_event_t* e){ + auto state = lv_obj_get_state(lv_event_get_target(e)); + bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED); + global_config.sort_macros = checked; + write_global_config(); +} + static void rotate_screen_switch(lv_event_t* e){ auto state = lv_obj_get_state(lv_event_get_target(e)); bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED); @@ -208,6 +215,8 @@ void settings_section_behaviour(lv_obj_t* panel) global_config.multi_printer_mode ? "Calls FILAMENT_RETRACT and\nFILAMENT_EXTRUDE in temperature menu\nwhen enabled. Stored per printer." : "Calls FILAMENT_RETRACT and\nFILAMENT_EXTRUDE in temperature menu\nwhen enabled"); + + lv_create_custom_menu_switch("Sort Macros A->Z", panel, sort_macros_switch, global_config.sort_macros); } void settings_section_device(lv_obj_t* panel)