TopBar: Added "Show settings" button

This commit is contained in:
YuSanka 2024-04-19 10:47:36 +02:00 committed by Lukas Matena
parent cd5d30d3b1
commit 9beef5e847
5 changed files with 64 additions and 23 deletions

View File

@ -37,7 +37,7 @@
</g>
<g>
<g>
<path fill="#FFFFFF" d="M97.4,122.5h-7.98c-2.11,0-3.83-1.72-3.83-3.83v-2.81c-0.86-0.3-1.71-0.65-2.53-1.05l-1.99,1.99
<path fill="#808080" d="M97.4,122.5h-7.98c-2.11,0-3.83-1.72-3.83-3.83v-2.81c-0.86-0.3-1.71-0.65-2.53-1.05l-1.99,1.99
c-1.49,1.49-3.92,1.49-5.41,0l-5.64-5.65c-0.72-0.72-1.12-1.68-1.12-2.71c0-1.02,0.4-1.98,1.12-2.71l1.99-1.99
c-0.4-0.82-0.75-1.67-1.05-2.53h-2.81c-2.11,0-3.83-1.72-3.83-3.83v-7.98c0-2.11,1.72-3.83,3.83-3.83h2.81
c0.3-0.86,0.65-1.71,1.05-2.53l-1.99-1.99c-1.49-1.49-1.49-3.92,0-5.41l5.64-5.64c1.49-1.49,3.92-1.49,5.41,0L83.06,72
@ -59,7 +59,7 @@
C104.52,72.39,104.52,72.39,104.52,72.39z"/>
</g>
<g>
<path fill="#FFFFFF" d="M93.41,106.54c-7.24,0-13.14-5.89-13.14-13.14s5.89-13.14,13.14-13.14s13.14,5.89,13.14,13.14
<path fill="#808080" d="M93.41,106.54c-7.24,0-13.14-5.89-13.14-13.14s5.89-13.14,13.14-13.14s13.14,5.89,13.14,13.14
S100.65,106.54,93.41,106.54z M93.41,85.27c-4.49,0-8.14,3.65-8.14,8.14s3.65,8.14,8.14,8.14s8.14-3.65,8.14-8.14
S97.89,85.27,93.41,85.27z"/>
</g>

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

View File

@ -5137,7 +5137,7 @@ bool GLCanvas3D::_init_main_toolbar()
if (!m_main_toolbar.add_separator())
return false;
/*
item.name = "settings";
item.icon_filename = "settings.svg";
item.tooltip = _u8L("Switch to Settings") + "\n" + "[" + GUI::shortkey_ctrl_prefix() + "2] - " + _u8L("Print Settings Tab") +
@ -5149,7 +5149,7 @@ bool GLCanvas3D::_init_main_toolbar()
item.left.action_callback = []() { wxGetApp().mainframe->select_tab(); };
if (!m_main_toolbar.add_item(item))
return false;
*/
if (!m_main_toolbar.add_separator())
return false;

View File

