Adapt settings label colors to light vs dark UI themes

This commit is contained in:
Vojtech Kral 2018-04-09 14:41:55 +02:00
parent 601185f113
commit 388deb71ab
3 changed files with 45 additions and 13 deletions

View File

@ -1,6 +1,7 @@
#include "GUI.hpp" #include "GUI.hpp"
#include <assert.h> #include <assert.h>
#include <cmath>
#include <boost/algorithm/string/predicate.hpp> #include <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
@ -37,6 +38,7 @@
#include <wx/sizer.h> #include <wx/sizer.h>
#include <wx/combo.h> #include <wx/combo.h>
#include <wx/window.h> #include <wx/window.h>
#include <wx/settings.h>
#include "wxExtensions.hpp" #include "wxExtensions.hpp"
@ -174,6 +176,8 @@ wxFrame *g_wxMainFrame = nullptr;
wxNotebook *g_wxTabPanel = nullptr; wxNotebook *g_wxTabPanel = nullptr;
AppConfig *g_AppConfig = nullptr; AppConfig *g_AppConfig = nullptr;
PresetBundle *g_PresetBundle= nullptr; PresetBundle *g_PresetBundle= nullptr;
wxColour g_color_label_modified;
wxColour g_color_label_sys;
std::vector<Tab *> g_tabs_list; std::vector<Tab *> g_tabs_list;
@ -182,9 +186,22 @@ wxLocale* g_wxLocale;
std::shared_ptr<ConfigOptionsGroup> m_optgroup; std::shared_ptr<ConfigOptionsGroup> m_optgroup;
double m_brim_width = 0.0; double m_brim_width = 0.0;
static void init_label_colours()
{
auto luma = get_colour_approx_luma(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
if (luma >= 128) {
g_color_label_modified = wxColour(253, 88, 0);
g_color_label_sys = wxColour(26, 132, 57);
} else {
g_color_label_modified = wxColour(253, 111, 40);
g_color_label_sys = wxColour(115, 220, 103);
}
}
void set_wxapp(wxApp *app) void set_wxapp(wxApp *app)
{ {
g_wxApp = app; g_wxApp = app;
init_label_colours();
} }
void set_main_frame(wxFrame *main_frame) void set_main_frame(wxFrame *main_frame)
@ -514,12 +531,25 @@ wxApp* get_app(){
return g_wxApp; return g_wxApp;
} }
wxColour* get_modified_label_clr(){ const wxColour& get_modified_label_clr() {
return new wxColour(253, 88, 0); return g_color_label_modified;
} }
wxColour* get_sys_label_clr(){ const wxColour& get_sys_label_clr() {
return new wxColour(26, 132, 57); return g_color_label_sys;
}
unsigned get_colour_approx_luma(const wxColour &colour)
{
double r = colour.Red();
double g = colour.Green();
double b = colour.Blue();
std::round(std::sqrt(
r * r * .241 +
g * g * .691 +
b * b * .068
));
} }
void create_combochecklist(wxComboCtrl* comboCtrl, std::string text, std::string items, bool initial_value) void create_combochecklist(wxComboCtrl* comboCtrl, std::string text, std::string items, bool initial_value)

View File

@ -79,8 +79,10 @@ void set_preset_bundle(PresetBundle *preset_bundle);
AppConfig* get_app_config(); AppConfig* get_app_config();
wxApp* get_app(); wxApp* get_app();
wxColour* get_modified_label_clr();
wxColour* get_sys_label_clr(); const wxColour& get_modified_label_clr();
const wxColour& get_sys_label_clr();
unsigned get_colour_approx_luma(const wxColour &colour);
void add_debug_menu(wxMenuBar *menu, int event_language_change); void add_debug_menu(wxMenuBar *menu, int event_language_change);

View File

@ -265,14 +265,14 @@ void Tab::update_changed_ui()
bool is_modified_value = true; bool is_modified_value = true;
std::string sys_icon = wxMSW ? "sys_lock.png" : "lock.png"; std::string sys_icon = wxMSW ? "sys_lock.png" : "lock.png";
std::string icon = wxMSW ? "action_undo.png" : "arrow_undo.png"; std::string icon = wxMSW ? "action_undo.png" : "arrow_undo.png";
wxColour& color = *get_sys_label_clr(); wxColour color = get_sys_label_clr();
if (find(m_sys_options.begin(), m_sys_options.end(), opt_key) == m_sys_options.end()) { if (find(m_sys_options.begin(), m_sys_options.end(), opt_key) == m_sys_options.end()) {
is_nonsys_value = true; is_nonsys_value = true;
sys_icon = m_nonsys_btn_icon; sys_icon = m_nonsys_btn_icon;
if(find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) == m_dirty_options.end()) if(find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) == m_dirty_options.end())
color = wxSYS_COLOUR_WINDOWTEXT; color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
else else
color = *get_modified_label_clr(); color = get_modified_label_clr();
} }
if (find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) == m_dirty_options.end()) if (find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) == m_dirty_options.end())
{ {
@ -343,7 +343,7 @@ void Tab::update_sys_ui_after_sel_preset()
field->m_Undo_to_sys_btn->SetBitmap(wxBitmap(from_u8(var(m_nonsys_btn_icon)), wxBITMAP_TYPE_PNG)); field->m_Undo_to_sys_btn->SetBitmap(wxBitmap(from_u8(var(m_nonsys_btn_icon)), wxBITMAP_TYPE_PNG));
field->m_is_nonsys_value = true; field->m_is_nonsys_value = true;
if (field->m_Label != nullptr){ if (field->m_Label != nullptr){
field->m_Label->SetForegroundColour(wxSYS_COLOUR_WINDOWTEXT); field->m_Label->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
field->m_Label->Refresh(true); field->m_Label->Refresh(true);
} }
} }
@ -386,11 +386,11 @@ void Tab::update_changed_tree_ui()
break; break;
} }
if (sys_page) if (sys_page)
m_treectrl->SetItemTextColour(cur_item, *get_sys_label_clr()); m_treectrl->SetItemTextColour(cur_item, get_sys_label_clr());
else if (modified_page) else if (modified_page)
m_treectrl->SetItemTextColour(cur_item, *get_modified_label_clr()); m_treectrl->SetItemTextColour(cur_item, get_modified_label_clr());
else else
m_treectrl->SetItemTextColour(cur_item, wxSYS_COLOUR_WINDOWTEXT); m_treectrl->SetItemTextColour(cur_item, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
page->m_is_nonsys_values = !sys_page; page->m_is_nonsys_values = !sys_page;
page->m_is_modified_values = modified_page; page->m_is_modified_values = modified_page;