Browse Source

Backends: SDL2/SDL3: Fixed IME text input rectangle position with viewports. (#6071, #1953)

ocornut 2 years ago
parent
commit
1668693bcf
3 changed files with 7 additions and 6 deletions
  1. 3 3
      backends/imgui_impl_sdl2.cpp
  2. 3 3
      backends/imgui_impl_sdl3.cpp
  3. 1 0
      docs/CHANGELOG.txt

+ 3 - 3
backends/imgui_impl_sdl2.cpp

@@ -156,13 +156,13 @@ static void ImGui_ImplSDL2_SetClipboardText(void*, const char* text)
 }
 
 // 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);

+ 3 - 3
backends/imgui_impl_sdl3.cpp

@@ -97,13 +97,13 @@ static void ImGui_ImplSDL3_SetClipboardText(void*, const char* text)
     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);

+ 1 - 0
docs/CHANGELOG.txt

@@ -163,6 +163,7 @@ Docking+Viewports Branch:
 - 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]