diff --git a/imgui.cpp b/imgui.cpp index 021ddd5f..d37d3f02 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2368,6 +2368,7 @@ static void NavUpdate() g.NavWindowingTarget = g.NavWindow->RootNonPopupWindow; if (g.NavWindowingTarget) { + // Select window to focus // FIXME-NAVIGATION: Need to clarify input semantic, naming is misleading/incorrect here. int focus_change_dir = IsKeyPressedMap(ImGuiKey_NavTweakFaster, true) ? -1 : IsKeyPressedMap(ImGuiKey_NavTweakSlower, true) ? +1 : 0; if (focus_change_dir != 0 && !(g.NavWindowingTarget->Flags & ImGuiWindowFlags_Modal)) @@ -2379,16 +2380,13 @@ static void NavUpdate() i_current = i; int i_target = -1; for (int i = i_current+focus_change_dir; i >= 0 && i < g.Windows.Size && i_target == -1; i += focus_change_dir) - if (g.Windows[i]->Active && g.Windows[i] == g.Windows[i]->RootNonPopupWindow) + if (g.Windows[i]->IsNavigableTo()) i_target = i; for (int i = (focus_change_dir < 0) ? (g.Windows.Size-1) : 0; i >= 0 && i < g.Windows.Size && i_target == -1 && i_target != i_current; i += focus_change_dir) - if (g.Windows[i]->Active && g.Windows[i] == g.Windows[i]->RootNonPopupWindow) + if (g.Windows[i]->IsNavigableTo()) i_target = i; - if (i_target != -1) - { - IM_ASSERT(i_target != i_current); + if (i_target != -1 && i_target != i_current) // i_target might be == i_current in rare situation where we only have 1 navigable window g.NavWindowingTarget = g.Windows[i_target]; - } } // Apply actual focus only when leaving NavWindowing mode (until then the window was merely rendered front-most) diff --git a/imgui_internal.h b/imgui_internal.h index 7f6de494..084196dc 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -735,6 +735,7 @@ public: ImRect TitleBarRect() const { return ImRect(Pos, ImVec2(Pos.x + SizeFull.x, Pos.y + TitleBarHeight())); } float MenuBarHeight() const { return (Flags & ImGuiWindowFlags_MenuBar) ? CalcFontSize() + GImGui->Style.FramePadding.y * 2.0f : 0.0f; } ImRect MenuBarRect() const { float y1 = Pos.y + TitleBarHeight(); return ImRect(Pos.x, y1, Pos.x + SizeFull.x, y1 + MenuBarHeight()); } + bool IsNavigableTo() const { return Active && this == this->RootNonPopupWindow && (!(Flags & ImGuiWindowFlags_NoNav) || this == GImGui->FocusedWindow); } }; //-----------------------------------------------------------------------------