FIX:fixed appconfig is not saved when switching dark mode

Change-Id: I77fc3808309a23497000c34b6047a359d12c4622
This commit is contained in:
tao wang 2022-11-29 22:29:44 +08:00 committed by Lane.Wei
parent 4a5c473058
commit eca5897a25
22 changed files with 84 additions and 26 deletions

View file

@ -116,8 +116,6 @@
</array>
<key>CSResourcesFileMapped</key>
<true/>
<key>NSRequiresAquaSystemAppearance</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>${MACOSX_BUNDLE_COPYRIGHT}</string>
</dict>

View file

@ -1,6 +1,6 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M20.3556 14.4697C20.6041 14.5377 20.862 14.3916 20.9157 14.1396C21.1513 13.0338 21.1544 11.8893 20.9225 10.7792C20.6588 9.51666 20.0988 8.33487 19.2888 7.33122C18.4787 6.32757 17.4417 5.5308 16.2633 5.00656C15.0849 4.48233 13.7987 4.24564 12.5109 4.31601C11.223 4.38638 9.97033 4.76179 8.85604 5.41131C7.74174 6.06082 6.79775 6.96584 6.10187 8.05178C5.40598 9.13772 4.97812 10.3735 4.85355 11.6572C4.74402 12.786 4.87172 13.9234 5.22643 14.9969C5.30725 15.2415 5.5796 15.3586 5.81919 15.2639C6.05877 15.1692 6.17467 14.8986 6.09567 14.6534C5.79424 13.7179 5.68686 12.7289 5.78211 11.7473C5.8924 10.6107 6.27122 9.5166 6.88735 8.55513C7.50347 7.59366 8.33927 6.79237 9.32584 6.2173C10.3124 5.64223 11.4215 5.30985 12.5618 5.24754C13.702 5.18524 14.8407 5.3948 15.8841 5.85895C16.9275 6.3231 17.8456 7.02855 18.5628 7.91716C19.28 8.80578 19.7758 9.85211 20.0093 10.9699C20.2109 11.9353 20.2119 12.9301 20.0142 13.8929C19.9624 14.1452 20.1071 14.4016 20.3556 14.4697Z" fill="#323A3D"/>
<path d="M18.3707 10.4798C18.5481 10.4065 18.6333 10.2028 18.5499 10.0299C18.1474 9.19567 17.5584 8.46323 16.8266 7.89035C16.0035 7.24596 15.0277 6.82535 13.994 6.66938C12.9603 6.5134 11.9039 6.62735 10.9273 7.00017C10.059 7.33161 9.2801 7.85763 8.64938 8.53599C8.51872 8.67653 8.54001 8.89632 8.68779 9.01871C8.83557 9.14111 9.05381 9.11965 9.18551 8.98009C9.73906 8.39351 10.4188 7.93806 11.1751 7.64936C12.0398 7.31927 12.9751 7.21838 13.8903 7.35648C14.8055 7.49458 15.6695 7.86698 16.3983 8.43751C17.0357 8.93652 17.5508 9.57226 17.9066 10.2961C17.9912 10.4683 18.1934 10.5532 18.3707 10.4798Z" fill="#323A3D"/>
<path d="M16.7422 11.4449L13.5908 15.7765" stroke="#323A3D" stroke-width="1.04628" stroke-linecap="round"/>
<path d="M13.1477 17.5962C13.8819 17.5962 14.477 17.0011 14.477 16.2669C14.477 15.5327 13.8819 14.9375 13.1477 14.9375C12.4135 14.9375 11.8183 15.5327 11.8183 16.2669C11.8183 17.0011 12.4135 17.5962 13.1477 17.5962Z" fill="#323A3D"/>
<svg width="20" height="21" viewBox="0 0 20 21" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M17.4005 12.7763C17.649 12.8443 17.907 12.6982 17.9606 12.4463C18.1963 11.3405 18.1993 10.1959 17.9674 9.08583C17.7037 7.8233 17.1438 6.64152 16.3337 5.63787C15.5236 4.63422 14.4866 3.83744 13.3082 3.3132C12.1298 2.78897 10.8436 2.55228 9.55579 2.62265C8.26794 2.69302 7.01524 3.06843 5.90095 3.71795C4.78665 4.36746 3.84266 5.27248 3.14678 6.35842C2.45089 7.44436 2.02303 8.68012 1.89846 9.96387C1.78893 11.0926 1.91663 12.23 2.27134 13.3036C2.35217 13.5482 2.62452 13.6653 2.8641 13.5706V13.5706C3.10368 13.4759 3.21959 13.2053 3.14058 12.9601C2.83915 12.0245 2.73177 11.0355 2.82702 10.054C2.93731 8.91737 3.31613 7.82324 3.93226 6.86177C4.54839 5.9003 5.38418 5.09901 6.37076 4.52394C7.35733 3.94887 8.46645 3.61649 9.60669 3.55418C10.7469 3.49188 11.8857 3.70144 12.929 4.16559C13.9724 4.62974 14.8905 5.33519 15.6077 6.2238C16.3249 7.11242 16.8207 8.15875 17.0542 9.27658C17.2558 10.2419 17.2569 11.2367 17.0592 12.1995C17.0073 12.4519 17.152 12.7083 17.4005 12.7763V12.7763Z" fill="#323A3D"/>
<path d="M15.4157 8.78647C15.593 8.71313 15.6782 8.50941 15.5948 8.33658C15.1923 7.50231 14.6033 6.76987 13.8715 6.19699C13.0484 5.5526 12.0726 5.13199 11.0389 4.97602C10.0053 4.82004 8.94883 4.93399 7.9722 5.30681C7.10396 5.63825 6.32502 6.16427 5.6943 6.84264C5.56365 6.98317 5.58494 7.20296 5.73272 7.32535V7.32535C5.88051 7.44775 6.09873 7.42629 6.23043 7.28674C6.78398 6.70015 7.46373 6.2447 8.22002 5.956C9.08471 5.62591 10.0201 5.52502 10.9353 5.66312C11.8504 5.80122 12.7144 6.17362 13.4432 6.74415C14.0806 7.24316 14.5957 7.8789 14.9515 8.60271C15.0362 8.77491 15.2383 8.85981 15.4157 8.78647V8.78647Z" fill="#323A3D"/>
<path d="M13.7871 9.75159L10.6357 14.0831" stroke="#323A3D" stroke-width="1.04628" stroke-linecap="round"/>
<circle cx="10.1926" cy="14.5735" r="1.32935" fill="#323A3D"/>
</svg>

