Skip to content

Commit

Permalink
TestSuite: added "nav_ctrl_tab_customization", "nav_ctrl_tab_disabled"
Browse files Browse the repository at this point in the history
Also adds test for ensuring Ctrl+Shift+Tab works in the typical case.
Functional test for ocornut/imgui#4828
  • Loading branch information
PathogenDavid committed Mar 21, 2023
1 parent e2b98e4 commit b39594b
Showing 1 changed file with 113 additions and 0 deletions.
113 changes: 113 additions & 0 deletions imgui_test_suite/imgui_tests_nav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,18 @@ void RegisterTests_Nav(ImGuiTestEngine* e)
ctx->KeyUp(ImGuiMod_Ctrl);
IM_CHECK(g.NavWindow == ctx->GetWindowByRef("Window 2"));

// Test previous windowing key combo with UI
ctx->KeyDown(ImGuiMod_Ctrl);
ctx->KeyPress(ImGuiKey_Tab);
ctx->SleepNoSkip(0.5f, 0.1f);
IM_CHECK(g.NavWindowingTarget == ctx->GetWindowByRef("Window 1"));
IM_CHECK(g.NavWindowingTarget->SkipItems == false);
ctx->KeyPress(ImGuiMod_Shift | ImGuiKey_Tab);
IM_CHECK(g.NavWindowingTarget == ctx->GetWindowByRef("Window 2"));
IM_CHECK(g.NavWindowingTarget->SkipItems == false);
ctx->KeyUp(ImGuiMod_Ctrl);
IM_CHECK(g.NavWindow == ctx->GetWindowByRef("Window 2"));

// Set up window focus order, focus child window.
ctx->WindowFocus("Window 1");
ctx->WindowFocus("Window 2"); // FIXME: Needed for case when docked
Expand Down Expand Up @@ -648,6 +660,107 @@ void RegisterTests_Nav(ImGuiTestEngine* e)
ctx->Sleep(1.0f);
};

#if IMGUI_VERSION_NUM >= 18837
// ## Test CTRL+TAB customization (#4828)
t = IM_REGISTER_TEST(e, "nav", "nav_ctrl_tab_customization");
t->GuiFunc = [](ImGuiTestContext* ctx)
{
ImGui::Begin("Window 1", NULL, ImGuiWindowFlags_NoSavedSettings);
ImGui::TextUnformatted("Oh dear");
ImGui::End();

ImGui::Begin("Window 2", NULL, ImGuiWindowFlags_NoSavedSettings);
ImGui::TextUnformatted("Oh dear");
ImGui::End();
};
t->TestFunc = [](ImGuiTestContext* ctx)
{
ImGuiContext& g = *ctx->UiContext;

// Configure custom windowing key combinations
g.ConfigNavWindowingKeyNext = ImGuiMod_Alt | ImGuiKey_N;
g.ConfigNavWindowingKeyPrev = ImGuiMod_Alt | ImGuiKey_P;

// Set up window focus order.
ctx->WindowFocus("Window 1");
ctx->WindowFocus("Window 2");

// Press default windowing keys and ensure window focus is unchanged
ctx->KeyPress(ImGuiMod_Ctrl | ImGuiKey_Tab);
IM_CHECK(g.NavWindow == ctx->GetWindowByRef("Window 2"));

ctx->KeyPress(ImGuiMod_Ctrl | ImGuiMod_Shift | ImGuiKey_Tab);
IM_CHECK(g.NavWindow == ctx->GetWindowByRef("Window 2"));

// Press custom windowing key and ensure focus changed
ctx->KeyPress(ImGuiMod_Alt | ImGuiKey_N);
IM_CHECK(g.NavWindow == ctx->GetWindowByRef("Window 1"));

// Intentionally perform a "SLOW" windowing key combo to make sure the UI appears!
ctx->KeyDown(ImGuiMod_Alt);
ctx->KeyPress(ImGuiKey_N);
ctx->SleepNoSkip(0.5f, 0.1f);
IM_CHECK(g.NavWindowingTarget == ctx->GetWindowByRef("Window 2"));
IM_CHECK(g.NavWindowingTarget->SkipItems == false);
ctx->KeyUp(ImGuiMod_Alt);
IM_CHECK(g.NavWindow == ctx->GetWindowByRef("Window 2"));

// Test previous windowing key combo with UI
ctx->KeyDown(ImGuiMod_Alt);
ctx->KeyPress(ImGuiKey_N);
ctx->SleepNoSkip(0.5f, 0.1f);
IM_CHECK(g.NavWindowingTarget == ctx->GetWindowByRef("Window 1"));
IM_CHECK(g.NavWindowingTarget->SkipItems == false);
ctx->KeyPress(ImGuiKey_P);
IM_CHECK(g.NavWindowingTarget == ctx->GetWindowByRef("Window 2"));
IM_CHECK(g.NavWindowingTarget->SkipItems == false);
ctx->KeyUp(ImGuiMod_Alt);
IM_CHECK(g.NavWindow == ctx->GetWindowByRef("Window 2"));

// Restore configuration
g.ConfigNavWindowingKeyNext = ImGuiMod_Ctrl | ImGuiKey_Tab;
g.ConfigNavWindowingKeyPrev = ImGuiMod_Ctrl | ImGuiMod_Shift | ImGuiKey_Tab;
};
#endif

#if IMGUI_VERSION_NUM >= 18837
// ## Test CTRL+TAB disabled (#4828)
t = IM_REGISTER_TEST(e, "nav", "nav_ctrl_tab_disabled");
t->GuiFunc = [](ImGuiTestContext* ctx)
{
ImGui::Begin("Window 1", NULL, ImGuiWindowFlags_NoSavedSettings);
ImGui::TextUnformatted("Oh dear");
ImGui::End();

ImGui::Begin("Window 2", NULL, ImGuiWindowFlags_NoSavedSettings);
ImGui::TextUnformatted("Oh dear");
ImGui::End();
};
t->TestFunc = [](ImGuiTestContext* ctx)
{
ImGuiContext& g = *ctx->UiContext;

// Disable windowing key combinations
g.ConfigNavWindowingKeyNext = 0;
g.ConfigNavWindowingKeyPrev = 0;

// Set up window focus order.
ctx->WindowFocus("Window 1");
ctx->WindowFocus("Window 2");

// Press Ctrl+Tab and Ctrl+Shift+Tab and ensure window focus is unchanged
ctx->KeyPress(ImGuiMod_Ctrl | ImGuiKey_Tab);
IM_CHECK(g.NavWindow == ctx->GetWindowByRef("Window 2"));

ctx->KeyPress(ImGuiMod_Ctrl | ImGuiMod_Shift | ImGuiKey_Tab);
IM_CHECK(g.NavWindow == ctx->GetWindowByRef("Window 2"));

// Restore configuration
g.ConfigNavWindowingKeyNext = ImGuiMod_Ctrl | ImGuiKey_Tab;
g.ConfigNavWindowingKeyPrev = ImGuiMod_Ctrl | ImGuiMod_Shift | ImGuiKey_Tab;
};
#endif

// ## Test remote ActivateItem()
t = IM_REGISTER_TEST(e, "nav", "nav_activate");
t->GuiFunc = [](ImGuiTestContext* ctx)
Expand Down

0 comments on commit b39594b

Please sign in to comment.