Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest SDL API breaks build - The text input state has been changed to be window-specific #7735

Closed
adrian-purser opened this issue Jun 24, 2024 · 2 comments
Labels

Comments

@adrian-purser
Copy link

Version/Branch of Dear ImGui:

Version 1.90.9, Branch: docking

Back-ends:

imgui_impl_SDL3 + imgui_impl_opengl3

Compiler, OS:

Linux GCC 14.1.1

Full config/build information:

Dear ImGui 1.90.9 WIP (19083)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=202002
define: __linux__
define: __GNUC__=14
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_sdl3
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000480
 DockingEnable
 ViewportsEnable
io.ConfigViewportsNoDecoration
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00001C0E
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 HasMouseHoveredViewport
 RendererHasVtxOffset
 RendererHasViewports
--------------------------------
io.Fonts: 8 fonts, Flags: 0x00000000, TexSize: 512,1024
io.DisplaySize: 1024.00,768.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 1.00,1.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 3.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Details:

Changes to SDL keyboard code cause the build to fail. The relevant SDL commit is -

The text input state has been changed to be window-specific.
SDL_StartTextInput(), SDL_StopTextInput(), SDL_TextInputActive(), SDL_ClearComposition(), and SDL_SetTextInputRect() all now take a window parameter.

This change also fixes IME candidate positioning when SDL_SetTextInputRect() is called before SDL_StartTextInput(), as is recommended in the documentation.

Apologies if I've posted this in the wrong place.
I don't know the correct way to get the window pointer but below is my best attempt which seems to have got me up and running in Linux.

static void ImGui_ImplSDL3_SetPlatformImeData(ImGuiViewport* viewport, ImGuiPlatformImeData* data)
{
    SDL_Window * p_window = (SDL_Window *)viewport->PlatformHandle;
    if (data->WantVisible)
    {
        SDL_Rect r;
        r.x = (int)(data->InputPos.x - viewport->Pos.x);
        r.y = (int)(data->InputPos.y - viewport->Pos.y + data->InputLineHeight);
        r.w = 1;
        r.h = (int)data->InputLineHeight;
        SDL_SetTextInputRect(p_window, &r);
        SDL_StartTextInput(p_window);
    }
    else
    {
        SDL_StopTextInput(p_window);
    }
}

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

#include <imgui_impl_sdl3.h>
@zmertens
Copy link

I followed your replacement code but used SDL_Window * p_window = (SDL_Window *)viewport->PlatformHandleRaw;, note the Raw addition to the code, and it compiled the SDL3 imgui example. I am running on Ubuntu 24.

@ocornut
Copy link
Owner

ocornut commented Jun 26, 2024

Fixed with 7c24769. Note some logic changes required to handle change of windows.
It required adding viewport->PlatformHandle to master.
using PlatformHandleRaw is incorrect, it would be e.g. a HWND on Windows.

I will merge into docking soon.

@ocornut ocornut closed this as completed Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants