From 12133f95993ba33064b059e971f27e02fcc046d8 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 19 Jun 2019 11:38:42 +0200 Subject: [PATCH] Code cleaning and last msw_rescale() improvements --- src/slic3r/GUI/GUI_Utils.hpp | 32 +++++++++++--------------------- src/slic3r/GUI/MainFrame.cpp | 4 +++- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/slic3r/GUI/GUI_Utils.hpp b/src/slic3r/GUI/GUI_Utils.hpp index 39b68ea7a..c47714e46 100644 --- a/src/slic3r/GUI/GUI_Utils.hpp +++ b/src/slic3r/GUI/GUI_Utils.hpp @@ -64,6 +64,12 @@ public: m_prev_scale_factor = m_scale_factor; m_normal_font = get_default_font_for_dpi(dpi); + /* 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 // 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); @@ -139,19 +145,7 @@ private: // check if new scale is differ from previous bool is_new_scale_factor() const { return fabs(m_scale_factor - m_prev_scale_factor) > 0.001; } - // recursive function for scaling fonts for all controls in Window - void scale_controls_fonts(wxWindow *window, const float scale_f) - { - auto children = window->GetChildren(); - - for (auto child : children) { - scale_controls_fonts(child, scale_f); - child->SetFont(child->GetFont().Scaled(scale_f)); - } - - window->Layout(); - } - + // function for a font scaling of the window void scale_win_font(wxWindow *window, const int font_point_size) { wxFont new_font(window->GetFont()); @@ -175,22 +169,18 @@ private: void rescale(const wxRect &suggested_rect) { this->Freeze(); -// const float relative_scale_factor = m_scale_factor / m_prev_scale_factor; // rescale fonts of all controls -// scale_controls_fonts(this, relative_scale_factor); scale_controls_fonts(this, m_new_font_point_size); - -// this->SetFont(this->GetFont().Scaled(relative_scale_factor)); + // rescale current window font scale_win_font(this, m_new_font_point_size); - // rescale normal_font value -// m_normal_font = m_normal_font.Scaled(relative_scale_factor); + // set normal application font as a current window font m_normal_font = this->GetFont(); - // An analog of em_unit value from GUI_App. - m_em_unit = std::max(10, 10 * m_scale_factor); + // update em_unit value for new window font + m_em_unit = std::max(10, this->GetTextExtent("m").x - 1); // 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 7e5b3ec05..47d012fdf 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -38,10 +38,12 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S { // Fonts were created by the DPIFrame constructor for the monitor, on which the window opened. wxGetApp().update_fonts(this); +/* #ifndef __WXOSX__ // Don't call SetFont under OSX to avoid name cutting in ObjectList this->SetFont(this->normal_font()); #endif - + // Font is already set in DPIFrame constructor +*/ // Load the icon either from the exe, or from the ico file. #if _WIN32 {