MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / TabBarLayout

Method TabBarLayout

KBotExt/imgui/imgui_widgets.cpp:7659–7899  ·  view source on GitHub ↗

This is called only once a frame before by the first call to ItemTab() The reason we're not calling it in BeginTabBar() is to leave a chance to the user to call the SetTabItemClosed() functions.

Source from the content-addressed store, hash-verified

7657// This is called only once a frame before by the first call to ItemTab()
7658// The reason we're not calling it in BeginTabBar() is to leave a chance to the user to call the SetTabItemClosed() functions.
7659static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar)
7660{
7661 ImGuiContext& g = *GImGui;
7662 tab_bar->WantLayout = false;
7663
7664 // Garbage collect by compacting list
7665 // Detect if we need to sort out tab list (e.g. in rare case where a tab changed section)
7666 int tab_dst_n = 0;
7667 bool need_sort_by_section = false;
7668 ImGuiTabBarSection sections[3]; // Layout sections: Leading, Central, Trailing
7669 for (int tab_src_n = 0; tab_src_n < tab_bar->Tabs.Size; tab_src_n++)
7670 {
7671 ImGuiTabItem* tab = &tab_bar->Tabs[tab_src_n];
7672 if (tab->LastFrameVisible < tab_bar->PrevFrameVisible || tab->WantClose)
7673 {
7674 // Remove tab
7675 if (tab_bar->VisibleTabId == tab->ID) { tab_bar->VisibleTabId = 0; }
7676 if (tab_bar->SelectedTabId == tab->ID) { tab_bar->SelectedTabId = 0; }
7677 if (tab_bar->NextSelectedTabId == tab->ID) { tab_bar->NextSelectedTabId = 0; }
7678 continue;
7679 }
7680 if (tab_dst_n != tab_src_n)
7681 tab_bar->Tabs[tab_dst_n] = tab_bar->Tabs[tab_src_n];
7682
7683 tab = &tab_bar->Tabs[tab_dst_n];
7684 tab->IndexDuringLayout = (ImS16)tab_dst_n;
7685
7686 // We will need sorting if tabs have changed section (e.g. moved from one of Leading/Central/Trailing to another)
7687 int curr_tab_section_n = TabItemGetSectionIdx(tab);
7688 if (tab_dst_n > 0)
7689 {
7690 ImGuiTabItem* prev_tab = &tab_bar->Tabs[tab_dst_n - 1];
7691 int prev_tab_section_n = TabItemGetSectionIdx(prev_tab);
7692 if (curr_tab_section_n == 0 && prev_tab_section_n != 0)
7693 need_sort_by_section = true;
7694 if (prev_tab_section_n == 2 && curr_tab_section_n != 2)
7695 need_sort_by_section = true;
7696 }
7697
7698 sections[curr_tab_section_n].TabCount++;
7699 tab_dst_n++;
7700 }
7701 if (tab_bar->Tabs.Size != tab_dst_n)
7702 tab_bar->Tabs.resize(tab_dst_n);
7703
7704 if (need_sort_by_section)
7705 ImQsort(tab_bar->Tabs.Data, tab_bar->Tabs.Size, sizeof(ImGuiTabItem), TabItemComparerBySection);
7706
7707 // Calculate spacing between sections
7708 sections[0].Spacing = sections[0].TabCount > 0 && (sections[1].TabCount + sections[2].TabCount) > 0 ? g.Style.ItemInnerSpacing.x : 0.0f;
7709 sections[1].Spacing = sections[1].TabCount > 0 && sections[2].TabCount > 0 ? g.Style.ItemInnerSpacing.x : 0.0f;
7710
7711 // Setup next selected tab
7712 ImGuiID scroll_to_tab_id = 0;
7713 if (tab_bar->NextSelectedTabId)
7714 {
7715 tab_bar->SelectedTabId = tab_bar->NextSelectedTabId;
7716 tab_bar->NextSelectedTabId = 0;

Callers

nothing calls this directly

Calls 8

TabItemGetSectionIdxFunction · 0.85
ImQsortFunction · 0.85
ImMaxFunction · 0.85
ImMinFunction · 0.85
ImLinearSweepFunction · 0.85
ItemSizeFunction · 0.85
ImVec2Function · 0.85

Tested by

no test coverage detected