OSX specific: Set window variant for regular buttons to correct rendering with big font

This commit is contained in:
YuSanka 2023-10-16 11:10:11 +02:00 committed by Lukas Matena
parent 1a182999a8
commit 168dadc0fa
15 changed files with 77 additions and 18 deletions

View File

@ -83,6 +83,7 @@ CopyrightsDialog::CopyrightsDialog()
m_html->Bind(wxEVT_HTML_LINK_CLICKED, &CopyrightsDialog::onLinkClicked, this);
wxStdDialogButtonSizer* buttons = this->CreateStdDialogButtonSizer(wxCLOSE);
wxGetApp().SetWindowVariantForButton(buttons->GetCancelButton());
wxGetApp().UpdateDlgDarkUI(this, true);
this->SetEscapeId(wxID_CLOSE);
this->Bind(wxEVT_BUTTON, &CopyrightsDialog::onCloseDialog, this, wxID_CLOSE);
@ -309,16 +310,19 @@ AboutDialog::AboutDialog()
wxStdDialogButtonSizer* buttons = this->CreateStdDialogButtonSizer(wxCLOSE);
wxGetApp().SetWindowVariantForButton(buttons->GetCancelButton());
m_copy_rights_btn_id = NewControlId();
auto copy_rights_btn = new wxButton(this, m_copy_rights_btn_id, _L("Portions copyright")+dots);
buttons->Insert(0, copy_rights_btn, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 5);
copy_rights_btn->Bind(wxEVT_BUTTON, &AboutDialog::onCopyrightBtn, this);
wxGetApp().SetWindowVariantForButton(copy_rights_btn);
m_copy_version_btn_id = NewControlId();
auto copy_version_btn = new wxButton(this, m_copy_version_btn_id, _L("Copy Version Info"));
buttons->Insert(1, copy_version_btn, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 5);
copy_version_btn->Bind(wxEVT_BUTTON, &AboutDialog::onCopyToClipboard, this);
wxGetApp().SetWindowVariantForButton(copy_version_btn);
wxGetApp().UpdateDlgDarkUI(this, true);

View File

