TabItem: honor ImGuiTabItemFlags_NoCloseButton passed as parameter (although undocumented and part of private api) (#2923)
diff --git a/imgui_demo.cpp b/imgui_demo.cpp
index bdc9738..c9f9c73 100644
--- a/imgui_demo.cpp
+++ b/imgui_demo.cpp
@@ -2027,7 +2027,7 @@
if (ImGui::BeginTabBar("MyTabBar", tab_bar_flags))
{
for (int n = 0; n < IM_ARRAYSIZE(opened); n++)
- if (opened[n] && ImGui::BeginTabItem(names[n], &opened[n]))
+ if (opened[n] && ImGui::BeginTabItem(names[n], &opened[n], ImGuiTabItemFlags_None))
{
ImGui::Text("This is the %s tab!", names[n]);
if (n & 1)
diff --git a/imgui_internal.h b/imgui_internal.h
index 4cc2af8..af661af 100644
--- a/imgui_internal.h
+++ b/imgui_internal.h
@@ -1512,7 +1512,7 @@
// Extend ImGuiTabItemFlags_
enum ImGuiTabItemFlagsPrivate_
{
- ImGuiTabItemFlags_NoCloseButton = 1 << 20 // Store whether p_open is set or not, which we need to recompute ContentWidth during layout.
+ ImGuiTabItemFlags_NoCloseButton = 1 << 20 // Track whether p_open was set or not (we'll need this info on the next frame to recompute ContentWidth during layout)
};
// Storage for one active tab item (sizeof() 26~32 bytes)
diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp
index 572c829..d605e2d 100644
--- a/imgui_widgets.cpp
+++ b/imgui_widgets.cpp
@@ -6927,6 +6927,12 @@
return false;
}
+ // Store into ImGuiTabItemFlags_NoCloseButton, also honor ImGuiTabItemFlags_NoCloseButton passed by user (although not documented)
+ if (flags & ImGuiTabItemFlags_NoCloseButton)
+ p_open = NULL;
+ else if (p_open == NULL)
+ flags |= ImGuiTabItemFlags_NoCloseButton;
+
// Calculate tab contents size
ImVec2 size = TabItemCalcSize(label, p_open != NULL);
@@ -6944,9 +6950,6 @@
tab_bar->LastTabItemIdx = (short)tab_bar->Tabs.index_from_ptr(tab);
tab->ContentWidth = size.x;
- if (p_open == NULL)
- flags |= ImGuiTabItemFlags_NoCloseButton;
-
const bool tab_bar_appearing = (tab_bar->PrevFrameVisible + 1 < g.FrameCount);
const bool tab_bar_focused = (tab_bar->Flags & ImGuiTabBarFlags_IsFocused) != 0;
const bool tab_appearing = (tab->LastFrameVisible + 1 < g.FrameCount);