Nav: Tidying up. Comments. (#323)

This commit is contained in:
ocornut 2016-08-20 23:27:25 +02:00
parent 4f7c63a7af
commit 695ca7bb45
2 changed files with 26 additions and 25 deletions

View File

@ -2333,6 +2333,24 @@ int ImGui::GetFrameCount()
return GImGui->FrameCount; return GImGui->FrameCount;
} }
static void SetNavId(ImGuiID id)
{
ImGuiContext& g = *GImGui;
g.NavId = id;
if (g.NavLayer == 0)
g.NavWindow->NavLastId = g.NavId;
}
static void SetNavIdAndMoveMouse(ImGuiID id, const ImRect& rect_rel)
{
ImGuiContext& g = *GImGui;
SetNavId(id);
g.NavRefRectRel = rect_rel;
g.NavMousePosDirty = true;
g.NavDisableHighlight = false;
g.NavDisableMouseHover = true;
}
// This needs to be called before we submit any widget (aka in or before Begin) // This needs to be called before we submit any widget (aka in or before Begin)
static void NavInitWindow(ImGuiWindow* window, bool force_reinit) static void NavInitWindow(ImGuiWindow* window, bool force_reinit)
{ {
@ -2340,9 +2358,7 @@ static void NavInitWindow(ImGuiWindow* window, bool force_reinit)
IM_ASSERT(window == g.NavWindow); IM_ASSERT(window == g.NavWindow);
if (!(window->Flags & ImGuiWindowFlags_ChildWindow) || (window->Flags & ImGuiWindowFlags_Popup) || (window->NavLastId == 0) || force_reinit) if (!(window->Flags & ImGuiWindowFlags_ChildWindow) || (window->Flags & ImGuiWindowFlags_Popup) || (window->NavLastId == 0) || force_reinit)
{ {
g.NavId = 0; SetNavId(0);
if (g.NavLayer == 0)
window->NavLastId = 0;
g.NavInitDefaultRequest = true; g.NavInitDefaultRequest = true;
g.NavInitDefaultResultId = 0; g.NavInitDefaultResultId = 0;
g.NavInitDefaultResultExplicit = false; g.NavInitDefaultResultExplicit = false;
@ -2364,18 +2380,6 @@ static ImVec2 NavCalcPreferredMousePos()
return ImClamp(p, r.Min, r.Max); return ImClamp(p, r.Min, r.Max);
} }
static void SetNavIdAndMoveMouse(ImGuiID id, const ImRect& rect_rel)
{
ImGuiContext& g = *GImGui;
g.NavId = id;
if (g.NavLayer == 0)
g.NavWindow->NavLastId = g.NavId;
g.NavRefRectRel = rect_rel;
g.NavMousePosDirty = true;
g.NavDisableHighlight = false;
g.NavDisableMouseHover = true;
}
static int FindWindowIndex(ImGuiWindow* window) // FIXME-OPT O(N) static int FindWindowIndex(ImGuiWindow* window) // FIXME-OPT O(N)
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
@ -2461,12 +2465,10 @@ static void NavUpdate()
{ {
// Apply result from previous navigation init request (typically select the first item, unless SetItemDefaultFocus() has been called) // Apply result from previous navigation init request (typically select the first item, unless SetItemDefaultFocus() has been called)
IM_ASSERT(g.NavWindow); IM_ASSERT(g.NavWindow);
g.NavId = g.NavInitDefaultResultId; SetNavId(g.NavInitDefaultResultId);
g.NavRefRectRel = g.NavInitDefaultResultRectRel; g.NavRefRectRel = g.NavInitDefaultResultRectRel;
if (g.NavDisableMouseHover) if (g.NavDisableMouseHover)
g.NavMousePosDirty = true; g.NavMousePosDirty = true;
if (g.NavLayer == 0)
g.NavWindow->NavLastId = g.NavId;
} }
g.NavInitDefaultRequest = false; g.NavInitDefaultRequest = false;
g.NavInitDefaultResultExplicit = false; g.NavInitDefaultResultExplicit = false;
@ -2616,9 +2618,7 @@ static void NavUpdate()
ImGuiWindow* child_window = g.NavWindow; ImGuiWindow* child_window = g.NavWindow;
ImGuiWindow* parent_window = g.NavWindow->ParentWindow; ImGuiWindow* parent_window = g.NavWindow->ParentWindow;
ImGui::FocusWindow(parent_window); ImGui::FocusWindow(parent_window);
g.NavId = parent_window->GetChildID(child_window); SetNavId(parent_window->GetChildID(child_window));
if (g.NavLayer == 0)
parent_window->NavLastId = g.NavId;
g.NavIdIsAlive = false; g.NavIdIsAlive = false;
if (g.NavDisableMouseHover) if (g.NavDisableMouseHover)
g.NavMousePosDirty = true; g.NavMousePosDirty = true;
@ -9756,7 +9756,8 @@ bool ImGui::BeginMenu(const char* label, bool enabled)
if (!enabled) PopStyleColor(); if (!enabled) PopStyleColor();
} }
bool hovered = enabled && IsHovered(window->DC.LastItemRect, id); bool hovered = enabled && IsHovered(window->DC.LastItemRect, id); // FIXME: Why not using window->DC.LastItemHoveredAndUsable / IsItemHovered() ?
if (menuset_is_open) if (menuset_is_open)
g.NavWindow = backed_nav_window; g.NavWindow = backed_nav_window;
@ -10724,7 +10725,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
ImGui::Text("HoveredRootWindow: '%s'", g.HoveredRootWindow ? g.HoveredRootWindow->Name : "NULL"); ImGui::Text("HoveredRootWindow: '%s'", g.HoveredRootWindow ? g.HoveredRootWindow->Name : "NULL");
ImGui::Text("HoveredId: 0x%08X/0x%08X", g.HoveredId, g.HoveredIdPreviousFrame); // Data is "in-flight" so depending on when the Metrics window is called we may see current frame information or not ImGui::Text("HoveredId: 0x%08X/0x%08X", g.HoveredId, g.HoveredIdPreviousFrame); // Data is "in-flight" so depending on when the Metrics window is called we may see current frame information or not
ImGui::Text("ActiveId: 0x%08X/0x%08X, ActiveIdWindow: %s", g.ActiveId, g.ActiveIdPreviousFrame, g.ActiveIdWindow ? g.ActiveIdWindow->Name : "NULL"); ImGui::Text("ActiveId: 0x%08X/0x%08X, ActiveIdWindow: %s", g.ActiveId, g.ActiveIdPreviousFrame, g.ActiveIdWindow ? g.ActiveIdWindow->Name : "NULL");
ImGui::Text("NavWindow: '%s', NavId: 0x%08X", g.NavWindow ? g.NavWindow->Name : "NULL", g.NavId); ImGui::Text("NavWindow: '%s', NavId: 0x%08X, NavLayer: %d", g.NavWindow ? g.NavWindow->Name : "NULL", g.NavId, g.NavLayer);
ImGui::Text("NavRefRectRel: (%.1f,%.1f)(%.1f,%.1f)", g.NavRefRectRel.Min.x, g.NavRefRectRel.Min.y, g.NavRefRectRel.Max.x, g.NavRefRectRel.Max.y); ImGui::Text("NavRefRectRel: (%.1f,%.1f)(%.1f,%.1f)", g.NavRefRectRel.Min.x, g.NavRefRectRel.Min.y, g.NavRefRectRel.Max.x, g.NavRefRectRel.Max.y);
ImGui::Text("NavUsable: %d, NavActive: %d", g.IO.NavUsable, g.IO.NavActive); ImGui::Text("NavUsable: %d, NavActive: %d", g.IO.NavUsable, g.IO.NavActive);
ImGui::Text("NavDisableHighlight: %d, NavDisableMouseHover: %d", g.NavDisableHighlight, g.NavDisableMouseHover); ImGui::Text("NavDisableHighlight: %d, NavDisableMouseHover: %d", g.NavDisableHighlight, g.NavDisableMouseHover);