@ -585,12 +585,20 @@ void MainFrame::update_title()
SetTitle(title);
}
static wxString GetTooltipForSettingsButton(PrinterTechnology pt)
{
std::string tooltip = _u8L("Switch to Settings") + "\n" + "[" + shortkey_ctrl_prefix() + "2] - " + _u8L("Print Settings Tab") +
"\n" + "[" + shortkey_ctrl_prefix() + "3] - " + (pt == ptFFF ? _u8L("Filament Settings Tab") : _u8L("Material Settings Tab")) +
"\n" + "[" + shortkey_ctrl_prefix() + "4] - " + _u8L("Printer Settings Tab");
return from_u8(tooltip);
}
void MainFrame::init_tabpanel()
{
wxGetApp().update_ui_colours_from_appconfig();
if (wxGetApp().is_editor()) {
m_tmp_top_bar = new TopBar(this, &m_bar_menus);
m_tmp_top_bar = new TopBar(this, &m_bar_menus, false);
m_tmp_top_bar->SetFont(Slic3r::GUI::wxGetApp().normal_font());
m_tmp_top_bar->Hide();
}
@ -651,6 +659,9 @@ void MainFrame::init_tabpanel()
if (full_config.has("nozzle_diameter")) {
m_plater->sidebar().set_extruders_count(full_config.option<ConfigOptionFloats>("nozzle_diameter")->values.size());
}
if (wxGetApp().is_editor())
m_tmp_top_bar->SetSettingsButtonTooltip(GetTooltipForSettingsButton(m_plater->printer_technology()));
}
}
@ -2076,10 +2087,12 @@ void MainFrame::add_to_recent_projects(const wxString& filename)
void MainFrame::technology_changed()
{
PrinterTechnology pt = plater()->printer_technology();
m_tmp_top_bar->SetSettingsButtonTooltip(GetTooltipForSettingsButton(pt));
if (!m_menubar)
return;
// update menu titles
PrinterTechnology pt = plater()->printer_technology();
if (int id = m_menubar->FindMenu(pt == ptFFF ? _L("Material Settings") : _L("Filament Settings")); id != wxNOT_FOUND)
m_menubar->SetMenuLabel(id , pt == ptSLA ? _L("Material Settings") : _L("Filament Settings"));

View File

@ -2,6 +2,7 @@
#include "TopBarMenus.hpp"
#include "GUI_App.hpp"
#include "MainFrame.hpp"
#include "Plater.hpp"
#include "Search.hpp"
#include "UserAccount.hpp"
@ -34,21 +35,18 @@ TopBarItemsCtrl::Button::Button(wxWindow* parent, const wxString& label, const s
{
int btn_margin = em_unit(this);
int x, y;
GetTextExtent(label, &x, &y);
GetTextExtent(label.IsEmpty() ? "a" : label, &x, &y);
wxSize size(x + 4 * btn_margin, y + int(1.5 * btn_margin));
if (icon_name.empty())
this->SetMinSize(size);
#ifdef _WIN32
else if (label.IsEmpty()) {
const int btn_side = px_cnt + btn_margin;
const int btn_side = size.y;
this->SetMinSize(wxSize(btn_side, btn_side));
}
else
#ifdef _WIN32
this->SetMinSize(wxSize(-1, size.y));
#else
else if (label.IsEmpty())
this->SetMinSize(wxSize(px_cnt, px_cnt));
else
this->SetMinSize(wxSize(size.x + px_cnt, size.y));
#endif
@ -130,9 +128,11 @@ void TopBarItemsCtrl::Button::render()
wxPoint pt = { 0, 0 };
wxString text = GetLabelText();
if (m_bmp_bundle.IsOk()) {
wxSize szIcon = get_preferred_size(m_bmp_bundle, this);
pt.x = em;
pt.x = text.IsEmpty() ? ((rc.width - szIcon.x) / 2) : em;
pt.y = (rc.height - szIcon.y) / 2;
#ifdef __WXGTK3__
dc.DrawBitmap(m_bmp_bundle.GetBitmap(szIcon), pt);
@ -144,7 +144,6 @@ void TopBarItemsCtrl::Button::render()
// Draw text
wxString text = GetLabelText();
if (!text.IsEmpty()) {
wxSize labelSize = dc.GetTextExtent(text);
if (labelSize.x > rc.width)
@ -277,7 +276,7 @@ wxPoint TopBarItemsCtrl::ButtonWithPopup::get_popup_pos()
return pos;
}
TopBarItemsCtrl::TopBarItemsCtrl(wxWindow *parent, TopBarMenus* menus/* = nullptr*/) :
TopBarItemsCtrl::TopBarItemsCtrl(wxWindow *parent, TopBarMenus* menus/* = nullptr*/, bool is_main/* = true*/) :
wxControl(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE | wxTAB_TRAVERSAL)
,m_menus(menus)
{
@ -306,6 +305,14 @@ TopBarItemsCtrl::TopBarItemsCtrl(wxWindow *parent, TopBarMenus* menus/* = nullpt
});
#endif
if (!is_main) {
m_settings_btn = new Button(this, "", "settings");
m_settings_btn->Bind(wxEVT_BUTTON, [](wxCommandEvent& event) {
wxGetApp().mainframe->select_tab();
});
left_sizer->Add(m_settings_btn, 0, wxALIGN_CENTER_VERTICAL);
}
m_buttons_sizer = new wxFlexGridSizer(1, m_btn_margin, m_btn_margin);
left_sizer->Add(m_buttons_sizer, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, m_btn_margin);
@ -394,6 +401,8 @@ void TopBarItemsCtrl::OnColorsChanged()
wxGetApp().UpdateDarkUI(this);
if (m_menu_btn)
m_menu_btn->sys_color_changed();
if (m_settings_btn)
m_settings_btn->sys_color_changed();
m_workspace_btn->sys_color_changed();
m_account_btn->sys_color_changed();
@ -478,6 +487,8 @@ void TopBarItemsCtrl::ShowFull()
{
if (m_menu_btn)
m_menu_btn->Show();
if (m_settings_btn)
m_settings_btn->Show();
m_account_btn->Show();
UpdateAccountButton();
m_menus->set_cb_on_user_item([this]() {
@ -490,6 +501,14 @@ void TopBarItemsCtrl::ShowJustMode()
{
if (m_menu_btn)
m_menu_btn->Hide();
if (m_settings_btn)
m_settings_btn->Hide();
m_account_btn->Hide();
m_menus->set_cb_on_user_item(nullptr);
}
void TopBarItemsCtrl::SetSettingsButtonTooltip(const wxString& tooltip)
{
if (m_settings_btn)
m_settings_btn->SetToolTip(tooltip);
}

View File

@ -63,7 +63,8 @@ class TopBarItemsCtrl : public wxControl
public:
TopBarItemsCtrl(wxWindow* parent,
TopBarMenus* menus = nullptr);
TopBarMenus* menus = nullptr,
bool is_main = true);
~TopBarItemsCtrl() {}
void OnPaint(wxPaintEvent&);
@ -84,15 +85,17 @@ public:
void CreateSearch();
void ShowFull();
void ShowJustMode();
void SetSettingsButtonTooltip(const wxString& tooltip);
wxWindow* GetSearchCtrl() { return m_search->GetTextCtrl(); }
private:
wxFlexGridSizer* m_buttons_sizer;
wxFlexGridSizer* m_sizer;
ButtonWithPopup* m_menu_btn {nullptr};
ButtonWithPopup* m_menu_btn {nullptr};
ButtonWithPopup* m_workspace_btn {nullptr};
ButtonWithPopup* m_account_btn {nullptr};
ButtonWithPopup* m_account_btn {nullptr};
Button* m_settings_btn {nullptr};
std::vector<Button*> m_pageButtons;
int m_selection {-1};
int m_btn_margin;
@ -115,12 +118,13 @@ public:
}
TopBar( wxWindow * parent,
TopBarMenus* menus)
TopBarMenus* menus,
bool is_main = true)
{
Init();
// wxNB_NOPAGETHEME: Disable Windows Vista theme for the Notebook background. The theme performance is terrible on Windows 10
// with multiple high resolution displays connected.
Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_TOP | wxTAB_TRAVERSAL | wxNB_NOPAGETHEME, menus);
Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_TOP | wxTAB_TRAVERSAL | wxNB_NOPAGETHEME, menus, is_main);
}
bool Create(wxWindow * parent,
@ -128,12 +132,13 @@ public:
const wxPoint & pos = wxDefaultPosition,
const wxSize & size = wxDefaultSize,
long style = 0,
TopBarMenus* menus = nullptr)
TopBarMenus* menus = nullptr,
bool is_main = true)
{
if (!wxBookCtrlBase::Create(parent, winid, pos, size, style | wxBK_TOP))
return false;
m_bookctrl = new TopBarItemsCtrl(this, menus);
m_bookctrl = new TopBarItemsCtrl(this, menus, is_main);
wxSizer* mainSizer = new wxBoxSizer(IsVertical() ? wxVERTICAL : wxHORIZONTAL);
@ -429,7 +434,11 @@ public:
void ShowJustMode() {
Show();
GetTopBarItemsCtrl()->ShowJustMode();
};
}
void SetSettingsButtonTooltip(const wxString& tooltip) {
GetTopBarItemsCtrl()->SetSettingsButtonTooltip(tooltip);
}
protected:
virtual void UpdateSelectedPage(size_t WXUNUSED(newsel)) override