Merge branch 'ys_ui_fixes'

This commit is contained in:
Lukas Matena 2024-07-22 12:19:48 +02:00
commit 7594ba338a
6 changed files with 96 additions and 115 deletions

View File

@ -188,8 +188,8 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S
wxAcceleratorEntry entries[100]; wxAcceleratorEntry entries[100];
int id = 0; int id = 0;
for (const auto* entry : entries_cache) //for (const auto* entry : entries_cache)
entries[id++].Set(entry->GetFlags(), entry->GetKeyCode(), entry->GetMenuItem()->GetId()); // entries[id++].Set(entry->GetFlags(), entry->GetKeyCode(), entry->GetMenuItem()->GetId());
#if _WIN32 #if _WIN32
// This is needed on Windows to fake the CTRL+# of the window menu when using the numpad // This is needed on Windows to fake the CTRL+# of the window menu when using the numpad
@ -1624,7 +1624,7 @@ void MainFrame::init_menubar_as_editor()
// Help menu // Help menu
auto helpMenu = generate_help_menu(); auto helpMenu = generate_help_menu();
#ifndef __APPLE__ #if 0//ndef__APPLE__
// append menus for Menu button from TopBar // append menus for Menu button from TopBar
m_bar_menus.AppendMenuItem(fileMenu, _L("&File")); m_bar_menus.AppendMenuItem(fileMenu, _L("&File"));
@ -1660,10 +1660,12 @@ void MainFrame::init_menubar_as_editor()
SetMenuBar(m_menubar); SetMenuBar(m_menubar);
#ifdef __APPLE__
init_macos_application_menu(m_menubar, this); init_macos_application_menu(m_menubar, this);
#endif // __APPLE__ #endif // __APPLE__
#endif
if (plater()->printer_technology() == ptSLA) if (plater()->printer_technology() == ptSLA)
update_menubar(); update_menubar();
} }

View File

@ -92,9 +92,6 @@ class MainFrame : public DPIFrame
wxMenuBar* m_menubar{ nullptr }; wxMenuBar* m_menubar{ nullptr };
TopBarMenus m_bar_menus; TopBarMenus m_bar_menus;
#if 0
wxMenuItem* m_menu_item_repeat { nullptr }; // doesn't used now
#endif
wxMenuItem* m_menu_item_reslice_now { nullptr }; wxMenuItem* m_menu_item_reslice_now { nullptr };
wxSizer* m_main_sizer{ nullptr }; wxSizer* m_main_sizer{ nullptr };

View File

