| 8281 | } |
| 8282 | |
| 8283 | bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, ImGuiTabItemFlags flags, ImGuiWindow* docked_window) |
| 8284 | { |
| 8285 | // Layout whole tab bar if not already done |
| 8286 | ImGuiContext& g = *GImGui; |
| 8287 | if (tab_bar->WantLayout) |
| 8288 | { |
| 8289 | ImGuiNextItemData backup_next_item_data = g.NextItemData; |
| 8290 | TabBarLayout(tab_bar); |
| 8291 | g.NextItemData = backup_next_item_data; |
| 8292 | } |
| 8293 | ImGuiWindow* window = g.CurrentWindow; |
| 8294 | if (window->SkipItems) |
| 8295 | return false; |
| 8296 | |
| 8297 | const ImGuiStyle& style = g.Style; |
| 8298 | const ImGuiID id = TabBarCalcTabID(tab_bar, label, docked_window); |
| 8299 | |
| 8300 | // If the user called us with *p_open == false, we early out and don't render. |
| 8301 | // 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. |
| 8302 | IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags); |
| 8303 | if (p_open && !*p_open) |
| 8304 | { |
| 8305 | ItemAdd(ImRect(), id, NULL, ImGuiItemFlags_NoNav); |
| 8306 | return false; |
| 8307 | } |
| 8308 | |
| 8309 | IM_ASSERT(!p_open || !(flags & ImGuiTabItemFlags_Button)); |
| 8310 | IM_ASSERT((flags & (ImGuiTabItemFlags_Leading | ImGuiTabItemFlags_Trailing)) != (ImGuiTabItemFlags_Leading | ImGuiTabItemFlags_Trailing)); // Can't use both Leading and Trailing |
| 8311 | |
| 8312 | // Store into ImGuiTabItemFlags_NoCloseButton, also honor ImGuiTabItemFlags_NoCloseButton passed by user (although not documented) |
| 8313 | if (flags & ImGuiTabItemFlags_NoCloseButton) |
| 8314 | p_open = NULL; |
| 8315 | else if (p_open == NULL) |
| 8316 | flags |= ImGuiTabItemFlags_NoCloseButton; |
| 8317 | |
| 8318 | // Acquire tab data |
| 8319 | ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, id); |
| 8320 | bool tab_is_new = false; |
| 8321 | if (tab == NULL) |
| 8322 | { |
| 8323 | tab_bar->Tabs.push_back(ImGuiTabItem()); |
| 8324 | tab = &tab_bar->Tabs.back(); |
| 8325 | tab->ID = id; |
| 8326 | tab_bar->TabsAddedNew = tab_is_new = true; |
| 8327 | } |
| 8328 | tab_bar->LastTabItemIdx = (ImS16)tab_bar->Tabs.index_from_ptr(tab); |
| 8329 | |
| 8330 | // Calculate tab contents size |
| 8331 | ImVec2 size = TabItemCalcSize(label, (p_open != NULL) || (flags & ImGuiTabItemFlags_UnsavedDocument)); |
| 8332 | tab->RequestedWidth = -1.0f; |
| 8333 | if (g.NextItemData.Flags & ImGuiNextItemDataFlags_HasWidth) |
| 8334 | size.x = tab->RequestedWidth = g.NextItemData.Width; |
| 8335 | if (tab_is_new) |
| 8336 | tab->Width = ImMax(1.0f, size.x); |
| 8337 | tab->ContentWidth = size.x; |
| 8338 | tab->BeginOrder = tab_bar->TabsActiveCount++; |
| 8339 | |
| 8340 | const bool tab_bar_appearing = (tab_bar->PrevFrameVisible + 1 < g.FrameCount); |
nothing calls this directly
no test coverage detected