From 1979baf619025cd8bb1c7524e69e93546e9bba48 Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Tue, 2 Apr 2019 13:26:22 +0200 Subject: [PATCH] imgui: Fix font size and scaling on Windows --- src/slic3r/GUI/GLCanvas3D.cpp | 6 +++--- src/slic3r/GUI/ImGuiWrapper.cpp | 11 +++++++---- src/slic3r/GUI/ImGuiWrapper.hpp | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index ca3f6261b..a600f9ce1 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -4405,12 +4405,12 @@ void GLCanvas3D::_resize(unsigned int w, unsigned int h) auto *imgui = wxGetApp().imgui(); imgui->set_display_size((float)w, (float)h); + const float font_size = 1.5f * wxGetApp().em_unit(); #if ENABLE_RETINA_GL - const float scaling = m_retina_helper->get_scale_factor(); + imgui->set_scaling(font_size, 1.0f, m_retina_helper->get_scale_factor()); #else - const float scaling = m_canvas->GetContentScaleFactor(); + imgui->set_scaling(font_size, m_canvas->GetContentScaleFactor(), 1.0f); #endif - imgui->set_scaling(m_canvas->GetFont().GetPixelSize().y, scaling); // ensures that this canvas is current _set_current(); diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index b008c17a7..1b4d4edf9 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -92,16 +92,19 @@ void ImGuiWrapper::set_display_size(float w, float h) io.DisplayFramebufferScale = ImVec2(1.0f, 1.0f); } -void ImGuiWrapper::set_scaling(float font_size, float scaling) +void ImGuiWrapper::set_scaling(float font_size, float scale_style, float scale_both) { - if (m_font_size == font_size && m_style_scaling == scaling) { + font_size *= scale_both; + scale_style *= scale_both; + + if (m_font_size == font_size && m_style_scaling == scale_style) { return; } m_font_size = font_size; - ImGui::GetStyle().ScaleAllSizes(scaling / m_style_scaling); - m_style_scaling = scaling; + ImGui::GetStyle().ScaleAllSizes(scale_style / m_style_scaling); + m_style_scaling = scale_style; destroy_font(); } diff --git a/src/slic3r/GUI/ImGuiWrapper.hpp b/src/slic3r/GUI/ImGuiWrapper.hpp index 84a60e3d1..c1bf491e1 100644 --- a/src/slic3r/GUI/ImGuiWrapper.hpp +++ b/src/slic3r/GUI/ImGuiWrapper.hpp @@ -35,7 +35,7 @@ public: void set_language(const std::string &language); void set_display_size(float w, float h); - void set_scaling(float font_size, float scaling); + void set_scaling(float font_size, float scale_style, float scale_both); bool update_mouse_data(wxMouseEvent &evt); bool update_key_data(wxKeyEvent &evt);