Added "smart" setting of label color

This commit is contained in:
YuSanka 2018-04-17 10:15:48 +02:00
parent 6e870e8466
commit d254c39a77
4 changed files with 37 additions and 22 deletions

View file

@ -20,23 +20,18 @@ namespace Slic3r { namespace GUI {
void Field::PostInitialize(){
auto color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
m_Undo_btn = new wxButton(m_parent, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER);
m_Undo_to_sys_btn = new wxButton(m_parent, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER);
m_Undo_btn = new wxButton(m_parent, wxID_ANY, "", wxDefaultPosition, wxSize(16, 16), wxNO_BORDER);
m_Undo_to_sys_btn = new wxButton(m_parent, wxID_ANY, "", wxDefaultPosition, wxSize(16, 16), wxNO_BORDER);
if (wxMSW) {
m_Undo_btn->SetBackgroundColour(color);
m_Undo_to_sys_btn->SetBackgroundColour(color);
}
// m_Undo_btn->SetBitmap(wxBitmap(from_u8(var("bullet_white.png")), wxBITMAP_TYPE_PNG));
m_Undo_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent){ on_back_to_initial_value(); }));
m_Undo_to_sys_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent){ on_back_to_sys_value(); }));
BUILD();
}
// void Field::set_nonsys_btn_icon(const wxBitmap& icon){
// m_Undo_to_sys_btn->SetBitmap(icon);
// }
void Field::on_kill_focus(wxEvent& event) {
// Without this, there will be nasty focus bugs on Windows.
// Also, docs for wxEvent::Skip() say "In general, it is recommended to skip all

View file

@ -90,9 +90,7 @@ public:
virtual void enable() = 0;
virtual void disable() = 0;
wxStaticText* m_Label = nullptr;
/// Fires the enable or disable function, based on the input.
/// Fires the enable or disable function, based on the input.
inline void toggle(bool en) { en ? enable() : disable(); }
virtual wxString get_tooltip_text(const wxString& default_string);
@ -137,6 +135,16 @@ public:
return false;
}
bool set_label_colour(const wxColour *clr) {
if (m_Label == nullptr) return false;
if (m_label_color != clr) {
m_label_color = clr;
m_Label->SetForegroundColour(*clr);
m_Label->Refresh(true);
}
return false;
}
protected:
wxButton* m_Undo_btn = nullptr;
// Bitmap for m_Undo_btn. The wxButton will be updated only if the new wxBitmap pointer differs from the currently rendered one.
@ -145,6 +153,10 @@ protected:
// Bitmap for m_Undo_to_sys_btn. The wxButton will be updated only if the new wxBitmap pointer differs from the currently rendered one.
const wxBitmap* m_undo_to_sys_bitmap = nullptr;
wxStaticText* m_Label = nullptr;
// Color for Label. The wxColour will be updated only if the new wxColour pointer differs from the currently rendered one.
const wxColour* m_label_color;
friend class OptionsGroup;
};

View file

@ -23,6 +23,7 @@
#include <boost/algorithm/string/predicate.hpp>
#include "wxExtensions.hpp"
#include <wx/wupdlock.h>
namespace Slic3r {
namespace GUI {
@ -115,6 +116,11 @@ void Tab::create_preset_tab(PresetBundle *preset_bundle)
m_undo_to_sys_btn->SetBitmap(m_bmp_white_bullet);
m_undo_to_sys_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent){ on_back_to_sys_value(); }));
// Colors for ui "decoration"
m_sys_label_clr = get_sys_label_clr();
m_modified_label_clr = get_modified_label_clr();
m_default_text_clr = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
m_hsizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(m_hsizer, 0, wxBOTTOM, 3);
m_hsizer->Add(m_presets_choice, 1, wxLEFT | wxRIGHT | wxTOP | wxALIGN_CENTER_VERTICAL, 3);
@ -344,14 +350,14 @@ void Tab::update_changed_ui()
bool is_modified_value = true;
const wxBitmap *sys_icon = &m_bmp_value_lock;
const wxBitmap *icon = &m_bmp_value_revert;
wxColour color = get_sys_label_clr();
const wxColour *color = &m_sys_label_clr;
if (find(m_sys_options.begin(), m_sys_options.end(), opt_key) == m_sys_options.end()) {
is_nonsys_value = true;
sys_icon = m_bmp_non_system;
if(find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) == m_dirty_options.end())
color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
color = &m_default_text_clr;
else
color = get_modified_label_clr();
color = &m_modified_label_clr;
}
if (find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) == m_dirty_options.end())
{
@ -360,7 +366,7 @@ void Tab::update_changed_ui()
}
if (opt_key == "bed_shape" || opt_key == "compatible_printers") {
if (m_colored_Label != nullptr) {
m_colored_Label->SetForegroundColour(color);
m_colored_Label->SetForegroundColour(*color);
m_colored_Label->Refresh(true);
}
continue;
@ -372,10 +378,7 @@ void Tab::update_changed_ui()
field->m_is_modified_value = is_modified_value;
field->set_undo_bitmap(icon);
field->set_undo_to_sys_bitmap(sys_icon);
if (field->m_Label != nullptr){
field->m_Label->SetForegroundColour(color);
field->m_Label->Refresh(true);
}
field->set_label_colour(color);
}
Thaw();
@ -425,15 +428,13 @@ void Tab::update_full_options_list()
void Tab::update_sys_ui_after_sel_preset()
{
const wxColour* clr = &m_default_text_clr;
for (const auto opt_key : m_full_options_list){
Field* field = get_field(opt_key);
if (field != nullptr){
field->set_undo_to_sys_bitmap(m_bmp_non_system);
field->m_is_nonsys_value = true;
if (field->m_Label != nullptr){
field->m_Label->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
field->m_Label->Refresh(true);
}
field->set_label_colour(clr);
}
}
m_sys_options.resize(0);
@ -2039,6 +2040,8 @@ bool Tab::may_discard_current_dirty_preset(PresetCollection* presets /*= nullptr
void Tab::OnTreeSelChange(wxTreeEvent& event)
{
if (m_disable_tree_sel_changed_event) return;
wxWindowUpdateLocker noUpdates(this);
Page* page = nullptr;
auto selection = m_treectrl->GetItemText(m_treectrl->GetSelection());
for (auto p : m_pages)

View file

@ -112,6 +112,11 @@ protected:
wxBitmap m_bmp_value_revert;
wxBitmap m_bmp_value_unmodified;
// Colors for ui "decoration"
wxColour m_sys_label_clr;
wxColour m_modified_label_clr;
wxColour m_default_text_clr;
int m_icon_count;
std::map<std::string, size_t> m_icon_index; // Map from an icon file name to its index
std::vector<PageShp> m_pages;