Skip to content

Commit

Permalink
Backends: SDL2: Implement SetPlatformImeDataFn. (ocornut#6071, ocornu…
Browse files Browse the repository at this point in the history
  • Loading branch information
imkzh authored and kjblanchard committed May 5, 2023
1 parent 37b0d1a commit b9d8de5
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions backends/imgui_impl_sdl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 0
#endif
#define SDL_HAS_VULKAN SDL_VERSION_ATLEAST(2,0,6)
#define SDL_HAS_SET_TEXT_INPUT_RECT SDL_VERSION_ATLEAST(2,0,0)

// SDL Data
struct ImGui_ImplSDL2_Data
Expand Down Expand Up @@ -336,6 +337,27 @@ bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event)
return false;
}

#if SDL_HAS_SET_TEXT_INPUT_RECT
static void ImGui_ImplSDL2_SetPlatformImeData(ImGuiViewport* viewport, ImGuiPlatformImeData* data)
{
(void)viewport;
if (data->WantVisible)
{
SDL_Rect r;
r.x = (int)data->InputPos.x;
r.y = (int)data->InputPos.y;
r.w = 1;
r.h = (int)data->InputLineHeight;
SDL_SetTextInputRect(&r);
SDL_StartTextInput();
}
else
{
SDL_StopTextInput();
}
}
#endif

static bool ImGui_ImplSDL2_Init(SDL_Window* window, SDL_Renderer* renderer)
{
ImGuiIO& io = ImGui::GetIO();
Expand Down Expand Up @@ -367,6 +389,10 @@ static bool ImGui_ImplSDL2_Init(SDL_Window* window, SDL_Renderer* renderer)
io.GetClipboardTextFn = ImGui_ImplSDL2_GetClipboardText;
io.ClipboardUserData = nullptr;

#if SDL_HAS_SET_TEXT_INPUT_RECT
io.SetPlatformImeDataFn = ImGui_ImplSDL2_SetPlatformImeData;
#endif

// Load mouse cursors
bd->MouseCursors[ImGuiMouseCursor_Arrow] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
bd->MouseCursors[ImGuiMouseCursor_TextInput] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM);
Expand Down

0 comments on commit b9d8de5

Please sign in to comment.