Examples: GLFW+Vulkan: Fixed not applying content scale. (#8921, #8756)

This commit is contained in:
ocornut
2025-09-12 21:32:46 +02:00
parent 9f13684d70
commit cd476b27f8
2 changed files with 8 additions and 2 deletions

View File

@@ -107,7 +107,7 @@ Other Changes:
while navigating and to not close popup automatically. while navigating and to not close popup automatically.
- CI: Updates Windows CI to use a more recent VulkanSDK. (#8925, #8778) [@yaz0r] - CI: Updates Windows CI to use a more recent VulkanSDK. (#8925, #8778) [@yaz0r]
- Examples: Android: Android+OpenGL3: update Gradle project (#8888, #8878) [@scribam] - Examples: Android: Android+OpenGL3: update Gradle project (#8888, #8878) [@scribam]
- Examples: GLFW+OpenGL2: Fixed not applying content scale. (#8921) - Examples: GLFW+OpenGL2, GLFW+Vulkan: Fixed not applying content scale. (#8921, #8756)
- Backends: SDL_GPU: Added ImGui_ImplSDLGPU3_InitInfo::SwapchainComposition and - Backends: SDL_GPU: Added ImGui_ImplSDLGPU3_InitInfo::SwapchainComposition and
PresentMode to configure how secondary viewports are created. Currently only used PresentMode to configure how secondary viewports are created. Currently only used
multi-viewport mode. (#8892) [@PTSVU] multi-viewport mode. (#8892) [@PTSVU]

View File

@@ -357,7 +357,8 @@ int main(int, char**)
// Create window with Vulkan context // Create window with Vulkan context
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
GLFWwindow* window = glfwCreateWindow(1280, 720, "Dear ImGui GLFW+Vulkan example", nullptr, nullptr); float main_scale = ImGui_ImplGlfw_GetContentScaleForMonitor(glfwGetPrimaryMonitor()); // Valid on GLFW 3.3+ only
GLFWwindow* window = glfwCreateWindow((int)(1280 * main_scale), (int)(800 * main_scale), "Dear ImGui GLFW+Vulkan example", nullptr, nullptr);
if (!glfwVulkanSupported()) if (!glfwVulkanSupported())
{ {
printf("GLFW: Vulkan Not Supported\n"); printf("GLFW: Vulkan Not Supported\n");
@@ -393,6 +394,11 @@ int main(int, char**)
ImGui::StyleColorsDark(); ImGui::StyleColorsDark();
//ImGui::StyleColorsLight(); //ImGui::StyleColorsLight();
// Setup scaling
ImGuiStyle& style = ImGui::GetStyle();
style.ScaleAllSizes(main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again)
style.FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose)
// Setup Platform/Renderer backends // Setup Platform/Renderer backends
ImGui_ImplGlfw_InitForVulkan(window, true); ImGui_ImplGlfw_InitForVulkan(window, true);
ImGui_ImplVulkan_InitInfo init_info = {}; ImGui_ImplVulkan_InitInfo init_info = {};