TabItem: honor ImGuiTabItemFlags_NoCloseButton passed as parameter (although undocumented and part of private api) (#2923)

This commit is contained in:
omar 2019-12-07 16:22:07 +01:00
parent f656e7775e
commit e4a59d0025
3 changed files with 8 additions and 5 deletions

View File

@ -2027,7 +2027,7 @@ static void ShowDemoWindowLayout()
if (ImGui::BeginTabBar("MyTabBar", tab_bar_flags)) if (ImGui::BeginTabBar("MyTabBar", tab_bar_flags))
{ {
for (int n = 0; n < IM_ARRAYSIZE(opened); n++) 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]); ImGui::Text("This is the %s tab!", names[n]);
if (n & 1) if (n & 1)

View File

@ -1512,7 +1512,7 @@ enum ImGuiTabBarFlagsPrivate_
// Extend ImGuiTabItemFlags_ // Extend ImGuiTabItemFlags_
enum ImGuiTabItemFlagsPrivate_ 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) // Storage for one active tab item (sizeof() 26~32 bytes)

View File

@ -6927,6 +6927,12 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open,
return false; 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 // Calculate tab contents size
ImVec2 size = TabItemCalcSize(label, p_open != NULL); 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_bar->LastTabItemIdx = (short)tab_bar->Tabs.index_from_ptr(tab);
tab->ContentWidth = size.x; 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_appearing = (tab_bar->PrevFrameVisible + 1 < g.FrameCount);
const bool tab_bar_focused = (tab_bar->Flags & ImGuiTabBarFlags_IsFocused) != 0; const bool tab_bar_focused = (tab_bar->Flags & ImGuiTabBarFlags_IsFocused) != 0;
const bool tab_appearing = (tab->LastFrameVisible + 1 < g.FrameCount); const bool tab_appearing = (tab->LastFrameVisible + 1 < g.FrameCount);