Before

Width:  |  Height:  |  Size: 2 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View file

@ -47,11 +47,7 @@ CopyrightsDialog::CopyrightsDialog()
wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{
this->SetFont(wxGetApp().normal_font());
#ifdef _WIN32
wxGetApp().UpdateDarkUI(this);
#else
this->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
#endif
this->SetBackgroundColour(*wxWHITE);
std::string icon_path = (boost::format("%1%/images/BambuStudioTitle.ico") % resources_dir()).str();
SetIcon(wxIcon(encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO));
@ -66,6 +62,7 @@ CopyrightsDialog::CopyrightsDialog()
m_html = new wxHtmlWindow(this, wxID_ANY, wxDefaultPosition,
wxSize(40 * em_unit(), 20 * em_unit()), wxHW_SCROLLBAR_AUTO);
m_html->SetMinSize(wxSize(FromDIP(870),FromDIP(520)));
m_html->SetBackgroundColour(*wxWHITE);
wxFont font = get_default_font(this);
const int fs = font.GetPointSize();
const int fs2 = static_cast<int>(1.2f*fs);
@ -81,6 +78,7 @@ CopyrightsDialog::CopyrightsDialog()
SetSizer(sizer);
sizer->SetSizeHints(this);
CenterOnParent();
wxGetApp().UpdateDlgDarkUI(this);
}
void CopyrightsDialog::fill_entries()

View file

