Implement file sorting (implement #89)

This commit is contained in:
suchmememanyskill
2024-06-11 20:49:13 +02:00
parent d69446a11b
commit d780c8d55e
3 changed files with 17 additions and 0 deletions

View File

@@ -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;
};
};

View File

@@ -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 {

View File

@@ -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)