ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
58.37k stars 10k forks source link

SDL2 text input using Android onscreen keyboard #7636

Open claudeha opened 2 months ago

claudeha commented 2 months ago

Version/Branch of Dear ImGui:

Version 1.90.8 WIP 97a1111b

Back-ends:

imgui_impl_sdl2.cpp + imgui_impl_opengl3.cpp

Compiler, OS:

Android NDK 25.2 on Debian Bookworm x86_64 targetting Android 5 (tested on Android 7)

Full config/build information:

No response

Details:

My Issue/Question:

Text input stopped using Android on screen keyboard in a7703fe6. This was reverted for SDL3 in fab96a6e. Suggest also reverting for SDL2.

I tried this patch and it fixed it for me with SDL2 2.30.3:

diff --git a/backends/imgui_impl_sdl2.cpp b/backends/imgui_impl_sdl2.cpp
index 892fe905..c3f6a343 100644
--- a/backends/imgui_impl_sdl2.cpp
+++ b/backends/imgui_impl_sdl2.cpp
@@ -160,6 +160,11 @@ static void ImGui_ImplSDL2_SetPlatformImeData(ImGuiViewport*, ImGuiPlatformImeDa
         r.w = 1;
         r.h = (int)data->InputLineHeight;
         SDL_SetTextInputRect(&r);
+        SDL_StartTextInput();
+    }
+    else
+    {
+        SDL_StopTextInput();
     }
 }

Thanks, keep up the good work!

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

No response

ocornut commented 2 months ago

SDL text input model IMHO is desperately broken for desktop users. We needed a7703fe6f for a reason AFAIK.

I can't comprehend why their design make those calls required to receive text input. IMHO we should always receive inputs, and they can provide a call to request OSD keyboard. Another problem is how SDL messes with Windows IME, putting more burden on app/user code than WIndows IME would strictly require.