From 67e5f3505d481519cf038aa9d054c5d0805a768d Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 16 Oct 2024 19:55:50 +0200 Subject: [PATCH] InvisibleButton: disable navigation properly + added ImGuiButtonFlags_EnableNav to enable navigation. (#8057) --- docs/CHANGELOG.txt | 5 ++++- imgui.h | 2 +- imgui_internal.h | 2 +- imgui_widgets.cpp | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 0ade98733c85..27b7dd780349 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -73,7 +73,10 @@ Other changes: - Nav: fixed Ctrl+Tab so when starting with no focused window it starts from the top-most window. (#3200) - Nav: rectangle highlight not rendered for items with ImGuiItemFlags_NoNav. Can be relevant - when e.g activating the item with mouse, then ctrl+tabbing back and forth. + when e.g activating the item with mouse, then Ctrl+Tabbing back and forth. +- InvisibleButton, Nav: fixed an issue when InvisibleButton() would be navigable into but + not display navigation highlight. Properly navigation on it by default. (#8057) +- InvisibleButton: added ImGuiButtonFlags_EnableNav to enable navigation. (#8057) - Tooltips: fixed incorrect tooltip positioning when using keyboard/gamepad navigation (1.91.3 regression). (#8036) - DrawList: AddCallback() added an optional size parameter allowing to copy and diff --git a/imgui.h b/imgui.h index 2f9f18c2b8a4..ec5d572b94df 100644 --- a/imgui.h +++ b/imgui.h @@ -1744,7 +1744,7 @@ enum ImGuiButtonFlags_ ImGuiButtonFlags_MouseButtonRight = 1 << 1, // React on right mouse button ImGuiButtonFlags_MouseButtonMiddle = 1 << 2, // React on center mouse button ImGuiButtonFlags_MouseButtonMask_ = ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight | ImGuiButtonFlags_MouseButtonMiddle, // [Internal] - //ImGuiButtonFlags_MouseButtonDefault_ = ImGuiButtonFlags_MouseButtonLeft, + ImGuiButtonFlags_EnableNav = 1 << 3, // InvisibleButton(): do not disable navigation/tabbing. Otherwise disabled by default. }; // Flags for ColorEdit3() / ColorEdit4() / ColorPicker3() / ColorPicker4() / ColorButton() diff --git a/imgui_internal.h b/imgui_internal.h index f96e7091db66..6e207d60e766 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -947,7 +947,7 @@ enum ImGuiSelectableFlagsPrivate_ enum ImGuiTreeNodeFlagsPrivate_ { ImGuiTreeNodeFlags_ClipLabelForTrailingButton = 1 << 28,// FIXME-WIP: Hard-coded for CollapsingHeader() - ImGuiTreeNodeFlags_UpsideDownArrow = 1 << 29,// FIXME-WIP: Turn Down arrow into an Up arrow, but reversed trees (#6517) + ImGuiTreeNodeFlags_UpsideDownArrow = 1 << 29,// FIXME-WIP: Turn Down arrow into an Up arrow, for reversed trees (#6517) ImGuiTreeNodeFlags_OpenOnMask_ = ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_OpenOnArrow, }; diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 2a7b1e9a89b4..1cd18c359c89 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -785,11 +785,12 @@ bool ImGui::InvisibleButton(const char* str_id, const ImVec2& size_arg, ImGuiBut ImVec2 size = CalcItemSize(size_arg, 0.0f, 0.0f); const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size); ItemSize(size); - if (!ItemAdd(bb, id)) + if (!ItemAdd(bb, id, NULL, (flags & ImGuiButtonFlags_EnableNav) ? ImGuiItemFlags_None : ImGuiItemFlags_NoNav)) return false; bool hovered, held; bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags); + RenderNavHighlight(bb, id); IMGUI_TEST_ENGINE_ITEM_INFO(id, str_id, g.LastItemData.StatusFlags); return pressed;