mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-18 14:16:36 +00:00
Refactor: Internals: Removing new lines from NavUpdate solely because I couldn't find another way to get a neat diff/patch when moving it. (part 4) (#2036, #787)
This commit is contained in:
parent
6bda59e5b7
commit
73052dc00c
31
imgui.cpp
31
imgui.cpp
@ -2966,19 +2966,15 @@ static void ImGui::NavUpdate()
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
g.IO.WantSetMousePos = false;
|
||||
|
||||
#if 0
|
||||
if (g.NavScoringCount > 0) printf("[%05d] NavScoringCount %d for '%s' layer %d (Init:%d, Move:%d)\n", g.FrameCount, g.NavScoringCount, g.NavWindow ? g.NavWindow->Name : "NULL", g.NavLayer, g.NavInitRequest || g.NavInitResultId != 0, g.NavMoveRequest);
|
||||
#endif
|
||||
|
||||
// Set input source as Gamepad when buttons are pressed before we map Keyboard (some features differs when used with Gamepad vs Keyboard)
|
||||
bool nav_keyboard_active = (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0;
|
||||
bool nav_gamepad_active = (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (g.IO.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0;
|
||||
|
||||
// Set input source as Gamepad when buttons are pressed before we map Keyboard (some features differs when used with Gamepad vs Keyboard)
|
||||
if (nav_gamepad_active)
|
||||
if (g.IO.NavInputs[ImGuiNavInput_Activate] > 0.0f || g.IO.NavInputs[ImGuiNavInput_Input] > 0.0f || g.IO.NavInputs[ImGuiNavInput_Cancel] > 0.0f || g.IO.NavInputs[ImGuiNavInput_Menu] > 0.0f)
|
||||
g.NavInputSource = ImGuiInputSource_NavGamepad;
|
||||
|
||||
// Update Keyboard->Nav inputs mapping
|
||||
if (nav_keyboard_active)
|
||||
{
|
||||
@ -2995,11 +2991,9 @@ static void ImGui::NavUpdate()
|
||||
if (g.IO.KeyAlt) g.IO.NavInputs[ImGuiNavInput_KeyMenu_] = 1.0f;
|
||||
#undef NAV_MAP_KEY
|
||||
}
|
||||
|
||||
memcpy(g.IO.NavInputsDownDurationPrev, g.IO.NavInputsDownDuration, sizeof(g.IO.NavInputsDownDuration));
|
||||
for (int i = 0; i < IM_ARRAYSIZE(g.IO.NavInputs); i++)
|
||||
g.IO.NavInputsDownDuration[i] = (g.IO.NavInputs[i] > 0.0f) ? (g.IO.NavInputsDownDuration[i] < 0.0f ? 0.0f : g.IO.NavInputsDownDuration[i] + g.IO.DeltaTime) : -1.0f;
|
||||
|
||||
// Process navigation init request (select first/default focus)
|
||||
if (g.NavInitResultId != 0 && (!g.NavDisableHighlight || g.NavInitRequestFromMove))
|
||||
{
|
||||
@ -3015,11 +3009,9 @@ static void ImGui::NavUpdate()
|
||||
g.NavInitRequestFromMove = false;
|
||||
g.NavInitResultId = 0;
|
||||
g.NavJustMovedToId = 0;
|
||||
|
||||
// Process navigation move request
|
||||
if (g.NavMoveRequest && (g.NavMoveResultLocal.ID != 0 || g.NavMoveResultOther.ID != 0))
|
||||
NavUpdateMoveResult();
|
||||
|
||||
// When a forwarded move request failed, we restore the highlight that we disabled during the forward frame
|
||||
if (g.NavMoveRequestForward == ImGuiNavForward_ForwardActive)
|
||||
{
|
||||
@ -3028,7 +3020,6 @@ static void ImGui::NavUpdate()
|
||||
g.NavDisableHighlight = false;
|
||||
g.NavMoveRequestForward = ImGuiNavForward_None;
|
||||
}
|
||||
|
||||
// Apply application mouse position movement, after we had a chance to process move request result.
|
||||
if (g.NavMousePosDirty && g.NavIdIsAlive)
|
||||
{
|
||||
@ -3046,19 +3037,16 @@ static void ImGui::NavUpdate()
|
||||
g.NavIdIsAlive = false;
|
||||
g.NavJustTabbedId = 0;
|
||||
IM_ASSERT(g.NavLayer == 0 || g.NavLayer == 1);
|
||||
|
||||
// Store our return window (for returning from Layer 1 to Layer 0) and clear it as soon as we step back in our own Layer 0
|
||||
if (g.NavWindow)
|
||||
NavSaveLastChildNavWindow(g.NavWindow);
|
||||
if (g.NavWindow && g.NavWindow->NavLastChildNavWindow != NULL && g.NavLayer == 0)
|
||||
g.NavWindow->NavLastChildNavWindow = NULL;
|
||||
|
||||
// Update CTRL+TAB and Windowing features (hold Square to move/resize/etc.)
|
||||
NavUpdateWindowing();
|
||||
|
||||
// Set output flags for user application
|
||||
g.IO.NavActive = (nav_keyboard_active || nav_gamepad_active) && g.NavWindow && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs);
|
||||
g.IO.NavVisible = (g.IO.NavActive && g.NavId != 0 && !g.NavDisableHighlight) || (g.NavWindowingTarget != NULL) || g.NavInitRequest;
|
||||
|
||||
// Process NavCancel input (to close a popup, get back to parent, clear focus)
|
||||
if (IsNavInputPressed(ImGuiNavInput_Cancel, ImGuiInputReadMode_Pressed))
|
||||
{
|
||||
@ -3097,7 +3085,6 @@ static void ImGui::NavUpdate()
|
||||
g.NavId = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Process manual activation request
|
||||
g.NavActivateId = g.NavActivateDownId = g.NavActivatePressedId = g.NavInputId = 0;
|
||||
if (g.NavId != 0 && !g.NavDisableHighlight && !g.NavWindowingTarget && g.NavWindow && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs))
|
||||
@ -3118,12 +3105,10 @@ static void ImGui::NavUpdate()
|
||||
if (g.NavActivateId != 0)
|
||||
IM_ASSERT(g.NavActivateDownId == g.NavActivateId);
|
||||
g.NavMoveRequest = false;
|
||||
|
||||
// Process programmatic activation request
|
||||
if (g.NavNextActivateId != 0)
|
||||
g.NavActivateId = g.NavActivateDownId = g.NavActivatePressedId = g.NavInputId = g.NavNextActivateId;
|
||||
g.NavNextActivateId = 0;
|
||||
|
||||
// Initiate directional inputs request
|
||||
const int allowed_dir_flags = (g.ActiveId == 0) ? ~0 : g.ActiveIdAllowNavDirFlags;
|
||||
if (g.NavMoveRequestForward == ImGuiNavForward_None)
|
||||
@ -3147,28 +3132,23 @@ static void ImGui::NavUpdate()
|
||||
IM_ASSERT(g.NavMoveRequestForward == ImGuiNavForward_ForwardQueued);
|
||||
g.NavMoveRequestForward = ImGuiNavForward_ForwardActive;
|
||||
}
|
||||
|
||||
// PageUp/PageDown scroll
|
||||
// Update PageUp/PageDown scroll
|
||||
float nav_scoring_rect_offset_y = 0.0f;
|
||||
if (nav_keyboard_active)
|
||||
nav_scoring_rect_offset_y = NavUpdatePageUpPageDown(allowed_dir_flags);
|
||||
|
||||
// If we initiate a movement request and have no current NavId, we initiate a InitDefautRequest that will be used as a fallback if the direction fails to find a match
|
||||
if (g.NavMoveDir != ImGuiDir_None)
|
||||
{
|
||||
g.NavMoveRequest = true;
|
||||
g.NavMoveDirLast = g.NavMoveDir;
|
||||
}
|
||||
|
||||
// If we initiate a movement request and have no current NavId, we initiate a InitDefautRequest that will be used as a fallback if the direction fails to find a match
|
||||
if (g.NavMoveRequest && g.NavId == 0)
|
||||
{
|
||||
g.NavInitRequest = g.NavInitRequestFromMove = true;
|
||||
g.NavInitResultId = 0;
|
||||
g.NavDisableHighlight = false;
|
||||
}
|
||||
|
||||
NavUpdateAnyRequestFlag();
|
||||
|
||||
// Scrolling
|
||||
if (g.NavWindow && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs) && !g.NavWindowingTarget)
|
||||
{
|
||||
@ -3197,12 +3177,10 @@ static void ImGui::NavUpdate()
|
||||
g.NavMoveFromClampedRefRect = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Reset search results
|
||||
g.NavMoveResultLocal.Clear();
|
||||
g.NavMoveResultLocalVisibleSet.Clear();
|
||||
g.NavMoveResultOther.Clear();
|
||||
|
||||
// When we have manually scrolled (without using navigation) and NavId becomes out of bounds, we project its bounding box to the visible area to restart navigation within visible items
|
||||
if (g.NavMoveRequest && g.NavMoveFromClampedRefRect && g.NavLayer == 0)
|
||||
{
|
||||
@ -3217,7 +3195,6 @@ static void ImGui::NavUpdate()
|
||||
}
|
||||
g.NavMoveFromClampedRefRect = false;
|
||||
}
|
||||
|
||||
// For scoring we use a single segment on the left side our current item bounding box (not touching the edge to avoid box overlap with zero-spaced items)
|
||||
ImRect nav_rect_rel = (g.NavWindow && !g.NavWindow->NavRectRel[g.NavLayer].IsInverted()) ? g.NavWindow->NavRectRel[g.NavLayer] : ImRect(0,0,0,0);
|
||||
g.NavScoringRectScreen = g.NavWindow ? ImRect(g.NavWindow->Pos + nav_rect_rel.Min, g.NavWindow->Pos + nav_rect_rel.Max) : GetViewportRect();
|
||||
|
Loading…
Reference in New Issue
Block a user