imgui: Fix font size and scaling on Windows

This commit is contained in:
Vojtech Kral 2019-04-02 13:26:22 +02:00
parent ba4f0445c3
commit 1979baf619
3 changed files with 11 additions and 8 deletions

View file

@ -4405,12 +4405,12 @@ void GLCanvas3D::_resize(unsigned int w, unsigned int h)
auto *imgui = wxGetApp().imgui(); auto *imgui = wxGetApp().imgui();
imgui->set_display_size((float)w, (float)h); imgui->set_display_size((float)w, (float)h);
const float font_size = 1.5f * wxGetApp().em_unit();
#if ENABLE_RETINA_GL #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 #else
const float scaling = m_canvas->GetContentScaleFactor(); imgui->set_scaling(font_size, m_canvas->GetContentScaleFactor(), 1.0f);
#endif #endif
imgui->set_scaling(m_canvas->GetFont().GetPixelSize().y, scaling);
// ensures that this canvas is current // ensures that this canvas is current
_set_current(); _set_current();

View file

@ -92,16 +92,19 @@ void ImGuiWrapper::set_display_size(float w, float h)
io.DisplayFramebufferScale = ImVec2(1.0f, 1.0f); 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; return;
} }
m_font_size = font_size; m_font_size = font_size;
ImGui::GetStyle().ScaleAllSizes(scaling / m_style_scaling); ImGui::GetStyle().ScaleAllSizes(scale_style / m_style_scaling);
m_style_scaling = scaling; m_style_scaling = scale_style;
destroy_font(); destroy_font();
} }

View file

@ -35,7 +35,7 @@ public:
void set_language(const std::string &language); void set_language(const std::string &language);
void set_display_size(float w, float h); 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_mouse_data(wxMouseEvent &evt);
bool update_key_data(wxKeyEvent &evt); bool update_key_data(wxKeyEvent &evt);