Skip to content

Commit

Permalink
TestSuite: added "nav_focus_api_remote"
Browse files Browse the repository at this point in the history
Test for regression ocornut/imgui#7226
  • Loading branch information
ocornut committed Jan 15, 2024
1 parent 88d3691 commit 1fba964
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions imgui_test_suite/imgui_tests_inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,9 @@ void RegisterTests_Inputs(ImGuiTestEngine* e)
};

ImGui::Begin("WindowA");
#if IMGUI_VERSION_NUM >= 19012
ImGui::Text("Chord: %s", ImGui::GetKeyChordName(vars.KeyChord));
#endif
ImGui::Button("WindowA");
DoRoute('A');

Expand Down
42 changes: 42 additions & 0 deletions imgui_test_suite/imgui_tests_nav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2389,6 +2389,48 @@ void RegisterTests_Nav(ImGuiTestEngine* e)
};
#endif

#if IMGUI_VERSION_NUM < 19002 || IMGUI_VERSION_NUM >= 19012
// ## Test SetKeyboardFocusHere() accross windows (#7226)
t = IM_REGISTER_TEST(e, "nav", "nav_focus_api_remote");
t->GuiFunc = [](ImGuiTestContext* ctx)
{
int set_focus = -1;
ImGui::Begin("Test Window 1", NULL, ImGuiWindowFlags_NoSavedSettings);
if (ImGui::Button("Focus A")) { set_focus = 0; }
if (ImGui::Button("Focus B")) { set_focus = 1; }
ImGui::End();

ImGui::Begin("Test Window 2", NULL, ImGuiWindowFlags_NoSavedSettings);
if (ImGui::Button("Focus A")) { set_focus = 0; }
if (ImGui::Button("Focus B")) { set_focus = 1; }
ImGui::End();

char dummy[16];
ImGui::Begin("Test Window 1", NULL, ImGuiWindowFlags_NoSavedSettings);
if (set_focus == 0)
ImGui::SetKeyboardFocusHere();
ImGui::InputText("Item A", dummy, IM_ARRAYSIZE(dummy));
ImGui::End();
ImGui::Begin("Test Window 2", NULL, ImGuiWindowFlags_NoSavedSettings);
if (set_focus == 1)
ImGui::SetKeyboardFocusHere();
ImGui::InputText("Item B", dummy, IM_ARRAYSIZE(dummy));
ImGui::End();
};
t->TestFunc = [](ImGuiTestContext* ctx)
{
ImGuiContext& g = *ctx->UiContext;
ctx->ItemClick("//Test Window 1/Focus A");
IM_CHECK_EQ(g.ActiveId, ctx->GetID("//Test Window 1/Item A"));
ctx->ItemClick("//Test Window 1/Focus B");
IM_CHECK_EQ(g.ActiveId, ctx->GetID("//Test Window 2/Item B"));
ctx->ItemClick("//Test Window 2/Focus A");
IM_CHECK_EQ(g.ActiveId, ctx->GetID("//Test Window 1/Item A"));
ctx->ItemClick("//Test Window 2/Focus B");
IM_CHECK_EQ(g.ActiveId, ctx->GetID("//Test Window 2/Item B"));
};
#endif

// ## Test wrapping behavior
t = IM_REGISTER_TEST(e, "nav", "nav_wrapping");
struct NavWrappingWars { ImGuiNavMoveFlags WrapFlags = ImGuiNavMoveFlags_WrapY; bool UseButton = false; bool AltLayout = false; };
Expand Down

0 comments on commit 1fba964

Please sign in to comment.