Skip to content

Commit 18dca11

Browse files
pthomocornut
authored andcommitted
Backends: GLFW, SDL2: ImplXXX_GetContentScaleXXX() helpers return 1.0f on emscripten / apple / android (#8742, #8733)
We can divide platforms into two cases based on how they report screen geometry: - Case 1: Platforms which report screen size in "physical pixels": Windows (for "Dpi aware" apps), Linux (with Wayland) - Case 2: Platforms which report screen size in "density-independent pixels": macOS, iOS, Android, emscripten As a consequence, there are two important things we need to know: - FramebufferScale: The scaling factor FrameBufferSize / ScreenSize - In case 1, the framebuffer size is equal to the screen size and DisplayFramebufferScale=1. - In case 2, the framebuffer size is equal to the screen size multiplied by a factor, for example DisplayFramebufferScale=2. - ContentScale The scaling factor for the content that we will display - In case 1, the content scale will often need to be > 1 (e.g., 2), because we will need to display bigger elements so that they show with a correct physical size on the screen. - In case 2, the content scale is equal to 1 This commit fixes ContentScale for platforms in case 2.
1 parent 7c51c0e commit 18dca11

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

backends/imgui_impl_glfw.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
// CHANGELOG
3131
// (minor and older changes stripped away, please see git history for details)
32+
// 2025-07-08: Made ImGui_ImplGlfw_GetContentScaleForWindow(), ImGui_ImplGlfw_GetContentScaleForMonitor() helpers return 1.0f on Emscripten and Android platforms, matching macOS logic. (#8742, #8733)
3233
// 2025-06-18: Added support for multiple Dear ImGui contexts. (#8676, #8239, #8069)
3334
// 2025-06-11: Added ImGui_ImplGlfw_GetContentScaleForWindow(GLFWwindow* window) and ImGui_ImplGlfw_GetContentScaleForMonitor(GLFWmonitor* monitor) helper to facilitate making DPI-aware apps.
3435
// 2025-03-10: Map GLFW_KEY_WORLD_1 and GLFW_KEY_WORLD_2 into ImGuiKey_Oem102.
@@ -876,7 +877,7 @@ static void ImGui_ImplGlfw_UpdateGamepads()
876877
// - Some accessibility applications are declaring virtual monitors with a DPI of 0.0f, see #7902. We preserve this value for caller to handle.
877878
float ImGui_ImplGlfw_GetContentScaleForWindow(GLFWwindow* window)
878879
{
879-
#if GLFW_HAS_PER_MONITOR_DPI && !defined(__APPLE__)
880+
#if GLFW_HAS_PER_MONITOR_DPI && !(defined(__APPLE__) || defined(__EMSCRIPTEN__) || defined(__ANDROID__))
880881
float x_scale, y_scale;
881882
glfwGetWindowContentScale(window, &x_scale, &y_scale);
882883
return x_scale;
@@ -888,7 +889,7 @@ float ImGui_ImplGlfw_GetContentScaleForWindow(GLFWwindow* window)
888889

889890
float ImGui_ImplGlfw_GetContentScaleForMonitor(GLFWmonitor* monitor)
890891
{
891-
#if GLFW_HAS_PER_MONITOR_DPI && !defined(__APPLE__)
892+
#if GLFW_HAS_PER_MONITOR_DPI && !(defined(__APPLE__) || defined(__EMSCRIPTEN__) || defined(__ANDROID__))
892893
float x_scale, y_scale;
893894
glfwGetMonitorContentScale(monitor, &x_scale, &y_scale);
894895
return x_scale;

backends/imgui_impl_sdl2.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
// CHANGELOG
2323
// (minor and older changes stripped away, please see git history for details)
24+
// 2025-07-08: Made ImGui_ImplSDL2_GetContentScaleForWindow(), ImGui_ImplSDL2_GetContentScaleForDisplay() helpers return 1.0f on Emscripten and Android platforms, matching macOS logic. (#8742, #8733)
2425
// 2025-06-11: Added ImGui_ImplSDL2_GetContentScaleForWindow(SDL_Window* window) and ImGui_ImplSDL2_GetContentScaleForDisplay(int display_index) helper to facilitate making DPI-aware apps.
2526
// 2025-04-09: Don't attempt to call SDL_CaptureMouse() on drivers where we don't call SDL_GetGlobalMouseState(). (#8561)
2627
// 2025-03-21: Fill gamepad inputs and set ImGuiBackendFlags_HasGamepad regardless of ImGuiConfigFlags_NavEnableGamepad being set.
@@ -719,7 +720,7 @@ float ImGui_ImplSDL2_GetContentScaleForWindow(SDL_Window* window)
719720
float ImGui_ImplSDL2_GetContentScaleForDisplay(int display_index)
720721
{
721722
#if SDL_HAS_PER_MONITOR_DPI
722-
#ifndef __APPLE__
723+
#if !defined(__APPLE__) && !defined(__EMSCRIPTEN__) && !defined(__ANDROID__)
723724
float dpi = 0.0f;
724725
if (SDL_GetDisplayDPI(display_index, &dpi, nullptr, nullptr) == 0)
725726
return dpi / 96.0f;

docs/CHANGELOG.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ Other changes:
6161
- Demo: Added "Text -> Font Size" demo section. (#8738) [@Demonese]
6262
- CI: Fixed dllimport/dllexport tests. (#8757) [@AidanSun05]
6363
- CI: Updated to use latest Windows image + VS2022.
64+
- Backends: GLFW, SDL2 made ImGui_ImplGLFW_GetContentScaleXXX() and
65+
ImGui_ImplSDL2_GetContentScaleXXXX() helpers return 1.0f on Emscripten
66+
and Android platforms, matching macOS logic. (#8742, #8733) [@pthom]
6467
- Backends: SDL3: avoid calling SDL_StartTextInput() again if already active.
6568
(fixes e.g.: an issue on iOS where the keyboard animation will popup every
6669
time the user types a key + probably other things) (#8727) [@morrazzzz]

imgui.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
// Library Version
3030
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345')
3131
#define IMGUI_VERSION "1.92.1 WIP"
32-
#define IMGUI_VERSION_NUM 19201
32+
#define IMGUI_VERSION_NUM 19202
3333
#define IMGUI_HAS_TABLE // Added BeginTable() - from IMGUI_VERSION_NUM >= 18000
3434
#define IMGUI_HAS_TEXTURES // Added ImGuiBackendFlags_RendererHasTextures - from IMGUI_VERSION_NUM >= 19198
3535

0 commit comments

Comments
 (0)