Navigation: Can nav-out but not nav-in a window with ImGuiWindowFlags_NoNav flag (#323)

This commit is contained in:
ocornut 2016-07-24 14:41:27 +02:00
parent 67feb5ac6c
commit 175f42420c
2 changed files with 5 additions and 6 deletions

View File

@ -2368,6 +2368,7 @@ static void NavUpdate()
g.NavWindowingTarget = g.NavWindow->RootNonPopupWindow; g.NavWindowingTarget = g.NavWindow->RootNonPopupWindow;
if (g.NavWindowingTarget) if (g.NavWindowingTarget)
{ {
// Select window to focus
// FIXME-NAVIGATION: Need to clarify input semantic, naming is misleading/incorrect here. // 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; 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)) if (focus_change_dir != 0 && !(g.NavWindowingTarget->Flags & ImGuiWindowFlags_Modal))
@ -2379,16 +2380,13 @@ static void NavUpdate()
i_current = i; i_current = i;
int i_target = -1; 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) 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; 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) 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; i_target = i;
if (i_target != -1) if (i_target != -1 && i_target != i_current) // i_target might be == i_current in rare situation where we only have 1 navigable window
{
IM_ASSERT(i_target != i_current);
g.NavWindowingTarget = g.Windows[i_target]; g.NavWindowingTarget = g.Windows[i_target];
}
} }
// Apply actual focus only when leaving NavWindowing mode (until then the window was merely rendered front-most) // Apply actual focus only when leaving NavWindowing mode (until then the window was merely rendered front-most)

View File

@ -735,6 +735,7 @@ public:
ImRect TitleBarRect() const { return ImRect(Pos, ImVec2(Pos.x + SizeFull.x, Pos.y + TitleBarHeight())); } 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; } 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()); } 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); }
}; };
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------