Example console keeps focus on input box at all times

This commit is contained in:
ocornut 2015-03-13 12:28:23 +00:00
parent 1c1a55f6b1
commit 153454a0fb

View File

@ -9478,7 +9478,7 @@ struct ExampleAppConsole
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0)); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0));
static ImGuiTextFilter filter; static ImGuiTextFilter filter;
filter.Draw("Filter (\"incl,-excl\") (\"error\")", 180); 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::PopStyleVar();
ImGui::Separator(); ImGui::Separator();
@ -9516,7 +9516,9 @@ struct ExampleAppConsole
strcpy(InputBuf, ""); 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(); ImGui::End();
} }