1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-11-28 09:30:56 +01:00

Nav: Added NavJustNavigatedId internal info to record when we land on a given item after a navigation request, useful for various algorithms (currently looking at range selection stuff) (#787)

This commit is contained in:
omar 2017-10-03 11:22:38 -07:00
parent 491edfd8d8
commit 74da533c93
2 changed files with 8 additions and 5 deletions

View File

@ -1928,7 +1928,7 @@ void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window)
if (id) if (id)
{ {
g.ActiveIdIsAlive = true; g.ActiveIdIsAlive = true;
g.ActiveIdSource = (g.NavActivateId == id || g.NavInputId == id || g.NavTabbedId == id) ? ImGuiInputSource_Nav : ImGuiInputSource_Mouse; g.ActiveIdSource = (g.NavActivateId == id || g.NavInputId == id || g.NavJustTabbedId == id || g.NavJustNavigatedId == id) ? ImGuiInputSource_Nav : ImGuiInputSource_Mouse;
if (g.ActiveIdSource == ImGuiInputSource_Nav) if (g.ActiveIdSource == ImGuiInputSource_Nav)
g.NavDisableMouseHover = true; g.NavDisableMouseHover = true;
else else
@ -2318,7 +2318,7 @@ bool ImGui::FocusableItemRegister(ImGuiWindow* window, ImGuiID id, bool tab_stop
return true; return true;
if (allow_keyboard_focus && window->FocusIdxTabCounter == window->FocusIdxTabRequestCurrent) if (allow_keyboard_focus && window->FocusIdxTabCounter == window->FocusIdxTabRequestCurrent)
{ {
g.NavTabbedId = id; g.NavJustTabbedId = id;
return true; return true;
} }
@ -2592,6 +2592,7 @@ static void NavUpdate()
g.NavInitDefaultRequest = false; g.NavInitDefaultRequest = false;
g.NavInitDefaultResultExplicit = false; g.NavInitDefaultResultExplicit = false;
g.NavInitDefaultResultId = 0; g.NavInitDefaultResultId = 0;
g.NavJustNavigatedId = 0;
// Process navigation move request // Process navigation move request
if (g.NavMoveRequest && g.NavMoveResultId != 0) if (g.NavMoveRequest && g.NavMoveResultId != 0)
@ -2633,6 +2634,7 @@ static void NavUpdate()
// Apply result from previous frame navigation directional move request // Apply result from previous frame navigation directional move request
ImGui::ClearActiveID(); ImGui::ClearActiveID();
SetNavIdAndMoveMouse(g.NavMoveResultId, g.NavLayer, g.NavMoveResultRectRel); SetNavIdAndMoveMouse(g.NavMoveResultId, g.NavLayer, g.NavMoveResultRectRel);
g.NavJustNavigatedId = g.NavMoveResultId;
g.NavMoveFromClampedRefRect = false; g.NavMoveFromClampedRefRect = false;
} }
@ -2657,7 +2659,7 @@ static void NavUpdate()
g.NavMousePosDirty = false; g.NavMousePosDirty = false;
} }
g.NavIdIsAlive = false; g.NavIdIsAlive = false;
g.NavTabbedId = 0; g.NavJustTabbedId = 0;
// Navigation windowing mode (change focus, move/resize window) // Navigation windowing mode (change focus, move/resize window)
if (!g.NavWindowingTarget && IsNavInputPressed(ImGuiNavInput_PadMenu, ImGuiNavReadMode_Pressed)) if (!g.NavWindowingTarget && IsNavInputPressed(ImGuiNavInput_PadMenu, ImGuiNavReadMode_Pressed))

View File

@ -458,7 +458,8 @@ struct ImGuiContext
ImGuiWindow* NavWindow; // Nav/focused window for navigation ImGuiWindow* NavWindow; // Nav/focused window for navigation
ImGuiID NavId; // Nav/focused item for navigation ImGuiID NavId; // Nav/focused item for navigation
ImGuiID NavActivateId, NavInputId; // ~~ IsKeyPressedMap(ImGuiKey_NavActive) ? NavId : 0, etc. (to make widget code terser) ImGuiID NavActivateId, NavInputId; // ~~ IsKeyPressedMap(ImGuiKey_NavActive) ? NavId : 0, etc. (to make widget code terser)
ImGuiID NavTabbedId; // ImGuiID NavJustTabbedId; // Just tabbed to this id.
ImGuiID NavJustNavigatedId; // Just navigated to this id (result of a successfully MoveRequest)
ImRect NavScoringRectScreen; // Rectangle used for scoring, in screen space. Based of window->DC.NavRefRectRel[], modified for directional navigation scoring. ImRect NavScoringRectScreen; // Rectangle used for scoring, in screen space. Based of window->DC.NavRefRectRel[], modified for directional navigation scoring.
ImGuiWindow* NavWindowingTarget; ImGuiWindow* NavWindowingTarget;
float NavWindowingDisplayAlpha; float NavWindowingDisplayAlpha;
@ -571,7 +572,7 @@ struct ImGuiContext
SettingsDirtyTimer = 0.0f; SettingsDirtyTimer = 0.0f;
NavWindow = NULL; NavWindow = NULL;
NavId = NavActivateId = NavInputId = NavTabbedId = 0; NavId = NavActivateId = NavInputId = NavJustTabbedId = 0;
NavScoringRectScreen = ImRect(); NavScoringRectScreen = ImRect();
NavWindowingTarget = NULL; NavWindowingTarget = NULL;
NavWindowingDisplayAlpha = 0.0f; NavWindowingDisplayAlpha = 0.0f;