From aff9e1f7ea5cbaec4e9b259ad375ba73fc667a59 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 1 Nov 2021 16:24:31 +0100 Subject: [PATCH] MSW_DarkMode: Next Improvements * Refreshed title bar for all Dialogs and MainFrame * Refreshed header of the DataViewCtrl and ListView * Refresh tooltips * Redraw SpinCtrls * Use system menu with is colored in respect to the color mode * Preferences: Added parameter "Use system menu for application" and moved to the "Dark mode" tab with "Enable Dark mode parameter" --- src/libslic3r/AppConfig.cpp | 3 ++ src/slic3r/GUI/BonjourDialog.cpp | 2 +- src/slic3r/GUI/ConfigWizard.cpp | 13 ++++++-- src/slic3r/GUI/GUI_App.cpp | 53 +++++++++++++++++++++++++------- src/slic3r/GUI/GUI_App.hpp | 3 ++ src/slic3r/GUI/Plater.cpp | 4 +++ src/slic3r/GUI/Preferences.cpp | 53 ++++++++++++++++++++++---------- src/slic3r/GUI/Preferences.hpp | 3 ++ src/slic3r/GUI/Search.cpp | 14 ++++++++- src/slic3r/GUI/Search.hpp | 8 +++-- 10 files changed, 123 insertions(+), 33 deletions(-) diff --git a/src/libslic3r/AppConfig.cpp b/src/libslic3r/AppConfig.cpp index e5af1fa731..b6406bf414 100644 --- a/src/libslic3r/AppConfig.cpp +++ b/src/libslic3r/AppConfig.cpp @@ -182,6 +182,9 @@ void AppConfig::set_defaults() if (get("dark_color_mode").empty()) set("dark_color_mode", "0"); + + if (get("sys_menu_enabled").empty()) + set("sys_menu_enabled", "1"); #endif // _WIN32 // Remove legacy window positions/sizes diff --git a/src/slic3r/GUI/BonjourDialog.cpp b/src/slic3r/GUI/BonjourDialog.cpp index be0e20eb20..516b1ab4a5 100644 --- a/src/slic3r/GUI/BonjourDialog.cpp +++ b/src/slic3r/GUI/BonjourDialog.cpp @@ -53,7 +53,7 @@ struct LifetimeGuard BonjourDialog::BonjourDialog(wxWindow *parent, Slic3r::PrinterTechnology tech) : wxDialog(parent, wxID_ANY, _(L("Network lookup")), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER) - , list(new wxListView(this, wxID_ANY)) + , list(new wxListView(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxSIMPLE_BORDER)) , replies(new ReplySet) , label(new wxStaticText(this, wxID_ANY, "")) , timer(new wxTimer()) diff --git a/src/slic3r/GUI/ConfigWizard.cpp b/src/slic3r/GUI/ConfigWizard.cpp index cceaff2e2b..b3b00f60c8 100644 --- a/src/slic3r/GUI/ConfigWizard.cpp +++ b/src/slic3r/GUI/ConfigWizard.cpp @@ -27,6 +27,10 @@ #include #include +#ifdef _MSW_DARK_MODE +#include +#endif // _MSW_DARK_MODE + #include "libslic3r/Platform.hpp" #include "libslic3r/Utils.hpp" #include "libslic3r/Config.hpp" @@ -2796,7 +2800,11 @@ ConfigWizard::ConfigWizard(wxWindow *parent) auto *vsizer = new wxBoxSizer(wxVERTICAL); auto *topsizer = new wxBoxSizer(wxHORIZONTAL); - auto *hline = new wxStaticLine(this); + wxStaticLine* hline = nullptr; +#ifdef _MSW_DARK_MODE + if (!NppDarkMode::IsEnabled()) +#endif //_MSW_DARK_MODE + hline = new wxStaticLine(this); p->btnsizer = new wxBoxSizer(wxHORIZONTAL); // Initially we _do not_ SetScrollRate in order to figure out the overall width of the Wizard without scrolling. @@ -2872,7 +2880,8 @@ ConfigWizard::ConfigWizard(wxWindow *parent) p->index->go_to(size_t{0}); vsizer->Add(topsizer, 1, wxEXPAND | wxALL, DIALOG_MARGIN); - vsizer->Add(hline, 0, wxEXPAND); + if (hline) + vsizer->Add(hline, 0, wxEXPAND); vsizer->Add(p->btnsizer, 0, wxEXPAND | wxALL, DIALOG_MARGIN); SetSizer(vsizer); diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index cd286e45ae..bab07b4664 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -3,6 +3,7 @@ #include "GUI_Init.hpp" #include "GUI_ObjectList.hpp" #include "GUI_ObjectManipulation.hpp" +#include "GUI_Factories.hpp" #include "format.hpp" #include "I18N.hpp" @@ -1020,11 +1021,7 @@ bool GUI_App::on_init_inner() wxInitAllImageHandlers(); #ifdef _MSW_DARK_MODE - if (bool dark_mode = app_config->get("dark_color_mode") == "1") { - NppDarkMode::InitDarkMode(); - if (dark_mode != NppDarkMode::IsDarkMode()) - NppDarkMode::SetDarkMode(dark_mode); - } + NppDarkMode::InitDarkMode(app_config->get("dark_color_mode") == "1", app_config->get("sys_menu_enabled") == "1"); #endif SplashScreen* scrn = nullptr; if (app_config->get("show_splash_screen") == "1") { @@ -1347,10 +1344,9 @@ void GUI_App::UpdateDVCDarkUI(wxDataViewCtrl* dvc, bool highlited/* = false*/) { #ifdef _WIN32 UpdateDarkUI(dvc, highlited ? dark_mode() : false); - wxItemAttr attr(dark_mode() ? m_color_highlight_default : m_color_label_default, - m_color_window_default, - m_normal_font); - dvc->SetHeaderAttr(attr); +#ifdef _MSW_DARK_MODE + dvc->RefreshHeaderDarkMode(&m_normal_font); +#endif //_MSW_DARK_MODE if (dvc->HasFlag(wxDV_ROW_LINES)) dvc->SetAlternateRowColour(m_color_highlight_default); if (dvc->GetBorder() != wxBORDER_SIMPLE) @@ -1574,12 +1570,44 @@ void fatal_error(wxWindow* parent) } #ifdef _WIN32 + +#ifdef _MSW_DARK_MODE +static void update_scrolls(wxWindow* window) +{ + wxWindowList::compatibility_iterator node = window->GetChildren().GetFirst(); + while (node) + { + wxWindow* win = node->GetData(); + if (dynamic_cast(win) || + dynamic_cast(win) || + dynamic_cast(win)) + NppDarkMode::SetDarkExplorerTheme(win->GetHWND()); + + update_scrolls(win); + node = node->GetNext(); + } +} +#endif //_MSW_DARK_MODE + + +#ifdef _MSW_DARK_MODE +void GUI_App::force_menu_update() +{ + NppDarkMode::SetSystemMenuForApp(app_config->get("sys_menu_enabled") == "1"); +} +#endif //_MSW_DARK_MODE + void GUI_App::force_colors_update() { +#ifdef _MSW_DARK_MODE NppDarkMode::SetDarkMode(app_config->get("dark_color_mode") == "1"); + if (WXHWND wxHWND = wxToolTip::GetToolTipCtrl()) + NppDarkMode::SetDarkExplorerTheme((HWND)wxHWND); + NppDarkMode::SetDarkTitleBar(mainframe->GetHWND()); +#endif //_MSW_DARK_MODE m_force_colors_update = true; } -#endif +#endif //_WIN32 // Called after the Preferences dialog is closed and the program settings are saved. // Update the UI based on the current preferences. @@ -1587,11 +1615,14 @@ void GUI_App::update_ui_from_settings() { update_label_colours(); #ifdef _WIN32 - // Upadte UU colors before Update UI from settings + // Upadte UI colors before Update UI from settings if (m_force_colors_update) { m_force_colors_update = false; mainframe->force_color_changed(); mainframe->diff_dialog.force_color_changed(); +#ifdef _MSW_DARK_MODE + update_scrolls(mainframe); +#endif //_MSW_DARK_MODE } #endif mainframe->update_ui_from_settings(); diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 90a8776a67..1d281cafef 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -210,6 +210,9 @@ public: const wxColour& get_color_hovered_btn_label() { return m_color_hovered_btn_label; } const wxColour& get_color_selected_btn_bg() { return m_color_selected_btn_bg; } void force_colors_update(); +#ifdef _MSW_DARK_MODE + void force_menu_update(); +#endif //_MSW_DARK_MODE #endif const wxFont& small_font() { return m_small_font; } diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 710a6ffd25..eb64fb08ca 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1087,6 +1087,8 @@ void Sidebar::msw_rescale() p->btn_reslice ->SetMinSize(wxSize(-1, scaled_height)); p->scrolled->Layout(); + + p->searcher.dlg_msw_rescale(); } void Sidebar::sys_color_changed() @@ -1125,6 +1127,8 @@ void Sidebar::sys_color_changed() p->btn_export_gcode_removable->msw_rescale(); p->scrolled->Layout(); + + p->searcher.dlg_sys_color_changed(); } void Sidebar::search() diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 3748e2251f..c73fd40644 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -350,8 +350,6 @@ void PreferencesDialog::build(size_t selected_tab) tabs->Layout(); this->layout(); } - - }; def.label = L("Sequential slider applied only to top layer"); @@ -395,16 +393,6 @@ void PreferencesDialog::build(size_t selected_tab) m_optgroup_gui->append_single_option_line(option); #ifdef _MSW_DARK_MODE - } - def.label = L("Use Dark color mode (experimental)"); - def.type = coBool; - def.tooltip = L("If enabled, UI will use Dark mode colors. " - "If disabled, old UI will be used."); - def.set_default_value(new ConfigOptionBool{ app_config->get("dark_color_mode") == "1" }); - option = Option(def, "dark_color_mode"); - m_optgroup_gui->append_single_option_line(option); - - if (is_editor) { def.label = L("Set settings tabs as menu items (experimental)"); def.type = coBool; def.tooltip = L("If enabled, Settings Tabs will be placed as menu items. " @@ -484,6 +472,36 @@ void PreferencesDialog::build(size_t selected_tab) } #endif // ENABLE_ENVIRONMENT_MAP +#ifdef _WIN32 + // Add "Dark Mode" tab + if (is_editor) { + // Add "Dark Mode" tab + m_optgroup_dark_mode = create_options_tab(_L("Dark mode (experimental)"), tabs); + m_optgroup_dark_mode->m_on_change = [this](t_config_option_key opt_key, boost::any value) { + m_values[opt_key] = boost::any_cast(value) ? "1" : "0"; + }; + + def.label = L("Enable dark mode"); + def.type = coBool; + def.tooltip = L("If enabled, UI will use Dark mode colors. " + "If disabled, old UI will be used."); + def.set_default_value(new ConfigOptionBool{ app_config->get("dark_color_mode") == "1" }); + option = Option(def, "dark_color_mode"); + m_optgroup_dark_mode->append_single_option_line(option); + + def.label = L("Use system menu for application"); + def.type = coBool; + def.tooltip = L("If enabled, application will use standart Windows system menu,\n" + "but on some combination od display scales it can looks ugly. " + "If disabled, old UI will be used."); + def.set_default_value(new ConfigOptionBool{ app_config->get("sys_menu_enabled") == "1" }); + option = Option(def, "sys_menu_enabled"); + m_optgroup_dark_mode->append_single_option_line(option); + + activate_options_tab(m_optgroup_dark_mode); + } +#endif //_WIN32 + // update alignment of the controls for all tabs update_ctrls_alignment(); @@ -525,7 +543,7 @@ void PreferencesDialog::accept(wxEvent&) // if (m_values.find("no_defaults") != m_values.end() // warning_catcher(this, wxString::Format(_L("You need to restart %s to make the changes effective."), SLIC3R_APP_NAME)); - std::vector options_to_recreate_GUI = { "no_defaults", "tabs_as_menu" }; + std::vector options_to_recreate_GUI = { "no_defaults", "tabs_as_menu", "sys_menu_enabled" }; for (const std::string& option : options_to_recreate_GUI) { if (m_values.find(option) != m_values.end()) { @@ -588,11 +606,14 @@ void PreferencesDialog::accept(wxEvent&) EndModal(wxID_OK); -#ifdef _MSW_DARK_MODE +#ifdef _WIN32 if (m_values.find("dark_color_mode") != m_values.end()) wxGetApp().force_colors_update(); -#endif - +#ifdef _MSW_DARK_MODE + if (m_values.find("sys_menu_enabled") != m_values.end()) + wxGetApp().force_menu_update(); +#endif //_MSW_DARK_MODE +#endif // _WIN32 if (m_settings_layout_changed) ;// application will be recreated after Preference dialog will be destroyed else diff --git a/src/slic3r/GUI/Preferences.hpp b/src/slic3r/GUI/Preferences.hpp index 01f116760c..210b04d4fd 100644 --- a/src/slic3r/GUI/Preferences.hpp +++ b/src/slic3r/GUI/Preferences.hpp @@ -29,6 +29,9 @@ class PreferencesDialog : public DPIDialog std::shared_ptr m_optgroup_general; std::shared_ptr m_optgroup_camera; std::shared_ptr m_optgroup_gui; +#ifdef _WIN32 + std::shared_ptr m_optgroup_dark_mode; +#endif //_WIN32 #if ENABLE_ENVIRONMENT_MAP std::shared_ptr m_optgroup_render; #endif // ENABLE_ENVIRONMENT_MAP diff --git a/src/slic3r/GUI/Search.cpp b/src/slic3r/GUI/Search.cpp index 1e37dc3729..add5dc0024 100644 --- a/src/slic3r/GUI/Search.cpp +++ b/src/slic3r/GUI/Search.cpp @@ -401,6 +401,18 @@ void OptionsSearcher::show_dialog() search_dialog->Popup(); } +void OptionsSearcher::dlg_sys_color_changed() +{ + if (search_dialog) + search_dialog->on_sys_color_changed(); +} + +void OptionsSearcher::dlg_msw_rescale() +{ + if (search_dialog) + search_dialog->msw_rescale(); +} + void OptionsSearcher::add_key(const std::string& opt_key, Preset::Type type, const wxString& group, const wxString& category) { groups_and_categories[get_key(opt_key, type)] = GroupAndCategory{group, category}; @@ -666,7 +678,7 @@ void SearchDialog::OnLeftDown(wxMouseEvent& event) ProcessSelection(search_list->GetSelection()); } -void SearchDialog::on_dpi_changed(const wxRect& suggested_rect) +void SearchDialog::msw_rescale() { const int& em = em_unit(); diff --git a/src/slic3r/GUI/Search.hpp b/src/slic3r/GUI/Search.hpp index 19de58f961..d5add92629 100644 --- a/src/slic3r/GUI/Search.hpp +++ b/src/slic3r/GUI/Search.hpp @@ -138,6 +138,8 @@ public: void sort_options_by_label() { sort_options(); } void show_dialog(); + void dlg_sys_color_changed(); + void dlg_msw_rescale(); }; @@ -180,9 +182,11 @@ public: void Popup(wxPoint position = wxDefaultPosition); void ProcessSelection(wxDataViewItem selection); -protected: - void on_dpi_changed(const wxRect& suggested_rect) override; + void msw_rescale(); void on_sys_color_changed() override; + +protected: + void on_dpi_changed(const wxRect& suggested_rect) override { msw_rescale(); } };