@ -316,9 +316,9 @@ wxBitmap* BitmapCache::load_svg(const std::string &bitmap_name, unsigned target_
+ (grayscale ? "-gs" : "")
+ new_color;
auto it = m_map.find(bitmap_key);
/*auto it = m_map.find(bitmap_key);
if (it != m_map.end())
return it->second;
return it->second;*/
// map of color replaces
std::map<std::string, std::string> replaces;
@ -329,6 +329,8 @@ wxBitmap* BitmapCache::load_svg(const std::string &bitmap_name, unsigned target_
//replaces["\"#ACACAC\""] = "\"#54545A\"";
replaces["\"#CECECE\""] = "\"#54545B\"";
replaces["\"#6B6B6B\""] = "\"#818182\"";
replaces["\"#909090\""] = "\"#FFFFFF\"";
replaces["\"#00FF00\""] = "\"#FF0000\"";
}
//if (!new_color.empty())
// replaces["\"#ED6B21\""] = "\"" + new_color + "\"";

View file

@ -7,6 +7,7 @@
#include <wx/progdlg.h>
#include <wx/clipbrd.h>
#include <wx/dcgraph.h>
#include "GUI_App.hpp"
namespace Slic3r {
namespace GUI {
@ -116,6 +117,7 @@ CameraPopup::CameraPopup(wxWindow *parent, MachineObject* obj)
#endif //APPLE
check_func_supported();
wxGetApp().UpdateDarkUIWin(this);
}
void CameraPopup::sdcard_absent_hint()

View file

@ -2752,6 +2752,8 @@ static void update_dark_children_ui(wxWindow* window, bool just_buttons_update =
{
/*bool is_btn = dynamic_cast<wxButton*>(window) != nullptr;
is_btn = false;*/
if (!window) return;
wxGetApp().UpdateDarkUI(window);
auto children = window->GetChildren();
@ -2774,6 +2776,16 @@ void GUI_App::UpdateDlgDarkUI(wxDialog* dlg)
#endif
update_dark_children_ui(dlg);
}
void GUI_App::UpdateFrameDarkUI(wxFrame* dlg)
{
#ifdef __WINDOWS__
NppDarkMode::SetDarkExplorerTheme(dlg->GetHWND());
NppDarkMode::SetDarkTitleBar(dlg->GetHWND());
#endif
update_dark_children_ui(dlg);
}
void GUI_App::UpdateDVCDarkUI(wxDataViewCtrl* dvc, bool highlited/* = false*/)
{
#ifdef __WINDOWS__
@ -3133,14 +3145,18 @@ void GUI_App::update_ui_from_settings()
//UpdateDlgDarkUI(&mainframe->m_settings_dialog);
//mainframe->m_settings_dialog.Refresh();
//mainframe->m_settings_dialog.Update();
if (mainframe) {
#ifdef __WINDOWS__
mainframe->force_color_changed();
update_scrolls(mainframe);
update_scrolls(&mainframe->m_settings_dialog);
mainframe->force_color_changed();
update_scrolls(mainframe);
update_scrolls(&mainframe->m_settings_dialog);
#endif //_MSW_DARK_MODE
update_dark_children_ui(mainframe);
update_dark_children_ui(mainframe);
}
}
mainframe->update_ui_from_settings();
if (mainframe) {mainframe->update_ui_from_settings();}
}
void GUI_App::persist_window_geometry(wxTopLevelWindow *window, bool default_maximized)

View file

@ -326,6 +326,7 @@ public:
void UpdateDarkUIWin(wxWindow* win);
// update color mode for whole dialog including all children
void UpdateDlgDarkUI(wxDialog* dlg);
void UpdateFrameDarkUI(wxFrame* dlg);
// update color mode for DataViewControl
void UpdateDVCDarkUI(wxDataViewCtrl* dvc, bool highlited = false);
// update color mode for panel including all static texts controls

View file

@ -268,6 +268,13 @@ void update_dark_ui(wxWindow* window)
}
#endif
void update_dark_config()
{
wxSystemAppearance app = wxSystemSettings::GetAppearance();
GUI::wxGetApp().app_config->set("dark_color_mode", app.IsDark() ? "1" : "0");
GUI::wxGetApp().app_config->save();
}
CheckboxFileDialog::ExtraPanel::ExtraPanel(wxWindow *parent)
: wxPanel(parent, wxID_ANY)

View file

@ -82,6 +82,7 @@ wxFont get_default_font_for_dpi(const wxWindow* window, int dpi);
inline wxFont get_default_font(const wxWindow* window) { return get_default_font_for_dpi(window, get_dpi_for_window(window)); }
bool check_dark_mode();
void update_dark_config();
#ifdef _WIN32
void update_dark_ui(wxWindow* window);
#endif
@ -188,8 +189,9 @@ public:
this->Bind(wxEVT_SYS_COLOUR_CHANGED, [this](wxSysColourChangedEvent& event)
{
event.Skip();
update_dark_config();
on_sys_color_changed();
event.Skip();
});
if (std::is_same<wxDialog, P>::value) {

View file

@ -1804,6 +1804,7 @@ void MainFrame::on_sys_color_changed()
// update Plater
wxGetApp().plater()->sys_color_changed();
m_monitor->on_sys_color_changed();
// update Tabs
for (auto tab : wxGetApp().tabs_list)

View file

@ -40,7 +40,7 @@ MediaFilePanel::MediaFilePanel(wxWindow * parent)
b->SetTextColor(StateColor(
std::make_pair(0x3B4446, (int) StateColor::Checked),
std::make_pair(*wxLIGHT_GREY, (int) StateColor::Hovered),
std::make_pair(0xACACAC, (int) StateColor::Normal)
std::make_pair(0xABACAC, (int) StateColor::Normal)
));
}

View file

@ -165,6 +165,7 @@ namespace GUI {
void ModelMallDialog::on_show(wxShowEvent& event)
{
wxGetApp().UpdateFrameDarkUI(this);
if (event.IsShown()) {
Centre(wxBOTH);
}

View file

@ -245,6 +245,11 @@ wxWindow* MonitorPanel::create_side_tools()
return panel;
}
void MonitorPanel::on_sys_color_changed()
{
m_status_info_panel->on_sys_color_changed();
}
void MonitorPanel::msw_rescale()
{
init_bitmap();

View file

@ -130,7 +130,8 @@ public:
void set_default();
wxWindow* create_side_tools();
void msw_rescale();
void on_sys_color_changed();
void msw_rescale();
void select_machine(std::string machine_sn);
void on_update_all(wxMouseEvent &event);

View file

@ -49,7 +49,6 @@ ButtonsListCtrl::ButtonsListCtrl(wxWindow *parent, wxBoxSizer* side_tools) :
// BBS: disable custom paint
//this->Bind(wxEVT_PAINT, &ButtonsListCtrl::OnPaint, this);
Bind(wxEVT_SYS_COLOUR_CHANGED, [this](auto& e){
auto a = 10;
});
}

View file

@ -64,6 +64,7 @@ void ParamsDialog::Popup()
#ifdef __WIN32__
Reparent(wxGetApp().mainframe);
#endif
wxGetApp().UpdateDlgDarkUI(this);
Center();
Show();
}

View file

@ -386,7 +386,7 @@ wxBoxSizer *PreferencesDialog::create_item_backup_input(wxString title, wxWindow
input_title->Wrap(-1);
auto input = new ::TextInput(parent, wxEmptyString, wxEmptyString, wxEmptyString, wxDefaultPosition, DESIGN_INPUT_SIZE, wxTE_PROCESS_ENTER);
StateColor input_bg(std::pair<wxColour, int>(wxColour("#F0F0F1"), StateColor::Disabled));
StateColor input_bg(std::pair<wxColour, int>(wxColour("#F0F0F1"), StateColor::Disabled), std::pair<wxColour, int>(*wxWHITE, StateColor::Enabled));
input->SetBackgroundColor(input_bg);
input->GetTextCtrl()->SetValue(app_config->get(param));
@ -840,8 +840,11 @@ wxWindow* PreferencesDialog::create_general_page()
auto item_downloads = create_item_downloads(page,50,"download_path");
//dark mode
#ifdef _WIN32
auto title_darkmode = create_item_title(_L("Dark Mode"), page, _L("Dark Mode"));
auto item_darkmode = create_item_darkmode_checkbox(_L("Enable Dark mode"), page,_L("Enable Dark mode"), 50, "dark_color_mode");
#endif
sizer_page->Add(title_general_settings, 0, wxEXPAND, 0);
sizer_page->Add(item_language, 0, wxTOP, FromDIP(3));
@ -863,8 +866,10 @@ wxWindow* PreferencesDialog::create_general_page()
sizer_page->Add(title_downloads, 0, wxTOP| wxEXPAND, FromDIP(20));
sizer_page->Add(item_downloads, 0, wxEXPAND, FromDIP(3));
#ifdef _WIN32
sizer_page->Add(title_darkmode, 0, wxTOP | wxEXPAND, FromDIP(20));
sizer_page->Add(item_darkmode, 0, wxEXPAND, FromDIP(3));
#endif
page->SetSizer(sizer_page);

View file

@ -437,6 +437,7 @@ SecondaryCheckDialog::SecondaryCheckDialog(wxWindow* parent, wxWindowID id, cons
m_sizer_main->Fit(this);
CenterOnParent();
wxGetApp().UpdateFrameDarkUI(this);
}
void SecondaryCheckDialog::update_text(wxString text)
@ -470,6 +471,7 @@ void SecondaryCheckDialog::update_text(wxString text)
void SecondaryCheckDialog::on_show()
{
wxGetApp().UpdateFrameDarkUI(this);
// recover button color
wxMouseEvent evt_ok(wxEVT_LEFT_UP);
m_button_ok->GetEventHandler()->ProcessEvent(evt_ok);
@ -477,7 +479,7 @@ void SecondaryCheckDialog::on_show()
m_button_cancel->GetEventHandler()->ProcessEvent(evt_cancel);
this->Show();
this->SetFocus();
this->SetFocus();
}
void SecondaryCheckDialog::on_hide()

View file

@ -38,7 +38,7 @@ static const wxColour BUTTON_NORMAL2_COL = wxColour(206, 206, 206);
static const wxColour BUTTON_PRESS_COL = wxColour(172, 172, 172);
static const wxColour BUTTON_HOVER_COL = wxColour(0, 174, 66);
static const wxColour DISCONNECT_TEXT_COL = wxColour(172, 172, 172);
static const wxColour DISCONNECT_TEXT_COL = wxColour(171, 172, 172);
static const wxColour NORMAL_TEXT_COL = wxColour(48,58,60);
static const wxColour NORMAL_FAN_TEXT_COL = wxColour(107, 107, 107);
static const wxColour WARNING_INFO_BG_COL = wxColour(255, 111, 0);
@ -2770,6 +2770,13 @@ void StatusPanel::set_hold_count(int& count)
count = COMMAND_TIMEOUT;
}
void StatusPanel::on_sys_color_changed()
{
m_bitmap_speed.msw_rescale();
m_bitmap_speed_active.msw_rescale();
m_switch_speed->SetImages(m_bitmap_speed, m_bitmap_speed);
}
void StatusPanel::msw_rescale()
{
init_bitmaps();
@ -2817,6 +2824,9 @@ void StatusPanel::msw_rescale()
m_tempCtrl_frame->SetMinSize(TEMP_CTRL_MIN_SIZE);
m_tempCtrl_frame->Rescale();
m_bitmap_speed.msw_rescale();
m_bitmap_speed_active.msw_rescale();
m_switch_speed->SetImages(m_bitmap_speed, m_bitmap_speed);
m_switch_speed->SetMinSize(MISC_BUTTON_SIZE);
m_switch_speed->Rescale();
@ -2833,6 +2843,7 @@ void StatusPanel::msw_rescale()
m_ams_control->msw_rescale();
// m_filament_step->Rescale();
m_calibration_btn->SetMinSize(wxSize(-1, FromDIP(26)));
m_calibration_btn->Rescale();

View file

@ -394,6 +394,7 @@ public:
void set_hold_count(int& count);
void on_sys_color_changed();
void msw_rescale();
};
}

View file

@ -1849,6 +1849,9 @@ void AMSControl::StopRridLoading(wxString amsid, wxString canid)
void AMSControl::msw_rescale()
{
m_button_ams_setting_normal.msw_rescale();
m_button_ams_setting_hover.msw_rescale();
m_button_ams_setting_press.msw_rescale();
m_extruder->msw_rescale();
m_button_extruder_back->SetMinSize(wxSize(-1, FromDIP(24)));
m_button_extruder_feed->SetMinSize(wxSize(-1, FromDIP(24)));

View file

@ -35,6 +35,8 @@ static std::map<wxColour, wxColour> gDarkColors{
{"#F0F0F1", "#404040"},
{"#9E9E9E", "#53545A"},
{"#D7E8DE", "#1F2B27"},
{"#2B3436", "#808080"},
{"#ABABAB", "#ABABAB"},
//{"#F0F0F0", "#3E3E44"},
};