Closed
Description
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();
Activity