| 8776 | } |
| 8777 | |
| 8778 | bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, ImGuiTabItemFlags flags, ImGuiWindow* docked_window) |
| 8779 | { |
| 8780 | // Layout whole tab bar if not already done |
| 8781 | ImGuiContext& g = *GImGui; |
| 8782 | if (tab_bar->WantLayout) |
| 8783 | { |
| 8784 | ImGuiNextItemData backup_next_item_data = g.NextItemData; |
| 8785 | TabBarLayout(tab_bar); |
| 8786 | g.NextItemData = backup_next_item_data; |
| 8787 | } |
| 8788 | ImGuiWindow* window = g.CurrentWindow; |
| 8789 | if (window->SkipItems) |
| 8790 | return false; |
| 8791 | |
| 8792 | const ImGuiStyle& style = g.Style; |
| 8793 | const ImGuiID id = TabBarCalcTabID(tab_bar, label, docked_window); |
| 8794 | |
| 8795 | // If the user called us with *p_open == false, we early out and don't render. |
| 8796 | // 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. |
| 8797 | IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags); |
| 8798 | if (p_open && !*p_open) |
| 8799 | { |
| 8800 | ItemAdd(ImRect(), id, NULL, ImGuiItemFlags_NoNav); |
| 8801 | return false; |
| 8802 | } |
| 8803 | |
| 8804 | IM_ASSERT(!p_open || !(flags & ImGuiTabItemFlags_Button)); |
| 8805 | IM_ASSERT((flags & (ImGuiTabItemFlags_Leading | ImGuiTabItemFlags_Trailing)) != (ImGuiTabItemFlags_Leading | ImGuiTabItemFlags_Trailing)); // Can't use both Leading and Trailing |
| 8806 | |
| 8807 | // Store into ImGuiTabItemFlags_NoCloseButton, also honor ImGuiTabItemFlags_NoCloseButton passed by user (although not documented) |
| 8808 | if (flags & ImGuiTabItemFlags_NoCloseButton) |
| 8809 | p_open = NULL; |
| 8810 | else if (p_open == NULL) |
| 8811 | flags |= ImGuiTabItemFlags_NoCloseButton; |
| 8812 | |
| 8813 | // Acquire tab data |
| 8814 | ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, id); |
| 8815 | bool tab_is_new = false; |
| 8816 | if (tab == NULL) |
| 8817 | { |
| 8818 | tab_bar->Tabs.push_back(ImGuiTabItem()); |
| 8819 | tab = &tab_bar->Tabs.back(); |
| 8820 | tab->ID = id; |
| 8821 | tab_bar->TabsAddedNew = tab_is_new = true; |
| 8822 | } |
| 8823 | tab_bar->LastTabItemIdx = (ImS16)tab_bar->Tabs.index_from_ptr(tab); |
| 8824 | |
| 8825 | // Calculate tab contents size |
| 8826 | ImVec2 size = TabItemCalcSize(label, (p_open != NULL) || (flags & ImGuiTabItemFlags_UnsavedDocument)); |
| 8827 | tab->RequestedWidth = -1.0f; |
| 8828 | if (g.NextItemData.Flags & ImGuiNextItemDataFlags_HasWidth) |
| 8829 | size.x = tab->RequestedWidth = g.NextItemData.Width; |
| 8830 | if (tab_is_new) |
| 8831 | tab->Width = ImMax(1.0f, size.x); |
| 8832 | tab->ContentWidth = size.x; |
| 8833 | tab->BeginOrder = tab_bar->TabsActiveCount++; |
| 8834 | |
| 8835 | const bool tab_bar_appearing = (tab_bar->PrevFrameVisible + 1 < g.FrameCount); |
nothing calls this directly
no test coverage detected