View File

@ -416,8 +416,8 @@ struct ImGuiContext
int NavIdTabCounter; // == NavWindow->DC.FocusIdxTabCounter at time of NavId processing int NavIdTabCounter; // == NavWindow->DC.FocusIdxTabCounter at time of NavId processing
bool NavIdIsAlive; // Nav widget has been seen this frame ~~ NavRefRectRel is valid bool NavIdIsAlive; // Nav widget has been seen this frame ~~ NavRefRectRel is valid
bool NavMousePosDirty; bool NavMousePosDirty;
bool NavDisableHighlight; // When user starts using mouse, we hide gamepad/keyboard functionalities bool NavDisableHighlight; // When user starts using mouse, we hide gamepad/keyboard highlight (nb: but they are still available, which is why NavDisableHighlight isn't always != NavDisableMouseHover)
bool NavDisableMouseHover; // When user starts using gamepad/keyboard, we disable mouse hovering until mouse is touched again bool NavDisableMouseHover; // When user starts using gamepad/keyboard, we hide mouse hovering highlight until mouse is touched again.
bool NavInitDefaultRequest; // Init request for appearing window to select first item bool NavInitDefaultRequest; // Init request for appearing window to select first item
ImGuiID NavInitDefaultResultId; ImGuiID NavInitDefaultResultId;
ImRect NavInitDefaultResultRectRel; ImRect NavInitDefaultResultRectRel;