mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-22 11:57:00 +00:00
Nav: always disable highlight if nav is disabled, fix for IMGUI_DEBUG_NAV_SCORING, minor renaming.
This commit is contained in:
parent
dff15acdb5
commit
5ee40c8d34
33
imgui.cpp
33
imgui.cpp
@ -3685,13 +3685,15 @@ static void ImGui::UpdateMouseInputs()
|
|||||||
|
|
||||||
// Round mouse position to avoid spreading non-rounded position (e.g. UpdateManualResize doesn't support them well)
|
// Round mouse position to avoid spreading non-rounded position (e.g. UpdateManualResize doesn't support them well)
|
||||||
if (IsMousePosValid(&g.IO.MousePos))
|
if (IsMousePosValid(&g.IO.MousePos))
|
||||||
g.IO.MousePos = g.LastValidMousePos = ImFloor(g.IO.MousePos);
|
g.IO.MousePos = g.MouseLastValidPos = ImFloor(g.IO.MousePos);
|
||||||
|
|
||||||
// If mouse just appeared or disappeared (usually denoted by -FLT_MAX components) we cancel out movement in MouseDelta
|
// If mouse just appeared or disappeared (usually denoted by -FLT_MAX components) we cancel out movement in MouseDelta
|
||||||
if (IsMousePosValid(&g.IO.MousePos) && IsMousePosValid(&g.IO.MousePosPrev))
|
if (IsMousePosValid(&g.IO.MousePos) && IsMousePosValid(&g.IO.MousePosPrev))
|
||||||
g.IO.MouseDelta = g.IO.MousePos - g.IO.MousePosPrev;
|
g.IO.MouseDelta = g.IO.MousePos - g.IO.MousePosPrev;
|
||||||
else
|
else
|
||||||
g.IO.MouseDelta = ImVec2(0.0f, 0.0f);
|
g.IO.MouseDelta = ImVec2(0.0f, 0.0f);
|
||||||
|
|
||||||
|
// If mouse moved we re-enable mouse hovering in case it was disabled by gamepad/keyboard. In theory should use a >0.0f threshold but would need to reset in everywhere we set this to true.
|
||||||
if (g.IO.MouseDelta.x != 0.0f || g.IO.MouseDelta.y != 0.0f)
|
if (g.IO.MouseDelta.x != 0.0f || g.IO.MouseDelta.y != 0.0f)
|
||||||
g.NavDisableMouseHover = false;
|
g.NavDisableMouseHover = false;
|
||||||
|
|
||||||
@ -8762,7 +8764,7 @@ static bool ImGui::NavScoreItem(ImGuiNavItemData* result)
|
|||||||
// FIXME: Those are not good variables names
|
// FIXME: Those are not good variables names
|
||||||
ImRect cand = g.LastItemData.NavRect; // Current item nav rectangle
|
ImRect cand = g.LastItemData.NavRect; // Current item nav rectangle
|
||||||
const ImRect curr = g.NavScoringRect; // Current modified source rect (NB: we've applied Max.x = Min.x in NavUpdate() to inhibit the effect of having varied item width)
|
const ImRect curr = g.NavScoringRect; // Current modified source rect (NB: we've applied Max.x = Min.x in NavUpdate() to inhibit the effect of having varied item width)
|
||||||
g.NavScoringCount++;
|
g.NavScoringDebugCount++;
|
||||||
|
|
||||||
// When entering through a NavFlattened border, we consider child window items as fully clipped for scoring
|
// When entering through a NavFlattened border, we consider child window items as fully clipped for scoring
|
||||||
if (window->ParentWindow == g.NavWindow)
|
if (window->ParentWindow == g.NavWindow)
|
||||||
@ -8929,14 +8931,7 @@ static void ImGui::NavProcessItem()
|
|||||||
if ((g.NavId != id || (g.NavMoveFlags & ImGuiNavMoveFlags_AllowCurrentNavId)) && !(item_flags & (ImGuiItemFlags_Disabled | ImGuiItemFlags_NoNav)))
|
if ((g.NavId != id || (g.NavMoveFlags & ImGuiNavMoveFlags_AllowCurrentNavId)) && !(item_flags & (ImGuiItemFlags_Disabled | ImGuiItemFlags_NoNav)))
|
||||||
{
|
{
|
||||||
ImGuiNavItemData* result = (window == g.NavWindow) ? &g.NavMoveResultLocal : &g.NavMoveResultOther;
|
ImGuiNavItemData* result = (window == g.NavWindow) ? &g.NavMoveResultLocal : &g.NavMoveResultOther;
|
||||||
bool new_best = NavScoreItem(result);
|
if (NavScoreItem(result))
|
||||||
|
|
||||||
#if IMGUI_DEBUG_NAV_SCORING
|
|
||||||
// [DEBUG] Scoring all items in NavWindow at all times
|
|
||||||
if (g.NavMoveFlags & ImGuiNavMoveFlags_DebugNoResult)
|
|
||||||
new_best = false;
|
|
||||||
#endif
|
|
||||||
if (new_best)
|
|
||||||
NavApplyItemToResult(result);
|
NavApplyItemToResult(result);
|
||||||
|
|
||||||
// Features like PageUp/PageDown need to maintain a separate score for the visible set of items.
|
// Features like PageUp/PageDown need to maintain a separate score for the visible set of items.
|
||||||
@ -8972,6 +8967,7 @@ void ImGui::NavMoveRequestSubmit(ImGuiDir move_dir, ImGuiDir clip_dir, ImGuiNavM
|
|||||||
IM_ASSERT(g.NavWindow != NULL);
|
IM_ASSERT(g.NavWindow != NULL);
|
||||||
g.NavMoveSubmitted = g.NavMoveScoringItems = true;
|
g.NavMoveSubmitted = g.NavMoveScoringItems = true;
|
||||||
g.NavMoveDir = move_dir;
|
g.NavMoveDir = move_dir;
|
||||||
|
g.NavMoveDirForDebug = move_dir;
|
||||||
g.NavMoveClipDir = clip_dir;
|
g.NavMoveClipDir = clip_dir;
|
||||||
g.NavMoveFlags = move_flags;
|
g.NavMoveFlags = move_flags;
|
||||||
g.NavMoveForwardToNextFrame = false;
|
g.NavMoveForwardToNextFrame = false;
|
||||||
@ -9098,7 +9094,7 @@ static ImVec2 ImGui::NavCalcPreferredRefPos()
|
|||||||
// Mouse (we need a fallback in case the mouse becomes invalid after being used)
|
// Mouse (we need a fallback in case the mouse becomes invalid after being used)
|
||||||
if (IsMousePosValid(&g.IO.MousePos))
|
if (IsMousePosValid(&g.IO.MousePos))
|
||||||
return g.IO.MousePos;
|
return g.IO.MousePos;
|
||||||
return g.LastValidMousePos;
|
return g.MouseLastValidPos;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -9155,7 +9151,7 @@ static void ImGui::NavUpdate()
|
|||||||
|
|
||||||
io.WantSetMousePos = false;
|
io.WantSetMousePos = false;
|
||||||
#if 0
|
#if 0
|
||||||
if (g.NavScoringCount > 0) IMGUI_DEBUG_LOG("NavScoringCount %d for '%s' layer %d (Init:%d, Move:%d)\n", g.NavScoringCount, g.NavWindow ? g.NavWindow->Name : "NULL", g.NavLayer, g.NavInitRequest || g.NavInitResultId != 0, g.NavMoveRequest);
|
if (g.NavScoringDebugCount > 0) IMGUI_DEBUG_LOG("NavScoringDebugCount %d for '%s' layer %d (Init:%d, Move:%d)\n", g.NavScoringDebugCount, 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 (as some features differs when used with Gamepad vs Keyboard)
|
// Set input source as Gamepad when buttons are pressed (as some features differs when used with Gamepad vs Keyboard)
|
||||||
@ -9289,8 +9285,15 @@ static void ImGui::NavUpdate()
|
|||||||
SetScrollY(window, ImFloor(window->Scroll.y + scroll_dir.y * scroll_speed));
|
SetScrollY(window, ImFloor(window->Scroll.y + scroll_dir.y * scroll_speed));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Always prioritize mouse highlight if navigation is disabled
|
||||||
|
if (!nav_keyboard_active && !nav_gamepad_active)
|
||||||
|
{
|
||||||
|
g.NavDisableHighlight = true;
|
||||||
|
g.NavDisableMouseHover = g.NavMousePosDirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
// [DEBUG]
|
// [DEBUG]
|
||||||
g.NavScoringCount = 0;
|
g.NavScoringDebugCount = 0;
|
||||||
#if IMGUI_DEBUG_NAV_RECTS
|
#if IMGUI_DEBUG_NAV_RECTS
|
||||||
if (g.NavWindow)
|
if (g.NavWindow)
|
||||||
{
|
{
|
||||||
@ -9417,6 +9420,10 @@ void ImGui::NavUpdateCreateMoveRequest()
|
|||||||
void ImGui::NavMoveRequestApplyResult()
|
void ImGui::NavMoveRequestApplyResult()
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
|
#if IMGUI_DEBUG_NAV_SCORING
|
||||||
|
if (g.NavMoveFlags & ImGuiNavMoveFlags_DebugNoResult) // [DEBUG] Scoring all items in NavWindow at all times
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
// No result
|
// No result
|
||||||
// In a situation when there is no results but NavId != 0, re-enable the Navigation highlight (because g.NavId is not considered as a possible result)
|
// In a situation when there is no results but NavId != 0, re-enable the Navigation highlight (because g.NavId is not considered as a possible result)
|
||||||
|
@ -1527,7 +1527,7 @@ struct ImGuiContext
|
|||||||
ImGuiDir NavMoveDirForDebug;
|
ImGuiDir NavMoveDirForDebug;
|
||||||
ImGuiDir NavMoveClipDir; // FIXME-NAV: Describe the purpose of this better. Might want to rename?
|
ImGuiDir NavMoveClipDir; // FIXME-NAV: Describe the purpose of this better. Might want to rename?
|
||||||
ImRect NavScoringRect; // Rectangle used for scoring, in screen space. Based of window->NavRectRel[], modified for directional navigation scoring.
|
ImRect NavScoringRect; // Rectangle used for scoring, in screen space. Based of window->NavRectRel[], modified for directional navigation scoring.
|
||||||
int NavScoringCount; // Metrics for debugging
|
int NavScoringDebugCount; // Metrics for debugging
|
||||||
ImGuiNavItemData NavMoveResultLocal; // Best move request candidate within NavWindow
|
ImGuiNavItemData NavMoveResultLocal; // Best move request candidate within NavWindow
|
||||||
ImGuiNavItemData NavMoveResultLocalVisible; // Best move request candidate within NavWindow that are mostly visible (when using ImGuiNavMoveFlags_AlsoScoreVisibleSet flag)
|
ImGuiNavItemData NavMoveResultLocalVisible; // Best move request candidate within NavWindow that are mostly visible (when using ImGuiNavMoveFlags_AlsoScoreVisibleSet flag)
|
||||||
ImGuiNavItemData NavMoveResultOther; // Best move request candidate within NavWindow's flattened hierarchy (when using ImGuiWindowFlags_NavFlattened flag)
|
ImGuiNavItemData NavMoveResultOther; // Best move request candidate within NavWindow's flattened hierarchy (when using ImGuiWindowFlags_NavFlattened flag)
|
||||||
@ -1587,7 +1587,7 @@ struct ImGuiContext
|
|||||||
ImVector<ImGuiShrinkWidthItem> ShrinkWidthBuffer;
|
ImVector<ImGuiShrinkWidthItem> ShrinkWidthBuffer;
|
||||||
|
|
||||||
// Widget state
|
// Widget state
|
||||||
ImVec2 LastValidMousePos;
|
ImVec2 MouseLastValidPos;
|
||||||
ImGuiInputTextState InputTextState;
|
ImGuiInputTextState InputTextState;
|
||||||
ImFont InputTextPasswordFont;
|
ImFont InputTextPasswordFont;
|
||||||
ImGuiID TempInputId; // Temporary text input when CTRL+clicking on a slider, etc.
|
ImGuiID TempInputId; // Temporary text input when CTRL+clicking on a slider, etc.
|
||||||
@ -1728,7 +1728,7 @@ struct ImGuiContext
|
|||||||
NavMoveFlags = ImGuiNavMoveFlags_None;
|
NavMoveFlags = ImGuiNavMoveFlags_None;
|
||||||
NavMoveKeyMods = ImGuiKeyModFlags_None;
|
NavMoveKeyMods = ImGuiKeyModFlags_None;
|
||||||
NavMoveDir = NavMoveDirForDebug = NavMoveClipDir = ImGuiDir_None;
|
NavMoveDir = NavMoveDirForDebug = NavMoveClipDir = ImGuiDir_None;
|
||||||
NavScoringCount = 0;
|
NavScoringDebugCount = 0;
|
||||||
|
|
||||||
NavWindowingTarget = NavWindowingTargetAnim = NavWindowingListWindow = NULL;
|
NavWindowingTarget = NavWindowingTargetAnim = NavWindowingListWindow = NULL;
|
||||||
NavWindowingTimer = NavWindowingHighlightAlpha = 0.0f;
|
NavWindowingTimer = NavWindowingHighlightAlpha = 0.0f;
|
||||||
@ -1758,7 +1758,6 @@ struct ImGuiContext
|
|||||||
CurrentTableStackIdx = -1;
|
CurrentTableStackIdx = -1;
|
||||||
CurrentTabBar = NULL;
|
CurrentTabBar = NULL;
|
||||||
|
|
||||||
LastValidMousePos = ImVec2(0.0f, 0.0f);
|
|
||||||
TempInputId = 0;
|
TempInputId = 0;
|
||||||
ColorEditOptions = ImGuiColorEditFlags_DefaultOptions_;
|
ColorEditOptions = ImGuiColorEditFlags_DefaultOptions_;
|
||||||
ColorEditLastHue = ColorEditLastSat = 0.0f;
|
ColorEditLastHue = ColorEditLastSat = 0.0f;
|
||||||
|
Loading…
Reference in New Issue
Block a user