| 8113 | } |
| 8114 | |
| 8115 | bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, ImGuiTabItemFlags flags, ImGuiWindow* docked_window) |
| 8116 | { |
| 8117 | // Layout whole tab bar if not already done |
| 8118 | ImGuiContext& g = *GImGui; |
| 8119 | if (tab_bar->WantLayout) |
| 8120 | { |
| 8121 | ImGuiNextItemData backup_next_item_data = g.NextItemData; |
| 8122 | TabBarLayout(tab_bar); |
| 8123 | g.NextItemData = backup_next_item_data; |
| 8124 | } |
| 8125 | ImGuiWindow* window = g.CurrentWindow; |
| 8126 | if (window->SkipItems) |
| 8127 | return false; |
| 8128 | |
| 8129 | const ImGuiStyle& style = g.Style; |
| 8130 | const ImGuiID id = TabBarCalcTabID(tab_bar, label, docked_window); |
| 8131 | |
| 8132 | // If the user called us with *p_open == false, we early out and don't render. |
| 8133 | // We make a call to ItemAdd() so that attempts to use a contextual popup menu with an implicit ID won't use an older ID. |
| 8134 | IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags); |
| 8135 | if (p_open && !*p_open) |
| 8136 | { |
| 8137 | ItemAdd(ImRect(), id, NULL, ImGuiItemFlags_NoNav); |
| 8138 | return false; |
| 8139 | } |
| 8140 | |
| 8141 | IM_ASSERT(!p_open || !(flags & ImGuiTabItemFlags_Button)); |
| 8142 | IM_ASSERT((flags & (ImGuiTabItemFlags_Leading | ImGuiTabItemFlags_Trailing)) != (ImGuiTabItemFlags_Leading | ImGuiTabItemFlags_Trailing)); // Can't use both Leading and Trailing |
| 8143 | |
| 8144 | // Store into ImGuiTabItemFlags_NoCloseButton, also honor ImGuiTabItemFlags_NoCloseButton passed by user (although not documented) |
| 8145 | if (flags & ImGuiTabItemFlags_NoCloseButton) |
| 8146 | p_open = NULL; |
| 8147 | else if (p_open == NULL) |
| 8148 | flags |= ImGuiTabItemFlags_NoCloseButton; |
| 8149 | |
| 8150 | // Acquire tab data |
| 8151 | ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, id); |
| 8152 | bool tab_is_new = false; |
| 8153 | if (tab == NULL) |
| 8154 | { |
| 8155 | tab_bar->Tabs.push_back(ImGuiTabItem()); |
| 8156 | tab = &tab_bar->Tabs.back(); |
| 8157 | tab->ID = id; |
| 8158 | tab_bar->TabsAddedNew = tab_is_new = true; |
| 8159 | } |
| 8160 | tab_bar->LastTabItemIdx = (ImS16)tab_bar->Tabs.index_from_ptr(tab); |
| 8161 | |
| 8162 | // Calculate tab contents size |
| 8163 | ImVec2 size = TabItemCalcSize(label, (p_open != NULL) || (flags & ImGuiTabItemFlags_UnsavedDocument)); |
| 8164 | tab->RequestedWidth = -1.0f; |
| 8165 | if (g.NextItemData.Flags & ImGuiNextItemDataFlags_HasWidth) |
| 8166 | size.x = tab->RequestedWidth = g.NextItemData.Width; |
| 8167 | if (tab_is_new) |
| 8168 | tab->Width = ImMax(1.0f, size.x); |
| 8169 | tab->ContentWidth = size.x; |
| 8170 | tab->BeginOrder = tab_bar->TabsActiveCount++; |
| 8171 | |
| 8172 | const bool tab_bar_appearing = (tab_bar->PrevFrameVisible + 1 < g.FrameCount); |
nothing calls this directly
no test coverage detected