From 29a8ee0826e2de4f77368bedca248c5de10dc7dc Mon Sep 17 00:00:00 2001 From: actboy168 Date: Wed, 5 Jan 2022 13:20:54 +0100 Subject: [PATCH] Platform IME: add ImGuiPlatformImeData::WantVisible, hide IME when not used. (#2589) --- docs/CHANGELOG.txt | 1 + imgui.cpp | 3 +++ imgui.h | 3 +++ imgui_widgets.cpp | 3 +++ 4 files changed, 10 insertions(+) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 4c427303..9fb0e9cd 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -61,6 +61,7 @@ Other Changes: - Platform IME: changed io.ImeSetInputScreenPosFn() to io.SetPlatformImeDataFn() API, now taking a ImGuiPlatformImeData structure which we can more easily extend in the future. - Platform IME: moved io.ImeWindowHandle to GetMainViewport()->PlatformHandleRaw. +- Platform IME: add ImGuiPlatformImeData::WantVisible, hide IME composition window when not used. (#2589) [@actboy168] - Platform IME: [windows] call ImmSetCandidateWindow() to position candidate window. - Backends: OpenGL3: Fixed a buffer overflow in imgui_impl_opengl3_loader.h init (added in 1.86). (#4468, #4830) [@dymk] It would generally not have noticeable side-effect at runtime but would be detected by runtime checkers. diff --git a/imgui.cpp b/imgui.cpp index ebde53df..7a3f9f13 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4149,6 +4149,7 @@ void ImGui::NewFrame() // Platform IME data: reset for the frame g.PlatformImeDataPrev = g.PlatformImeData; + g.PlatformImeData.WantVisible = false; // Mouse wheel scrolling, scale UpdateMouseWheel(); @@ -11510,6 +11511,8 @@ static void SetPlatformImeDataFn_DefaultImpl(ImGuiViewport* viewport, ImGuiPlatf if (hwnd == 0) return; + ::ImmAssociateContextEx(hwnd, NULL, data->WantVisible ? IACE_DEFAULT : 0); + if (HIMC himc = ::ImmGetContext(hwnd)) { COMPOSITIONFORM composition_form = {}; diff --git a/imgui.h b/imgui.h index 4f7a5333..3279f5f0 100644 --- a/imgui.h +++ b/imgui.h @@ -2832,7 +2832,10 @@ struct ImGuiViewport // (Optional) Support for IME (Input Method Editor) via the io.SetPlatformImeDataFn() function. struct ImGuiPlatformImeData { + bool WantVisible; // A widget wants the IME to be visible ImVec2 InputPos; // Position of the input cursor + + ImGuiPlatformImeData() { memset(this, 0, sizeof(*this)); } }; //----------------------------------------------------------------------------- diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index eb464dcc..be7fe47a 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -4760,7 +4760,10 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ // Notify OS of text input position for advanced IME (-1 x offset so that Windows IME can cover our cursor. Bit of an extra nicety.) if (!is_readonly) + { + g.PlatformImeData.WantVisible = true; g.PlatformImeData.InputPos = ImVec2(cursor_screen_pos.x - 1.0f, cursor_screen_pos.y - g.FontSize); + } } } else