TabBar: Internals: add tab_bar->VisibleTabContentsJustAppeared. (#9581)

This commit is contained in:
ocornut 2026-10-27 15:50:22 +01:00
parent 86b853ae8a
commit 50ae760fce
2 changed files with 10 additions and 3 deletions

View File

@ -2946,6 +2946,7 @@ struct ImGuiTabItem
ImS16 BeginOrder; // BeginTabItem() order, used to re-order tabs after toggling ImGuiTabBarFlags_Reorderable
ImS16 IndexDuringLayout; // Index only used during TabBarLayout(). Tabs gets reordered so 'Tabs[n].IndexDuringLayout == n' but may mismatch during additions.
bool WantClose; // Marked as closed by SetTabItemClosed()
bool ContentsIsVisible;
ImGuiTabItem() { memset((void*)this, 0, sizeof(*this)); LastFrameVisible = LastFrameSelected = -1; RequestedWidth = -1.0f; NameOffset = -1; BeginOrder = IndexDuringLayout = -1; }
};
@ -2982,6 +2983,7 @@ struct IMGUI_API ImGuiTabBar
ImS8 BeginCount;
bool WantLayout;
bool VisibleTabWasSubmitted;
bool VisibleTabContentsJustAppeared;
bool TabsAddedNew; // Set to true when a new tab item or button has been added to the tab bar during last frame
bool ScrollButtonEnabled;
ImS16 TabsActiveCount; // Number of tabs submitted this frame.

View File

@ -10323,7 +10323,7 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar)
// Lock in visible tab
tab_bar->VisibleTabContentsId = tab_bar->SelectedTabId;
tab_bar->VisibleTabWasSubmitted = false;
tab_bar->VisibleTabWasSubmitted = tab_bar->VisibleTabContentsJustAppeared = false;
// Apply request requests
if (scroll_to_tab_id != 0)
@ -10866,14 +10866,19 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open,
// Lock visibility
// (Note: tab_contents_visible != tab_selected... because Ctrl+Tab operations may preview some tabs without selecting them!)
bool tab_contents_visible = (tab_bar->VisibleTabContentsId == id);
if (tab_contents_visible)
tab_bar->VisibleTabWasSubmitted = true;
// On the very first frame of a tab bar we let first tab contents be visible to minimize appearing glitches
if (!tab_contents_visible && tab_bar->SelectedTabId == 0 && tab_bar_appearing)
if (tab_bar->Tabs.Size == 1 && !(tab_bar->Flags & ImGuiTabBarFlags_AutoSelectNewTabs))
tab_contents_visible = true;
if (tab_contents_visible)
{
tab_bar->VisibleTabWasSubmitted = true;
tab_bar->VisibleTabContentsJustAppeared = tab_contents_visible && !tab->ContentsIsVisible;
}
tab->ContentsIsVisible = tab_contents_visible;
// Note that tab_is_new is not necessarily the same as tab_appearing! When a tab bar stops being submitted
// and then gets submitted again, the tabs will have 'tab_appearing=true' but 'tab_is_new=false'.
if (tab_appearing && (!tab_bar_appearing || tab_is_new))