diff --git a/imgui_demo.cpp b/imgui_demo.cpp index bdc97384..c9f9c73a 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -2027,7 +2027,7 @@ static void ShowDemoWindowLayout() 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 4cc2af84..af661afb 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1512,7 +1512,7 @@ enum ImGuiTabBarFlagsPrivate_ // 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 572c829c..d605e2d7 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -6927,6 +6927,12 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, 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 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, 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);