From f27ad88d558f02c9feac850407f3a80840b47e79 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Fri, 21 Jul 2023 16:59:18 +0200 Subject: [PATCH] WIP (NewUI with fonts): Next improvements for fonts. * Fixed new font applying for TreeCtrl and DataViewCtrl * Fixed update of the em_unit in respect to the new font size + MSW specific: Fixed re-scaling of the non-standard buttons --- src/slic3r/GUI/ExtraRenderers.cpp | 29 +++++++++++++++---------- src/slic3r/GUI/GUI_Utils.hpp | 18 ++++++++------- src/slic3r/GUI/MainFrame.cpp | 10 +-------- src/slic3r/GUI/Tab.cpp | 1 + src/slic3r/GUI/UnsavedChangesDialog.cpp | 20 ++++------------- src/slic3r/GUI/wxExtensions.cpp | 4 ++-- src/slic3r/GUI/wxExtensions.hpp | 2 +- 7 files changed, 37 insertions(+), 47 deletions(-) diff --git a/src/slic3r/GUI/ExtraRenderers.cpp b/src/slic3r/GUI/ExtraRenderers.cpp index 678dc6f7bd..357c58468a 100644 --- a/src/slic3r/GUI/ExtraRenderers.cpp +++ b/src/slic3r/GUI/ExtraRenderers.cpp @@ -154,7 +154,14 @@ bool BitmapTextRenderer::Render(wxRect rect, wxDC *dc, int state) // workaround for Windows DarkMode : Don't respect to the state & wxDATAVIEW_CELL_SELECTED to avoid update of the text color RenderText(m_value.GetText(), xoffset, rect, dc, state & wxDATAVIEW_CELL_SELECTED ? 0 :state); #else + { + wxDataViewCtrl* const view = GetView(); + if (GetAttr().HasFont()) + dc->SetFont(GetAttr().GetEffectiveFont(view->GetFont())); + else + dc->SetFont(view->GetFont()); RenderText(m_value.GetText(), xoffset, rect, dc, state); + } #endif return true; @@ -165,22 +172,22 @@ wxSize BitmapTextRenderer::GetSize() const if (!m_value.GetText().empty()) { wxSize size; + wxDataViewCtrl* const view = GetView(); + wxClientDC dc(view); + if (GetAttr().HasFont()) + dc.SetFont(GetAttr().GetEffectiveFont(view->GetFont())); + else + dc.SetFont(view->GetFont()); + #if defined(SUPPORTS_MARKUP) && defined(wxHAS_GENERIC_DATAVIEWCTRL) if (m_markupText) - { - wxDataViewCtrl* const view = GetView(); - wxClientDC dc(view); - if (GetAttr().HasFont()) - dc.SetFont(GetAttr().GetEffectiveFont(view->GetFont())); - size = m_markupText->Measure(dc); - - int lines = m_value.GetText().Freq('\n') + 1; - size.SetHeight(size.GetHeight() * lines); - } else #endif // SUPPORTS_MARKUP && wxHAS_GENERIC_DATAVIEWCTRL - size = GetTextExtent(m_value.GetText()); + size = dc.GetTextExtent(m_value.GetText()); + + int lines = m_value.GetText().Freq('\n') + 1; + size.SetHeight(size.GetHeight() * lines); if (m_value.GetBitmap().IsOk()) size.x += m_value.GetBitmap().GetWidth() + 4; diff --git a/src/slic3r/GUI/GUI_Utils.hpp b/src/slic3r/GUI/GUI_Utils.hpp index fcd410ff22..7d22a3370d 100644 --- a/src/slic3r/GUI/GUI_Utils.hpp +++ b/src/slic3r/GUI/GUI_Utils.hpp @@ -94,17 +94,13 @@ public: m_prev_scale_factor = m_scale_factor; m_normal_font = get_default_font_for_dpi(this, dpi); - if (font_point_size > 0) { - m_font_size = font_point_size; + if (font_point_size > 0) m_normal_font.SetPointSize(font_point_size); - } /* Because of default window font is a primary display font, * We should set correct font for window before getting em_unit value. */ -#ifndef __WXOSX__ // Don't call SetFont under OSX to avoid name cutting in ObjectList this->SetFont(m_normal_font); -#endif this->CenterOnParent(); #ifdef _WIN32 update_dark_ui(this); @@ -113,7 +109,13 @@ public: // Linux specific issue : get_dpi_for_window(this) still doesn't responce to the Display's scale in new wxWidgets(3.1.3). // So, calculate the m_em_unit value from the font size, as before #if !defined(__WXGTK__) - m_em_unit = std::max(10/*m_font_size*/, int(m_scale_factor * m_font_size)); +#ifdef _WIN32 + const double font_to_em_koef = 10./9.;// Default font point size on Windows is 9 pt +#else // ifdef __WXOSX__ + const double font_to_em_koef = 10./11.;// Default font point size on OSX is 11 pt +#endif + m_em_unit_from_font_size = int(font_to_em_koef * m_normal_font.GetPointSize()); + m_em_unit = std::max(10, int(m_scale_factor * m_em_unit_from_font_size)); #else // initialize default width_unit according to the width of the one symbol ("m") of the currently active font of this window. m_em_unit = std::max(10, this->GetTextExtent("m").x - 1); @@ -198,7 +200,7 @@ protected: private: float m_scale_factor; int m_em_unit; - int m_font_size {10}; + int m_em_unit_from_font_size {10}; wxFont m_normal_font; float m_prev_scale_factor; @@ -247,7 +249,7 @@ private: m_normal_font = this->GetFont(); // update em_unit value for new window font - m_em_unit = std::max(m_font_size, int(m_scale_factor * m_font_size)); + m_em_unit = std::max(10, int(m_scale_factor * m_em_unit_from_font_size)); // rescale missed controls sizes and images on_dpi_changed(suggested_rect); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index c6bb44851c..b979d8c8b6 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -2305,15 +2305,7 @@ SettingsDialog::SettingsDialog(MainFrame* mainframe) if (wxGetApp().is_gcode_viewer()) return; -#if defined(__WXMSW__) - // ys_FIXME! temporary workaround for correct font scaling - // Because of from wxWidgets 3.1.3 auto rescaling is implemented for the Fonts, - // From the very beginning set dialog font to the wxSYS_DEFAULT_GUI_FONT - this->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); -#else - this->SetFont(wxGetApp().normal_font()); -// this->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); -#endif // __WXMSW__ +// this->SetFont(wxGetApp().normal_font()); // Load the icon either from the exe, or from the ico file. #if _WIN32 diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 5199e45220..9fb14d7eb4 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -3712,6 +3712,7 @@ void Tab::rebuild_page_tree() continue; auto itemId = m_treectrl->AppendItem(rootItem, translate_category(p->title(), m_type), p->iconID()); m_treectrl->SetItemTextColour(itemId, p->get_item_colour()); + m_treectrl->SetItemFont(itemId, wxGetApp().normal_font()); if (translate_category(p->title(), m_type) == selected) item = itemId; } diff --git a/src/slic3r/GUI/UnsavedChangesDialog.cpp b/src/slic3r/GUI/UnsavedChangesDialog.cpp index 5ae26ea9e8..723937aafa 100644 --- a/src/slic3r/GUI/UnsavedChangesDialog.cpp +++ b/src/slic3r/GUI/UnsavedChangesDialog.cpp @@ -839,13 +839,7 @@ UnsavedChangesDialog::UnsavedChangesDialog(Preset::Type type, PresetCollection* void UnsavedChangesDialog::build(Preset::Type type, PresetCollection* dependent_presets, const std::string& new_selected_preset, const wxString& header) { -#if defined(__WXMSW__) - // ys_FIXME! temporary workaround for correct font scaling - // Because of from wxWidgets 3.1.3 auto rescaling is implemented for the Fonts, - // From the very beginning set dialog font to the wxSYS_DEFAULT_GUI_FONT -// this->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); this->SetFont(wxGetApp().normal_font()); -#endif // __WXMSW__ int border = 10; int em = em_unit(); @@ -1338,7 +1332,7 @@ void UnsavedChangesDialog::on_dpi_changed(const wxRect& suggested_rect) { int em = em_unit(); - msw_buttons_rescale(this, em, { wxID_CANCEL, m_save_btn_id, m_move_btn_id, m_continue_btn_id }); + msw_buttons_rescale(this, em, { wxID_CANCEL, m_save_btn_id, m_move_btn_id, m_continue_btn_id }, 1.5); const wxSize& size = wxSize(70 * em, 30 * em); SetMinSize(size); @@ -1485,6 +1479,7 @@ void DiffPresetDialog::create_presets_sizer() auto add_preset_combobox = [collection, sizer, new_type, this](PresetComboBox** cb_, PresetBundle* preset_bundle) { *cb_ = new PresetComboBox(this, new_type, wxSize(em_unit() * 35, -1), preset_bundle); PresetComboBox*cb = (*cb_); + cb->SetFont(this->GetFont()); cb->show_modif_preset_separately(); cb->set_selection_changed_function([this, new_type, preset_bundle, cb](int selection) { std::string preset_name = Preset::remove_suffix_modified(cb->GetString(selection).ToUTF8().data()); @@ -1549,6 +1544,7 @@ void DiffPresetDialog::create_info_lines() void DiffPresetDialog::create_tree() { m_tree = new DiffViewCtrl(this, wxSize(em_unit() * 65, em_unit() * 40)); + m_tree->SetFont(this->GetFont()); m_tree->AppendToggleColumn_(L"\u2714", DiffModel::colToggle, wxLinux ? 9 : 6); m_tree->AppendBmpTextColumn("", DiffModel::colIconText, 35); m_tree->AppendBmpTextColumn(_L("Left Preset Value"), DiffModel::colOldValue, 15); @@ -1670,17 +1666,9 @@ void DiffPresetDialog::complete_dialog_creation() } DiffPresetDialog::DiffPresetDialog(MainFrame* mainframe) - : DPIDialog(mainframe, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER), + : DPIDialog(mainframe, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER, "diff_presets_dialog", mainframe->normal_font().GetPointSize()), m_pr_technology(wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology()) { -#if defined(__WXMSW__) - // ys_FIXME! temporary workaround for correct font scaling - // Because of from wxWidgets 3.1.3 auto rescaling is implemented for the Fonts, - // From the very beginning set dialog font to the wxSYS_DEFAULT_GUI_FONT -// this->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); - this->SetFont(mainframe->normal_font()); -#endif // __WXMSW__ - // Init bundles assert(wxGetApp().preset_bundle); diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index 0984c82c57..71ace3dbe0 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -372,9 +372,9 @@ void edit_tooltip(wxString& tooltip) /* Function for rescale of buttons in Dialog under MSW if dpi is changed. * btn_ids - vector of buttons identifiers */ -void msw_buttons_rescale(wxDialog* dlg, const int em_unit, const std::vector& btn_ids) +void msw_buttons_rescale(wxDialog* dlg, const int em_unit, const std::vector& btn_ids, double height_koef/* = 1.*/) { - const wxSize& btn_size = wxSize(-1, int(2.5f * em_unit + 0.5f)); + const wxSize& btn_size = wxSize(-1, int(2.5 * em_unit * height_koef + 0.5f)); for (int btn_id : btn_ids) { // There is a case [FirmwareDialog], when we have wxControl instead of wxButton diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index a0ed1bbd4c..803c0cc656 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -50,7 +50,7 @@ void enable_menu_item(wxUpdateUIEvent& evt, std::function const cb_condi class wxDialog; void edit_tooltip(wxString& tooltip); -void msw_buttons_rescale(wxDialog* dlg, const int em_unit, const std::vector& btn_ids); +void msw_buttons_rescale(wxDialog* dlg, const int em_unit, const std::vector& btn_ids, double height_koef = 1.); int em_unit(wxWindow* win); int mode_icon_px_size();