From 68d3e139a74ed9d7cad4abb0f36466544ef24620 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 1 Feb 2018 22:28:58 +0100 Subject: [PATCH] Nav: When focusing a parent window while closing a popup, hide its highlight for one frame to avoid potential double highlight and flicker with the common pattern of menu items leading to the opening other windows. (#787) --- imgui.cpp | 6 +++++- imgui_internal.h | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index fce0c566..60863f3d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4247,6 +4247,8 @@ void ImGui::RenderNavHighlight(const ImRect& bb, ImGuiID id, ImGuiNavHighlightFl if (g.NavDisableHighlight && !(flags & ImGuiNavHighlightFlags_AlwaysDraw)) return; ImGuiWindow* window = ImGui::GetCurrentWindow(); + if (window->DC.NavHideHighlightOneFrame) + return; float rounding = (flags & ImGuiNavHighlightFlags_NoRounding) ? 0.0f : g.Style.FrameRounding; ImRect display_rect = bb; @@ -4767,6 +4769,7 @@ static void ClosePopupToLevel(int remaining) if (g.NavLayer == 0) focus_window = NavRestoreLastChildNavWindow(focus_window); ImGui::FocusWindow(focus_window); + focus_window->DC.NavHideHighlightOneFrame = true; g.OpenPopupStack.resize(remaining); } @@ -5901,9 +5904,10 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->DC.CursorMaxPos = window->DC.CursorStartPos; window->DC.CurrentLineHeight = window->DC.PrevLineHeight = 0.0f; window->DC.CurrentLineTextBaseOffset = window->DC.PrevLineTextBaseOffset = 0.0f; + window->DC.NavHideHighlightOneFrame = false; + window->DC.NavHasScroll = (GetScrollMaxY() > 0.0f); window->DC.NavLayerActiveMask = window->DC.NavLayerActiveMaskNext; window->DC.NavLayerActiveMaskNext = 0x00; - window->DC.NavHasScroll = (GetScrollMaxY() > 0.0f); window->DC.MenuBarAppending = false; window->DC.MenuBarOffsetX = ImMax(window->WindowPadding.x, style.ItemSpacing.x); window->DC.LogLinePosY = window->DC.CursorPos.y - 9999.0f; diff --git a/imgui_internal.h b/imgui_internal.h index 97fefb2f..37b32651 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -820,6 +820,7 @@ struct IMGUI_API ImGuiDrawContext ImGuiID LastItemId; ImRect LastItemRect; bool LastItemRectHoveredRect; + bool NavHideHighlightOneFrame; bool NavHasScroll; // Set when scrolling can be used (ScrollMax > 0.0f) int NavLayerCurrent; // Current layer, 0..31 (we currently only use 0..1) int NavLayerCurrentMask; // = (1 << NavLayerCurrent) used by ItemAdd prior to clipping. @@ -857,6 +858,7 @@ struct IMGUI_API ImGuiDrawContext LastItemId = 0; LastItemRect = ImRect(); LastItemRectHoveredRect = false; + NavHideHighlightOneFrame = false; NavHasScroll = false; NavLayerActiveMask = NavLayerActiveMaskNext = 0x00; NavLayerCurrent = 0;