From 428362ec5375d299d754da533bce64de54f43798 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 13 Jul 2021 18:27:15 +0200 Subject: [PATCH] Fixed Windows DarkMode for some dialogues. + ProjectDropDialog: wxRadiloBox was changes to the wxStaticBox with wxRadioButtons because of dark mode colors update + Preferences: Fixed update of the text colors --- src/slic3r/GUI/AboutDialog.cpp | 7 ++----- src/slic3r/GUI/BedShapeDialog.cpp | 9 +-------- src/slic3r/GUI/ButtonsDescription.cpp | 4 ++-- src/slic3r/GUI/GUI_App.cpp | 12 +++++++----- src/slic3r/GUI/GUI_App.hpp | 2 +- src/slic3r/GUI/Plater.cpp | 27 +++++++++++++++++++++------ src/slic3r/GUI/Preferences.cpp | 13 +++---------- src/slic3r/GUI/Preferences.hpp | 2 +- src/slic3r/GUI/SysInfoDialog.cpp | 3 +-- 9 files changed, 39 insertions(+), 40 deletions(-) diff --git a/src/slic3r/GUI/AboutDialog.cpp b/src/slic3r/GUI/AboutDialog.cpp index 5039b9de4..b9417c8a2 100644 --- a/src/slic3r/GUI/AboutDialog.cpp +++ b/src/slic3r/GUI/AboutDialog.cpp @@ -72,8 +72,7 @@ CopyrightsDialog::CopyrightsDialog() m_html->Bind(wxEVT_HTML_LINK_CLICKED, &CopyrightsDialog::onLinkClicked, this); wxStdDialogButtonSizer* buttons = this->CreateStdDialogButtonSizer(wxCLOSE); - wxGetApp().UpdateDarkUI(static_cast(this->FindWindowById(wxID_CLOSE, this))); - + wxGetApp().UpdateDlgDarkUI(this, true); this->SetEscapeId(wxID_CLOSE); this->Bind(wxEVT_BUTTON, &CopyrightsDialog::onCloseDialog, this, wxID_CLOSE); sizer->Add(buttons, 0, wxEXPAND | wxRIGHT | wxBOTTOM, 3); @@ -297,7 +296,6 @@ AboutDialog::AboutDialog() wxStdDialogButtonSizer* buttons = this->CreateStdDialogButtonSizer(wxCLOSE); - wxGetApp().UpdateDarkUI(static_cast(this->FindWindowById(wxID_CLOSE, this))); m_copy_rights_btn_id = NewControlId(); auto copy_rights_btn = new wxButton(this, m_copy_rights_btn_id, _L("Portions copyright")+dots); @@ -309,8 +307,7 @@ AboutDialog::AboutDialog() buttons->Insert(1, copy_version_btn, 0, wxLEFT, 5); copy_version_btn->Bind(wxEVT_BUTTON, &AboutDialog::onCopyToClipboard, this); - wxGetApp().UpdateDarkUI(copy_rights_btn); - wxGetApp().UpdateDarkUI(copy_version_btn); + wxGetApp().UpdateDlgDarkUI(this, true); this->SetEscapeId(wxID_CLOSE); this->Bind(wxEVT_BUTTON, &AboutDialog::onCloseDialog, this, wxID_CLOSE); diff --git a/src/slic3r/GUI/BedShapeDialog.cpp b/src/slic3r/GUI/BedShapeDialog.cpp index 7284bb51b..40d9ee3b2 100644 --- a/src/slic3r/GUI/BedShapeDialog.cpp +++ b/src/slic3r/GUI/BedShapeDialog.cpp @@ -177,7 +177,6 @@ void BedShape::apply_optgroup_values(ConfigOptionsGroupShp optgroup) void BedShapeDialog::build_dialog(const ConfigOptionPoints& default_pt, const ConfigOptionString& custom_texture, const ConfigOptionString& custom_model) { SetFont(wxGetApp().normal_font()); -// wxGetApp().UpdateDarkUI(this); m_panel = new BedShapePanel(this); m_panel->build_panel(default_pt, custom_texture, custom_model); @@ -186,8 +185,7 @@ void BedShapeDialog::build_dialog(const ConfigOptionPoints& default_pt, const Co main_sizer->Add(m_panel, 1, wxEXPAND); main_sizer->Add(CreateButtonSizer(wxOK | wxCANCEL), 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, 10); - wxGetApp().UpdateDarkUI(static_cast(this->FindWindowById(wxID_OK, this)), true); - wxGetApp().UpdateDarkUI(static_cast(this->FindWindowById(wxID_CANCEL, this)), true); + wxGetApp().UpdateDlgDarkUI(this, true); SetSizer(main_sizer); SetMinSize(GetSize()); @@ -249,7 +247,6 @@ void BedShapePanel::build_panel(const ConfigOptionPoints& default_pt, const Conf line.full_width = 1; line.widget = [this](wxWindow* parent) { wxButton* shape_btn = new wxButton(parent, wxID_ANY, _L("Load shape from STL...")); - wxGetApp().UpdateDarkUI(shape_btn, true); wxSizer* shape_sizer = new wxBoxSizer(wxHORIZONTAL); shape_sizer->Add(shape_btn, 1, wxEXPAND); @@ -333,7 +330,6 @@ wxPanel* BedShapePanel::init_texture_panel() line.full_width = 1; line.widget = [this](wxWindow* parent) { wxButton* load_btn = new wxButton(parent, wxID_ANY, _(L("Load..."))); - wxGetApp().UpdateDarkUI(load_btn, true); wxSizer* load_sizer = new wxBoxSizer(wxHORIZONTAL); load_sizer->Add(load_btn, 1, wxEXPAND); @@ -343,7 +339,6 @@ wxPanel* BedShapePanel::init_texture_panel() filename_sizer->Add(filename_lbl, 1, wxEXPAND); wxButton* remove_btn = new wxButton(parent, wxID_ANY, _(L("Remove"))); - wxGetApp().UpdateDarkUI(remove_btn, true); wxSizer* remove_sizer = new wxBoxSizer(wxHORIZONTAL); remove_sizer->Add(remove_btn, 1, wxEXPAND); @@ -417,7 +412,6 @@ wxPanel* BedShapePanel::init_model_panel() line.full_width = 1; line.widget = [this](wxWindow* parent) { wxButton* load_btn = new wxButton(parent, wxID_ANY, _(L("Load..."))); - wxGetApp().UpdateDarkUI(load_btn, true); wxSizer* load_sizer = new wxBoxSizer(wxHORIZONTAL); load_sizer->Add(load_btn, 1, wxEXPAND); @@ -426,7 +420,6 @@ wxPanel* BedShapePanel::init_model_panel() filename_sizer->Add(filename_lbl, 1, wxEXPAND); wxButton* remove_btn = new wxButton(parent, wxID_ANY, _(L("Remove"))); - wxGetApp().UpdateDarkUI(remove_btn, true); wxSizer* remove_sizer = new wxBoxSizer(wxHORIZONTAL); remove_sizer->Add(remove_btn, 1, wxEXPAND); diff --git a/src/slic3r/GUI/ButtonsDescription.cpp b/src/slic3r/GUI/ButtonsDescription.cpp index 78a9d2df5..cadb7ac24 100644 --- a/src/slic3r/GUI/ButtonsDescription.cpp +++ b/src/slic3r/GUI/ButtonsDescription.cpp @@ -70,9 +70,9 @@ ButtonsDescription::ButtonsDescription(wxWindow* parent, const std::vectorAdd(buttons, 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, 10); + wxGetApp().UpdateDlgDarkUI(this, true); + wxButton* btn = static_cast(FindWindowById(wxID_OK, this)); - wxGetApp().UpdateDarkUI(btn); - wxGetApp().UpdateDarkUI(static_cast(this->FindWindowById(wxID_CANCEL, this))); btn->Bind(wxEVT_BUTTON, [sys_colour, mod_colour, this](wxCommandEvent&) { wxGetApp().set_label_clr_sys(sys_colour->GetColour()); wxGetApp().set_label_clr_modified(mod_colour->GetColour()); diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 73f41e449..13246c543 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -1115,10 +1115,11 @@ void GUI_App::UpdateDarkUI(wxWindow* window, bool highlited/* = false*/, bool ju // recursive function for scaling fonts for all controls in Window #ifdef _WIN32 -static void update_dark_children_ui(wxWindow* window) +static void update_dark_children_ui(wxWindow* window, bool just_buttons_update = false) { - bool highlight_btn = dynamic_cast(window) != nullptr; - wxGetApp().UpdateDarkUI(window, highlight_btn); + bool is_btn = dynamic_cast(window) != nullptr; + if (!(just_buttons_update && !is_btn)) + wxGetApp().UpdateDarkUI(window, is_btn); auto children = window->GetChildren(); for (auto child : children) { @@ -1127,10 +1128,11 @@ static void update_dark_children_ui(wxWindow* window) } #endif -void GUI_App::UpdateDlgDarkUI(wxDialog* dlg) +// Note: Don't use this function for Dialog contains ScalableButtons +void GUI_App::UpdateDlgDarkUI(wxDialog* dlg, bool just_buttons_update/* = false*/) { #ifdef _WIN32 - update_dark_children_ui(dlg); + update_dark_children_ui(dlg, just_buttons_update); #endif } void GUI_App::UpdateDVCDarkUI(wxDataViewCtrl* dvc, bool highlited/* = false*/) diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index d88085ce7..92bfd67c4 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -182,7 +182,7 @@ public: // update color mode for window void UpdateDarkUI(wxWindow *window, bool highlited = false, bool just_font = false); // update color mode for whole dialog including all children - void UpdateDlgDarkUI(wxDialog* dlg); + void UpdateDlgDarkUI(wxDialog* dlg, bool just_buttons_update = false); // update color mode for DataViewControl void UpdateDVCDarkUI(wxDataViewCtrl* dvc, bool highlited = false); // update color mode for panel including all static texts controls diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index a82baf9b8..0287dcec7 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -4956,11 +4956,11 @@ enum class LoadType : unsigned char class ProjectDropDialog : public DPIDialog { - wxRadioBox* m_action{ nullptr }; + int m_action { 0 }; public: ProjectDropDialog(const std::string& filename); - int get_action() const { return m_action->GetSelection() + 1; } + int get_action() const { return m_action + 1; } protected: void on_dpi_changed(const wxRect& suggested_rect) override; @@ -4981,12 +4981,24 @@ ProjectDropDialog::ProjectDropDialog(const std::string& filename) main_sizer->Add(new wxStaticText(this, wxID_ANY, _L("Select an action to apply to the file") + ": " + from_u8(filename)), 0, wxEXPAND | wxALL, 10); - m_action = new wxRadioBox(this, wxID_ANY, _L("Action"), wxDefaultPosition, wxDefaultSize, - WXSIZEOF(choices), choices, 0, wxRA_SPECIFY_ROWS); + int action = std::clamp(std::stoi(wxGetApp().app_config->get("drop_project_action")), static_cast(LoadType::OpenProject), static_cast(LoadType::LoadConfig)) - 1; - m_action->SetSelection(action); - main_sizer->Add(m_action, 1, wxEXPAND | wxRIGHT | wxLEFT, 10); + + wxStaticBox* action_stb = new wxStaticBox(this, wxID_ANY, _L("Action")); + if (!wxOSX) action_stb->SetBackgroundStyle(wxBG_STYLE_PAINT); + action_stb->SetFont(wxGetApp().normal_font()); + + wxStaticBoxSizer* stb_sizer = new wxStaticBoxSizer(action_stb, wxVERTICAL); + int id = 0; + for (const wxString& label : choices) { + wxRadioButton* btn = new wxRadioButton(this, wxID_ANY, label, wxDefaultPosition, wxDefaultSize, id == 0 ? wxRB_GROUP : 0); + btn->SetValue(id == action); + btn->Bind(wxEVT_RADIOBUTTON, [this, id](wxCommandEvent&) { m_action = id; }); + stb_sizer->Add(btn, 0, wxEXPAND | wxTOP, 5); + id++; + } + main_sizer->Add(stb_sizer, 1, wxEXPAND | wxRIGHT | wxLEFT, 10); wxBoxSizer* bottom_sizer = new wxBoxSizer(wxHORIZONTAL); wxCheckBox* check = new wxCheckBox(this, wxID_ANY, _L("Don't show again")); @@ -5000,6 +5012,9 @@ ProjectDropDialog::ProjectDropDialog(const std::string& filename) SetSizer(main_sizer); main_sizer->SetSizeHints(this); + + // Update DarkUi just for buttons + wxGetApp().UpdateDlgDarkUI(this, true); } void ProjectDropDialog::on_dpi_changed(const wxRect& suggested_rect) diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 7b1558599..933737f2f 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -393,11 +393,9 @@ void PreferencesDialog::build() sizer->Add(tabs, 1, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 5); auto buttons = CreateStdDialogButtonSizer(wxOK | wxCANCEL); - wxButton* btn = static_cast(FindWindowById(wxID_OK, this)); - btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { accept(); }); + this->Bind(wxEVT_BUTTON, &PreferencesDialog::accept, this, wxID_OK); - wxGetApp().UpdateDarkUI(btn); - wxGetApp().UpdateDarkUI(static_cast(this->FindWindowById(wxID_CANCEL, this))); + wxGetApp().UpdateDlgDarkUI(this, true); sizer->Add(buttons, 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM | wxTOP, 10); @@ -406,7 +404,7 @@ void PreferencesDialog::build() this->CenterOnParent(); } -void PreferencesDialog::accept() +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)); @@ -434,11 +432,6 @@ void PreferencesDialog::accept() } } - if (m_values.empty()) { - EndModal(wxID_CANCEL); - return; - } - auto app_config = get_app_config(); m_seq_top_layer_only_changed = false; diff --git a/src/slic3r/GUI/Preferences.hpp b/src/slic3r/GUI/Preferences.hpp index bcfafff5d..e5626c90f 100644 --- a/src/slic3r/GUI/Preferences.hpp +++ b/src/slic3r/GUI/Preferences.hpp @@ -46,7 +46,7 @@ public: #endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER bool recreate_GUI() const { return m_recreate_GUI; } void build(); - void accept(); + void accept(wxEvent&); protected: void on_dpi_changed(const wxRect &suggested_rect) override; diff --git a/src/slic3r/GUI/SysInfoDialog.cpp b/src/slic3r/GUI/SysInfoDialog.cpp index 4dddf13c1..03faf935d 100644 --- a/src/slic3r/GUI/SysInfoDialog.cpp +++ b/src/slic3r/GUI/SysInfoDialog.cpp @@ -170,8 +170,7 @@ SysInfoDialog::SysInfoDialog() this->Bind(wxEVT_BUTTON, &SysInfoDialog::onCloseDialog, this, wxID_OK); main_sizer->Add(buttons, 0, wxEXPAND | wxRIGHT | wxBOTTOM, 3); - wxGetApp().UpdateDarkUI(static_cast(this->FindWindowById(wxID_OK, this)), true); - wxGetApp().UpdateDarkUI(m_btn_copy_to_clipboard, true); + wxGetApp().UpdateDlgDarkUI(this, true); // this->Bind(wxEVT_LEFT_DOWN, &SysInfoDialog::onCloseDialog, this); // logo->Bind(wxEVT_LEFT_DOWN, &SysInfoDialog::onCloseDialog, this);