Browse Source

Platform IME: add ImGuiPlatformImeData::WantVisible, hide IME when not used. (#2589)

actboy168 3 years ago
parent
commit
29a8ee0826
4 changed files with 10 additions and 0 deletions
  1. 1 0
      docs/CHANGELOG.txt
  2. 3 0
      imgui.cpp
  3. 3 0
      imgui.h
  4. 3 0
      imgui_widgets.cpp

+ 1 - 0
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.

+ 3 - 0
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 = {};

+ 3 - 0
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)); }
 };
 
 //-----------------------------------------------------------------------------

+ 3 - 0
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