Просмотр исходного кода

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.
Nico van Bentum 7 месяцев назад
Родитель
Сommit
c4a32a129d
2 измененных файлов с 6 добавлено и 3 удалено
  1. 3 1
      docs/CHANGELOG.txt
  2. 3 2
      imgui_widgets.cpp

+ 3 - 1
docs/CHANGELOG.txt

@@ -72,13 +72,15 @@ Other changes:
 - Tables, Error Handling: Recovery from invalid index in TableSetColumnIndex(). (#1651)
 - Tables, Error Handling: Recovery from invalid index in TableSetColumnIndex(). (#1651)
 - Selectable: Fixed horizontal label alignment with SelectableTextAlign.x > 0 and
 - Selectable: Fixed horizontal label alignment with SelectableTextAlign.x > 0 and
   specifying a selectable size. (#8338)
   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)
   without requiring to hover the tab. (#8387)
   - Added style.TabCloseButtonMinWidthSelected/TabCloseButtonMinWidthUnselected settings
   - Added style.TabCloseButtonMinWidthSelected/TabCloseButtonMinWidthUnselected settings
     to configure visibility of the Close Button for selected and unselected tabs.
     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)
     (-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 selected tabs: TabCloseButtonMinWidthSelected = -1.0f (always visible)
   - Default for unselected tabs: TabCloseButtonMinWidthUnselected = 0.0f (visible when hovered)
   - 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
 - TextLinkOpenURL(): fixed default Win32 io.PlatformOpenInShellFn handler to
   handle UTF-8 regardless of system regional settings. (#7660) [@achabense]
   handle UTF-8 regardless of system regional settings. (#7660) [@achabense]
 - Demo: Combos: demonstrate a very simple way to add a filter to a combo,
 - Demo: Combos: demonstrate a very simple way to add a filter to a combo,

+ 3 - 2
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
     //  '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_pressed = false;
     bool close_button_visible = 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)
     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)
         if (is_contents_visible)
             close_button_visible = (g.Style.TabCloseButtonMinWidthSelected < 0.0f) ? true : (is_hovered && bb.GetWidth() >= ImMax(button_sz, g.Style.TabCloseButtonMinWidthSelected));
             close_button_visible = (g.Style.TabCloseButtonMinWidthSelected < 0.0f) ? true : (is_hovered && bb.GetWidth() >= ImMax(button_sz, g.Style.TabCloseButtonMinWidthSelected));
         else
         else
@@ -10386,7 +10387,7 @@ void ImGui::TabItemLabelAndCloseButton(ImDrawList* draw_list, const ImRect& bb,
         g.LastItemData = last_item_backup;
         g.LastItemData = last_item_backup;
 
 
         // Close with middle mouse button
         // Close with middle mouse button
-        if (!(flags & ImGuiTabItemFlags_NoCloseWithMiddleMouseButton) && IsMouseClicked(2))
+        if (is_hovered && !(flags & ImGuiTabItemFlags_NoCloseWithMiddleMouseButton) && IsMouseClicked(2))
             close_button_pressed = true;
             close_button_pressed = true;
     }
     }
     else if (unsaved_marker_visible)
     else if (unsaved_marker_visible)