@ -158,6 +158,9 @@ void PreferencesDialog::show(const std::string& highlight_opt_key /*= std::strin
update_color(color_pickres[mode], palette[mode]); update_color(color_pickres[mode], palette[mode]);
} }
// invalidate this flag before show preferences
m_settings_layout_changed = false;
this->ShowModal(); this->ShowModal();
} }
@ -787,7 +790,6 @@ void PreferencesDialog::accept(wxEvent&)
if (auto it = m_values.find("seq_top_layer_only"); it != m_values.end()) if (auto it = m_values.find("seq_top_layer_only"); it != m_values.end())
m_seq_top_layer_only_changed = app_config->get("seq_top_layer_only") != it->second; m_seq_top_layer_only_changed = app_config->get("seq_top_layer_only") != it->second;
m_settings_layout_changed = false;
for (const std::string& key : { "old_settings_layout_mode", for (const std::string& key : { "old_settings_layout_mode",
"dlg_settings_layout_mode" }) "dlg_settings_layout_mode" })
{ {

View File

@ -455,6 +455,12 @@ void OptionsSearcher::update_dialog_position()
void OptionsSearcher::check_and_hide_dialog() void OptionsSearcher::check_and_hide_dialog()
{ {
#ifdef __linux__
// Temporary linux specific workaround:
// has_focus(search_dialog) always returns false
// That's why search dialog will be hidden whole the time
return;
#endif
if (search_dialog && search_dialog->IsShown() && !has_focus(search_dialog)) if (search_dialog && search_dialog->IsShown() && !has_focus(search_dialog))
show_dialog(false); show_dialog(false);
} }
@ -468,7 +474,7 @@ void OptionsSearcher::set_focus_to_parent()
void OptionsSearcher::show_dialog(bool show /*= true*/) void OptionsSearcher::show_dialog(bool show /*= true*/)
{ {
if (search_dialog && !show) { if (search_dialog && !show) {
search_dialog->EndModal(wxID_CLOSE); search_dialog->Hide();
return; return;
} }
@ -522,9 +528,13 @@ void OptionsSearcher::process_key_down_from_input(wxKeyEvent& e)
{ {
int key = e.GetKeyCode(); int key = e.GetKeyCode();
if (key == WXK_ESCAPE) if (key == WXK_ESCAPE)
search_dialog->EndModal(wxID_CLOSE); search_dialog->Hide();
else if (search_dialog && (key == WXK_UP || key == WXK_DOWN || key == WXK_NUMPAD_ENTER || key == WXK_RETURN)) else if (search_dialog && (key == WXK_UP || key == WXK_DOWN || key == WXK_NUMPAD_ENTER || key == WXK_RETURN)) {
search_dialog->KeyDown(e); search_dialog->KeyDown(e);
#ifdef __linux__
search_dialog->SetFocus();
#endif // __linux__
}
} }
void OptionsSearcher::set_search_input(TextInput* input_ctrl) void OptionsSearcher::set_search_input(TextInput* input_ctrl)
@ -667,7 +677,7 @@ void SearchDialog::ProcessSelection(wxDataViewItem selection)
{ {
if (!selection.IsOk()) if (!selection.IsOk())
return; return;
this->EndModal(wxID_CLOSE); this->Hide();
// If call GUI::wxGetApp().sidebar.jump_to_option() directly from here, // If call GUI::wxGetApp().sidebar.jump_to_option() directly from here,
// then mainframe will not have focus and found option will not be "active" (have cursor) as a result // then mainframe will not have focus and found option will not be "active" (have cursor) as a result

View File

@ -13,15 +13,8 @@ wxDEFINE_EVENT(wxCUSTOMEVT_TOPBAR_SEL_CHANGED, wxCommandEvent);
using namespace Slic3r::GUI; using namespace Slic3r::GUI;
#ifdef __APPLE__
#define down_arrow L"\u25BC";
#else
#define down_arrow L"\u23f7";
#endif
TopBarItemsCtrl::Button::Button(wxWindow* parent, const wxString& label, const std::string& icon_name, const int px_cnt, wxSize size_def) TopBarItemsCtrl::Button::Button(wxWindow* parent, const wxString& label, const std::string& icon_name, const int px_cnt, wxSize size_def)
:ScalableButton(parent, wxID_ANY, icon_name, label, size_def, wxDefaultPosition, wxNO_BORDER, px_cnt) :wxPanel(parent, wxID_ANY, wxDefaultPosition, size_def, wxBORDER_NONE | wxTAB_TRAVERSAL)
#ifdef _WIN32 #ifdef _WIN32
,m_background_color(wxGetApp().get_window_default_clr()) ,m_background_color(wxGetApp().get_window_default_clr())
#else #else
@ -29,6 +22,11 @@ TopBarItemsCtrl::Button::Button(wxWindow* parent, const wxString& label, const s
#endif #endif
,m_foreground_color(wxGetApp().get_label_clr_default()) ,m_foreground_color(wxGetApp().get_label_clr_default())
,m_bmp_bundle(icon_name.empty() ? wxBitmapBundle() : *get_bmp_bundle(icon_name, px_cnt)) ,m_bmp_bundle(icon_name.empty() ? wxBitmapBundle() : *get_bmp_bundle(icon_name, px_cnt))
,m_label(label)
,m_icon_name(icon_name)
,m_px_cnt(px_cnt)
,m_has_down_arrow(!icon_name.empty())
,m_dd_bmp_bundle(m_has_down_arrow ? *get_bmp_bundle("drop_down") : wxBitmapBundle())
{ {
int btn_margin = em_unit(this); int btn_margin = em_unit(this);
int x, y; int x, y;
@ -54,6 +52,15 @@ TopBarItemsCtrl::Button::Button(wxWindow* parent, const wxString& label, const s
Bind(wxEVT_LEAVE_WINDOW, [this](wxMouseEvent& event) { set_hovered(false); event.Skip(); }); Bind(wxEVT_LEAVE_WINDOW, [this](wxMouseEvent& event) { set_hovered(false); event.Skip(); });
Bind(wxEVT_PAINT, [this](wxPaintEvent&) { render(); }); Bind(wxEVT_PAINT, [this](wxPaintEvent&) { render(); });
#ifdef __linux__
Bind(wxEVT_LEFT_UP, [this](wxMouseEvent& event) {
#else
Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& event) {
#endif
wxCommandEvent evt(wxEVT_BUTTON, GetId());
GetEventHandler()->AddPendingEvent(evt);
event.Skip();
});
} }
void TopBarItemsCtrl::Button::set_selected(bool selected) void TopBarItemsCtrl::Button::set_selected(bool selected)
@ -67,14 +74,6 @@ void TopBarItemsCtrl::Button::set_selected(bool selected)
#else #else
wxTransparentColor; wxTransparentColor;
#endif #endif
#ifdef __linux__
this->SetBackgroundColour(m_background_color);
this->SetForegroundColour(m_foreground_color);
this->Refresh();
this->Update();
#endif // __linux__
} }
void TopBarItemsCtrl::Button::set_hovered(bool hovered) void TopBarItemsCtrl::Button::set_hovered(bool hovered)
@ -94,10 +93,6 @@ void TopBarItemsCtrl::Button::set_hovered(bool hovered)
wxTransparentColor; wxTransparentColor;
#endif #endif
#ifdef __linux__
this->SetBackgroundColour(m_background_color);
#endif // __linux__
this->Refresh(); this->Refresh();
this->Update(); this->Update();
} }
@ -107,14 +102,6 @@ void TopBarItemsCtrl::Button::render()
const wxRect rc(GetSize()); const wxRect rc(GetSize());
wxPaintDC dc(this); wxPaintDC dc(this);
#ifdef _WIN32
// Draw default background
dc.SetPen(wxGetApp().get_window_default_clr());
dc.SetBrush(wxGetApp().get_window_default_clr());
dc.DrawRectangle(rc);
#endif
int em = em_unit(this); int em = em_unit(this);
// Draw def rect with rounded corners // Draw def rect with rounded corners
@ -125,18 +112,14 @@ void TopBarItemsCtrl::Button::render()
wxPoint pt = { 0, 0 }; wxPoint pt = { 0, 0 };
wxString text = GetLabelText(); wxString text = m_label;
if (m_bmp_bundle.IsOk()) { if (m_bmp_bundle.IsOk()) {
wxSize szIcon = get_preferred_size(m_bmp_bundle, this); wxSize szIcon = get_preferred_size(m_bmp_bundle, this);
pt.x = text.IsEmpty() ? ((rc.width - szIcon.x) / 2) : em; pt.x = text.IsEmpty() ? ((rc.width - szIcon.x) / 2) : em;
pt.y = (rc.height - szIcon.y) / 2; pt.y = (rc.height - szIcon.y) / 2;
#ifdef __WXGTK3__
dc.DrawBitmap(m_bmp_bundle.GetBitmap(szIcon), pt, true);
#else
dc.DrawBitmap(m_bmp_bundle.GetBitmapFor(this), pt, true); dc.DrawBitmap(m_bmp_bundle.GetBitmapFor(this), pt, true);
#endif pt.x += szIcon.x + int(0.5 * em);
pt.x += szIcon.x;
} }
// Draw text // Draw text
@ -145,35 +128,44 @@ void TopBarItemsCtrl::Button::render()
wxSize labelSize = dc.GetTextExtent(text); wxSize labelSize = dc.GetTextExtent(text);
if (labelSize.x > rc.width) if (labelSize.x > rc.width)
text = wxControl::Ellipsize(text, dc, wxELLIPSIZE_END, rc.width); text = wxControl::Ellipsize(text, dc, wxELLIPSIZE_END, rc.width);
pt.x += (rc.width - pt.x - labelSize.x) / 2; if (!m_bmp_bundle.IsOk())
pt.x += (rc.width - pt.x - labelSize.x) / 2;
pt.y = (rc.height - labelSize.y) / 2; pt.y = (rc.height - labelSize.y) / 2;
dc.SetTextForeground(m_foreground_color); dc.SetTextForeground(m_foreground_color);
dc.SetFont(GetFont()); dc.SetFont(GetFont());
dc.DrawText(text, pt); dc.DrawText(text, pt);
pt.x += labelSize.x + int(0.5 * em);
// Draw down_arrow if needed
if (m_dd_bmp_bundle.IsOk()) {
wxSize szIcon = get_preferred_size(m_dd_bmp_bundle, this);
pt.y = (rc.height - szIcon.y) / 2;
dc.DrawBitmap(m_dd_bmp_bundle.GetBitmapFor(this), pt, true);
}
} }
} }
void TopBarItemsCtrl::Button::sys_color_changed() void TopBarItemsCtrl::Button::sys_color_changed()
{ {
ScalableButton::sys_color_changed(); m_bmp_bundle = m_icon_name.empty() ? wxBitmapBundle() : *get_bmp_bundle(m_icon_name, m_px_cnt);
#ifdef _WIN32 #ifdef _WIN32
m_background_color = wxGetApp().get_window_default_clr(); m_background_color = wxGetApp().get_window_default_clr();
#endif #endif
m_foreground_color = wxGetApp().get_label_clr_default(); m_foreground_color = wxGetApp().get_label_clr_default();
} }
#ifdef __linux__ const int login_icon_sz = 24;
const int icon_sz = 20;
#else
const int icon_sz = 24;
#endif
TopBarItemsCtrl::ButtonWithPopup::ButtonWithPopup(wxWindow* parent, const wxString& label, const std::string& icon_name, wxSize size) TopBarItemsCtrl::ButtonWithPopup::ButtonWithPopup(wxWindow* parent, const wxString& label, const std::string& icon_name, const int px_cnt, wxSize size)
:TopBarItemsCtrl::Button(parent, label, icon_name, icon_sz, size) :TopBarItemsCtrl::Button(parent, label, icon_name, px_cnt, size)
{ {
if (size != wxDefaultSize) if (size != wxDefaultSize)
m_fixed_width = size.x * 0.1; m_fixed_width = size.x * 0.1;
this->SetLabel(label); this->SetLabel(label);
} }
@ -188,39 +180,32 @@ void TopBarItemsCtrl::ButtonWithPopup::SetLabel(const wxString& label)
int btn_height = GetMinSize().GetHeight(); int btn_height = GetMinSize().GetHeight();
if (label.IsEmpty()) { if (label.IsEmpty()) {
ScalableButton::SetLabel(label); m_label = label;
SetMinSize(wxSize(btn_height, btn_height)); SetMinSize(wxSize(btn_height, btn_height));
return; return;
} }
const int em = em_unit(this);
const int label_width = GetTextExtent(text).GetWidth(); const int label_width = GetTextExtent(text).GetWidth();
bool resize_and_layout{ false }; int width_margins = int(0.1 * em * (m_px_cnt + 16 + 25));
this->SetMinSize(wxSize(label_width + width_margins, btn_height));
if (m_fixed_width != wxDefaultCoord) { if (m_fixed_width != wxDefaultCoord) {
const int text_width = m_fixed_width * em_unit(this) - 2 * btn_height; const int text_width = m_fixed_width * em_unit(this) - width_margins;
if (label_width > text_width || GetMinSize().GetWidth() <= btn_height) { if (label_width > text_width) {
wxWindowDC wdc(this); wxWindowDC wdc(this);
text = wxControl::Ellipsize(text, wdc, wxELLIPSIZE_END, text_width); text = wxControl::Ellipsize(text, wdc, wxELLIPSIZE_END, text_width);
resize_and_layout = true;
SetMinSize(wxSize(m_fixed_width * em_unit(this), btn_height));
SetSize(wxSize(m_fixed_width * em_unit(this), btn_height));
} }
} }
else if (GetMinSize().GetWidth() <= btn_height)
#ifdef _WIN32
this->SetMinSize(wxSize(-1, btn_height));
#elif __APPLE__
this->SetMinSize(wxSize(label_width + 3 * btn_height, btn_height));
#else
this->SetMinSize(wxSize(label_width + 2 * btn_height, btn_height));
#endif
wxString full_label = " " + text + " "; m_label = text;
#ifndef __linux__ Refresh();
full_label += down_arrow; GetParent()->Layout();
#endif
ScalableButton::SetLabel(full_label);
if (resize_and_layout) {
SetMinSize(wxSize(m_fixed_width * em_unit(this), btn_height));
GetParent()->Layout();
}
} }
void TopBarItemsCtrl::UpdateAccountButton(bool avatar/* = false*/) void TopBarItemsCtrl::UpdateAccountButton(bool avatar/* = false*/)
@ -228,37 +213,21 @@ void TopBarItemsCtrl::UpdateAccountButton(bool avatar/* = false*/)
TopBarMenus::UserAccountInfo user_account = m_menus->get_user_account_info(); TopBarMenus::UserAccountInfo user_account = m_menus->get_user_account_info();
const wxString user_name = user_account.is_logged ? from_u8(user_account.user_name) : _L("Log in"); const wxString user_name = user_account.is_logged ? from_u8(user_account.user_name) : _L("Log in");
m_account_btn->SetToolTip(user_name); m_account_btn->SetToolTip(user_name);
#ifdef __linux__
if (avatar) { if (avatar) {
if (user_account.is_logged) { if (user_account.is_logged) {
ScalableBitmap new_logo(this, user_account.avatar_path, wxSize(icon_sz, icon_sz)); ScalableBitmap new_logo(this, user_account.avatar_path, wxSize(login_icon_sz, login_icon_sz));
if (new_logo.IsOk())
m_account_btn->SetBitmap_(new_logo);
else
m_account_btn->SetBitmap_("user");
}
else {
m_account_btn->SetBitmap_("user");
}
}
#else
if (avatar) {
if (user_account.is_logged) {
ScalableBitmap new_logo(this, user_account.avatar_path, wxSize(icon_sz, icon_sz));
if (new_logo.IsOk()) if (new_logo.IsOk())
m_account_btn->SetBitmapBundle(new_logo.bmp()); m_account_btn->SetBitmapBundle(new_logo.bmp());
else else
m_account_btn->SetBitmapBundle(*get_bmp_bundle("user", icon_sz)); m_account_btn->SetBitmapBundle(*get_bmp_bundle("user", login_icon_sz));
} }
else { else {
m_account_btn->SetBitmapBundle(*get_bmp_bundle("user", icon_sz)); m_account_btn->SetBitmapBundle(*get_bmp_bundle("user", login_icon_sz));
} }
} }
#endif
m_account_btn->SetLabel(m_collapsed_btns ? "" : user_name); m_account_btn->SetLabel(m_collapsed_btns ? "" : user_name);
this->Layout(); this->Layout();
// m_account_btn->Refresh();
} }
void TopBarItemsCtrl::UnselectPopupButtons() void TopBarItemsCtrl::UnselectPopupButtons()
@ -275,7 +244,7 @@ void TopBarItemsCtrl::CreateSearch()
// than this max size will be used as a default control size and can't be resized. // than this max size will be used as a default control size and can't be resized.
// So, set initial size for some minimum value // So, set initial size for some minimum value
m_search = new ::TextInput(this, wxGetApp().searcher().default_string, "", "search", wxDefaultPosition, wxSize(2 * em_unit(this), -1), wxTE_PROCESS_ENTER); m_search = new ::TextInput(this, wxGetApp().searcher().default_string, "", "search", wxDefaultPosition, wxSize(2 * em_unit(this), -1), wxTE_PROCESS_ENTER);
m_search->SetMaxSize(wxSize(42*em_unit(this), -1)); m_search->SetMaxSize(wxSize(/*42*/30*em_unit(this), -1));
wxGetApp().UpdateDarkUI(m_search); wxGetApp().UpdateDarkUI(m_search);
m_search->Bind(wxEVT_TEXT, [](wxEvent& e) m_search->Bind(wxEVT_TEXT, [](wxEvent& e)
@ -368,7 +337,7 @@ void TopBarItemsCtrl::UpdateSearch(const wxString& search)
void TopBarItemsCtrl::update_margins() void TopBarItemsCtrl::update_margins()
{ {
int em = em_unit(this); int em = em_unit(this);
m_btn_margin = std::lround(0.9 * em); m_btn_margin = std::lround(0.5 * em);
} }
wxPoint TopBarItemsCtrl::ButtonWithPopup::get_popup_pos() wxPoint TopBarItemsCtrl::ButtonWithPopup::get_popup_pos()
@ -436,7 +405,7 @@ TopBarItemsCtrl::TopBarItemsCtrl(wxWindow *parent, TopBarMenus* menus/* = nullpt
this->SetSizer(m_sizer); this->SetSizer(m_sizer);
wxBoxSizer* left_sizer = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer* left_sizer = new wxBoxSizer(wxHORIZONTAL);
/*
#ifdef __APPLE__ #ifdef __APPLE__
auto logo = new wxStaticBitmap(this, wxID_ANY, *get_bmp_bundle(wxGetApp().logo_name(), 40)); auto logo = new wxStaticBitmap(this, wxID_ANY, *get_bmp_bundle(wxGetApp().logo_name(), 40));
left_sizer->Add(logo, 0, wxALIGN_CENTER_VERTICAL | wxALL, m_btn_margin); left_sizer->Add(logo, 0, wxALIGN_CENTER_VERTICAL | wxALL, m_btn_margin);
@ -449,11 +418,11 @@ TopBarItemsCtrl::TopBarItemsCtrl(wxWindow *parent, TopBarMenus* menus/* = nullpt
m_menus->Popup(this, &m_menus->main, m_menu_btn->get_popup_pos()); m_menus->Popup(this, &m_menus->main, m_menu_btn->get_popup_pos());
}); });
#endif #endif
*/
if (m_cb_settings_btn) { if (m_cb_settings_btn) {
m_settings_btn = new Button(this, _L("Settings"/*, "settings"*/)); m_settings_btn = new Button(this, _L("Settings"/*, "settings"*/));
m_settings_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent& event) { m_cb_settings_btn(); }); m_settings_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent& event) { m_cb_settings_btn(); });
left_sizer->Add(m_settings_btn, 0, wxALIGN_CENTER_VERTICAL); left_sizer->Add(m_settings_btn, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, m_btn_margin);
} }
m_buttons_sizer = new wxFlexGridSizer(1, m_btn_margin, m_btn_margin); m_buttons_sizer = new wxFlexGridSizer(1, m_btn_margin, m_btn_margin);
@ -480,7 +449,7 @@ TopBarItemsCtrl::TopBarItemsCtrl(wxWindow *parent, TopBarMenus* menus/* = nullpt
m_menus->Popup(this, &m_menus->workspaces, m_workspace_btn->get_popup_pos()); m_menus->Popup(this, &m_menus->workspaces, m_workspace_btn->get_popup_pos());
}); });
m_account_btn = new ButtonWithPopup(this, _L("Log in"), "user", wxSize(180, -1)); m_account_btn = new ButtonWithPopup(this, _L("Log in"), "user", login_icon_sz, wxSize(180, -1));
right_sizer->Add(m_account_btn, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxRIGHT, m_btn_margin); right_sizer->Add(m_account_btn, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxRIGHT, m_btn_margin);
m_account_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent& event) { m_account_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent& event) {
@ -498,14 +467,7 @@ TopBarItemsCtrl::TopBarItemsCtrl(wxWindow *parent, TopBarMenus* menus/* = nullpt
void TopBarItemsCtrl::UpdateMode() void TopBarItemsCtrl::UpdateMode()
{ {
wxBitmapBundle bmp = *m_menus->get_workspace_bitmap(); wxBitmapBundle bmp = *m_menus->get_workspace_bitmap();
#ifdef __linux__
m_workspace_btn->SetBitmap(bmp);
m_workspace_btn->SetBitmapCurrent(bmp);
m_workspace_btn->SetBitmapPressed(bmp);
#else
m_workspace_btn->SetBitmapBundle(bmp); m_workspace_btn->SetBitmapBundle(bmp);
#endif
m_workspace_btn->SetLabel(m_collapsed_btns ? "" : m_menus->get_workspace_name()); m_workspace_btn->SetLabel(m_collapsed_btns ? "" : m_menus->get_workspace_name());
this->Layout(); this->Layout();
@ -611,7 +573,7 @@ bool TopBarItemsCtrl::InsertPage(size_t n, const wxString& text, bool bSelect/*
void TopBarItemsCtrl::RemovePage(size_t n) void TopBarItemsCtrl::RemovePage(size_t n)
{ {
ScalableButton* btn = m_pageButtons[n]; auto btn = m_pageButtons[n];
m_pageButtons.erase(m_pageButtons.begin() + n); m_pageButtons.erase(m_pageButtons.begin() + n);
m_buttons_sizer->Remove(n); m_buttons_sizer->Remove(n);
@ -626,7 +588,7 @@ void TopBarItemsCtrl::RemovePage(size_t n)
void TopBarItemsCtrl::SetPageText(size_t n, const wxString& strText) void TopBarItemsCtrl::SetPageText(size_t n, const wxString& strText)
{ {
ScalableButton* btn = m_pageButtons[n]; auto btn = m_pageButtons[n];
btn->SetLabel(strText); btn->SetLabel(strText);
update_btns_width(); update_btns_width();
UpdateSearchSizeAndPosition(); UpdateSearchSizeAndPosition();
@ -634,7 +596,7 @@ void TopBarItemsCtrl::SetPageText(size_t n, const wxString& strText)
wxString TopBarItemsCtrl::GetPageText(size_t n) const wxString TopBarItemsCtrl::GetPageText(size_t n) const
{ {
ScalableButton* btn = m_pageButtons[n]; auto btn = m_pageButtons[n];
return btn->GetLabel(); return btn->GetLabel();
} }

View File

@ -2,7 +2,7 @@
#define slic3r_TopBar_hpp_ #define slic3r_TopBar_hpp_
#include <wx/bookctrl.h> #include <wx/bookctrl.h>
#include "wxExtensions.hpp" #include <wx/panel.h>
#include "Widgets/TextInput.hpp" #include "Widgets/TextInput.hpp"
class TopBarMenus; class TopBarMenus;
@ -12,13 +12,20 @@ wxDECLARE_EVENT(wxCUSTOMEVT_TOPBAR_SEL_CHANGED, wxCommandEvent);
class TopBarItemsCtrl : public wxControl class TopBarItemsCtrl : public wxControl
{ {
class Button : public ScalableButton class Button : public wxPanel
{ {
bool m_is_selected{ false }; bool m_is_selected{ false };
wxColour m_background_color; wxColour m_background_color;
wxColour m_foreground_color; wxColour m_foreground_color;
wxBitmapBundle m_bmp_bundle = wxBitmapBundle(); wxBitmapBundle m_bmp_bundle = wxBitmapBundle();
protected:
wxString m_label;
std::string m_icon_name;
int m_px_cnt { 16 };
bool m_has_down_arrow { false };
wxBitmapBundle m_dd_bmp_bundle = wxBitmapBundle();
public: public:
Button() {}; Button() {};
Button( wxWindow* parent, Button( wxWindow* parent,
@ -33,7 +40,7 @@ class TopBarItemsCtrl : public wxControl
void set_hovered (bool hovered); void set_hovered (bool hovered);
void render(); void render();
void sys_color_changed() override; void sys_color_changed();
void SetBitmapBundle(wxBitmapBundle bmp_bundle) { m_bmp_bundle = bmp_bundle; } void SetBitmapBundle(wxBitmapBundle bmp_bundle) { m_bmp_bundle = bmp_bundle; }
}; };
@ -45,6 +52,7 @@ class TopBarItemsCtrl : public wxControl
ButtonWithPopup(wxWindow* parent, ButtonWithPopup(wxWindow* parent,
const wxString& label, const wxString& label,
const std::string& icon_name = "", const std::string& icon_name = "",
const int px_cnt = 16,
wxSize size = wxDefaultSize); wxSize size = wxDefaultSize);
ButtonWithPopup(wxWindow* parent, ButtonWithPopup(wxWindow* parent,
const std::string& icon_name, const std::string& icon_name,