1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-11-12 02:00:58 +01:00

Nav: Comments, added enum to clarify NavForward code. (#787)

This commit is contained in:
omar 2018-01-29 17:35:36 +01:00
parent c8b9b2c6bd
commit 4654040bcb
2 changed files with 20 additions and 12 deletions

View File

@ -2896,12 +2896,12 @@ static void ImGui::NavUpdate()
}
// When a forwarded move request failed, we restore the highlight that we disabled during the forward frame
if (g.NavMoveRequestForwardStep == 2)
if (g.NavMoveRequestForward == ImGuiNavForward_ForwardResult)
{
IM_ASSERT(g.NavMoveRequest);
if (g.NavMoveResultId == 0)
g.NavDisableHighlight = false;
g.NavMoveRequestForwardStep = 0;
g.NavMoveRequestForward = ImGuiNavForward_None;
}
// Apply application mouse position movement, after we had a chance to process move request result.
@ -2993,7 +2993,7 @@ static void ImGui::NavUpdate()
// Initiate directional inputs request
const int allowed_dir_flags = (g.ActiveId == 0) ? ~0 : g.ActiveIdAllowNavDirFlags;
if (g.NavMoveRequestForwardStep == 0)
if (g.NavMoveRequestForward == ImGuiNavForward_None)
{
g.NavMoveDir = ImGuiDir_None;
if (g.NavWindow && !g.NavWindowingTarget && allowed_dir_flags && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs))
@ -3006,9 +3006,10 @@ static void ImGui::NavUpdate()
}
else
{
// Forwarding previous request (which has been modified, e.g. wrap around menus rewrite the requests with a starting rectangle at the other side of the window)
IM_ASSERT(g.NavMoveDir != ImGuiDir_None);
IM_ASSERT(g.NavMoveRequestForwardStep == 1);
g.NavMoveRequestForwardStep = 2;
IM_ASSERT(g.NavMoveRequestForward == ImGuiNavForward_Forwarding);
g.NavMoveRequestForward = ImGuiNavForward_ForwardResult;
}
if (g.NavMoveDir != ImGuiDir_None)
@ -4821,9 +4822,9 @@ static void NavProcessMoveRequestWrapAround(ImGuiWindow* window)
{
ImGuiContext& g = *GImGui;
if (g.NavMoveRequest && g.NavWindow == window && g.NavMoveResultId == 0)
if ((g.NavMoveDir == ImGuiDir_Up || g.NavMoveDir == ImGuiDir_Down) && g.NavMoveRequestForwardStep == 0 && g.NavLayer == 0)
if ((g.NavMoveDir == ImGuiDir_Up || g.NavMoveDir == ImGuiDir_Down) && g.NavMoveRequestForward == ImGuiNavForward_None && g.NavLayer == 0)
{
g.NavMoveRequestForwardStep = 1;
g.NavMoveRequestForward = ImGuiNavForward_Forwarding;
NavMoveRequestCancel();
g.NavWindow->NavRectRel[0].Min.y = g.NavWindow->NavRectRel[0].Max.y = ((g.NavMoveDir == ImGuiDir_Up) ? ImMax(window->SizeFull.y, window->SizeContents.y) : 0.0f) - window->Scroll.y;
}
@ -10860,7 +10861,7 @@ void ImGui::EndMenuBar()
ImGuiWindow* nav_earliest_child = g.NavWindow;
while (nav_earliest_child->ParentWindow && (nav_earliest_child->ParentWindow->Flags & ImGuiWindowFlags_ChildMenu))
nav_earliest_child = nav_earliest_child->ParentWindow;
if (nav_earliest_child->ParentWindow == window && nav_earliest_child->DC.ParentLayoutType == ImGuiLayoutType_Horizontal && g.NavMoveRequestForwardStep == 0)
if (nav_earliest_child->ParentWindow == window && nav_earliest_child->DC.ParentLayoutType == ImGuiLayoutType_Horizontal && g.NavMoveRequestForward == ImGuiNavForward_None)
{
// To do so we claim focus back, restore NavId and then process the movement request for yet another frame.
// This involve a one-frame delay which isn't very problematic in this situation. We could remove it by scoring in advance for multiple window (probably not worth the hassle/cost)
@ -10869,7 +10870,7 @@ void ImGui::EndMenuBar()
SetNavIDAndMoveMouse(window->NavLastIds[1], 1, window->NavRectRel[1]);
g.NavLayer = 1;
g.NavDisableHighlight = true; // Hide highlight for the current frame so we don't see the intermediary selection.
g.NavMoveRequestForwardStep = 1;
g.NavMoveRequestForward = ImGuiNavForward_Forwarding;
NavMoveRequestCancel();
}
}

View File

@ -292,6 +292,13 @@ enum ImGuiNavDirSourceFlags_
ImGuiNavDirSourceFlags_PadLStick = 1 << 2
};
enum ImGuiNavForward
{
ImGuiNavForward_None,
ImGuiNavForward_Forwarding,
ImGuiNavForward_ForwardResult
};
// 2D axis aligned bounding-box
// NB: we can't rely on ImVec2 math operators being available here
struct IMGUI_API ImRect
@ -610,11 +617,11 @@ struct ImGuiContext
bool NavInitResultExplicit; // Whether the result was explicitly requested with SetItemDefaultFocus()
bool NavMoveFromClampedRefRect; // Set by manual scrolling, if we scroll to a point where NavId isn't visible we reset navigation from visible items
bool NavMoveRequest; // Move request for this frame
int NavMoveRequestForwardStep; // 0: no forward, 1: forward request, 2: forward result (this is used to navigate sibling parent menus from a child menu)
ImGuiNavForward NavMoveRequestForward; // No forward / Forwarding / ForwardResult (this is used to navigate sibling parent menus from a child menu)
ImGuiDir NavMoveDir; // Direction of the move request (left/right/up/down)
ImGuiDir NavMoveDirLast; // Direction of the previous move request
ImGuiID NavMoveResultId; // Best move request candidate
ImGuiID NavMoveResultParentId; //
ImGuiID NavMoveResultParentId; // Best move request candidate window->IDStack.back() - to compare context
float NavMoveResultDistBox; // Best move request candidate box distance to current NavId
float NavMoveResultDistCenter; // Best move request candidate center distance to current NavId
float NavMoveResultDistAxial;
@ -729,7 +736,7 @@ struct ImGuiContext
NavInitResultExplicit = false;
NavMoveFromClampedRefRect = false;
NavMoveRequest = false;
NavMoveRequestForwardStep = 0;
NavMoveRequestForward = ImGuiNavForward_None;
NavMoveDir = NavMoveDirLast = ImGuiDir_None;
NavMoveResultId = 0;
NavMoveResultParentId = 0;