diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 9fb14d7eb4..46eaf3ed9d 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -86,7 +86,7 @@ Tab::Tab(wxBookCtrlBase* parent, const wxString& title, Preset::Type type) : #ifdef __WXMSW__ wxGetApp().UpdateDarkUI(this); -#else +#elif __WXOSX__ SetBackgroundColour(parent->GetBackgroundColour()); #endif @@ -296,6 +296,9 @@ void Tab::create_preset_tab() m_treectrl = new wxTreeCtrl(panel, wxID_ANY, wxDefaultPosition, wxSize(20 * m_em_unit, -1), wxTR_NO_BUTTONS | wxTR_HIDE_ROOT | wxTR_SINGLE | wxTR_NO_LINES | wxBORDER_SUNKEN | wxWANTS_CHARS); m_treectrl->SetFont(wxGetApp().normal_font()); +#ifdef __linux__ + m_treectrl->SetBackgroundColour(m_parent->GetBackgroundColour()); +#endif m_left_sizer->Add(m_treectrl, 1, wxEXPAND); // Index of the last icon inserted into m_treectrl m_icon_count = -1; diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index 69ac11f95c..0f41c0f9da 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -73,7 +73,7 @@ class SubstitutionManager std::function m_cb_hide_delete_all_btn{ nullptr }; std::vector m_substitutions; - std::vector m_chb_match_single_lines; + std::vector m_chb_match_single_lines; void validate_length(); bool is_compatible_with_ui(); diff --git a/src/slic3r/GUI/Widgets/BitmapToggleButton.cpp b/src/slic3r/GUI/Widgets/BitmapToggleButton.cpp index 4531446665..c8f2292090 100644 --- a/src/slic3r/GUI/Widgets/BitmapToggleButton.cpp +++ b/src/slic3r/GUI/Widgets/BitmapToggleButton.cpp @@ -4,17 +4,17 @@ BitmapToggleButton::BitmapToggleButton(wxWindow* parent, const wxString& label, wxWindowID id) { + if (label.IsEmpty()) + wxBitmapToggleButton::Create(parent, id, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE | wxBU_EXACTFIT); + else { #ifdef __linux__ - long style = wxBORDER_NONE | wxBU_EXACTFIT; - if (label.IsEmpty()) - style = style | wxBU_NOTEXT; - // Call Create() from wxToggleButton instead of wxBitmapToggleButton to allow add Label text under Linux - wxToggleButton::Create(parent, id, label, wxDefaultPosition, wxDefaultSize, style); + wxSize def_size = wxSize(parent->GetTextExtent(label).GetX() + 20, 20); #else - wxBitmapToggleButton::Create(parent, id, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE | wxBU_EXACTFIT); - if (!label.IsEmpty()) - SetLabel(label); + wxSize def_size = wxDefaultSize; #endif + // Call Create() from wxToggleButton instead of wxBitmapToggleButton to allow add Label text under Linux + wxToggleButton::Create(parent, id, label, wxDefaultPosition, def_size, wxBORDER_NONE | wxBU_EXACTFIT); + } #ifdef __WXMSW__ if (parent) { @@ -22,7 +22,7 @@ BitmapToggleButton::BitmapToggleButton(wxWindow* parent, const wxString& label, SetForegroundColour(parent->GetForegroundColour()); } #elif __linux__ - SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); #endif Bind(wxEVT_TOGGLEBUTTON, [this](auto& e) { @@ -39,9 +39,14 @@ BitmapToggleButton::BitmapToggleButton(wxWindow* parent, const wxString& label, void BitmapToggleButton::update_size() { #ifdef __linux__ + wxSize bmp_sz = GetBitmap().GetSize(); + wxSize sz = GetSize(); if (GetLabel().IsEmpty()) - SetSize(GetBitmap().GetSize()); - else + SetSize(bmp_sz); + else + SetSize(sz.x, bmp_sz.y); +#else + wxSize best_sz = GetBestSize(); + SetSize(best_sz); #endif - SetSize(GetBestSize()); } diff --git a/src/slic3r/GUI/Widgets/DropDown.cpp b/src/slic3r/GUI/Widgets/DropDown.cpp index 873a734e80..44e557e89f 100644 --- a/src/slic3r/GUI/Widgets/DropDown.cpp +++ b/src/slic3r/GUI/Widgets/DropDown.cpp @@ -87,7 +87,6 @@ void DropDown::Invalidate(bool clear) void DropDown::SetSelection(int n) { - assert(n < (int) texts.size()); if (n >= (int) texts.size()) n = -1; if (selection == n) return; diff --git a/src/slic3r/GUI/Widgets/SpinInput.cpp b/src/slic3r/GUI/Widgets/SpinInput.cpp index 1dce77bb8a..6634638784 100644 --- a/src/slic3r/GUI/Widgets/SpinInput.cpp +++ b/src/slic3r/GUI/Widgets/SpinInput.cpp @@ -73,8 +73,8 @@ void SpinInput::Create(wxWindow *parent, text_ctrl->Bind(wxEVT_TEXT_ENTER, &SpinInput::onTextEnter, this); text_ctrl->Bind(wxEVT_KEY_DOWN, &SpinInput::keyPressed, this); text_ctrl->Bind(wxEVT_RIGHT_DOWN, [this](auto &e) {}); // disable context menu - button_inc = createButton(true); - button_dec = createButton(false); + button_inc = create_button(ButtonId::btnIncrease); + button_dec = create_button(ButtonId::btnDecrease); delta = 0; timer.Bind(wxEVT_TIMER, &SpinInput::onTimer, this); @@ -265,11 +265,11 @@ void SpinInput::render(wxDC& dc) // draw seperator of buttons wxPoint pt = button_inc->GetPosition(); pt.y = size.y / 2; - pt.x += 1; dc.SetPen(wxPen(border_color.defaultColor())); const double scale = dc.GetContentScaleFactor(); - dc.DrawLine(pt, pt + wxSize{button_inc->GetSize().x - int(3. * scale), 0}); + const int btn_w = button_inc->GetSize().GetWidth(); + dc.DrawLine(pt, pt + wxSize{ btn_w - int(scale), 0}); // draw label auto label = GetLabel(); if (!label.IsEmpty()) { @@ -308,16 +308,16 @@ void SpinInput::messureSize() button_dec->SetPosition({size.x - btnSize.x - int(3. * scale), size.y / 2 + 1}); } -Button *SpinInput::createButton(bool inc) +Button *SpinInput::create_button(ButtonId id) { - auto btn = new Button(this, "", inc ? "spin_inc_act" : "spin_dec_act", wxBORDER_NONE, wxSize(12, 7)); + auto btn = new Button(this, "", id == ButtonId::btnIncrease ? "spin_inc_act" : "spin_dec_act", wxBORDER_NONE, wxSize(12, 7)); btn->SetCornerRadius(0); - btn->SetInactiveIcon(inc ? "spin_inc" : "spin_dec"); + btn->SetInactiveIcon(id == ButtonId::btnIncrease ? "spin_inc" : "spin_dec"); btn->DisableFocusFromKeyboard(); btn->SetSelected(false); btn->Bind(wxEVT_LEFT_DOWN, [=](auto &e) { - delta = inc ? 1 : -1; + delta = id == ButtonId::btnIncrease ? 1 : -1; SetValue(val + delta); text_ctrl->SetFocus(); btn->CaptureMouse(); @@ -326,7 +326,7 @@ Button *SpinInput::createButton(bool inc) sendSpinEvent(); }); btn->Bind(wxEVT_LEFT_DCLICK, [=](auto &e) { - delta = inc ? 1 : -1; + delta = id == ButtonId::btnIncrease ? 1 : -1; btn->CaptureMouse(); SetValue(val + delta); sendSpinEvent(); diff --git a/src/slic3r/GUI/Widgets/SpinInput.hpp b/src/slic3r/GUI/Widgets/SpinInput.hpp index 932958e138..364d8c71d5 100644 --- a/src/slic3r/GUI/Widgets/SpinInput.hpp +++ b/src/slic3r/GUI/Widgets/SpinInput.hpp @@ -24,6 +24,12 @@ class SpinInput : public wxNavigationEnabled static const int SpinInputWidth = 200; static const int SpinInputHeight = 50; + enum class ButtonId + { + btnIncrease, + btnDecrease + }; + public: SpinInput(); @@ -90,7 +96,7 @@ private: void messureSize(); - Button *createButton(bool inc); + Button *create_button(ButtonId id); // some useful events void mouseWheelMoved(wxMouseEvent& event);