Skip to content

Commit

Permalink
Fixed illegible text in dark/light mode
Browse files Browse the repository at this point in the history
  • Loading branch information
calvindo95 committed Jul 4, 2024
1 parent 507d510 commit ad3873d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
48 changes: 47 additions & 1 deletion src/slic3r/GUI/GUI_App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3270,6 +3270,30 @@ static bool is_default(wxWindow* win)
}
#endif

// Checks if fg is +/- 10 rgb values from bg
bool GUI_App::is_similar(const wxColour& bg, const wxColour& fg){
int bg_r = bg.Red();
int bg_g = bg.Green();
int bg_b = bg.Blue();

int fg_r = fg.Red();
int fg_g = fg.Green();
int fg_b = fg.Blue();

return (bg_r+10 >= fg_r && fg_r >= bg_r-10
&& bg_g+10 >= fg_g && fg_g >= bg_g-10
&& bg_b+10 >= fg_b && fg_b >= bg_b-10);
}

const wxColour GUI_App::invert_color(const wxColour& color){
int color_r = 255-color.Red();
int color_g = 255-color.Green();
int color_b = 255-color.Blue();

return wxColour(color_r, color_g, color_b);
}


void GUI_App::UpdateDarkUI(wxWindow* window, bool highlited/* = false*/, bool just_font/* = false*/)
{
if (wxButton *btn = dynamic_cast<wxButton*>(window)) {
Expand Down Expand Up @@ -3329,9 +3353,20 @@ void GUI_App::UpdateDarkUI(wxWindow* window, bool highlited/* = false*/, bool ju
original_col = window->GetForegroundColour();
auto fg_col = StateColor::darkModeColorFor(original_col);

#ifndef __LINUX__
if (fg_col != original_col) {
window->SetForegroundColour(fg_col);
}
#else
if (fg_col != original_col) {
if(bg_col != fg_col && !is_similar(bg_col, fg_col)){
window->SetForegroundColour(fg_col);
}
else{ // if bg and fg colors are the same, invert fg color
window->SetForegroundColour(invert_color(fg_col));
}
}
#endif
}
else {
auto original_col = window->GetBackgroundColour();
Expand All @@ -3344,9 +3379,20 @@ void GUI_App::UpdateDarkUI(wxWindow* window, bool highlited/* = false*/, bool ju
original_col = window->GetForegroundColour();
auto fg_col = StateColor::lightModeColorFor(original_col);

#ifndef __LINUX__
if (fg_col != original_col) {
window->SetForegroundColour(fg_col);
}
#else
if (fg_col != original_col) {
if(bg_col != fg_col && !is_similar(bg_col, fg_col)){
window->SetForegroundColour(fg_col);
}
else{ // if bg and fg colors are the same, invert fg color
window->SetForegroundColour(invert_color(fg_col));
}
}
#endif
}
}

Expand Down Expand Up @@ -3419,7 +3465,7 @@ void GUI_App::UpdateDVCDarkUI(wxDataViewCtrl* dvc, bool highlited/* = false*/)

void GUI_App::UpdateAllStaticTextDarkUI(wxWindow* parent)
{
#ifdef __WINDOWS__
#if defined(__WINDOWS__) || defined(__LINUX__)
wxGetApp().UpdateDarkUI(parent);

auto children = parent->GetChildren();
Expand Down
2 changes: 2 additions & 0 deletions src/slic3r/GUI/GUI_App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ class GUI_App : public wxApp
void update_publish_status();
bool has_model_mall();
void update_label_colours();
bool is_similar(const wxColour& bg, const wxColour& fg);
const wxColour invert_color(const wxColour& color);
// update color mode for window
void UpdateDarkUI(wxWindow *window, bool highlited = false, bool just_font = false);
void UpdateDarkUIWin(wxWindow* win);
Expand Down

0 comments on commit ad3873d

Please sign in to comment.