From 1069a952e026f2640462ec6a5156c31d6b3f4030 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 27 Oct 2026 16:27:10 +0100 Subject: [PATCH] TabBar: Internals: added TabItemIsContentsAppearing() and reworked 50ae760. (#9581) --- imgui_internal.h | 3 ++- imgui_widgets.cpp | 25 ++++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/imgui_internal.h b/imgui_internal.h index 69acf63eb..16743905c 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -2983,7 +2983,7 @@ struct IMGUI_API ImGuiTabBar ImS8 BeginCount; bool WantLayout; bool VisibleTabWasSubmitted; - bool VisibleTabContentsJustAppeared; + bool LastTabItemContentsAppearing; 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. @@ -3778,6 +3778,7 @@ namespace ImGui IMGUI_API void TabBarQueueReorderFromMousePos(ImGuiTabBar* tab_bar, ImGuiTabItem* tab, ImVec2 mouse_pos); IMGUI_API bool TabBarProcessReorder(ImGuiTabBar* tab_bar); IMGUI_API bool TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, ImGuiTabItemFlags flags, ImGuiWindow* docked_window); + IMGUI_API bool TabItemIsContentsAppearing(); IMGUI_API void TabItemSpacing(const char* str_id, ImGuiTabItemFlags flags, float width); IMGUI_API ImVec2 TabItemCalcSize(const char* label, bool has_close_button_or_unsaved_marker); IMGUI_API ImVec2 TabItemCalcSize(ImGuiWindow* window); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 22ffe8de5..ea5871a51 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -10323,7 +10323,7 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) // Lock in visible tab tab_bar->VisibleTabContentsId = tab_bar->SelectedTabId; - tab_bar->VisibleTabWasSubmitted = tab_bar->VisibleTabContentsJustAppeared = false; + tab_bar->VisibleTabWasSubmitted = tab_bar->LastTabItemContentsAppearing = false; // Apply request requests if (scroll_to_tab_id != 0) @@ -10752,6 +10752,12 @@ void ImGui::EndTabItem() PopID(); } +bool ImGui::TabItemIsContentsAppearing() +{ + ImGuiContext& g = *GImGui; + return g.CurrentTabBar->LastTabItemContentsAppearing; +} + bool ImGui::TabItemButton(const char* label, ImGuiTabItemFlags flags) { ImGuiContext& g = *GImGui; @@ -10863,20 +10869,17 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, TabBarQueueFocus(tab_bar, tab); } + // On the very first frame of a tab bar we let first tab contents be visible to minimize appearing glitches + if (tab_bar->VisibleTabContentsId == 0 && tab_bar->SelectedTabId == 0 && tab_bar_appearing) + if (tab_bar->Tabs.Size == 1 && !(tab_bar->Flags & ImGuiTabBarFlags_AutoSelectNewTabs)) + tab_bar->VisibleTabContentsId = id; + // 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); - - // 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; - + const bool tab_contents_visible = (tab_bar->VisibleTabContentsId == id); if (tab_contents_visible) - { tab_bar->VisibleTabWasSubmitted = true; - tab_bar->VisibleTabContentsJustAppeared = tab_contents_visible && !tab->ContentsIsVisible; - } + tab_bar->LastTabItemContentsAppearing = 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