From ad37b79bca2bf548c22ca2276dd209f05583e729 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 14 Oct 2024 17:30:14 +0200 Subject: [PATCH] Nav: shallow tidying up. --- imgui.cpp | 8 +++----- imgui_internal.h | 2 +- imgui_widgets.cpp | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 7da199c5c..eafb7a84d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4443,9 +4443,9 @@ bool ImGui::IsItemHovered(ImGuiHoveredFlags flags) if (g.NavDisableMouseHover && !g.NavDisableHighlight && !(flags & ImGuiHoveredFlags_NoNavOverride)) { - if ((g.LastItemData.InFlags & ImGuiItemFlags_Disabled) && !(flags & ImGuiHoveredFlags_AllowWhenDisabled)) + if (g.LastItemData.ID == g.NavId && g.NavId != 0) // IsItemFocused() return false; - if (!IsItemFocused()) + if ((g.LastItemData.InFlags & ImGuiItemFlags_Disabled) && !(flags & ImGuiHoveredFlags_AllowWhenDisabled)) return false; if (flags & ImGuiHoveredFlags_ForTooltip) @@ -5784,9 +5784,7 @@ bool ImGui::IsItemDeactivatedAfterEdit() bool ImGui::IsItemFocused() { ImGuiContext& g = *GImGui; - if (g.NavId != g.LastItemData.ID || g.NavId == 0) - return false; - return true; + return g.NavId == g.LastItemData.ID && g.NavId != 0; } // Important: this can be useful but it is NOT equivalent to the behavior of e.g.Button()! diff --git a/imgui_internal.h b/imgui_internal.h index 68593e8f4..99421b700 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -906,7 +906,7 @@ enum ImGuiButtonFlagsPrivate_ ImGuiButtonFlags_DontClosePopups = 1 << 13, // disable automatically closing parent popup on press // [UNUSED] //ImGuiButtonFlags_Disabled = 1 << 14, // disable interactions -> use BeginDisabled() or ImGuiItemFlags_Disabled ImGuiButtonFlags_AlignTextBaseLine = 1 << 15, // vertically align button to match text baseline - ButtonEx() only // FIXME: Should be removed and handled by SmallButton(), not possible currently because of DC.CursorPosPrevLine - ImGuiButtonFlags_NoKeyModifiers = 1 << 16, // disable mouse interaction if a key modifier is held + ImGuiButtonFlags_NoKeyModsAllowed = 1 << 16, // disable mouse interaction if a key modifier is held ImGuiButtonFlags_NoHoldingActiveId = 1 << 17, // don't set ActiveId while holding the mouse (ImGuiButtonFlags_PressedOnClick only) ImGuiButtonFlags_NoNavFocus = 1 << 18, // don't override navigation focus when activated (FIXME: this is essentially used every time an item uses ImGuiItemFlags_NoNav, but because legacy specs don't requires LastItemData to be set ButtonBehavior(), we can't poll g.LastItemData.InFlags) ImGuiButtonFlags_NoHoveredOnFocus = 1 << 19, // don't report as hovered when nav focus is on this item diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index aac7383b1..8cdd4aa27 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -561,7 +561,7 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool } // Process initial action - if (!(flags & ImGuiButtonFlags_NoKeyModifiers) || (!g.IO.KeyCtrl && !g.IO.KeyShift && !g.IO.KeyAlt)) + if (!(flags & ImGuiButtonFlags_NoKeyModsAllowed) || (!g.IO.KeyCtrl && !g.IO.KeyShift && !g.IO.KeyAlt)) { if (mouse_button_clicked != -1 && g.ActiveId != id) { @@ -6604,7 +6604,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l else { if (window != g.HoveredWindow || !is_mouse_x_over_arrow) - button_flags |= ImGuiButtonFlags_NoKeyModifiers; + button_flags |= ImGuiButtonFlags_NoKeyModsAllowed; } bool hovered, held;