Skip to content

Commit

Permalink
notebook tabbar fix
Browse files Browse the repository at this point in the history
  • Loading branch information
stxve4203 authored and supermerill committed Jul 8, 2024
1 parent 0c10d20 commit 7843f61
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 43 deletions.
5 changes: 0 additions & 5 deletions src/slic3r/GUI/GUI_App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,13 @@ class GUI_App : public wxApp
wxColour m_color_label_default;
wxColour m_color_label_phony;
wxColour m_color_window_default;
#ifdef _WIN32
wxColour m_color_highlight_label_default;
wxColour m_color_hovered_btn_label;
wxColour m_color_hovered_btn;
wxColour m_color_default_btn_label;
wxColour m_color_highlight_default;
wxColour m_color_selected_btn_bg;
bool m_force_colors_update { false };
#endif

wxFont m_small_font;
wxFont m_bold_font;
Expand Down Expand Up @@ -216,8 +214,6 @@ class GUI_App : public wxApp
const wxColour& get_label_clr_phony() { return m_color_label_phony; }
const wxColour& get_window_default_clr(){ return m_color_window_default; }


#ifdef _WIN32
const wxColour& get_label_highlight_clr() { return m_color_highlight_label_default; }
const wxColour& get_highlight_default_clr() { return m_color_highlight_default; }
const wxColour& get_color_hovered_btn_label() { return m_color_hovered_btn_label; }
Expand All @@ -227,7 +223,6 @@ class GUI_App : public wxApp
#ifdef _MSW_DARK_MODE
void force_menu_update();
#endif //_MSW_DARK_MODE
#endif

const wxFont& small_font() { return m_small_font; }
const wxFont& bold_font() { return m_bold_font; }
Expand Down
12 changes: 8 additions & 4 deletions src/slic3r/GUI/MainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,17 +318,21 @@ void MainFrame::update_icon() {
}
case ESettingsLayout::Tabs:
{
#ifdef __APPLE__
// no icons for macos
break;
#else
if (icon_size >= 8)
{
m_tabpanel->SetPageImage(0, 0);
m_tabpanel->SetPageImage(1, 1);
m_tabpanel->SetPageImage(2, 2);
m_tabpanel->SetPageImage(3, 3);
m_tabpanel->SetPageImage(4, m_plater->printer_technology() == PrinterTechnology::ptSLA ? 6 : 4);
m_tabpanel->SetPageImage(5, m_plater->printer_technology() == PrinterTechnology::ptSLA ? 7 : 5);
m_tabpanel->SetPageImage(3, m_plater->printer_technology() == PrinterTechnology::ptSLA ? 6 : 3);
m_tabpanel->SetPageImage(4, m_plater->printer_technology() == PrinterTechnology::ptSLA ? 7 : 4);
m_tabpanel->SetPageImage(5, m_plater->printer_technology() == PrinterTechnology::ptSLA ? 8 : 5);
}
break;
}

This comment has been minimized.

Copy link
@timschneider

timschneider Jul 9, 2024

Is this correct? There is one } missing after the commit.

Shouldn't it

        }
        break;
