mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-22 23:56:36 +00:00
This commit is contained in:
parent
84eb2682b7
commit
8a6fd237f6
19
imgui.cpp
19
imgui.cpp
@ -7523,12 +7523,14 @@ static void ImGui::NavUpdate()
|
|||||||
#if 0
|
#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);
|
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
|
#endif
|
||||||
|
|
||||||
// Set input source as Gamepad when buttons are pressed before we map Keyboard (some features differs when used with Gamepad vs Keyboard)
|
// 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_keyboard_active = (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0;
|
||||||
bool nav_gamepad_active = (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (g.IO.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0;
|
bool nav_gamepad_active = (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (g.IO.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0;
|
||||||
if (nav_gamepad_active)
|
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)
|
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;
|
g.NavInputSource = ImGuiInputSource_NavGamepad;
|
||||||
|
|
||||||
// Update Keyboard->Nav inputs mapping
|
// Update Keyboard->Nav inputs mapping
|
||||||
if (nav_keyboard_active)
|
if (nav_keyboard_active)
|
||||||
{
|
{
|
||||||
@ -7548,6 +7550,7 @@ static void ImGui::NavUpdate()
|
|||||||
memcpy(g.IO.NavInputsDownDurationPrev, g.IO.NavInputsDownDuration, sizeof(g.IO.NavInputsDownDuration));
|
memcpy(g.IO.NavInputsDownDurationPrev, g.IO.NavInputsDownDuration, sizeof(g.IO.NavInputsDownDuration));
|
||||||
for (int i = 0; i < IM_ARRAYSIZE(g.IO.NavInputs); i++)
|
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;
|
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)
|
// Process navigation init request (select first/default focus)
|
||||||
if (g.NavInitResultId != 0 && (!g.NavDisableHighlight || g.NavInitRequestFromMove))
|
if (g.NavInitResultId != 0 && (!g.NavDisableHighlight || g.NavInitRequestFromMove))
|
||||||
{
|
{
|
||||||
@ -7563,9 +7566,11 @@ static void ImGui::NavUpdate()
|
|||||||
g.NavInitRequestFromMove = false;
|
g.NavInitRequestFromMove = false;
|
||||||
g.NavInitResultId = 0;
|
g.NavInitResultId = 0;
|
||||||
g.NavJustMovedToId = 0;
|
g.NavJustMovedToId = 0;
|
||||||
|
|
||||||
// Process navigation move request
|
// Process navigation move request
|
||||||
if (g.NavMoveRequest && (g.NavMoveResultLocal.ID != 0 || g.NavMoveResultOther.ID != 0))
|
if (g.NavMoveRequest && (g.NavMoveResultLocal.ID != 0 || g.NavMoveResultOther.ID != 0))
|
||||||
NavUpdateMoveResult();
|
NavUpdateMoveResult();
|
||||||
|
|
||||||
// When a forwarded move request failed, we restore the highlight that we disabled during the forward frame
|
// When a forwarded move request failed, we restore the highlight that we disabled during the forward frame
|
||||||
if (g.NavMoveRequestForward == ImGuiNavForward_ForwardActive)
|
if (g.NavMoveRequestForward == ImGuiNavForward_ForwardActive)
|
||||||
{
|
{
|
||||||
@ -7574,6 +7579,7 @@ static void ImGui::NavUpdate()
|
|||||||
g.NavDisableHighlight = false;
|
g.NavDisableHighlight = false;
|
||||||
g.NavMoveRequestForward = ImGuiNavForward_None;
|
g.NavMoveRequestForward = ImGuiNavForward_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply application mouse position movement, after we had a chance to process move request result.
|
// Apply application mouse position movement, after we had a chance to process move request result.
|
||||||
if (g.NavMousePosDirty && g.NavIdIsAlive)
|
if (g.NavMousePosDirty && g.NavIdIsAlive)
|
||||||
{
|
{
|
||||||
@ -7591,16 +7597,20 @@ static void ImGui::NavUpdate()
|
|||||||
g.NavIdIsAlive = false;
|
g.NavIdIsAlive = false;
|
||||||
g.NavJustTabbedId = 0;
|
g.NavJustTabbedId = 0;
|
||||||
IM_ASSERT(g.NavLayer == 0 || g.NavLayer == 1);
|
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
|
// 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)
|
if (g.NavWindow)
|
||||||
NavSaveLastChildNavWindow(g.NavWindow);
|
NavSaveLastChildNavWindow(g.NavWindow);
|
||||||
if (g.NavWindow && g.NavWindow->NavLastChildNavWindow != NULL && g.NavLayer == 0)
|
if (g.NavWindow && g.NavWindow->NavLastChildNavWindow != NULL && g.NavLayer == 0)
|
||||||
g.NavWindow->NavLastChildNavWindow = NULL;
|
g.NavWindow->NavLastChildNavWindow = NULL;
|
||||||
|
|
||||||
// Update CTRL+TAB and Windowing features (hold Square to move/resize/etc.)
|
// Update CTRL+TAB and Windowing features (hold Square to move/resize/etc.)
|
||||||
NavUpdateWindowing();
|
NavUpdateWindowing();
|
||||||
|
|
||||||
// Set output flags for user application
|
// Set output flags for user application
|
||||||
g.IO.NavActive = (nav_keyboard_active || nav_gamepad_active) && g.NavWindow && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs);
|
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;
|
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)
|
// Process NavCancel input (to close a popup, get back to parent, clear focus)
|
||||||
if (IsNavInputPressed(ImGuiNavInput_Cancel, ImGuiInputReadMode_Pressed))
|
if (IsNavInputPressed(ImGuiNavInput_Cancel, ImGuiInputReadMode_Pressed))
|
||||||
{
|
{
|
||||||
@ -7639,6 +7649,7 @@ static void ImGui::NavUpdate()
|
|||||||
g.NavId = 0;
|
g.NavId = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process manual activation request
|
// Process manual activation request
|
||||||
g.NavActivateId = g.NavActivateDownId = g.NavActivatePressedId = g.NavInputId = 0;
|
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.NavId != 0 && !g.NavDisableHighlight && !g.NavWindowingTarget && g.NavWindow && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs))
|
||||||
@ -7659,10 +7670,12 @@ static void ImGui::NavUpdate()
|
|||||||
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 programmatic activation request
|
// Process programmatic activation request
|
||||||
if (g.NavNextActivateId != 0)
|
if (g.NavNextActivateId != 0)
|
||||||
g.NavActivateId = g.NavActivateDownId = g.NavActivatePressedId = 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
|
||||||
const int allowed_dir_flags = (g.ActiveId == 0) ? ~0 : g.ActiveIdAllowNavDirFlags;
|
const int allowed_dir_flags = (g.ActiveId == 0) ? ~0 : g.ActiveIdAllowNavDirFlags;
|
||||||
if (g.NavMoveRequestForward == ImGuiNavForward_None)
|
if (g.NavMoveRequestForward == ImGuiNavForward_None)
|
||||||
@ -7686,10 +7699,12 @@ static void ImGui::NavUpdate()
|
|||||||
IM_ASSERT(g.NavMoveRequestForward == ImGuiNavForward_ForwardQueued);
|
IM_ASSERT(g.NavMoveRequestForward == ImGuiNavForward_ForwardQueued);
|
||||||
g.NavMoveRequestForward = ImGuiNavForward_ForwardActive;
|
g.NavMoveRequestForward = ImGuiNavForward_ForwardActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update PageUp/PageDown scroll
|
// Update PageUp/PageDown scroll
|
||||||
float nav_scoring_rect_offset_y = 0.0f;
|
float nav_scoring_rect_offset_y = 0.0f;
|
||||||
if (nav_keyboard_active)
|
if (nav_keyboard_active)
|
||||||
nav_scoring_rect_offset_y = NavUpdatePageUpPageDown(allowed_dir_flags);
|
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 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)
|
if (g.NavMoveDir != ImGuiDir_None)
|
||||||
{
|
{
|
||||||
@ -7703,6 +7718,7 @@ static void ImGui::NavUpdate()
|
|||||||
g.NavDisableHighlight = false;
|
g.NavDisableHighlight = false;
|
||||||
}
|
}
|
||||||
NavUpdateAnyRequestFlag();
|
NavUpdateAnyRequestFlag();
|
||||||
|
|
||||||
// Scrolling
|
// Scrolling
|
||||||
if (g.NavWindow && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs) && !g.NavWindowingTarget)
|
if (g.NavWindow && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs) && !g.NavWindowingTarget)
|
||||||
{
|
{
|
||||||
@ -7731,10 +7747,12 @@ static void ImGui::NavUpdate()
|
|||||||
g.NavMoveFromClampedRefRect = true;
|
g.NavMoveFromClampedRefRect = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset search results
|
// Reset search results
|
||||||
g.NavMoveResultLocal.Clear();
|
g.NavMoveResultLocal.Clear();
|
||||||
g.NavMoveResultLocalVisibleSet.Clear();
|
g.NavMoveResultLocalVisibleSet.Clear();
|
||||||
g.NavMoveResultOther.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
|
// 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)
|
if (g.NavMoveRequest && g.NavMoveFromClampedRefRect && g.NavLayer == 0)
|
||||||
{
|
{
|
||||||
@ -7749,6 +7767,7 @@ static void ImGui::NavUpdate()
|
|||||||
}
|
}
|
||||||
g.NavMoveFromClampedRefRect = false;
|
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)
|
// 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);
|
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();
|
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