From 86a999253f86e7f1afb3ff92aa38044d711eb9bd Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Thu, 28 Mar 2024 20:26:57 +0100 Subject: [PATCH] Reorganise settings menu --- CYD-Klipper/src/conf/global_config.cpp | 1 + CYD-Klipper/src/ui/panels/settings_panel.cpp | 88 ++++++++++++-------- CYD-Klipper/src/ui/ui_utils.cpp | 21 +++-- CYD-Klipper/src/ui/ui_utils.h | 8 +- 4 files changed, 71 insertions(+), 47 deletions(-) diff --git a/CYD-Klipper/src/conf/global_config.cpp b/CYD-Klipper/src/conf/global_config.cpp index 768155a..cefc9d4 100644 --- a/CYD-Klipper/src/conf/global_config.cpp +++ b/CYD-Klipper/src/conf/global_config.cpp @@ -6,6 +6,7 @@ GLOBAL_CONFIG global_config = {0}; COLOR_DEF color_defs[] = { {LV_PALETTE_BLUE, 0, LV_PALETTE_RED}, + {LV_PALETTE_GREEN, 0, LV_PALETTE_PURPLE}, {LV_PALETTE_LIME, -2, LV_PALETTE_PURPLE}, {LV_PALETTE_GREY, 0, LV_PALETTE_CYAN}, {LV_PALETTE_YELLOW, -2, LV_PALETTE_PINK}, diff --git a/CYD-Klipper/src/ui/panels/settings_panel.cpp b/CYD-Klipper/src/ui/panels/settings_panel.cpp index ec9f979..9627fed 100644 --- a/CYD-Klipper/src/ui/panels/settings_panel.cpp +++ b/CYD-Klipper/src/ui/panels/settings_panel.cpp @@ -140,38 +140,56 @@ static void estimated_time_dropdown(lv_event_t * e){ write_global_config(); } -void settings_panel_init(lv_obj_t* panel){ - lv_obj_set_style_pad_all(panel, CYD_SCREEN_GAP_PX, 0); - lv_layout_flex_column(panel); - lv_obj_set_scrollbar_mode(panel, LV_SCROLLBAR_MODE_OFF); +#define PRINTER_SPECIFIC_SETTING global_config.multi_printer_mode ? LV_SYMBOL_PLUS " Stored per printer" : NULL - if (global_config.multi_printer_mode) - { - lv_obj_t * label = lv_label_create(panel); - lv_label_set_text(label, "Printer Specific Settings"); - } +void settings_section_theming(lv_obj_t* panel) +{ + lv_obj_t * label = lv_label_create(panel); + lv_label_set_text(label, "Theming"); - lv_create_custom_menu_dropdown("Estimated Time", panel, estimated_time_dropdown, estimated_time_options, get_current_printer_config()->remaining_time_calc_mode); - lv_create_custom_menu_dropdown("Theme", panel, theme_dropdown, "Blue\nGreen\nGrey\nYellow\nOrange\nRed\nPurple", get_current_printer_config()->color_scheme); + lv_create_custom_menu_dropdown("Theme", panel, theme_dropdown, "Blue\nGreen\nLime\nGrey\nYellow\nOrange\nRed\nPurple", get_current_printer_config()->color_scheme, NULL, PRINTER_SPECIFIC_SETTING); #ifndef CYD_SCREEN_DISABLE_INVERT_COLORS - lv_create_custom_menu_switch("Invert Colors", panel, invert_color_switch, get_current_printer_config()->invert_colors); + lv_create_custom_menu_switch("Invert Colors", panel, invert_color_switch, get_current_printer_config()->invert_colors, NULL, (global_config.multi_printer_mode) ? LV_SYMBOL_PLUS " Stored per printer\n" "Intended for the 2.8\" dual USB model screen" : "Intended for the 2.8\" dual USB model screen"); #endif // CYD_SCREEN_DISABLE_INVERT_COLORS - lv_create_custom_menu_switch("Light Mode", panel, light_mode_switch, get_current_printer_config()->light_mode); - lv_create_custom_menu_dropdown("Stats in Progress Screen", panel, show_stats_on_progress_panel_dropdown, "None\nLayers\nPartial\nAll", get_current_printer_config()->show_stats_on_progress_panel); - lv_create_custom_menu_button("Configure IP", panel, reset_ip_click, "Restart"); + lv_create_custom_menu_switch("Light Mode", panel, light_mode_switch, get_current_printer_config()->light_mode, NULL, PRINTER_SPECIFIC_SETTING); +} - if (global_config.multi_printer_mode) - { - lv_obj_t * label = lv_label_create(panel); - lv_label_set_text(label, "\nGlobal Settings"); +void settings_section_behaviour(lv_obj_t* panel) +{ + lv_obj_t * label = lv_label_create(panel); + lv_label_set_text(label, "\nBehaviour"); + + lv_create_custom_menu_dropdown("Estimated Time", panel, estimated_time_dropdown, estimated_time_options, get_current_printer_config()->remaining_time_calc_mode, NULL, PRINTER_SPECIFIC_SETTING); + lv_create_custom_menu_dropdown("Stats in Progress Screen", panel, show_stats_on_progress_panel_dropdown, "None\nLayers\nPartial\nAll", get_current_printer_config()->show_stats_on_progress_panel, NULL, PRINTER_SPECIFIC_SETTING); + +#ifndef CYD_SCREEN_DISABLE_TIMEOUT + int wake_timeout_settings_index = 0; + for (int i = 0; i < SIZEOF(wake_timeout_options_values); i++){ + if (wake_timeout_options_values[i] == global_config.screen_timeout){ + wake_timeout_settings_index = i; + break; + } } + lv_create_custom_menu_dropdown("Wake Timeout", panel, wake_timeout_dropdown, wake_timeout_options, wake_timeout_settings_index); +#endif + #ifndef CYD_SCREEN_DISABLE_TIMEOUT lv_create_custom_menu_switch("Screen On During Print", panel, on_during_print_switch, global_config.on_during_print); #endif + lv_create_custom_menu_switch("Multi Printer Mode", panel, multi_printer_switch, global_config.multi_printer_mode); + +lv_create_custom_menu_button("Configure IP", panel, reset_ip_click, "Restart"); +} + +void settings_section_device(lv_obj_t* panel) +{ + lv_obj_t * label = lv_label_create(panel); + lv_label_set_text(label, "\nDevice"); + int brightness_settings_index = 0; for (int i = 0; i < SIZEOF(brightness_options_values); i++){ if (brightness_options_values[i] == global_config.brightness){ @@ -182,23 +200,11 @@ void settings_panel_init(lv_obj_t* panel){ lv_create_custom_menu_dropdown("Brightness", panel, brightness_dropdown, brightness_options, brightness_settings_index); -#ifndef CYD_SCREEN_DISABLE_TIMEOUT - int wake_timeout_settings_index = 0; - for (int i = 0; i < SIZEOF(wake_timeout_options_values); i++){ - if (wake_timeout_options_values[i] == global_config.screen_timeout){ - wake_timeout_settings_index = i; - break; - } - } - - lv_create_custom_menu_dropdown("Wake Timeout", panel, wake_timeout_dropdown, wake_timeout_options, wake_timeout_settings_index); -#endif - #ifdef CYD_SCREEN_DRIVER_ESP32_2432S028R - lv_create_custom_menu_switch("Dual USB Screen Color Fix", panel, dualusb_screen_fix_switch, global_config.display_mode); + lv_create_custom_menu_switch("Screen Color Fix", panel, dualusb_screen_fix_switch, global_config.display_mode, NULL, "Intended for the 2.8\" dual USB model screen"); #endif + lv_create_custom_menu_switch("Rotate Screen", panel, rotate_screen_switch, global_config.rotate_screen); - lv_create_custom_menu_switch("Multi Printer Mode", panel, multi_printer_switch, global_config.multi_printer_mode); lv_create_custom_menu_switch("Auto Update", panel, auto_ota_update_switch, global_config.auto_ota_update); lv_create_custom_menu_label("Version", panel, REPO_VERSION " "); @@ -216,10 +222,20 @@ void settings_panel_init(lv_obj_t* panel){ lv_create_custom_menu_label("Device", panel, ARDUINO_BOARD " "); } - #ifndef CYD_SCREEN_DISABLE_TOUCH_CALIBRATION - lv_create_custom_menu_button("Calibrate Touch", panel, reset_calibration_click, "Restart"); - #endif // CYD_SCREEN_DISABLE_TOUCH_CALIBRATION +#ifndef CYD_SCREEN_DISABLE_TOUCH_CALIBRATION + lv_create_custom_menu_button("Calibrate Touch", panel, reset_calibration_click, "Restart"); +#endif // CYD_SCREEN_DISABLE_TOUCH_CALIBRATION lv_create_custom_menu_button("Configure WiFi", panel, reset_wifi_click, "Restart"); lv_create_custom_menu_button("Restart ESP", panel, reset_click, "Restart"); +} + +void settings_panel_init(lv_obj_t* panel){ + lv_obj_set_style_pad_all(panel, CYD_SCREEN_GAP_PX, 0); + lv_layout_flex_column(panel); + lv_obj_set_scrollbar_mode(panel, LV_SCROLLBAR_MODE_OFF); + + settings_section_theming(panel); + settings_section_behaviour(panel); + settings_section_device(panel); } \ No newline at end of file diff --git a/CYD-Klipper/src/ui/ui_utils.cpp b/CYD-Klipper/src/ui/ui_utils.cpp index 33e60c3..35b399e 100644 --- a/CYD-Klipper/src/ui/ui_utils.cpp +++ b/CYD-Klipper/src/ui/ui_utils.cpp @@ -149,7 +149,7 @@ void lv_create_keyboard_text_entry(lv_event_cb_t keyboard_callback, const char* const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2) * 0.85f), 0} }; -void lv_create_custom_menu_entry(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel, bool set_height) +void lv_create_custom_menu_entry(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel, bool set_height, const char * comment) { lv_obj_t * panel = lv_create_empty_panel(root_panel); lv_layout_flex_row(panel, LV_FLEX_ALIGN_END); @@ -165,6 +165,13 @@ void lv_create_custom_menu_entry(const char* label_text, lv_obj_t* object, lv_ob if (set_height) lv_obj_set_height(object, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + if (comment != NULL) + { + lv_obj_t * comment_label = lv_label_create(root_panel); + lv_label_set_text(comment_label, comment); + lv_obj_set_style_text_font(comment_label, &CYD_SCREEN_FONT_SMALL, 0); + } + lv_obj_t * line = lv_line_create(root_panel); lv_line_set_points(line, line_points, 2); lv_obj_set_style_line_width(line, 1, 0); @@ -174,7 +181,7 @@ void lv_create_custom_menu_entry(const char* label_text, lv_obj_t* object, lv_ob #define DROPDOWN_WIDTH CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 3.75 #define TOGGLE_WIDTH CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 2 -void lv_create_custom_menu_button(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_click, const char *btn_text, void * user_data) +void lv_create_custom_menu_button(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_click, const char *btn_text, void * user_data, const char * comment) { lv_obj_t * btn = lv_btn_create(lv_scr_act()); lv_obj_add_event_cb(btn, on_click, LV_EVENT_CLICKED, user_data); @@ -183,10 +190,10 @@ void lv_create_custom_menu_button(const char *label_text, lv_obj_t* root_panel, lv_label_set_text(label, btn_text); lv_obj_center(label); - lv_create_custom_menu_entry(label_text, btn, root_panel, true); + lv_create_custom_menu_entry(label_text, btn, root_panel, true, comment); } -void lv_create_custom_menu_switch(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_toggle, bool state, void * user_data) +void lv_create_custom_menu_switch(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_toggle, bool state, void * user_data, const char * comment) { lv_obj_t * toggle = lv_switch_create(lv_scr_act()); lv_obj_add_event_cb(toggle, on_toggle, LV_EVENT_VALUE_CHANGED, user_data); @@ -195,10 +202,10 @@ void lv_create_custom_menu_switch(const char *label_text, lv_obj_t* root_panel, if (state) lv_obj_add_state(toggle, LV_STATE_CHECKED); - lv_create_custom_menu_entry(label_text, toggle, root_panel, true); + lv_create_custom_menu_entry(label_text, toggle, root_panel, true, comment); } -void lv_create_custom_menu_dropdown(const char *label_text, lv_obj_t *root_panel, lv_event_cb_t on_change, const char *options, int index, void * user_data) +void lv_create_custom_menu_dropdown(const char *label_text, lv_obj_t *root_panel, lv_event_cb_t on_change, const char *options, int index, void * user_data, const char * comment) { lv_obj_t * dropdown = lv_dropdown_create(lv_scr_act()); lv_dropdown_set_options(dropdown, options); @@ -206,7 +213,7 @@ void lv_create_custom_menu_dropdown(const char *label_text, lv_obj_t *root_panel lv_obj_set_width(dropdown, DROPDOWN_WIDTH); lv_obj_add_event_cb(dropdown, on_change, LV_EVENT_VALUE_CHANGED, user_data); - lv_create_custom_menu_entry(label_text, dropdown, root_panel, true); + lv_create_custom_menu_entry(label_text, dropdown, root_panel, true, comment); } void lv_create_custom_menu_label(const char *label_text, lv_obj_t* root_panel, const char *text) diff --git a/CYD-Klipper/src/ui/ui_utils.h b/CYD-Klipper/src/ui/ui_utils.h index d787e1a..66dd6fc 100644 --- a/CYD-Klipper/src/ui/ui_utils.h +++ b/CYD-Klipper/src/ui/ui_utils.h @@ -39,10 +39,10 @@ void lv_layout_flex_row(lv_obj_t* obj, lv_flex_align_t allign = LV_FLEX_ALIGN_ST void lv_create_fullscreen_button_matrix_popup(lv_obj_t * root, lv_event_cb_t title, lv_button_column_t* columns, int column_count); void destroy_event_user_data(lv_event_t * e); void lv_create_keyboard_text_entry(lv_event_cb_t keyboard_callback, const char* title = NULL, lv_keyboard_mode_t keyboard_mode = LV_KEYBOARD_MODE_NUMBER, lv_coord_t width = CYD_SCREEN_PANEL_WIDTH_PX / 2, uint8_t max_length = 3, const char* fill_text = "", bool contain_in_panel= true); -void lv_create_custom_menu_entry(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel, bool set_height = true); -void lv_create_custom_menu_button(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_click, const char *btn_text, void * user_data = NULL); -void lv_create_custom_menu_switch(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_toggle, bool state, void * user_data = NULL); -void lv_create_custom_menu_dropdown(const char *label_text, lv_obj_t *root_panel, lv_event_cb_t on_change, const char *options, int index, void * user_data = NULL); +void lv_create_custom_menu_entry(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel, bool set_height = true, const char * comment = NULL); +void lv_create_custom_menu_button(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_click, const char *btn_text, void * user_data = NULL, const char * comment = NULL); +void lv_create_custom_menu_switch(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_toggle, bool state, void * user_data = NULL, const char * comment = NULL); +void lv_create_custom_menu_dropdown(const char *label_text, lv_obj_t *root_panel, lv_event_cb_t on_change, const char *options, int index, void * user_data = NULL, const char * comment = NULL); void lv_create_custom_menu_label(const char *label_text, lv_obj_t* root_panel, const char *text); void lv_create_popup_message(const char* message, uint16_t timeout_ms); lv_obj_t * lv_label_btn_create(lv_obj_t * parent, lv_event_cb_t btn_callback, void* user_data = NULL); \ No newline at end of file