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

This commit is contained in:
actboy168 2022-01-05 13:20:54 +01:00 committed by ocornut
parent 1cbfe93520
commit 29a8ee0826
4 changed files with 10 additions and 0 deletions

View File

@ -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.

View File

@ -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 = {};

View File

@ -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)); }
};
//-----------------------------------------------------------------------------

View File

@ -4760,9 +4760,12 @@ 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
{
// Render text only (no selection, no cursor)