diff --git a/backends/imgui_impl_emscripten.cpp b/backends/imgui_impl_emscripten.cpp index 52f24cd0c..a6c358d08 100644 --- a/backends/imgui_impl_emscripten.cpp +++ b/backends/imgui_impl_emscripten.cpp @@ -4,6 +4,7 @@ // // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2026-09-06: Emscripten: Added ImGui_ImplEmscripten_GetCssToImGuiScale() helper. // 2026-09-05: Emscripten: Use the canvas framebuffer dimensions for display sizing and exact per-axis mouse coordinate scaling. // 2026-09-04: Emscripten: Replaced TargetDevicePixelRatio global with an Init() parameter and runtime setter. // 2026-09-03: Updated coding style and simplified key translation table setup. @@ -402,6 +403,13 @@ void ImGui_ImplEmscripten_SetTargetDevicePixelRatio(float target_device_pixel_ra ImGui_ImplEmscripten_UpdateDisplayProperties(ImGui::GetIO(), bd); } +ImVec2 ImGui_ImplEmscripten_GetCssToImGuiScale() +{ + ImGui_ImplEmscripten_Data* bd = ImGui_ImplEmscripten_GetBackendData(); + IM_ASSERT(bd != nullptr && "Context or backend not initialized? Did you call ImGui_ImplEmscripten_Init()?"); + return bd != nullptr ? bd->CssToImGuiScale : ImVec2(1.0f, 1.0f); +} + void ImGui_ImplEmscripten_Shutdown() { ImGui_ImplEmscripten_Data* bd = ImGui_ImplEmscripten_GetBackendData(); diff --git a/backends/imgui_impl_emscripten.h b/backends/imgui_impl_emscripten.h index c81e867f3..357017517 100644 --- a/backends/imgui_impl_emscripten.h +++ b/backends/imgui_impl_emscripten.h @@ -47,6 +47,9 @@ IMGUI_IMPL_API bool ImGui_ImplEmscripten_Init(float target_device_pixel_ratio = // Change the target device pixel ratio at runtime and update display properties immediately. IMGUI_IMPL_API void ImGui_ImplEmscripten_SetTargetDevicePixelRatio(float target_device_pixel_ratio); +// Return the scale used to convert browser CSS pixel coordinates to Dear ImGui coordinates. Valid after Init(). +IMGUI_IMPL_API ImVec2 ImGui_ImplEmscripten_GetCssToImGuiScale(); + // Shut down the Emscripten backend. This unsets all Emscripten input callbacks set by Init. // Note it'll also unset any Emscripten input callbacks set elsewhere in the program! // Note also there is no obligation to ever call this, unless you intend to reset the backend (i.e. with ImGui::DestroyContext()).