From 77401ed79d230c3d9d58e01276eb32513a954192 Mon Sep 17 00:00:00 2001
From: YuSanka <yusanka@gmail.com>
Date: Thu, 25 Jul 2019 16:23:32 +0200
Subject: [PATCH] Upgrade for ModeButtons

---
 src/slic3r/GUI/Plater.cpp       |  2 +-
 src/slic3r/GUI/Tab.cpp          |  2 +-
 src/slic3r/GUI/wxExtensions.cpp | 18 +++++++-----------
 src/slic3r/GUI/wxExtensions.hpp |  2 +-
 4 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp
index 067d13b8a..1e9260d07 100644
--- a/src/slic3r/GUI/Plater.cpp
+++ b/src/slic3r/GUI/Plater.cpp
@@ -718,7 +718,7 @@ Sidebar::Sidebar(Plater *parent)
     p->scrolled->SetSizer(scrolled_sizer);
 
     // Sizer with buttons for mode changing
-    p->mode_sizer = new ModeSizer(p->scrolled, 2 * wxGetApp().em_unit());
+    p->mode_sizer = new ModeSizer(p->scrolled);
 
     // The preset chooser
     p->sizer_presets = new wxFlexGridSizer(10, 1, 1, 2);
diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp
index cb8bb0b6d..3d934770f 100644
--- a/src/slic3r/GUI/Tab.cpp
+++ b/src/slic3r/GUI/Tab.cpp
@@ -198,7 +198,7 @@ void Tab::create_preset_tab()
     // There is used just additional sizer for m_mode_sizer with right alignment
     auto mode_sizer = new wxBoxSizer(wxVERTICAL);
     mode_sizer->Add(m_mode_sizer, 1, wxALIGN_RIGHT);
-    m_hsizer->Add(mode_sizer, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, wxOSX ? 15 : 5);
+    m_hsizer->Add(mode_sizer, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, wxOSX ? 15 : 10);
 
 	//Horizontal sizer to hold the tree and the selected page.
 	m_hsizer = new wxBoxSizer(wxHORIZONTAL);
diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp
index 3fc404864..e5e429a02 100644
--- a/src/slic3r/GUI/wxExtensions.cpp
+++ b/src/slic3r/GUI/wxExtensions.cpp
@@ -2808,11 +2808,13 @@ ModeButton::ModeButton( wxWindow *          parent,
                         const wxString&     mode        /* = wxEmptyString*/,
                         const wxSize&       size        /* = wxDefaultSize*/,
                         const wxPoint&      pos         /* = wxDefaultPosition*/) :
-    ScalableButton(parent, id, icon_name, mode, size, pos)
+    ScalableButton(parent, id, icon_name, mode, size, pos, wxBU_EXACTFIT)
 {
     m_tt_focused = wxString::Format(_(L("Switch to the %s mode")), mode);
     m_tt_selected = wxString::Format(_(L("Current mode is %s")), mode);
 
+    SetBitmapMargins(3, 0);
+
     //button events
     Bind(wxEVT_BUTTON,          &ModeButton::OnButton, this);
     Bind(wxEVT_ENTER_WINDOW,    &ModeButton::OnEnterBtn, this);
@@ -2841,6 +2843,7 @@ void ModeButton::focus_button(const bool focus)
                              Slic3r::GUI::wxGetApp().normal_font();
 
     SetFont(new_font);
+    SetForegroundColour(wxSystemSettings::GetColour(focus ? wxSYS_COLOUR_BTNTEXT : wxSYS_COLOUR_BTNSHADOW));
 
     Refresh();
     Update();
@@ -2851,7 +2854,7 @@ void ModeButton::focus_button(const bool focus)
 // ModeSizer
 // ----------------------------------------------------------------------------
 
-ModeSizer::ModeSizer(wxWindow *parent, int hgap/* = 10*/) :
+ModeSizer::ModeSizer(wxWindow *parent, int hgap/* = 0*/) :
     wxFlexGridSizer(3, 0, hgap)
 {
     SetFlexibleDirection(wxHORIZONTAL);
@@ -2869,15 +2872,8 @@ ModeSizer::ModeSizer(wxWindow *parent, int hgap/* = 10*/) :
     
     m_mode_btns.reserve(3);
     for (const auto& button : buttons) {
-#ifdef __WXOSX__
-        wxSize sz = parent->GetTextExtent(button.first);
-        // set default width for ModeButtons to correct rendering on OnFocus under OSX
-        sz.x += 2 * em_unit(parent);
-        m_mode_btns.push_back(new ModeButton(parent, wxID_ANY, button.second, button.first, sz));
-#else
-        m_mode_btns.push_back(new ModeButton(parent, wxID_ANY, button.second, button.first));;
-#endif // __WXOSX__
-        
+        m_mode_btns.push_back(new ModeButton(parent, wxID_ANY, button.second, button.first));
+
         m_mode_btns.back()->Bind(wxEVT_BUTTON, std::bind(modebtnfn, std::placeholders::_1, int(m_mode_btns.size() - 1)));
         Add(m_mode_btns.back());
     }
diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp
index a704f79d7..d7d5fcac2 100644
--- a/src/slic3r/GUI/wxExtensions.hpp
+++ b/src/slic3r/GUI/wxExtensions.hpp
@@ -946,7 +946,7 @@ private:
 class ModeSizer : public wxFlexGridSizer
 {
 public:
-    ModeSizer( wxWindow *parent, int hgap = 10);
+    ModeSizer( wxWindow *parent, int hgap = 0);
     ~ModeSizer() {}
 
     void SetMode(const /*ConfigOptionMode*/int mode);