Skip to content

add Platform IME Data Export#26

Open
KarryCharon wants to merge 1 commit intonurpax:mainfrom
KarryCharon:add-PlatformImeData-export
Open

add Platform IME Data Export#26
KarryCharon wants to merge 1 commit intonurpax:mainfrom
KarryCharon:add-PlatformImeData-export

Conversation

@KarryCharon
Copy link
Copy Markdown

Export the PlatformImeData struct into python.

  • This structure is useful for input method candidates box positoin sync.
  • Such as some input action occurs, but the input method candidates box will display at the right bottom of screen.
  • Via this one, we can do some position changing.

@nurpax
Copy link
Copy Markdown
Owner

nurpax commented Jan 8, 2026

Do you have some examples from other projects how this is used? I'm quite unfamiliar with this feature, and I'm a little wary exposing anything that I don't know their intended usage for. I couldn't find any examples of PlatformImeData in imgui's own codebase, other than in the backends.

I also had trouble accessing the Imgui context fields directly and refactored the code earlier to not access the fields to get the docking branch to build. This was the change: 5f9469b. I'm a little worried that those build problems would make a comeback, as there seems to be no official accessor function for getting the ImeData instance.

@KarryCharon
Copy link
Copy Markdown
Author

Do you have some examples from other projects how this is used? I'm quite unfamiliar with this feature, and I'm a little wary exposing anything that I don't know their intended usage for. I couldn't find any examples of PlatformImeData in imgui's own codebase, other than in the backends.

I also had trouble accessing the Imgui context fields directly and refactored the code earlier to not access the fields to get the docking branch to build. This was the change: 5f9469b. I'm a little worried that those build problems would make a comeback, as there seems to be no official accessor function for getting the ImeData instance.

Without IME compositing position sync, it would be like this:

20260109155241_rec_.mp4

But if we have some IME input text position info, we will got this:

20260109155627_rec_.mp4

@KarryCharon
Copy link
Copy Markdown
Author

There is also some official backend example for text input box sync: https://github.com/ocornut/imgui/blob/7b3ad4a282dc6f5007c49d35853e32f364e3e3d7/backends/imgui_impl_sdl3.cpp#L202

@nurpax
Copy link
Copy Markdown
Owner

nurpax commented Jan 11, 2026

Reading the imgui source code, it looks like the IME is accessed via a callback mechanism where Imgui calls a backend callback. For example, in the ImGui::EndFrame(), I see this code:

    // Notify Platform/OS when our Input Method Editor cursor has moved (e.g. CJK inputs using Microsoft IME)
    ImGuiPlatformImeData* ime_data = &g.PlatformImeData;
    if (g.PlatformIO.Platform_SetImeDataFn != NULL && memcmp(ime_data, &g.PlatformImeDataPrev, sizeof(ImGuiPlatformImeData)) != 0)
    {
        IMGUI_DEBUG_LOG_IO("[io] Calling Platform_SetImeDataFn(): WantVisible: %d, InputPos (%.2f,%.2f)\n", ime_data->WantVisible, ime_data->InputPos.x, ime_data->InputPos.y);
        IM_ASSERT(ime_data->ViewportId == IMGUI_VIEWPORT_DEFAULT_ID); // master branch
        ImGuiViewport* viewport = GetMainViewport();
        g.PlatformIO.Platform_SetImeDataFn(&g, viewport, ime_data);
    }
    g.WantTextInputNextFrame = ime_data->WantTextInput ? 1 : 0;

I think I'd prefer the backend interface in Python to use this standard approach instead of sneakily exposing some members of the context struct.

Bear with me, I think this feature can be added, but I want to be in alignment with how Imgui expects it to be done.

@KarryCharon
Copy link
Copy Markdown
Author

SetImeDataFn

Yes, you're right! haha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants