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

SetKeyboardFocusHere(-1) not working as expected with InputTextMultiline #7870

Closed
SimonMaracine opened this issue Aug 7, 2024 · 1 comment

Comments

@SimonMaracine
Copy link

SimonMaracine commented Aug 7, 2024

Version/Branch of Dear ImGui:

Version 1.91.1 WIP and 1.90.4, Branch: docking and master

Back-ends:

imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp

Compiler, OS:

Linux + GCC

Full config/build information:

No response

Details:

My Issue/Question:

As per issue 4761, SetKeyboardFocusHere looks like it doesn't work correctly with InputTextMultiline:

static char buffer[16];
bool reclaim_focus {false};
const auto flags {ImGuiInputTextFlags_CtrlEnterForNewLine | ImGuiInputTextFlags_EnterReturnsTrue};

if (ImGui::InputTextMultiline("##", buffer, sizeof(buffer), {}, flags)) {
    reclaim_focus = true;
}

if (reclaim_focus) {
    ImGui::SetKeyboardFocusHere(-1);
}

Pressing enter still makes the input text box loose focus.

But with InputText it works:

static char buffer[16];
bool reclaim_focus {false};
const auto flags {ImGuiInputTextFlags_CtrlEnterForNewLine | ImGuiInputTextFlags_EnterReturnsTrue};

if (ImGui::InputText("##", buffer, sizeof(buffer), flags)) {
    reclaim_focus = true;
}

if (reclaim_focus) {
    ImGui::SetKeyboardFocusHere(-1);
}

It looks like resetting the focus every frame works (sets the focus), but it's undesirable:

static char buffer[16];
const auto flags {ImGuiInputTextFlags_CtrlEnterForNewLine | ImGuiInputTextFlags_EnterReturnsTrue};

ImGui::InputTextMultiline("##", buffer, sizeof(buffer), flags);

ImGui::SetKeyboardFocusHere(-1);

Screenshots/Video:

2024-08-07_22-19-55.mp4

Minimal, Complete and Verifiable Example code:

// Here's some code anyone can copy and paste to reproduce your issue
ImGui::Begin("Example Bug");
// Sorry, the code snippets are above
ImGui::End();
@ocornut
Copy link
Owner

ocornut commented Aug 21, 2024

Fixed again 521f84a + extra test ocornut/imgui_test_engine@633988e

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

No branches or pull requests

2 participants