Backends: SDL2/SDL3: Fixed IME text input rectangle position with viewports. (#6071, #1953)
diff --git a/backends/imgui_impl_sdl2.cpp b/backends/imgui_impl_sdl2.cpp
index 7928799..5e44f5a 100644
--- a/backends/imgui_impl_sdl2.cpp
+++ b/backends/imgui_impl_sdl2.cpp
@@ -156,13 +156,13 @@
}
// Note: native IME will only display if user calls SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1") _before_ SDL_CreateWindow().
-static void ImGui_ImplSDL2_SetPlatformImeData(ImGuiViewport*, ImGuiPlatformImeData* data)
+static void ImGui_ImplSDL2_SetPlatformImeData(ImGuiViewport* viewport, ImGuiPlatformImeData* data)
{
if (data->WantVisible)
{
SDL_Rect r;
- r.x = (int)data->InputPos.x;
- r.y = (int)data->InputPos.y;
+ r.x = (int)(data->InputPos.x - viewport->Pos.x);
+ r.y = (int)(data->InputPos.y - viewport->Pos.y + data->InputLineHeight);
r.w = 1;
r.h = (int)data->InputLineHeight;
SDL_SetTextInputRect(&r);
diff --git a/backends/imgui_impl_sdl3.cpp b/backends/imgui_impl_sdl3.cpp
index 64535e0..9f2fba4 100644
--- a/backends/imgui_impl_sdl3.cpp
+++ b/backends/imgui_impl_sdl3.cpp
@@ -97,13 +97,13 @@
SDL_SetClipboardText(text);
}
-static void ImGui_ImplSDL3_SetPlatformImeData(ImGuiViewport*, ImGuiPlatformImeData* data)
+static void ImGui_ImplSDL3_SetPlatformImeData(ImGuiViewport* viewport, ImGuiPlatformImeData* data)
{
if (data->WantVisible)
{
SDL_Rect r;
- r.x = (int)data->InputPos.x;
- r.y = (int)data->InputPos.y;
+ r.x = (int)(data->InputPos.x - viewport->Pos.x);
+ r.y = (int)(data->InputPos.y - viewport->Pos.y + data->InputLineHeight);
r.w = 1;
r.h = (int)data->InputLineHeight;
SDL_SetTextInputRect(&r);
diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt
index fad9f6b..c193260 100644
--- a/docs/CHANGELOG.txt
+++ b/docs/CHANGELOG.txt
@@ -163,6 +163,7 @@
- Docking: Fixed using GetItemXXX() or IsItemXXX() functions after a DockSpace(). (#6217)
- Backends: GLFW: Fixed key modifiers handling on secondary viewports. (#6248, #6034) [@aiekick]
- Backends: GLFW: Fixed Emscripten erroneously enabling multi-viewport support, leading to assert. (#5683)
+- Backends: SDL2/SDL3: Fixed IME text input rectangle position with viewports. (#6071, #1953)
- Backends: SDL3: Fixed for compilation with multi-viewports. (#6255) [@P3RK4N]