@ -150,7 +150,10 @@ void BedShapeDialog::build_dialog(const ConfigOptionPoints& default_pt, const Co
auto main_sizer = new wxBoxSizer(wxVERTICAL);
main_sizer->Add(m_panel, 1, wxEXPAND);
main_sizer->Add(CreateButtonSizer(wxOK | wxCANCEL), 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, 10);
wxStdDialogButtonSizer* buttons = CreateStdDialogButtonSizer(wxOK | wxCANCEL);
wxGetApp().SetWindowVariantForButton(buttons->GetAffirmativeButton());
wxGetApp().SetWindowVariantForButton(buttons->GetCancelButton());
main_sizer->Add(buttons, 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, 10);
wxGetApp().UpdateDlgDarkUI(this, true);
@ -214,6 +217,7 @@ void BedShapePanel::build_panel(const ConfigOptionPoints& default_pt, const Conf
line.full_width = 1;
line.widget = [this](wxWindow* parent) {
wxButton* shape_btn = new wxButton(parent, wxID_ANY, _L("Load shape from STL..."));
wxGetApp().SetWindowVariantForButton(shape_btn);
wxSizer* shape_sizer = new wxBoxSizer(wxHORIZONTAL);
shape_sizer->Add(shape_btn, 1, wxEXPAND);
@ -294,6 +298,7 @@ wxPanel* BedShapePanel::init_texture_panel()
line.full_width = 1;
line.widget = [this](wxWindow* parent) {
wxButton* load_btn = new wxButton(parent, wxID_ANY, _L("Load..."));
wxGetApp().SetWindowVariantForButton(load_btn);
wxSizer* load_sizer = new wxBoxSizer(wxHORIZONTAL);
load_sizer->Add(load_btn, 1, wxEXPAND);
@ -303,6 +308,7 @@ wxPanel* BedShapePanel::init_texture_panel()
filename_sizer->Add(filename_lbl, 1, wxEXPAND);
wxButton* remove_btn = new wxButton(parent, wxID_ANY, _L("Remove"));
wxGetApp().SetWindowVariantForButton(remove_btn);
wxSizer* remove_sizer = new wxBoxSizer(wxHORIZONTAL);
remove_sizer->Add(remove_btn, 1, wxEXPAND);
@ -365,6 +371,7 @@ wxPanel* BedShapePanel::init_model_panel()
line.full_width = 1;
line.widget = [this](wxWindow* parent) {
wxButton* load_btn = new wxButton(parent, wxID_ANY, _L("Load..."));
wxGetApp().SetWindowVariantForButton(load_btn);
wxSizer* load_sizer = new wxBoxSizer(wxHORIZONTAL);
load_sizer->Add(load_btn, 1, wxEXPAND);
@ -373,6 +380,7 @@ wxPanel* BedShapePanel::init_model_panel()
filename_sizer->Add(filename_lbl, 1, wxEXPAND);
wxButton* remove_btn = new wxButton(parent, wxID_ANY, _L("Remove"));
wxGetApp().SetWindowVariantForButton(remove_btn);
wxSizer* remove_sizer = new wxBoxSizer(wxHORIZONTAL);
remove_sizer->Add(remove_btn, 1, wxEXPAND);

View File

@ -160,7 +160,8 @@ ConfigSnapshotDialog::ConfigSnapshotDialog(const Config::SnapshotDB &snapshot_db
}
wxStdDialogButtonSizer* buttons = this->CreateStdDialogButtonSizer(wxCLOSE);
wxGetApp().UpdateDarkUI(static_cast<wxButton*>(this->FindWindowById(wxID_CLOSE, this)));
wxGetApp().SetWindowVariantForButton(buttons->GetCancelButton());
wxGetApp().UpdateDarkUI(buttons->GetCancelButton());
this->SetEscapeId(wxID_CLOSE);
this->Bind(wxEVT_BUTTON, &ConfigSnapshotDialog::onCloseDialog, this, wxID_CLOSE);
vsizer->Add(buttons, 0, wxEXPAND | wxRIGHT | wxBOTTOM, 3);

View File

@ -423,6 +423,10 @@ PrinterPicker::PrinterPicker(wxWindow *parent, const VendorProfile &vendor, wxSt
title_sizer->Add(sel_all, 0, wxRIGHT, BTN_SPACING);
title_sizer->Add(sel_none);
wxGetApp().SetWindowVariantForButton(sel_all_std);
wxGetApp().SetWindowVariantForButton(sel_all);
wxGetApp().SetWindowVariantForButton(sel_none);
wxGetApp().UpdateDarkUI(sel_all_std);
wxGetApp().UpdateDarkUI(sel_all);
wxGetApp().UpdateDarkUI(sel_none);
@ -748,6 +752,9 @@ PageMaterials::PageMaterials(ConfigWizard *parent, Materials *materials, wxStrin
wxGetApp().UpdateDarkUI(sel_all);
wxGetApp().UpdateDarkUI(sel_none);
wxGetApp().SetWindowVariantForButton(sel_all);
wxGetApp().SetWindowVariantForButton(sel_none);
grid->Add(new wxBoxSizer(wxHORIZONTAL));
grid->Add(new wxBoxSizer(wxHORIZONTAL));
grid->Add(new wxBoxSizer(wxHORIZONTAL));
@ -861,10 +868,8 @@ void PageMaterials::set_compatible_printers_html_window(const std::vector<std::s
"</style>"
"<body bgcolor= %s>"
"<font color=%s>"
"<font size=\"3\">"
"%s<br /><br />%s"
"</font>"
"</font>"
"</body>"
"</html>"
, bgr_clr_str
@ -886,7 +891,6 @@ void PageMaterials::set_compatible_printers_html_window(const std::vector<std::s
"</style>"
"<body bgcolor= %s>"
"<font color=%s>"
"<font size=\"3\">"
"%s<br /><br />%s"
"<table>"
"<tr>"
@ -907,15 +911,13 @@ void PageMaterials::set_compatible_printers_html_window(const std::vector<std::s
"</tr>"
"</table>"
"</font>"
"</font>"
"</body>"
"</html>"
);
}
}
wxFont font = get_default_font_for_dpi(this, get_dpi_for_window(this));
wxFont font = wxGetApp().normal_font();// get_default_font_for_dpi(this, get_dpi_for_window(this));
const int fs = font.GetPointSize();
int size[] = { fs,fs,fs,fs,fs,fs,fs };
html_window->SetFonts(font.GetFaceName(), font.GetFaceName(), size);
@ -1421,6 +1423,7 @@ Worker::Worker(wxWindow* parent)
this->Add(m_input_path, 1, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 5);
auto* button_path = new wxButton(m_parent, wxID_ANY, _L("Browse"));
wxGetApp().SetWindowVariantForButton(button_path);
this->Add(button_path, 0, wxEXPAND | wxTOP | wxLEFT, 5);
button_path->Bind(wxEVT_BUTTON, [this](wxCommandEvent& event) {
boost::filesystem::path chosen_dest(boost::nowide::narrow(m_input_path->GetValue()));
@ -3351,6 +3354,12 @@ ConfigWizard::ConfigWizard(wxWindow *parent)
wxGetApp().UpdateDarkUI(p->btn_finish);
wxGetApp().UpdateDarkUI(p->btn_cancel);
wxGetApp().SetWindowVariantForButton(p->btn_sel_all);
wxGetApp().SetWindowVariantForButton(p->btn_prev);
wxGetApp().SetWindowVariantForButton(p->btn_next);
wxGetApp().SetWindowVariantForButton(p->btn_finish);
wxGetApp().SetWindowVariantForButton(p->btn_cancel);
const auto prusa_it = p->bundles.find("PrusaResearch");
wxCHECK_RET(prusa_it != p->bundles.cend(), "Vendor PrusaResearch not found");
const VendorProfile *vendor_prusa = prusa_it->second.vendor_profile;

View File

@ -817,11 +817,13 @@ FirmwareDialog::FirmwareDialog(wxWindow *parent) :
p->hex_picker = new wxFilePickerCtrl(panel, wxID_ANY, wxEmptyString, /*wxFileSelectorPromptStr*/_L("Select a file"),
"Hex files (*.hex)|*.hex|All files|*.*");
p->hex_picker->GetPickerCtrl()->SetLabelText(_(L("Browse")));
GUI::wxGetApp().SetWindowVariantForButton(static_cast<wxButton*>(p->hex_picker->GetPickerCtrl()));
auto *label_port_picker = new wxStaticText(panel, wxID_ANY, _(L("Serial port:")));
p->port_picker = new wxComboBox(panel, wxID_ANY);
p->txt_port_autodetect = new wxStaticText(panel, wxID_ANY, _(L("Autodetected")));
p->btn_rescan = new wxButton(panel, wxID_ANY, _(L("Rescan")));
GUI::wxGetApp().SetWindowVariantForButton(p->btn_rescan);
auto *port_sizer = new wxBoxSizer(wxHORIZONTAL);
port_sizer->Add(p->port_picker, 1, wxEXPAND | wxRIGHT, SPACING);
port_sizer->Add(p->btn_rescan, 0);
@ -864,7 +866,9 @@ FirmwareDialog::FirmwareDialog(wxWindow *parent) :
vsizer->Add(p->spoiler, 1, wxEXPAND | wxBOTTOM, SPACING);
p->btn_close = new wxButton(panel, wxID_CLOSE, _(L("Close"))); // Note: The label needs to be present, otherwise we get accelerator bugs on Mac
GUI::wxGetApp().SetWindowVariantForButton(p->btn_close);
p->btn_flash = new wxButton(panel, wxID_ANY, p->btn_flash_label_ready);
GUI::wxGetApp().SetWindowVariantForButton(p->btn_flash);
p->btn_flash->Disable();
auto *bsizer = new wxBoxSizer(wxHORIZONTAL);
bsizer->Add(p->btn_close);

View File

@ -1649,6 +1649,19 @@ void GUI_App::UpdateAllStaticTextDarkUI(wxWindow* parent)
#endif
}
void GUI_App::SetWindowVariantForButton(wxButton* btn)
{
#ifdef __APPLE__
// This is a limit imposed by OSX. The way the native button widget is drawn only allows it to be stretched horizontally,
// and the vertical size is fixed. (see https://stackoverflow.com/questions/29083891/wxpython-button-size-being-ignored-on-osx)
// But standard height is possible to change using SetWindowVariant method (see https://docs.wxwidgets.org/3.0/window_8h.html#a879bccd2c987fedf06030a8abcbba8ac)
if (m_normal_font.GetPointSize() > 15) {
btn->SetWindowVariant(wxWINDOW_VARIANT_LARGE);
btn->SetFont(m_normal_font);
}
#endif
}
void GUI_App::init_fonts()
{
m_small_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);

View File

@ -214,6 +214,7 @@ public:
void UpdateDVCDarkUI(wxDataViewCtrl* dvc, bool highlited = false);
// update color mode for panel including all static texts controls
void UpdateAllStaticTextDarkUI(wxWindow* parent);
void SetWindowVariantForButton(wxButton* btn);
void init_fonts();
void update_fonts(const MainFrame *main_frame = nullptr);
void set_label_clr_modified(const wxColour& clr);

View File

@ -98,10 +98,12 @@ GalleryDialog::GalleryDialog(wxWindow* parent) :
#endif
wxStdDialogButtonSizer* buttons = this->CreateStdDialogButtonSizer(wxOK | wxCLOSE);
m_ok_btn = static_cast<wxButton*>(FindWindowById(wxID_OK, this));
wxGetApp().SetWindowVariantForButton(buttons->GetCancelButton());
m_ok_btn = buttons->GetAffirmativeButton();
wxGetApp().SetWindowVariantForButton(m_ok_btn);
m_ok_btn->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(!m_selected_items.empty()); });
static_cast<wxButton*>(FindWindowById(wxID_CLOSE, this))->Bind(wxEVT_BUTTON, [this](wxCommandEvent&){ this->EndModal(wxID_CLOSE); });
buttons->GetCancelButton()->Bind(wxEVT_BUTTON, [this](wxCommandEvent&){ this->EndModal(wxID_CLOSE); });
this->SetEscapeId(wxID_CLOSE);
auto add_btn = [this, buttons]( size_t pos, int& ID, wxString title, wxString tooltip,
void (GalleryDialog::* method)(wxEvent&),
@ -109,6 +111,7 @@ GalleryDialog::GalleryDialog(wxWindow* parent) :
ID = NewControlId();
wxButton* btn = new wxButton(this, ID, title);
btn->SetToolTip(tooltip);
wxGetApp().SetWindowVariantForButton(btn);
btn->Bind(wxEVT_UPDATE_UI, [enable_fn](wxUpdateUIEvent& evt) { evt.Enable(enable_fn()); });
buttons->Insert(pos, btn, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, BORDER_W);
this->Bind(wxEVT_BUTTON, method, this, ID);

View File

@ -50,7 +50,8 @@ KBShortcutsDialog::KBShortcutsDialog()
}
wxStdDialogButtonSizer* buttons = this->CreateStdDialogButtonSizer(wxOK);
wxGetApp().UpdateDarkUI(static_cast<wxButton*>(this->FindWindowById(wxID_OK, this)));
wxGetApp().SetWindowVariantForButton(buttons->GetAffirmativeButton());
wxGetApp().UpdateDarkUI(buttons->GetAffirmativeButton());
this->SetEscapeId(wxID_OK);
main_sizer->Add(buttons, 0, wxEXPAND | wxALL, 5);

View File

@ -85,6 +85,7 @@ void MsgDialog::SetButtonLabel(wxWindowID btn_id, const wxString& label, bool se
wxButton* MsgDialog::add_button(wxWindowID btn_id, bool set_focus /*= false*/, const wxString& label/* = wxString()*/)
{
wxButton* btn = new wxButton(this, btn_id, label);
wxGetApp().SetWindowVariantForButton(btn);
if (set_focus) {
btn->SetFocus();
// For non-MSW platforms SetFocus is not enought to use it as default, when the dialog is closed by ENTER

View File

@ -511,7 +511,7 @@ FreqChangedParams::FreqChangedParams(wxWindow* parent) :
auto wiping_dialog_btn = [this](wxWindow* parent) {
m_wiping_dialog_button = new wxButton(parent, wxID_ANY, _L("Purging volumes") + dots, wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
m_wiping_dialog_button->SetFont(wxGetApp().normal_font());
wxGetApp().SetWindowVariantForButton(m_wiping_dialog_button);
wxGetApp().UpdateDarkUI(m_wiping_dialog_button, true);
auto sizer = new wxBoxSizer(wxHORIZONTAL);
@ -939,6 +939,7 @@ Sidebar::Sidebar(Plater *parent)
#endif //__APPLE__
ScalableBitmap bmp = ScalableBitmap(this, icon_name, bmp_px_cnt);
*btn = new ScalableButton(this, wxID_ANY, bmp, "", wxBU_EXACTFIT);
wxGetApp().SetWindowVariantForButton((*btn));
#ifdef _WIN32
(*btn)->Bind(wxEVT_ENTER_WINDOW, [tooltip, btn, this](wxMouseEvent& event) {
@ -970,6 +971,7 @@ Sidebar::Sidebar(Plater *parent)
auto init_btn = [this](wxButton **btn, wxString label, const int button_height) {
*btn = new wxButton(this, wxID_ANY, label, wxDefaultPosition,
wxSize(-1, button_height), wxBU_EXACTFIT);
wxGetApp().SetWindowVariantForButton((*btn));
(*btn)->SetFont(wxGetApp().bold_font());
wxGetApp().UpdateDarkUI((*btn), true);
};
@ -979,7 +981,7 @@ Sidebar::Sidebar(Plater *parent)
enable_buttons(false);
auto *btns_sizer = new wxBoxSizer(wxVERTICAL);
auto *btns_sizer = new wxBoxSizer(wxHORIZONTAL);
auto* complect_btns_sizer = new wxBoxSizer(wxHORIZONTAL);
complect_btns_sizer->Add(p->btn_export_gcode, 1, wxEXPAND);
@ -988,8 +990,8 @@ Sidebar::Sidebar(Plater *parent)
// complect_btns_sizer->Add(p->btn_eject_device);
btns_sizer->Add(p->btn_reslice, 0, wxEXPAND | wxTOP, margin_5);
btns_sizer->Add(complect_btns_sizer, 0, wxEXPAND | wxTOP, margin_5);
btns_sizer->Add(p->btn_reslice, 1, wxEXPAND | wxTOP | wxBOTTOM, margin_5);
btns_sizer->Add(complect_btns_sizer, 1, wxEXPAND | wxTOP | wxBOTTOM, margin_5);
auto *sizer = new wxBoxSizer(wxVERTICAL);
sizer->Add(p->scrolled, 1, wxEXPAND);
@ -5301,7 +5303,7 @@ void Sidebar::set_btn_label(const ActionButtonType btn_type, const wxString& lab
// Plater / Public
Plater::Plater(wxWindow *parent, MainFrame *main_frame)
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxGetApp().get_min_size())
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxGetApp().get_min_size(parent))
, p(new priv(this, main_frame))
{
// Initialization performed in the private c-tor

View File

@ -687,6 +687,8 @@ void PreferencesDialog::build()
sizer->Add(tabs, 1, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 5);
auto buttons = CreateStdDialogButtonSizer(wxOK | wxCANCEL);
wxGetApp().SetWindowVariantForButton(buttons->GetAffirmativeButton());
wxGetApp().SetWindowVariantForButton(buttons->GetCancelButton());
this->Bind(wxEVT_BUTTON, &PreferencesDialog::accept, this, wxID_OK);
this->Bind(wxEVT_BUTTON, &PreferencesDialog::revert, this, wxID_CANCEL);

View File

@ -182,7 +182,9 @@ SysInfoDialog::SysInfoDialog()
}
wxStdDialogButtonSizer* buttons = this->CreateStdDialogButtonSizer(wxOK);
wxGetApp().SetWindowVariantForButton(buttons->GetAffirmativeButton());
m_btn_copy_to_clipboard = new wxButton(this, wxID_ANY, _L("Copy to Clipboard"), wxDefaultPosition, wxDefaultSize);
wxGetApp().SetWindowVariantForButton(m_btn_copy_to_clipboard);
buttons->Insert(0, m_btn_copy_to_clipboard, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 5);
m_btn_copy_to_clipboard->Bind(wxEVT_BUTTON, &SysInfoDialog::onCopyToClipboard, this);

View File

@ -2249,6 +2249,7 @@ void TabFilament::build()
create_line_with_widget(optgroup.get(), "filament_ramming_parameters", "", [this](wxWindow* parent) {
auto ramming_dialog_btn = new wxButton(parent, wxID_ANY, _(L("Ramming settings"))+dots, wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
wxGetApp().SetWindowVariantForButton(ramming_dialog_btn);
wxGetApp().UpdateDarkUI(ramming_dialog_btn);
ramming_dialog_btn->SetFont(Slic3r::GUI::wxGetApp().normal_font());
ramming_dialog_btn->SetSize(ramming_dialog_btn->GetBestSize());

View File

@ -42,7 +42,10 @@ RammingDialog::RammingDialog(wxWindow* parent,const std::string& parameters)
auto main_sizer = new wxBoxSizer(wxVERTICAL);
main_sizer->Add(m_panel_ramming, 1, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 5);
main_sizer->Add(CreateButtonSizer(wxOK | wxCANCEL), 0, wxALIGN_CENTER_HORIZONTAL | wxTOP | wxBOTTOM, 10);
auto buttons = CreateStdDialogButtonSizer(wxOK | wxCANCEL);
Slic3r::GUI::wxGetApp().SetWindowVariantForButton(buttons->GetAffirmativeButton());
Slic3r::GUI::wxGetApp().SetWindowVariantForButton(buttons->GetCancelButton());
main_sizer->Add(buttons, 0, wxALIGN_CENTER_HORIZONTAL | wxTOP | wxBOTTOM, 10);
SetSizer(main_sizer);
main_sizer->SetSizeHints(this);
@ -181,6 +184,7 @@ WipingDialog::WipingDialog(wxWindow* parent, const std::vector<float>& matrix, c
update_ui(this);
auto widget_button = new wxButton(this,wxID_ANY,"-",wxPoint(0,0),wxDefaultSize);
update_ui(widget_button);
Slic3r::GUI::wxGetApp().SetWindowVariantForButton(widget_button);
m_panel_wiping = new WipingPanel(this,matrix,extruders, extruder_colours, widget_button);
auto main_sizer = new wxBoxSizer(wxVERTICAL);
@ -191,7 +195,10 @@ WipingDialog::WipingDialog(wxWindow* parent, const std::vector<float>& matrix, c
main_sizer->Add(m_panel_wiping, 0, wxEXPAND | wxALL, 5);
main_sizer->Add(widget_button, 0, wxALIGN_CENTER_HORIZONTAL | wxCENTER | wxBOTTOM, 5);
main_sizer->Add(CreateButtonSizer(wxOK | wxCANCEL), 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, 10);
auto buttons = CreateStdDialogButtonSizer(wxOK | wxCANCEL);
Slic3r::GUI::wxGetApp().SetWindowVariantForButton(buttons->GetAffirmativeButton());
Slic3r::GUI::wxGetApp().SetWindowVariantForButton(buttons->GetCancelButton());
main_sizer->Add(buttons, 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, 10);
SetSizer(main_sizer);
main_sizer->SetSizeHints(this);