Nav: Maintaining a NavActivatePressedId field that widget can conveniently use along with NavActivateDownId.

This commit is contained in:
omar 2018-02-05 19:07:26 +01:00
parent fb7cf4a475
commit e5e3cc617e
2 changed files with 16 additions and 12 deletions

View File

@ -3042,28 +3042,31 @@ static void ImGui::NavUpdate()
} }
} }
g.NavActivateId = g.NavActivateDownId = g.NavInputId = 0; // Process manual activation request
if (g.NavId != 0 && !g.NavDisableHighlight && !g.NavWindowingTarget) g.NavActivateId = g.NavActivateDownId = g.NavActivatePressedId = g.NavInputId = 0;
if (g.NavId != 0 && !g.NavDisableHighlight && !g.NavWindowingTarget && g.NavWindow && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs))
{ {
if (g.ActiveId == 0 && IsNavInputPressed(ImGuiNavInput_PadActivate, ImGuiInputReadMode_Pressed)) bool activate_down = IsNavInputDown(ImGuiNavInput_PadActivate);
bool activate_pressed = activate_down && IsNavInputPressed(ImGuiNavInput_PadActivate, ImGuiInputReadMode_Pressed);
if (g.ActiveId == 0 && activate_pressed)
g.NavActivateId = g.NavId; g.NavActivateId = g.NavId;
if ((g.ActiveId == 0 || g.ActiveId == g.NavId) && IsNavInputDown(ImGuiNavInput_PadActivate)) if ((g.ActiveId == 0 || g.ActiveId == g.NavId) && activate_down)
g.NavActivateDownId = g.NavId; g.NavActivateDownId = g.NavId;
if ((g.ActiveId == 0 || g.ActiveId == g.NavId) && activate_pressed)
g.NavActivatePressedId = g.NavId;
if (g.ActiveId == 0 && IsNavInputPressed(ImGuiNavInput_PadInput, ImGuiInputReadMode_Pressed)) if (g.ActiveId == 0 && IsNavInputPressed(ImGuiNavInput_PadInput, ImGuiInputReadMode_Pressed))
g.NavInputId = g.NavId; g.NavInputId = g.NavId;
} }
if (g.NavWindow && (g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs)) if (g.NavWindow && (g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs))
{
g.NavActivateId = g.NavActivateDownId = g.NavInputId = 0;
g.NavDisableHighlight = true; g.NavDisableHighlight = true;
}
if (g.NavActivateId != 0) if (g.NavActivateId != 0)
IM_ASSERT(g.NavActivateDownId == g.NavActivateId); IM_ASSERT(g.NavActivateDownId == g.NavActivateId);
g.NavMoveRequest = false; g.NavMoveRequest = false;
// Process explicit activation request // Process programmatic activation request
if (g.NavNextActivateId != 0) if (g.NavNextActivateId != 0)
g.NavActivateId = g.NavActivateDownId = g.NavInputId = g.NavNextActivateId; g.NavActivateId = g.NavActivateDownId = g.NavActivatePressedId = g.NavInputId = g.NavNextActivateId;
g.NavNextActivateId = 0; g.NavNextActivateId = 0;
// Initiate directional inputs request // Initiate directional inputs request

View File

@ -608,8 +608,9 @@ struct ImGuiContext
// Navigation data (for gamepad/keyboard) // Navigation data (for gamepad/keyboard)
ImGuiWindow* NavWindow; // Focused window for navigation. Could be called 'FocusWindow' ImGuiWindow* NavWindow; // Focused window for navigation. Could be called 'FocusWindow'
ImGuiID NavId; // Focused item for navigation ImGuiID NavId; // Focused item for navigation
ImGuiID NavActivateId; // ~~ IsNavInputPressed(ImGuiNavInput_PadActivate) ? NavId : 0, also set when calling ActivateItem() ImGuiID NavActivateId; // ~~ (g.ActiveId == 0) && IsNavInputPressed(ImGuiNavInput_PadActivate) ? NavId : 0, also set when calling ActivateItem()
ImGuiID NavActivateDownId; // ~~ IsNavInputPressed(ImGuiNavInput_PadActivate) ? NavId : 0 ImGuiID NavActivateDownId; // ~~ IsNavInputDown(ImGuiNavInput_PadActivate) ? NavId : 0
ImGuiID NavActivatePressedId; // ~~ IsNavInputPressed(ImGuiNavInput_PadActivate) ? NavId : 0
ImGuiID NavInputId; // ~~ IsNavInputPressed(ImGuiNavInput_PadInput) ? NavId : 0 ImGuiID NavInputId; // ~~ IsNavInputPressed(ImGuiNavInput_PadInput) ? NavId : 0
ImGuiID NavJustTabbedId; // Just tabbed to this id. ImGuiID NavJustTabbedId; // Just tabbed to this id.
ImGuiID NavNextActivateId; // Set by ActivateItem(), queued until next frame ImGuiID NavNextActivateId; // Set by ActivateItem(), queued until next frame
@ -730,7 +731,7 @@ struct ImGuiContext
NextTreeNodeOpenCond = 0; NextTreeNodeOpenCond = 0;
NavWindow = NULL; NavWindow = NULL;
NavId = NavActivateId = NavActivateDownId = NavInputId = 0; NavId = NavActivateId = NavActivateDownId = NavActivatePressedId = NavInputId = 0;
NavJustTabbedId = NavJustMovedToId = NavNextActivateId = 0; NavJustTabbedId = NavJustMovedToId = NavNextActivateId = 0;
NavScoringRectScreen = ImRect(); NavScoringRectScreen = ImRect();
NavScoringCount = 0; NavScoringCount = 0;