Browse Source

Scale default fonts when we detect that we are handling our own high DPI modes.

Jeffery Myers 10 months ago
parent
commit
d6676e3a56
1 changed files with 23 additions and 2 deletions
  1. 23 2
      rlImGui.cpp

+ 23 - 2
rlImGui.cpp

@@ -249,7 +249,14 @@ void SetupFontAwesome(void)
 
     ImGuiIO& io = ImGui::GetIO();
 
-    io.Fonts->AddFontFromMemoryCompressedTTF((void*)fa_solid_900_compressed_data, fa_solid_900_compressed_size, FONT_AWESOME_ICON_SIZE, &icons_config, icons_ranges);
+    float size = FONT_AWESOME_ICON_SIZE;
+    if (!IsWindowState(FLAG_WINDOW_HIGHDPI))
+    {
+        size *= GetWindowScaleDPI().y;
+        icons_config.RasterizerMultiply = GetWindowScaleDPI().y;
+    }
+
+    io.Fonts->AddFontFromMemoryCompressedTTF((void*)fa_solid_900_compressed_data, fa_solid_900_compressed_size, size, &icons_config, icons_ranges);
 #endif
 
 }
@@ -417,7 +424,21 @@ void rlImGuiBeginInitImGui(void)
     SetupKeymap();
 
     ImGuiIO& io = ImGui::GetIO();
-    io.Fonts->AddFontDefault();
+
+    ImFontConfig defaultConfig;
+
+	static constexpr int DefaultFonSize = 13;
+
+    defaultConfig.SizePixels = DefaultFonSize;
+
+	if (!IsWindowState(FLAG_WINDOW_HIGHDPI))
+	{
+        defaultConfig.SizePixels = ceilf(defaultConfig.SizePixels * GetWindowScaleDPI().y);
+        defaultConfig.RasterizerMultiply = GetWindowScaleDPI().y;
+	}
+
+    defaultConfig.PixelSnapH = true;
+    io.Fonts->AddFontDefault(&defaultConfig);
 }
 
 void rlImGuiSetup(bool dark)