mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-26 05:27:01 +00:00
Nav: fixed IMGUI_DEBUG_NAV_SCORING not setting NavMoveClipDir, leading to debug result not matching real results.
This commit is contained in:
parent
662ce46971
commit
8d9e50c807
29
imgui.cpp
29
imgui.cpp
@ -5312,7 +5312,8 @@ bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, b
|
|||||||
parent_window->DC.CursorPos = child_window->Pos;
|
parent_window->DC.CursorPos = child_window->Pos;
|
||||||
|
|
||||||
// Process navigation-in immediately so NavInit can run on first frame
|
// Process navigation-in immediately so NavInit can run on first frame
|
||||||
if (g.NavActivateId == id && !(flags & ImGuiWindowFlags_NavFlattened) && (child_window->DC.NavLayersActiveMask != 0 || child_window->DC.NavHasScroll))
|
// Can enter a child if (A) it has navigatable items or (B) it can be scrolled.
|
||||||
|
if (g.NavActivateId == id && !(flags & ImGuiWindowFlags_NavFlattened) && (child_window->DC.NavLayersActiveMask != 0 || child_window->DC.NavWindowHasScrollY))
|
||||||
{
|
{
|
||||||
FocusWindow(child_window);
|
FocusWindow(child_window);
|
||||||
NavInitWindow(child_window, false);
|
NavInitWindow(child_window, false);
|
||||||
@ -5359,7 +5360,7 @@ void ImGui::EndChild()
|
|||||||
ImGuiWindow* parent_window = g.CurrentWindow;
|
ImGuiWindow* parent_window = g.CurrentWindow;
|
||||||
ImRect bb(parent_window->DC.CursorPos, parent_window->DC.CursorPos + sz);
|
ImRect bb(parent_window->DC.CursorPos, parent_window->DC.CursorPos + sz);
|
||||||
ItemSize(sz);
|
ItemSize(sz);
|
||||||
if ((window->DC.NavLayersActiveMask != 0 || window->DC.NavHasScroll) && !(window->Flags & ImGuiWindowFlags_NavFlattened))
|
if ((window->DC.NavLayersActiveMask != 0 || window->DC.NavWindowHasScrollY) && !(window->Flags & ImGuiWindowFlags_NavFlattened))
|
||||||
{
|
{
|
||||||
ItemAdd(bb, window->ChildId);
|
ItemAdd(bb, window->ChildId);
|
||||||
RenderNavHighlight(bb, window->ChildId);
|
RenderNavHighlight(bb, window->ChildId);
|
||||||
@ -6670,7 +6671,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
|||||||
window->DC.NavLayersActiveMask = window->DC.NavLayersActiveMaskNext;
|
window->DC.NavLayersActiveMask = window->DC.NavLayersActiveMaskNext;
|
||||||
window->DC.NavLayersActiveMaskNext = 0x00;
|
window->DC.NavLayersActiveMaskNext = 0x00;
|
||||||
window->DC.NavHideHighlightOneFrame = false;
|
window->DC.NavHideHighlightOneFrame = false;
|
||||||
window->DC.NavHasScroll = (window->ScrollMax.y > 0.0f);
|
window->DC.NavWindowHasScrollY = (window->ScrollMax.y > 0.0f);
|
||||||
|
|
||||||
window->DC.MenuBarAppending = false;
|
window->DC.MenuBarAppending = false;
|
||||||
window->DC.MenuColumns.Update(style.ItemSpacing.x, window_just_activated_by_user);
|
window->DC.MenuColumns.Update(style.ItemSpacing.x, window_just_activated_by_user);
|
||||||
@ -9368,6 +9369,8 @@ bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb_arg, ImGu
|
|||||||
DebugLocateItemResolveWithLastItem();
|
DebugLocateItemResolveWithLastItem();
|
||||||
#endif
|
#endif
|
||||||
//if (g.IO.KeyAlt) window->DrawList->AddRect(bb.Min, bb.Max, IM_COL32(255,255,0,120)); // [DEBUG]
|
//if (g.IO.KeyAlt) window->DrawList->AddRect(bb.Min, bb.Max, IM_COL32(255,255,0,120)); // [DEBUG]
|
||||||
|
//if ((g.LastItemData.InFlags & ImGuiItemFlags_NoNav) == 0)
|
||||||
|
// window->DrawList->AddRect(g.LastItemData.NavRect.Min, g.LastItemData.NavRect.Max, IM_COL32(255,255,0,255)); // [DEBUG]
|
||||||
|
|
||||||
// We need to calculate this now to take account of the current clipping rectangle (as items like Selectable may change them)
|
// We need to calculate this now to take account of the current clipping rectangle (as items like Selectable may change them)
|
||||||
if (is_rect_visible)
|
if (is_rect_visible)
|
||||||
@ -10651,12 +10654,12 @@ ImGuiDir ImGetDirQuadrantFromDelta(float dx, float dy)
|
|||||||
return (dy > 0.0f) ? ImGuiDir_Down : ImGuiDir_Up;
|
return (dy > 0.0f) ? ImGuiDir_Down : ImGuiDir_Up;
|
||||||
}
|
}
|
||||||
|
|
||||||
static float inline NavScoreItemDistInterval(float a0, float a1, float b0, float b1)
|
static float inline NavScoreItemDistInterval(float cand_min, float cand_max, float curr_min, float curr_max)
|
||||||
{
|
{
|
||||||
if (a1 < b0)
|
if (cand_max < curr_min)
|
||||||
return a1 - b0;
|
return cand_max - curr_min;
|
||||||
if (b1 < a0)
|
if (curr_max < cand_min)
|
||||||
return a0 - b1;
|
return cand_min - curr_max;
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -10738,11 +10741,12 @@ static bool ImGui::NavScoreItem(ImGuiNavItemData* result)
|
|||||||
quadrant = (g.LastItemData.ID < g.NavId) ? ImGuiDir_Left : ImGuiDir_Right;
|
quadrant = (g.LastItemData.ID < g.NavId) ? ImGuiDir_Left : ImGuiDir_Right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ImGuiDir move_dir = g.NavMoveDir;
|
||||||
#if IMGUI_DEBUG_NAV_SCORING
|
#if IMGUI_DEBUG_NAV_SCORING
|
||||||
char buf[200];
|
char buf[200];
|
||||||
if (g.IO.KeyCtrl) // Hold CTRL to preview score in matching quadrant. CTRL+Arrow to rotate.
|
if (g.IO.KeyCtrl) // Hold CTRL to preview score in matching quadrant. CTRL+Arrow to rotate.
|
||||||
{
|
{
|
||||||
if (quadrant == g.NavMoveDir)
|
if (quadrant == move_dir)
|
||||||
{
|
{
|
||||||
ImFormatString(buf, IM_ARRAYSIZE(buf), "%.0f/%.0f", dist_box, dist_center);
|
ImFormatString(buf, IM_ARRAYSIZE(buf), "%.0f/%.0f", dist_box, dist_center);
|
||||||
ImDrawList* draw_list = GetForegroundDrawList(window);
|
ImDrawList* draw_list = GetForegroundDrawList(window);
|
||||||
@ -10766,7 +10770,6 @@ static bool ImGui::NavScoreItem(ImGuiNavItemData* result)
|
|||||||
|
|
||||||
// Is it in the quadrant we're interested in moving to?
|
// Is it in the quadrant we're interested in moving to?
|
||||||
bool new_best = false;
|
bool new_best = false;
|
||||||
const ImGuiDir move_dir = g.NavMoveDir;
|
|
||||||
if (quadrant == move_dir)
|
if (quadrant == move_dir)
|
||||||
{
|
{
|
||||||
// Does it beat the current best candidate?
|
// Does it beat the current best candidate?
|
||||||
@ -11271,7 +11274,7 @@ static void ImGui::NavUpdate()
|
|||||||
ImGuiWindow* window = g.NavWindow;
|
ImGuiWindow* window = g.NavWindow;
|
||||||
const float scroll_speed = IM_ROUND(window->CalcFontSize() * 100 * io.DeltaTime); // We need round the scrolling speed because sub-pixel scroll isn't reliably supported.
|
const float scroll_speed = IM_ROUND(window->CalcFontSize() * 100 * io.DeltaTime); // We need round the scrolling speed because sub-pixel scroll isn't reliably supported.
|
||||||
const ImGuiDir move_dir = g.NavMoveDir;
|
const ImGuiDir move_dir = g.NavMoveDir;
|
||||||
if (window->DC.NavLayersActiveMask == 0x00 && window->DC.NavHasScroll && move_dir != ImGuiDir_None)
|
if (window->DC.NavLayersActiveMask == 0x00 && window->DC.NavWindowHasScrollY && move_dir != ImGuiDir_None)
|
||||||
{
|
{
|
||||||
if (move_dir == ImGuiDir_Left || move_dir == ImGuiDir_Right)
|
if (move_dir == ImGuiDir_Left || move_dir == ImGuiDir_Right)
|
||||||
SetScrollX(window, ImFloor(window->Scroll.x + ((move_dir == ImGuiDir_Left) ? -1.0f : +1.0f) * scroll_speed));
|
SetScrollX(window, ImFloor(window->Scroll.x + ((move_dir == ImGuiDir_Left) ? -1.0f : +1.0f) * scroll_speed));
|
||||||
@ -11389,6 +11392,7 @@ void ImGui::NavUpdateCreateMoveRequest()
|
|||||||
{
|
{
|
||||||
if (g.NavMoveDir == ImGuiDir_None)
|
if (g.NavMoveDir == ImGuiDir_None)
|
||||||
g.NavMoveDir = g.NavMoveDirForDebug;
|
g.NavMoveDir = g.NavMoveDirForDebug;
|
||||||
|
g.NavMoveClipDir = g.NavMoveDir;
|
||||||
g.NavMoveFlags |= ImGuiNavMoveFlags_DebugNoResult;
|
g.NavMoveFlags |= ImGuiNavMoveFlags_DebugNoResult;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -11502,6 +11506,7 @@ void ImGui::NavMoveRequestApplyResult()
|
|||||||
g.NavMoveFlags |= ImGuiNavMoveFlags_DontSetNavHighlight;
|
g.NavMoveFlags |= ImGuiNavMoveFlags_DontSetNavHighlight;
|
||||||
if (g.NavId != 0 && (g.NavMoveFlags & ImGuiNavMoveFlags_DontSetNavHighlight) == 0)
|
if (g.NavId != 0 && (g.NavMoveFlags & ImGuiNavMoveFlags_DontSetNavHighlight) == 0)
|
||||||
NavRestoreHighlightAfterMove();
|
NavRestoreHighlightAfterMove();
|
||||||
|
IMGUI_DEBUG_LOG_NAV("[nav] NavMoveSubmitted but not led to a result!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -11638,7 +11643,7 @@ static float ImGui::NavUpdatePageUpPageDown()
|
|||||||
if (g.NavLayer != ImGuiNavLayer_Main)
|
if (g.NavLayer != ImGuiNavLayer_Main)
|
||||||
NavRestoreLayer(ImGuiNavLayer_Main);
|
NavRestoreLayer(ImGuiNavLayer_Main);
|
||||||
|
|
||||||
if (window->DC.NavLayersActiveMask == 0x00 && window->DC.NavHasScroll)
|
if (window->DC.NavLayersActiveMask == 0x00 && window->DC.NavWindowHasScrollY)
|
||||||
{
|
{
|
||||||
// Fallback manual-scroll when window has no navigable item
|
// Fallback manual-scroll when window has no navigable item
|
||||||
if (IsKeyPressed(ImGuiKey_PageUp, ImGuiKeyOwner_None, ImGuiInputFlags_Repeat))
|
if (IsKeyPressed(ImGuiKey_PageUp, ImGuiKeyOwner_None, ImGuiInputFlags_Repeat))
|
||||||
|
@ -2226,14 +2226,14 @@ struct IMGUI_API ImGuiWindowTempData
|
|||||||
ImVec1 Indent; // Indentation / start position from left of window (increased by TreePush/TreePop, etc.)
|
ImVec1 Indent; // Indentation / start position from left of window (increased by TreePush/TreePop, etc.)
|
||||||
ImVec1 ColumnsOffset; // Offset to the current column (if ColumnsCurrent > 0). FIXME: This and the above should be a stack to allow use cases like Tree->Column->Tree. Need revamp columns API.
|
ImVec1 ColumnsOffset; // Offset to the current column (if ColumnsCurrent > 0). FIXME: This and the above should be a stack to allow use cases like Tree->Column->Tree. Need revamp columns API.
|
||||||
ImVec1 GroupOffset;
|
ImVec1 GroupOffset;
|
||||||
ImVec2 CursorStartPosLossyness;// Record the loss of precision of CursorStartPos due to really large scrolling amount. This is used by clipper to compensentate and fix the most common use case of large scroll area.
|
ImVec2 CursorStartPosLossyness;// Record the loss of precision of CursorStartPos due to really large scrolling amount. This is used by clipper to compensate and fix the most common use case of large scroll area.
|
||||||
|
|
||||||
// Keyboard/Gamepad navigation
|
// Keyboard/Gamepad navigation
|
||||||
ImGuiNavLayer NavLayerCurrent; // Current layer, 0..31 (we currently only use 0..1)
|
ImGuiNavLayer NavLayerCurrent; // Current layer, 0..31 (we currently only use 0..1)
|
||||||
short NavLayersActiveMask; // Which layers have been written to (result from previous frame)
|
short NavLayersActiveMask; // Which layers have been written to (result from previous frame)
|
||||||
short NavLayersActiveMaskNext;// Which layers have been written to (accumulator for current frame)
|
short NavLayersActiveMaskNext;// Which layers have been written to (accumulator for current frame)
|
||||||
bool NavHideHighlightOneFrame;
|
bool NavHideHighlightOneFrame;
|
||||||
bool NavHasScroll; // Set when scrolling can be used (ScrollMax > 0.0f)
|
bool NavWindowHasScrollY; // Set per window when scrolling can be used (== ScrollMax.y > 0.0f)
|
||||||
|
|
||||||
// Miscellaneous
|
// Miscellaneous
|
||||||
bool MenuBarAppending; // FIXME: Remove this
|
bool MenuBarAppending; // FIXME: Remove this
|
||||||
|
Loading…
Reference in New Issue
Block a user