Tabs: Enforcing minimum size of 1.0f, fixed asserting on zero-tab widths. (#5572)
Also fixed SetNextItemWidth(0.0f) not being consistent with tabs. (#5262)
diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt
index 6d9b0bf..d9f43db 100644
--- a/docs/CHANGELOG.txt
+++ b/docs/CHANGELOG.txt
@@ -100,6 +100,7 @@
- Tabs: Fixed shrinking policy leading to infinite loops when fed unrounded tab widths. (#5652)
- Tabs: Fixed shrinking policy sometimes erroneously making right-most tabs stray a little out
bar boundaries (bug in 1.88). (#5652).
+- Tabs: Enforcing minimum size of 1.0f, fixed asserting on zero-tab widths. (#5572)
- Window: Fixed a potential crash when appending to a child window. (#5515, #3496, #4797) [@rokups]
- IO: Added ImGuiKey_MouseXXX aliases for mouse buttons/wheel so all operations done on ImGuiKey
can apply to mouse data as well. (#4921)
diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp
index ac4a61c..c4bcc56 100644
--- a/imgui_widgets.cpp
+++ b/imgui_widgets.cpp
@@ -7552,7 +7552,7 @@
// and we cannot wait for the next BeginTabItem() call. We cannot compute this width within TabBarAddTab() because font size depends on the active window.
const char* tab_name = tab_bar->GetTabName(tab);
const bool has_close_button = (tab->Flags & ImGuiTabItemFlags_NoCloseButton) ? false : true;
- tab->ContentWidth = (tab->RequestedWidth > 0.0f) ? tab->RequestedWidth : TabItemCalcSize(tab_name, has_close_button).x;
+ tab->ContentWidth = (tab->RequestedWidth >= 0.0f) ? tab->RequestedWidth : TabItemCalcSize(tab_name, has_close_button).x;
int section_n = TabItemGetSectionIdx(tab);
ImGuiTabBarSection* section = §ions[section_n];
@@ -7564,9 +7564,7 @@
ImGuiShrinkWidthItem* shrink_width_item = &g.ShrinkWidthBuffer[shrink_buffer_indexes[section_n]++];
shrink_width_item->Index = tab_n;
shrink_width_item->Width = shrink_width_item->InitialWidth = tab->ContentWidth;
-
- IM_ASSERT(tab->ContentWidth > 0.0f);
- tab->Width = tab->ContentWidth;
+ tab->Width = ImMax(tab->ContentWidth, 1.0f);
}
// Compute total ideal width (used for e.g. auto-resizing a window)
@@ -7610,6 +7608,7 @@
if (shrinked_width < 0.0f)
continue;
+ shrinked_width = ImMax(1.0f, shrinked_width);
int section_n = TabItemGetSectionIdx(tab);
sections[section_n].Width -= (tab->Width - shrinked_width);
tab->Width = shrinked_width;
@@ -8085,7 +8084,7 @@
if (g.NextItemData.Flags & ImGuiNextItemDataFlags_HasWidth)
size.x = tab->RequestedWidth = g.NextItemData.Width;
if (tab_is_new)
- tab->Width = size.x;
+ tab->Width = ImMax(1.0f, size.x);
tab->ContentWidth = size.x;
tab->BeginOrder = tab_bar->TabsActiveCount++;