From 55f590c1d17cf8bf1130e7c87c62eeface9001ac Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 10 Sep 2025 22:29:42 +0200 Subject: [PATCH] Selectable: ImGuiSelectableFlags_SelectOnNav doesn't select when holding Ctrl, to be consistent with multi-select. Amend e66afbb + remove needless line in CloseCurrentPopup() block --- docs/CHANGELOG.txt | 2 +- imgui.h | 2 +- imgui_widgets.cpp | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 7994e79e1..2658bdb69 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -73,7 +73,7 @@ Other Changes: on InputTextMultiline() fields with ImGuiInputTextFlags_AllowTabInput, since they normally inhibit activation to allow tabbing through multiple items. (#8928) - Selectable: added ImGuiSelectableFlags_SelectOnNav to auto-select an item when - moved into (automatic when in a BeginMultiSelect() block). + moved into, unless Ctrl is held. (automatic when in a BeginMultiSelect() block). - TabBar: fixed an issue were forcefully selecting a tab using internal API would be ignored on first/appearing frame before tabs are submitted (#8929, #6681) - DrawList: fixed CloneOutput() unnecessarily taking a copy of the ImDrawListSharedData diff --git a/imgui.h b/imgui.h index a087c9e4d..e50ab814f 100644 --- a/imgui.h +++ b/imgui.h @@ -1341,7 +1341,7 @@ enum ImGuiSelectableFlags_ ImGuiSelectableFlags_Disabled = 1 << 3, // Cannot be selected, display grayed out text ImGuiSelectableFlags_AllowOverlap = 1 << 4, // (WIP) Hit testing to allow subsequent widgets to overlap this one ImGuiSelectableFlags_Highlight = 1 << 5, // Make the item be displayed as if it is hovered - ImGuiSelectableFlags_SelectOnNav = 1 << 6, // Auto-select when moved into. Automatic when in a BeginMultiSelect() block. + ImGuiSelectableFlags_SelectOnNav = 1 << 6, // Auto-select when moved into, unless Ctrl is held. Automatic when in a BeginMultiSelect() block. #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS ImGuiSelectableFlags_DontClosePopups = ImGuiSelectableFlags_NoAutoClosePopups, // Renamed in 1.91.0 diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index dd24b74a6..55410b1f3 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -7366,7 +7366,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl // - (2) usage will fail with clipped items // The multi-select API aim to fix those issues, e.g. may be replaced with a BeginSelection() API. if ((flags & ImGuiSelectableFlags_SelectOnNav) && g.NavJustMovedToId != 0 && g.NavJustMovedToFocusScopeId == g.CurrentFocusScopeId) - if (g.NavJustMovedToId == id) + if (g.NavJustMovedToId == id && (g.NavJustMovedToKeyMods & ImGuiMod_Ctrl) == 0) selected = pressed = auto_selected = true; } @@ -7419,8 +7419,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl // Automatically close popups if (pressed && !auto_selected && (window->Flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiSelectableFlags_NoAutoClosePopups) && (g.LastItemData.ItemFlags & ImGuiItemFlags_AutoClosePopups)) - if (!(flags & ImGuiSelectableFlags_SelectOnNav) || g.NavJustMovedToId != id) - CloseCurrentPopup(); + CloseCurrentPopup(); if (disabled_item && !disabled_global) EndDisabled();