From 153454a0fb656a74f5790912986de71bcfe01b11 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 13 Mar 2015 12:28:23 +0000 Subject: [PATCH] Example console keeps focus on input box at all times --- imgui.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 9e102876..35b50820 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9478,7 +9478,7 @@ struct ExampleAppConsole ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0)); static ImGuiTextFilter filter; filter.Draw("Filter (\"incl,-excl\") (\"error\")", 180); - if (ImGui::IsItemHovered()) ImGui::SetKeyboardFocusHere(-1); // Auto focus on hover + //if (ImGui::IsItemHovered()) ImGui::SetKeyboardFocusHere(-1); // Auto focus on hover ImGui::PopStyleVar(); ImGui::Separator(); @@ -9516,7 +9516,9 @@ struct ExampleAppConsole strcpy(InputBuf, ""); } - if (ImGui::IsItemHovered()) ImGui::SetKeyboardFocusHere(-1); // Auto focus on hover + // Demonstrate keeping auto focus on the input box + if (ImGui::IsItemHovered() || (ImGui::IsRootWindowOrAnyChildFocused() && !ImGui::IsAnyItemActive() && !ImGui::IsMouseClicked(0))) + ImGui::SetKeyboardFocusHere(-1); // Auto focus ImGui::End(); }