Skip to content

Commit 29a8ee0

Browse files
actboy168ocornut
authored andcommitted
Platform IME: add ImGuiPlatformImeData::WantVisible, hide IME when not used. (ocornut#2589)
1 parent 1cbfe93 commit 29a8ee0

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

docs/CHANGELOG.txt

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Other Changes:
6161
- Platform IME: changed io.ImeSetInputScreenPosFn() to io.SetPlatformImeDataFn() API,
6262
now taking a ImGuiPlatformImeData structure which we can more easily extend in the future.
6363
- Platform IME: moved io.ImeWindowHandle to GetMainViewport()->PlatformHandleRaw.
64+
- Platform IME: add ImGuiPlatformImeData::WantVisible, hide IME composition window when not used. (#2589) [@actboy168]
6465
- Platform IME: [windows] call ImmSetCandidateWindow() to position candidate window.
6566
- Backends: OpenGL3: Fixed a buffer overflow in imgui_impl_opengl3_loader.h init (added in 1.86). (#4468, #4830) [@dymk]
6667
It would generally not have noticeable side-effect at runtime but would be detected by runtime checkers.

imgui.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -4149,6 +4149,7 @@ void ImGui::NewFrame()
41494149

41504150
// Platform IME data: reset for the frame
41514151
g.PlatformImeDataPrev = g.PlatformImeData;
4152+
g.PlatformImeData.WantVisible = false;
41524153

41534154
// Mouse wheel scrolling, scale
41544155
UpdateMouseWheel();
@@ -11510,6 +11511,8 @@ static void SetPlatformImeDataFn_DefaultImpl(ImGuiViewport* viewport, ImGuiPlatf
1151011511
if (hwnd == 0)
1151111512
return;
1151211513

11514+
::ImmAssociateContextEx(hwnd, NULL, data->WantVisible ? IACE_DEFAULT : 0);
11515+
1151311516
if (HIMC himc = ::ImmGetContext(hwnd))
1151411517
{
1151511518
COMPOSITIONFORM composition_form = {};

imgui.h

+3
Original file line numberDiff line numberDiff line change
@@ -2832,7 +2832,10 @@ struct ImGuiViewport
28322832
// (Optional) Support for IME (Input Method Editor) via the io.SetPlatformImeDataFn() function.
28332833
struct ImGuiPlatformImeData
28342834
{
2835+
bool WantVisible; // A widget wants the IME to be visible
28352836
ImVec2 InputPos; // Position of the input cursor
2837+
2838+
ImGuiPlatformImeData() { memset(this, 0, sizeof(*this)); }
28362839
};
28372840

28382841
//-----------------------------------------------------------------------------

imgui_widgets.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -4760,7 +4760,10 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
47604760

47614761
// 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.)
47624762
if (!is_readonly)
4763+
{
4764+
g.PlatformImeData.WantVisible = true;
47634765
g.PlatformImeData.InputPos = ImVec2(cursor_screen_pos.x - 1.0f, cursor_screen_pos.y - g.FontSize);
4766+
}
47644767
}
47654768
}
47664769
else

0 commit comments

Comments
 (0)