TabBar: rename VisibleTabId->VisibleTabContentsId for clarify and correctness.

Toward #9581
This commit is contained in:
ocornut 2026-10-27 15:43:57 +01:00
parent 2f1552d4d5
commit 86b853ae8a
2 changed files with 12 additions and 11 deletions

View File

@ -2936,7 +2936,7 @@ struct ImGuiTabItem
{ {
ImGuiID ID; ImGuiID ID;
ImGuiTabItemFlags Flags; ImGuiTabItemFlags Flags;
int LastFrameVisible; int LastFrameVisible; // TabItem visibility (not contents visibility)
int LastFrameSelected; // This allows us to infer an ordered list of the last activated tabs with little maintenance int LastFrameSelected; // This allows us to infer an ordered list of the last activated tabs with little maintenance
float Offset; // Position relative to beginning of tab bar float Offset; // Position relative to beginning of tab bar
float Width; // Width currently displayed float Width; // Width currently displayed
@ -2960,7 +2960,7 @@ struct IMGUI_API ImGuiTabBar
ImGuiID SelectedTabId; // Selected tab/window ImGuiID SelectedTabId; // Selected tab/window
ImGuiID NextSelectedTabId; // Next selected tab/window. Will also trigger a scrolling animation ImGuiID NextSelectedTabId; // Next selected tab/window. Will also trigger a scrolling animation
ImGuiID NextScrollToTabId; ImGuiID NextScrollToTabId;
ImGuiID VisibleTabId; // Can occasionally be != SelectedTabId (e.g. when previewing contents for Ctrl+Tab preview) ImGuiID VisibleTabContentsId; // Can occasionally be != SelectedTabId (e.g. when previewing contents for Ctrl+Tab preview)
int CurrFrameVisible; int CurrFrameVisible;
int PrevFrameVisible; int PrevFrameVisible;
ImRect BarRect; ImRect BarRect;

View File

@ -10069,7 +10069,7 @@ void ImGui::EndTabBar()
// Restore the last visible height if no tab is visible, this reduce vertical flicker/movement when a tabs gets removed without calling SetTabItemClosed(). // Restore the last visible height if no tab is visible, this reduce vertical flicker/movement when a tabs gets removed without calling SetTabItemClosed().
const bool tab_bar_appearing = (tab_bar->PrevFrameVisible + 1 < g.FrameCount); const bool tab_bar_appearing = (tab_bar->PrevFrameVisible + 1 < g.FrameCount);
if (tab_bar->VisibleTabWasSubmitted || tab_bar->VisibleTabId == 0 || tab_bar_appearing) if (tab_bar->VisibleTabWasSubmitted || tab_bar->VisibleTabContentsId == 0 || tab_bar_appearing)
{ {
tab_bar->CurrTabsContentsHeight = ImMax(window->DC.CursorPos.y - tab_bar->BarRect.Max.y, tab_bar->CurrTabsContentsHeight); tab_bar->CurrTabsContentsHeight = ImMax(window->DC.CursorPos.y - tab_bar->BarRect.Max.y, tab_bar->CurrTabsContentsHeight);
window->DC.CursorPos.y = tab_bar->BarRect.Max.y + tab_bar->CurrTabsContentsHeight; window->DC.CursorPos.y = tab_bar->BarRect.Max.y + tab_bar->CurrTabsContentsHeight;
@ -10117,7 +10117,7 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar)
if (tab->LastFrameVisible < tab_bar->PrevFrameVisible || tab->WantClose) if (tab->LastFrameVisible < tab_bar->PrevFrameVisible || tab->WantClose)
{ {
// Remove tab // Remove tab
if (tab_bar->VisibleTabId == tab->ID) { tab_bar->VisibleTabId = 0; } if (tab_bar->VisibleTabContentsId == tab->ID) { tab_bar->VisibleTabContentsId = 0; }
if (tab_bar->SelectedTabId == tab->ID) { tab_bar->SelectedTabId = 0; } if (tab_bar->SelectedTabId == tab->ID) { tab_bar->SelectedTabId = 0; }
if (tab_bar->NextSelectedTabId == tab->ID) { tab_bar->NextSelectedTabId = 0; } if (tab_bar->NextSelectedTabId == tab->ID) { tab_bar->NextSelectedTabId = 0; }
continue; continue;
@ -10322,7 +10322,7 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar)
scroll_to_tab_id = tab_bar->SelectedTabId = most_recently_selected_tab->ID; scroll_to_tab_id = tab_bar->SelectedTabId = most_recently_selected_tab->ID;
// Lock in visible tab // Lock in visible tab
tab_bar->VisibleTabId = tab_bar->SelectedTabId; tab_bar->VisibleTabContentsId = tab_bar->SelectedTabId;
tab_bar->VisibleTabWasSubmitted = false; tab_bar->VisibleTabWasSubmitted = false;
// Apply request requests // Apply request requests
@ -10436,7 +10436,7 @@ void ImGui::TabBarRemoveTab(ImGuiTabBar* tab_bar, ImGuiID tab_id)
{ {
if (ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, tab_id)) if (ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, tab_id))
tab_bar->Tabs.erase(tab); tab_bar->Tabs.erase(tab);
if (tab_bar->VisibleTabId == tab_id) { tab_bar->VisibleTabId = 0; } if (tab_bar->VisibleTabContentsId == tab_id){ tab_bar->VisibleTabContentsId = 0; }
if (tab_bar->SelectedTabId == tab_id) { tab_bar->SelectedTabId = 0; } if (tab_bar->SelectedTabId == tab_id) { tab_bar->SelectedTabId = 0; }
if (tab_bar->NextSelectedTabId == tab_id) { tab_bar->NextSelectedTabId = 0; } if (tab_bar->NextSelectedTabId == tab_id) { tab_bar->NextSelectedTabId = 0; }
} }
@ -10452,7 +10452,7 @@ void ImGui::TabBarCloseTab(ImGuiTabBar* tab_bar, ImGuiTabItem* tab)
// This will remove a frame of lag for selecting another tab on closure. // This will remove a frame of lag for selecting another tab on closure.
// However we don't run it in the case where the 'Unsaved' flag is set, so user gets a chance to fully undo the closure // However we don't run it in the case where the 'Unsaved' flag is set, so user gets a chance to fully undo the closure
tab->WantClose = true; tab->WantClose = true;
if (tab_bar->VisibleTabId == tab->ID) if (tab_bar->VisibleTabContentsId == tab->ID)
{ {
tab->LastFrameVisible = -1; tab->LastFrameVisible = -1;
tab_bar->SelectedTabId = tab_bar->NextSelectedTabId = 0; tab_bar->SelectedTabId = tab_bar->NextSelectedTabId = 0;
@ -10461,7 +10461,7 @@ void ImGui::TabBarCloseTab(ImGuiTabBar* tab_bar, ImGuiTabItem* tab)
else else
{ {
// Actually select before expecting closure attempt (on an UnsavedDocument tab user is expect to e.g. show a popup) // Actually select before expecting closure attempt (on an UnsavedDocument tab user is expect to e.g. show a popup)
if (tab_bar->VisibleTabId != tab->ID) if (tab_bar->VisibleTabContentsId != tab->ID)
TabBarQueueFocus(tab_bar, tab); TabBarQueueFocus(tab_bar, tab);
} }
} }
@ -10865,7 +10865,7 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open,
// Lock visibility // Lock visibility
// (Note: tab_contents_visible != tab_selected... because Ctrl+Tab operations may preview some tabs without selecting them!) // (Note: tab_contents_visible != tab_selected... because Ctrl+Tab operations may preview some tabs without selecting them!)
bool tab_contents_visible = (tab_bar->VisibleTabId == id); bool tab_contents_visible = (tab_bar->VisibleTabContentsId == id);
if (tab_contents_visible) if (tab_contents_visible)
tab_bar->VisibleTabWasSubmitted = true; tab_bar->VisibleTabWasSubmitted = true;
@ -10878,6 +10878,7 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open,
// and then gets submitted again, the tabs will have 'tab_appearing=true' but 'tab_is_new=false'. // 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)) if (tab_appearing && (!tab_bar_appearing || tab_is_new))
{ {
// This path doesn't render the tab.
ItemAdd(ImRect(), id, NULL, ImGuiItemFlags_NoNav); ItemAdd(ImRect(), id, NULL, ImGuiItemFlags_NoNav);
if (is_tab_button) if (is_tab_button)
return false; return false;