Tab Bar: Restore cursor position in EndTabBar() when amending (amend f2f32602) + made LastTabItemIdx consistent ImS8 as other tab storage relies on same type
diff --git a/imgui_internal.h b/imgui_internal.h
index 013c813..3cdc779 100644
--- a/imgui_internal.h
+++ b/imgui_internal.h
@@ -1743,10 +1743,11 @@
ImGuiTabItem() { ID = 0; Flags = ImGuiTabItemFlags_None; LastFrameVisible = LastFrameSelected = -1; NameOffset = -1; Offset = Width = ContentWidth = 0.0f; BeginOrder = -1; IndexDuringLayout = -1; WantClose = false; }
};
-// Storage for a tab bar (sizeof() 92~96 bytes)
+// Storage for a tab bar (sizeof() 152 bytes)
struct ImGuiTabBar
{
ImVector<ImGuiTabItem> Tabs;
+ ImGuiTabBarFlags Flags;
ImGuiID ID; // Zero for tab-bars used by docking
ImGuiID SelectedTabId; // Selected tab/window
ImGuiID NextSelectedTabId;
@@ -1764,16 +1765,17 @@
float ScrollingSpeed;
float ScrollingRectMinX;
float ScrollingRectMaxX;
- ImGuiTabBarFlags Flags;
ImGuiID ReorderRequestTabId;
ImS8 ReorderRequestDir;
ImS8 TabsActiveCount; // Number of tabs submitted this frame.
+ ImS8 LastTabItemIdx; // Index of last BeginTabItem() tab for use by EndTabItem()
+ ImS8 BeginCount;
bool WantLayout;
bool VisibleTabWasSubmitted;
bool TabsAddedNew; // Set to true when a new tab item or button has been added to the tab bar during last frame
- short LastTabItemIdx; // Index of last BeginTabItem() tab for use by EndTabItem()
ImVec2 FramePadding; // style.FramePadding locked at the time of BeginTabBar()
ImVec2 TabsContentsMin;
+ ImVec2 BackupCursorPos;
ImGuiTextBuffer TabsNames; // For non-docking tab bar we re-append names in a contiguous buffer.
ImGuiTabBar();
diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp
index a908184..b9346e3 100644
--- a/imgui_widgets.cpp
+++ b/imgui_widgets.cpp
@@ -6802,6 +6802,7 @@
ImGuiTabBar::ImGuiTabBar()
{
+ Flags = ImGuiTabBarFlags_None;
ID = 0;
SelectedTabId = NextSelectedTabId = VisibleTabId = 0;
CurrFrameVisible = PrevFrameVisible = -1;
@@ -6809,12 +6810,12 @@
WidthAllTabs = WidthAllTabsIdeal = 0.0f;
ScrollingAnim = ScrollingTarget = ScrollingTargetDistToVisibility = ScrollingSpeed = 0.0f;
ScrollingRectMinX = ScrollingRectMaxX = 0.0f;
- Flags = ImGuiTabBarFlags_None;
ReorderRequestTabId = 0;
ReorderRequestDir = 0;
TabsActiveCount = 0;
- WantLayout = VisibleTabWasSubmitted = TabsAddedNew = false;
LastTabItemIdx = -1;
+ BeginCount = 0;
+ WantLayout = VisibleTabWasSubmitted = TabsAddedNew = false;
}
static int IMGUI_CDECL TabItemComparerBySection(const void* lhs, const void* rhs)
@@ -6878,9 +6879,11 @@
g.CurrentTabBar = tab_bar;
// Append with multiple BeginTabBar()/EndTabBar() pairs.
+ tab_bar->BackupCursorPos = window->DC.CursorPos;
if (tab_bar->CurrFrameVisible == g.FrameCount)
{
window->DC.CursorPos = tab_bar->TabsContentsMin;
+ tab_bar->BeginCount++;
return true;
}
@@ -6903,6 +6906,7 @@
tab_bar->CurrTabsContentsHeight = 0.0f;
tab_bar->FramePadding = g.Style.FramePadding;
tab_bar->TabsActiveCount = 0;
+ tab_bar->BeginCount = 1;
// Set cursor pos in a way which only be used in the off-chance the user erroneously submits item before BeginTabItem(): items will overlap
tab_bar->TabsContentsMin.x = tab_bar->BarRect.Min.x;
@@ -6949,6 +6953,8 @@
{
window->DC.CursorPos.y = tab_bar->BarRect.Max.y + tab_bar->PrevTabsContentsHeight;
}
+ if (tab_bar->BeginCount > 1)
+ window->DC.CursorPos = tab_bar->BackupCursorPos;
if ((tab_bar->Flags & ImGuiTabBarFlags_DockNode) == 0)
PopID();
@@ -7543,7 +7549,7 @@
tab_bar->TabsAddedNew = true;
tab_is_new = true;
}
- tab_bar->LastTabItemIdx = (short)tab_bar->Tabs.index_from_ptr(tab);
+ tab_bar->LastTabItemIdx = (ImS8)tab_bar->Tabs.index_from_ptr(tab);
tab->ContentWidth = size.x;
tab->BeginOrder = tab_bar->TabsActiveCount++;