#endif
    }
    case ESettingsLayout::Dlg:
    {

This comment has been minimized.

Copy link
@legend069

legend069 Jul 10, 2024

if we could keep the statements curly brackets the same style that would be fantastic.
@ if (m_tabpanel->GetPageCount() == 4 && icon_size >= 8) {

this(){
//stuff
}

or

this2()
{
//stuff
}
#endif
case ESettingsLayout::Dlg:
{
if (m_tabpanel->GetPageCount() == 4 && icon_size >= 8) {
Expand Down
4 changes: 2 additions & 2 deletions src/slic3r/GUI/MainFrame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ class MainFrame : public DPIFrame
void update_menubar();
// Open item in menu by menu and item name (in actual language)
void open_menubar_item(const wxString& menu_name,const wxString& item_name);
#ifdef _WIN32

void show_tabs_menu(bool show);
#endif

void update_ui_from_settings();
bool is_loaded() const { return m_loaded; }
bool is_last_input_file() const { return !m_qs_last_input_file.IsEmpty(); }
Expand Down
71 changes: 46 additions & 25 deletions src/slic3r/GUI/Notebook.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "Notebook.hpp"

#ifdef _WIN32

#include "libslic3r/AppConfig.hpp"

#include "GUI_App.hpp"
Expand All @@ -22,18 +20,27 @@ ButtonsListCtrl::ButtonsListCtrl(wxWindow *parent, bool add_mode_buttons/* = fal
#endif //__WINDOWS__

int em = em_unit(this);// Slic3r::GUI::wxGetApp().em_unit();
m_btn_margin = std::lround(0.3 * em);
#ifdef __WINDOWS__
m_btn_margin = std::lround(0.3 * em);
#else
m_btn_margin = std::lround(0.4 * em);
#endif
m_line_margin = std::lround(0.1 * em);

m_sizer = new wxBoxSizer(wxHORIZONTAL);
this->SetSizer(m_sizer);

// Create the buttons sizer with adjustable gaps
m_buttons_sizer = new wxFlexGridSizer(1, m_btn_margin, m_btn_margin);
#ifdef __APPLE__
m_buttons_sizer->SetHGap(m_btn_margin); // Horizontal gap between buttons
m_buttons_sizer->SetVGap(m_btn_margin); // Vertical gap between buttons
#endif
m_sizer->Add(m_buttons_sizer, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxBOTTOM, m_btn_margin);

if (add_mode_buttons) {
m_mode_sizer = new Slic3r::GUI::ModeSizer(this, m_btn_margin, 0);
m_sizer->AddStretchSpacer(20);
m_sizer->AddStretchSpacer(20); // Adjust the stretch spacer to ensure buttons align correctly
m_sizer->Add(m_mode_sizer, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, m_btn_margin);
}

Expand All @@ -48,45 +55,42 @@ void ButtonsListCtrl::OnPaint(wxPaintEvent&)

if (m_selection < 0 || m_selection >= (int)m_pageButtons.size())
return;

const wxColour& selected_btn_bg = Slic3r::GUI::wxGetApp().get_color_selected_btn_bg();
const wxColour& default_btn_bg = Slic3r::GUI::wxGetApp().get_highlight_default_clr();
const wxColour& btn_marker_color = Slic3r::GUI::wxGetApp().get_color_hovered_btn(); //Slic3r::GUI::wxGetApp().get_color_hovered_btn_label();
const wxColour& btn_marker_color = Slic3r::GUI::wxGetApp().get_color_hovered_btn();

// highlight selected notebook button

for (int idx = 0; idx < int(m_pageButtons.size()); idx++) {
wxButton* btn = m_pageButtons[idx];

btn->SetBackgroundColour(idx == m_selection ? selected_btn_bg : default_btn_bg);

#ifdef __APPLE__
// Adding border to make it look more like buttons
btn->SetWindowStyle(wxBORDER_SUNKEN | wxBORDER_SIMPLE);
#else
wxPoint pos = btn->GetPosition();
wxSize size = btn->GetSize();
const wxColour& clr = idx == m_selection ? btn_marker_color : default_btn_bg;
dc.SetPen(clr);
dc.SetBrush(clr);
dc.DrawRectangle(pos.x, pos.y + size.y, size.x, sz.y - size.y);
#endif
}

// highlight selected mode button

if (m_mode_sizer) {
const std::vector<Slic3r::GUI::ModeButton*>& mode_btns = m_mode_sizer->get_btns();
for (int idx = 0; idx < int(mode_btns.size()); idx++) {
Slic3r::GUI::ModeButton* btn = mode_btns[idx];
btn->SetBackgroundColour(btn->is_selected() ? selected_btn_bg : default_btn_bg);

//wxPoint pos = btn->GetPosition();
//wxSize size = btn->GetSize();
//const wxColour& clr = btn->is_selected() ? btn_marker_color : default_btn_bg;
//dc.SetPen(clr);
//dc.SetBrush(clr);
//dc.DrawRectangle(pos.x, pos.y + size.y, size.x, sz.y - size.y);
#ifdef __APPLE_
// Adding border to make it look more like buttons
btn->SetWindowStyle(wxBORDER_SUNKEN | wxBORDER_SIMPLE);
#endif
}
}

// Draw orange bottom line

dc.SetPen(btn_marker_color);
dc.SetBrush(btn_marker_color);
dc.DrawRectangle(1, sz.y - m_line_margin, sz.x, m_line_margin);
Expand All @@ -104,10 +108,18 @@ void ButtonsListCtrl::Rescale()
btn->msw_rescale();

int em = em_unit(this);

#ifdef __APPLE__
// Adjust margins and sizes specifically for macOS
m_btn_margin = std::lround(0.4 * em);
m_line_margin = std::lround(0.1 * em);
#else
m_btn_margin = std::lround(0.3 * em);
m_line_margin = std::lround(0.1 * em);
m_buttons_sizer->SetVGap(m_btn_margin);
m_buttons_sizer->SetHGap(m_btn_margin);
#endif //__APPLE__

m_buttons_sizer->SetVGap(m_btn_margin); // Adjust vertical gap here
m_buttons_sizer->SetHGap(m_btn_margin); // Adjust horizontal gap here

m_sizer->Layout();
}
Expand All @@ -122,7 +134,18 @@ void ButtonsListCtrl::SetSelection(int sel)

bool ButtonsListCtrl::InsertPage(size_t n, const wxString& text, bool bSelect/* = false*/, const std::string& bmp_name/* = ""*/, const int bmp_size)
{
ScalableButton* btn = new ScalableButton(this, wxID_ANY, bmp_name, text, wxDefaultSize, wxDefaultPosition, wxBU_EXACTFIT | wxNO_BORDER | (bmp_name.empty() ? 0 : wxBU_LEFT), false, bmp_size);

ScalableButton* btn = new ScalableButton(this, wxID_ANY, bmp_name, text, wxDefaultSize, wxDefaultPosition,
#ifdef __APPLE__
wxBU_EXACTFIT | wxBORDER_SIMPLE | (bmp_name.empty() ? 0 : wxBU_LEFT),
#else
wxBU_EXACTFIT | wxNO_BORDER | (bmp_name.empty() ? 0 : wxBU_LEFT),
#endif //__APPLE__
false, bmp_size);

// Set custom background color for the button
btn->SetBackgroundColour(Slic3r::GUI::wxGetApp().get_color_hovered_btn());

btn->Bind(wxEVT_BUTTON, [this, btn](wxCommandEvent& event) {
if (auto it = std::find(m_pageButtons.begin(), m_pageButtons.end(), btn); it != m_pageButtons.end()) {
m_selection = (it - m_pageButtons.begin());
Expand All @@ -131,7 +154,7 @@ bool ButtonsListCtrl::InsertPage(size_t n, const wxString& text, bool bSelect/*
wxPostEvent(this->GetParent(), evt);
Refresh();
}
});
});
Slic3r::GUI::wxGetApp().UpdateDarkUI(btn);
m_pageButtons.insert(m_pageButtons.begin() + n, btn);
m_spacers.insert(m_spacers.begin() + n, false);
Expand Down Expand Up @@ -247,6 +270,4 @@ void Notebook::EmitEventSelChanged(int16_t new_sel) {
}
}
}
#endif // _WIN32



9 changes: 3 additions & 6 deletions src/slic3r/GUI/Notebook.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef slic3r_Notebook_hpp_
#define slic3r_Notebook_hpp_

#ifdef _WIN32

#include <wx/bookctrl.h>

namespace Slic3r {
Expand Down Expand Up @@ -98,7 +96,7 @@ class Notebook: public wxBookCtrlBase
SetSizer(mainSizer);

this->Bind(wxCUSTOMEVT_NOTEBOOK_SEL_CHANGED, [this](wxCommandEvent& evt)
{
{
if (int page_idx = evt.GetId(); page_idx >= 0)
SetBtSelection(page_idx);
});
Expand Down Expand Up @@ -246,7 +244,7 @@ class Notebook: public wxBookCtrlBase
}

//// get number of pages in the dialog
//virtual size_t GetPageCount() const override {
//virtual size_t GetPageCount() const override {
// return btidx_to_tabpage.size();
//}

Expand Down Expand Up @@ -545,7 +543,7 @@ class Notebook: public wxBookCtrlBase
// the base class version.
}

virtual wxBookCtrlEvent * CreatePageChangingEvent() const override
virtual wxBookCtrlEvent* CreatePageChangingEvent() const override
{
return new wxBookCtrlEvent(wxEVT_BOOKCTRL_PAGE_CHANGING,
GetId());
Expand Down Expand Up @@ -622,5 +620,4 @@ class Notebook: public wxBookCtrlBase
ButtonsListCtrl* m_ctrl{ nullptr };

};
#endif // _WIN32
#endif // slic3r_Notebook_hpp_
5 changes: 4 additions & 1 deletion src/slic3r/GUI/wxExtensions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ inline void msw_rescale_menu(wxMenu* /* menu */) {}
#endif /* __WXMSW__ */

#ifdef _MSW_DARK_MODE
#define _USE_CUSTOM_NOTEBOOK 1
#define _USE_CUSTOM_NOTEBOOK 1
#endif
#ifdef __APPLE__
#define _USE_CUSTOM_NOTEBOOK 1
#endif

wxMenuItem* append_menu_item(wxMenu* menu, int id, const wxString& string, const wxString& description,
Expand Down

0 comments on commit 7843f61

Please sign in to comment.