From c4a32a129d55eb66158408b61f51d40907a5aace Mon Sep 17 00:00:00 2001 From: Nico van Bentum Date: Thu, 13 Feb 2025 21:50:12 +0100 Subject: [PATCH] Tabs: fixed middle-button to close not checking hovering, only close button visibility. (#8399, #8387) Main bug has been here since 54a60aaa4, but it's only ef7ffaff7 which made it very visible. --- docs/CHANGELOG.txt | 4 +++- imgui_widgets.cpp | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 938b83aaf..19b334ba6 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -72,13 +72,15 @@ Other changes: - Tables, Error Handling: Recovery from invalid index in TableSetColumnIndex(). (#1651) - Selectable: Fixed horizontal label alignment with SelectableTextAlign.x > 0 and specifying a selectable size. (#8338) -- Styles, Tabs: made the Close Button of selected tabs always visible by default, +- Tabs, Style: made the Close Button of selected tabs always visible by default, without requiring to hover the tab. (#8387) - Added style.TabCloseButtonMinWidthSelected/TabCloseButtonMinWidthUnselected settings to configure visibility of the Close Button for selected and unselected tabs. (-1: always visible. 0.0f: visible when hovered. >0.0f: visible when hovered if minimum width) - Default for selected tabs: TabCloseButtonMinWidthSelected = -1.0f (always visible) - Default for unselected tabs: TabCloseButtonMinWidthUnselected = 0.0f (visible when hovered) +- Tabs: fixed middle-mouse-button to close tab not checking that close button + is hovered, merely it's visibility. (#8399, #8387) [@nicovanbentum] - TextLinkOpenURL(): fixed default Win32 io.PlatformOpenInShellFn handler to handle UTF-8 regardless of system regional settings. (#7660) [@achabense] - Demo: Combos: demonstrate a very simple way to add a filter to a combo, diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 2d45c5d51..6e08cec22 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -10368,9 +10368,10 @@ void ImGui::TabItemLabelAndCloseButton(ImDrawList* draw_list, const ImRect& bb, // 'g.ActiveId==close_button_id' will be true when we are holding on the close button, in which case both hovered booleans are false bool close_button_pressed = false; bool close_button_visible = false; + bool is_hovered = g.HoveredId == tab_id || g.HoveredId == close_button_id || g.ActiveId == tab_id || g.ActiveId == close_button_id; // Any interaction account for this too. + if (close_button_id != 0) { - bool is_hovered = g.HoveredId == tab_id || g.HoveredId == close_button_id || g.ActiveId == tab_id || g.ActiveId == close_button_id; // Any interaction account for this too. if (is_contents_visible) close_button_visible = (g.Style.TabCloseButtonMinWidthSelected < 0.0f) ? true : (is_hovered && bb.GetWidth() >= ImMax(button_sz, g.Style.TabCloseButtonMinWidthSelected)); else @@ -10386,7 +10387,7 @@ void ImGui::TabItemLabelAndCloseButton(ImDrawList* draw_list, const ImRect& bb, g.LastItemData = last_item_backup; // Close with middle mouse button - if (!(flags & ImGuiTabItemFlags_NoCloseWithMiddleMouseButton) && IsMouseClicked(2)) + if (is_hovered && !(flags & ImGuiTabItemFlags_NoCloseWithMiddleMouseButton) && IsMouseClicked(2)) close_button_pressed = true; } else if (unsaved_marker_visible)