Skip to content

Commit ef7ffaf

Browse files
committed
Styles, Tabs: (Breaking) Renamed TabMinWidthForCloseButton to TabCloseButtonMinWidthUnselected. Added TabCloseButtonMinWidthSelected. (ocornut#8387)
1 parent 3d900ed commit ef7ffaf

File tree

5 files changed

+34
-10
lines changed

5 files changed

+34
-10
lines changed

docs/CHANGELOG.txt

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ HOW TO UPDATE?
4242
Breaking changes:
4343

4444
- Renamed ImFontConfig::GlyphExtraSpacing.x option to GlyphExtraAdvanceX. (#242)
45+
- Renamed style.TabMinWidthForCloseButton to style.TabCloseButtonMinWidthUnselected.
4546

4647
Other changes:
4748

@@ -63,6 +64,13 @@ Other changes:
6364
to not leak the value into a subsequent window. (#8196)
6465
- Tables: fixed an issue where Columns Visible/Hidden state wouldn't be correctly
6566
overridden when hot-reloading .ini state. (#7934)
67+
- Styles, Tabs: made the Close Button of selected tabs always visible by default,
68+
without requiring to hover the tab. (#8387)
69+
- Added style.TabCloseButtonMinWidthSelected/TabCloseButtonMinWidthUnselected settings
70+
to configure visibility of the Close Button for selected and unselected tabs.
71+
(-1: always visible. 0.0f: visible when hovered. >0.0f: visible when hovered if minimum width)
72+
- Default for selected tabs: TabCloseButtonMinWidthSelected = -1.0f (always visible)
73+
- Default for unselected tabs: TabCloseButtonMinWidthUnselected = 0.0f (visible when hovered)
6674
- TextLinkOpenURL(): fixed default Win32 io.PlatformOpenInShellFn handler to
6775
handle UTF-8 regardless of system regional settings. (#7660) [@achabense]
6876
- Demo: Combos: demonstrate a very simple way to add a filter to a combo,

imgui.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,8 @@ ImGuiStyle::ImGuiStyle()
13391339
LogSliderDeadzone = 4.0f; // The size in pixels of the dead-zone around zero on logarithmic sliders that cross zero.
13401340
TabRounding = 5.0f; // Radius of upper corners of a tab. Set to 0.0f to have rectangular tabs.
13411341
TabBorderSize = 0.0f; // Thickness of border around tabs.
1342-
TabMinWidthForCloseButton = 0.0f; // Minimum width for close button to appear on an unselected tab when hovered. Set to 0.0f to always show when hovering, set to FLT_MAX to never show close button unless selected.
1342+
TabCloseButtonMinWidthSelected = -1.0f; // -1: always visible. 0.0f: visible when hovered. >0.0f: visible when hovered if minimum width.
1343+
TabCloseButtonMinWidthUnselected = 0.0f; // -1: always visible. 0.0f: visible when hovered. >0.0f: visible when hovered if minimum width. FLT_MAX: never show close button when unselected.
13431344
TabBarBorderSize = 1.0f; // Thickness of tab-bar separator, which takes on the tab active color to denote focus.
13441345
TabBarOverlineSize = 1.0f; // Thickness of tab-bar overline, which highlights the selected tab-bar.
13451346
TableAngledHeadersAngle = 35.0f * (IM_PI / 180.0f); // Angle of angled headers (supported values range from -50 degrees to +50 degrees).
@@ -1394,7 +1395,8 @@ void ImGuiStyle::ScaleAllSizes(float scale_factor)
13941395
GrabRounding = ImTrunc(GrabRounding * scale_factor);
13951396
LogSliderDeadzone = ImTrunc(LogSliderDeadzone * scale_factor);
13961397
TabRounding = ImTrunc(TabRounding * scale_factor);
1397-
TabMinWidthForCloseButton = (TabMinWidthForCloseButton != FLT_MAX) ? ImTrunc(TabMinWidthForCloseButton * scale_factor) : FLT_MAX;
1398+
TabCloseButtonMinWidthSelected = (TabCloseButtonMinWidthSelected > 0.0f && TabCloseButtonMinWidthSelected != FLT_MAX) ? ImTrunc(TabCloseButtonMinWidthSelected * scale_factor) : FLT_MAX;
1399+
TabCloseButtonMinWidthUnselected = (TabCloseButtonMinWidthUnselected > 0.0f && TabCloseButtonMinWidthUnselected != FLT_MAX) ? ImTrunc(TabCloseButtonMinWidthUnselected * scale_factor) : FLT_MAX;
13981400
TabBarOverlineSize = ImTrunc(TabBarOverlineSize * scale_factor);
13991401
SeparatorTextPadding = ImTrunc(SeparatorTextPadding * scale_factor);
14001402
DisplayWindowPadding = ImTrunc(DisplayWindowPadding * scale_factor);

imgui.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -2170,7 +2170,8 @@ struct ImGuiStyle
21702170
float LogSliderDeadzone; // The size in pixels of the dead-zone around zero on logarithmic sliders that cross zero.
21712171
float TabRounding; // Radius of upper corners of a tab. Set to 0.0f to have rectangular tabs.
21722172
float TabBorderSize; // Thickness of border around tabs.
2173-
float TabMinWidthForCloseButton; // Minimum width for close button to appear on an unselected tab when hovered. Set to 0.0f to always show when hovering, set to FLT_MAX to never show close button unless selected.
2173+
float TabCloseButtonMinWidthSelected; // -1: always visible. 0.0f: visible when hovered. >0.0f: visible when hovered if minimum width.
2174+
float TabCloseButtonMinWidthUnselected; // -1: always visible. 0.0f: visible when hovered. >0.0f: visible when hovered if minimum width. FLT_MAX: never show close button when unselected.
21742175
float TabBarBorderSize; // Thickness of tab-bar separator, which takes on the tab active color to denote focus.
21752176
float TabBarOverlineSize; // Thickness of tab-bar overline, which highlights the selected tab-bar.
21762177
float TableAngledHeadersAngle; // Angle of angled headers (supported values range from -50.0f degrees to +50.0f degrees).
@@ -2201,6 +2202,11 @@ struct ImGuiStyle
22012202

22022203
IMGUI_API ImGuiStyle();
22032204
IMGUI_API void ScaleAllSizes(float scale_factor);
2205+
2206+
// Obsolete names
2207+
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
2208+
// TabMinWidthForCloseButton = TabCloseButtonMinWidthUnselected // Renamed in 1.91.9.
2209+
#endif
22042210
};
22052211

22062212
//-----------------------------------------------------------------------------

imgui_demo.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -7991,10 +7991,6 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
79917991
ImGui::SliderFloat("ChildBorderSize", &style.ChildBorderSize, 0.0f, 1.0f, "%.0f");
79927992
ImGui::SliderFloat("PopupBorderSize", &style.PopupBorderSize, 0.0f, 1.0f, "%.0f");
79937993
ImGui::SliderFloat("FrameBorderSize", &style.FrameBorderSize, 0.0f, 1.0f, "%.0f");
7994-
ImGui::SliderFloat("TabBorderSize", &style.TabBorderSize, 0.0f, 1.0f, "%.0f");
7995-
ImGui::SliderFloat("TabBarBorderSize", &style.TabBarBorderSize, 0.0f, 2.0f, "%.0f");
7996-
ImGui::SliderFloat("TabBarOverlineSize", &style.TabBarOverlineSize, 0.0f, 3.0f, "%.0f");
7997-
ImGui::SameLine(); HelpMarker("Overline is only drawn over the selected tab when ImGuiTabBarFlags_DrawSelectedOverline is set.");
79987994

79997995
ImGui::SeparatorText("Rounding");
80007996
ImGui::SliderFloat("WindowRounding", &style.WindowRounding, 0.0f, 12.0f, "%.0f");
@@ -8003,6 +7999,14 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
80037999
ImGui::SliderFloat("PopupRounding", &style.PopupRounding, 0.0f, 12.0f, "%.0f");
80048000
ImGui::SliderFloat("ScrollbarRounding", &style.ScrollbarRounding, 0.0f, 12.0f, "%.0f");
80058001
ImGui::SliderFloat("GrabRounding", &style.GrabRounding, 0.0f, 12.0f, "%.0f");
8002+
8003+
ImGui::SeparatorText("Tabs");
8004+
ImGui::SliderFloat("TabBorderSize", &style.TabBorderSize, 0.0f, 1.0f, "%.0f");
8005+
ImGui::SliderFloat("TabBarBorderSize", &style.TabBarBorderSize, 0.0f, 2.0f, "%.0f");
8006+
ImGui::SliderFloat("TabBarOverlineSize", &style.TabBarOverlineSize, 0.0f, 3.0f, "%.0f");
8007+
ImGui::SameLine(); HelpMarker("Overline is only drawn over the selected tab when ImGuiTabBarFlags_DrawSelectedOverline is set.");
8008+
ImGui::DragFloat("TabCloseButtonMinWidthSelected", &style.TabCloseButtonMinWidthSelected, 0.1f, -1.0f, 100.0f, (style.TabCloseButtonMinWidthSelected < 0.0f) ? "%.0f (Always)" : "%.0f");
8009+
ImGui::DragFloat("TabCloseButtonMinWidthUnselected", &style.TabCloseButtonMinWidthUnselected, 0.1f, -1.0f, 100.0f, (style.TabCloseButtonMinWidthUnselected < 0.0f) ? "%.0f (Always)" : "%.0f");
80068010
ImGui::SliderFloat("TabRounding", &style.TabRounding, 0.0f, 12.0f, "%.0f");
80078011

80088012
ImGui::SeparatorText("Tables");

imgui_widgets.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -10369,9 +10369,13 @@ void ImGui::TabItemLabelAndCloseButton(ImDrawList* draw_list, const ImRect& bb,
1036910369
bool close_button_pressed = false;
1037010370
bool close_button_visible = false;
1037110371
if (close_button_id != 0)
10372-
if (is_contents_visible || bb.GetWidth() >= ImMax(button_sz, g.Style.TabMinWidthForCloseButton))
10373-
if (g.HoveredId == tab_id || g.HoveredId == close_button_id || g.ActiveId == tab_id || g.ActiveId == close_button_id)
10374-
close_button_visible = true;
10372+
{
10373+
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.
10374+
if (is_contents_visible)
10375+
close_button_visible = (g.Style.TabCloseButtonMinWidthSelected < 0.0f) ? true : (is_hovered && bb.GetWidth() >= ImMax(button_sz, g.Style.TabCloseButtonMinWidthSelected));
10376+
else
10377+
close_button_visible = (g.Style.TabCloseButtonMinWidthUnselected < 0.0f) ? true : (is_hovered && bb.GetWidth() >= ImMax(button_sz, g.Style.TabCloseButtonMinWidthUnselected));
10378+
}
1037510379
bool unsaved_marker_visible = (flags & ImGuiTabItemFlags_UnsavedDocument) != 0 && (button_pos.x + button_sz <= bb.Max.x);
1037610380

1037710381
if (close_button_visible)

0 commit comments

Comments
 (0)