| 10583 | } |
| 10584 | |
| 10585 | bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, ImGuiTabItemFlags flags, ImGuiWindow* docked_window) |
| 10586 | { |
| 10587 | // Layout whole tab bar if not already done |
| 10588 | ImGuiContext& g = *GImGui; |
| 10589 | if (tab_bar->WantLayout) |
| 10590 | { |
| 10591 | ImGuiNextItemData backup_next_item_data = g.NextItemData; |
| 10592 | TabBarLayout(tab_bar); |
| 10593 | g.NextItemData = backup_next_item_data; |
| 10594 | } |
| 10595 | ImGuiWindow* window = g.CurrentWindow; |
| 10596 | if (window->SkipItems) |
| 10597 | return false; |
| 10598 | |
| 10599 | const ImGuiStyle& style = g.Style; |
| 10600 | const ImGuiID id = TabBarCalcTabID(tab_bar, label, docked_window); |
| 10601 | |
| 10602 | // If the user called us with *p_open == false, we early out and don't render. |
| 10603 | // 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. |
| 10604 | IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags); |
| 10605 | if (p_open && !*p_open) |
| 10606 | { |
| 10607 | ItemAdd(ImRect(), id, NULL, ImGuiItemFlags_NoNav); |
| 10608 | return false; |
| 10609 | } |
| 10610 | |
| 10611 | IM_ASSERT(!p_open || !(flags & ImGuiTabItemFlags_Button)); |
| 10612 | IM_ASSERT((flags & (ImGuiTabItemFlags_Leading | ImGuiTabItemFlags_Trailing)) != (ImGuiTabItemFlags_Leading | ImGuiTabItemFlags_Trailing)); // Can't use both Leading and Trailing |
| 10613 | |
| 10614 | // Store into ImGuiTabItemFlags_NoCloseButton, also honor ImGuiTabItemFlags_NoCloseButton passed by user (although not documented) |
| 10615 | if (flags & ImGuiTabItemFlags_NoCloseButton) |
| 10616 | p_open = NULL; |
| 10617 | else if (p_open == NULL) |
| 10618 | flags |= ImGuiTabItemFlags_NoCloseButton; |
| 10619 | |
| 10620 | // Acquire tab data |
| 10621 | ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, id); |
| 10622 | bool tab_is_new = false; |
| 10623 | if (tab == NULL) |
| 10624 | { |
| 10625 | tab_bar->Tabs.push_back(ImGuiTabItem()); |
| 10626 | tab = &tab_bar->Tabs.back(); |
| 10627 | tab->ID = id; |
| 10628 | tab_bar->TabsAddedNew = tab_is_new = true; |
| 10629 | } |
| 10630 | tab_bar->LastTabItemIdx = (ImS16)tab_bar->Tabs.index_from_ptr(tab); |
| 10631 | |
| 10632 | // Calculate tab contents size |
| 10633 | ImVec2 size = TabItemCalcSize(label, (p_open != NULL) || (flags & ImGuiTabItemFlags_UnsavedDocument)); |
| 10634 | tab->RequestedWidth = -1.0f; |
| 10635 | if (g.NextItemData.HasFlags & ImGuiNextItemDataFlags_HasWidth) |
| 10636 | size.x = tab->RequestedWidth = g.NextItemData.Width; |
| 10637 | if (tab_is_new) |
| 10638 | tab->Width = ImMax(1.0f, size.x); |
| 10639 | tab->ContentWidth = size.x; |
| 10640 | tab->BeginOrder = tab_bar->TabsActiveCount++; |
| 10641 | |
| 10642 | const bool tab_bar_appearing = (tab_bar->PrevFrameVisible + 1 < g.FrameCount); |
nothing calls this directly
no test coverage detected