mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
Tab Bar: Restore cursor position in EndTabBar() when amending (amend f2f32602
) + made LastTabItemIdx consistent ImS8 as other tab storage relies on same type
This commit is contained in:
parent
c9fafd5ea4
commit
748bd1ba9c
@ -1743,10 +1743,11 @@ struct ImGuiTabItem
|
|||||||
ImGuiTabItem() { ID = 0; Flags = ImGuiTabItemFlags_None; LastFrameVisible = LastFrameSelected = -1; NameOffset = -1; Offset = Width = ContentWidth = 0.0f; BeginOrder = -1; IndexDuringLayout = -1; WantClose = false; }
|
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
|
struct ImGuiTabBar
|
||||||
{
|
{
|
||||||
ImVector<ImGuiTabItem> Tabs;
|
ImVector<ImGuiTabItem> Tabs;
|
||||||
|
ImGuiTabBarFlags Flags;
|
||||||
ImGuiID ID; // Zero for tab-bars used by docking
|
ImGuiID ID; // Zero for tab-bars used by docking
|
||||||
ImGuiID SelectedTabId; // Selected tab/window
|
ImGuiID SelectedTabId; // Selected tab/window
|
||||||
ImGuiID NextSelectedTabId;
|
ImGuiID NextSelectedTabId;
|
||||||
@ -1764,16 +1765,17 @@ struct ImGuiTabBar
|
|||||||
float ScrollingSpeed;
|
float ScrollingSpeed;
|
||||||
float ScrollingRectMinX;
|
float ScrollingRectMinX;
|
||||||
float ScrollingRectMaxX;
|
float ScrollingRectMaxX;
|
||||||
ImGuiTabBarFlags Flags;
|
|
||||||
ImGuiID ReorderRequestTabId;
|
ImGuiID ReorderRequestTabId;
|
||||||
ImS8 ReorderRequestDir;
|
ImS8 ReorderRequestDir;
|
||||||
ImS8 TabsActiveCount; // Number of tabs submitted this frame.
|
ImS8 TabsActiveCount; // Number of tabs submitted this frame.
|
||||||
|
ImS8 LastTabItemIdx; // Index of last BeginTabItem() tab for use by EndTabItem()
|
||||||
|
ImS8 BeginCount;
|
||||||
bool WantLayout;
|
bool WantLayout;
|
||||||
bool VisibleTabWasSubmitted;
|
bool VisibleTabWasSubmitted;
|
||||||
bool TabsAddedNew; // Set to true when a new tab item or button has been added to the tab bar during last frame
|
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 FramePadding; // style.FramePadding locked at the time of BeginTabBar()
|
||||||
ImVec2 TabsContentsMin;
|
ImVec2 TabsContentsMin;
|
||||||
|
ImVec2 BackupCursorPos;
|
||||||
ImGuiTextBuffer TabsNames; // For non-docking tab bar we re-append names in a contiguous buffer.
|
ImGuiTextBuffer TabsNames; // For non-docking tab bar we re-append names in a contiguous buffer.
|
||||||
|
|
||||||
ImGuiTabBar();
|
ImGuiTabBar();
|
||||||
|
@ -6802,6 +6802,7 @@ namespace ImGui
|
|||||||
|
|
||||||
ImGuiTabBar::ImGuiTabBar()
|
ImGuiTabBar::ImGuiTabBar()
|
||||||
{
|
{
|
||||||
|
Flags = ImGuiTabBarFlags_None;
|
||||||
ID = 0;
|
ID = 0;
|
||||||
SelectedTabId = NextSelectedTabId = VisibleTabId = 0;
|
SelectedTabId = NextSelectedTabId = VisibleTabId = 0;
|
||||||
CurrFrameVisible = PrevFrameVisible = -1;
|
CurrFrameVisible = PrevFrameVisible = -1;
|
||||||
@ -6809,12 +6810,12 @@ ImGuiTabBar::ImGuiTabBar()
|
|||||||
WidthAllTabs = WidthAllTabsIdeal = 0.0f;
|
WidthAllTabs = WidthAllTabsIdeal = 0.0f;
|
||||||
ScrollingAnim = ScrollingTarget = ScrollingTargetDistToVisibility = ScrollingSpeed = 0.0f;
|
ScrollingAnim = ScrollingTarget = ScrollingTargetDistToVisibility = ScrollingSpeed = 0.0f;
|
||||||
ScrollingRectMinX = ScrollingRectMaxX = 0.0f;
|
ScrollingRectMinX = ScrollingRectMaxX = 0.0f;
|
||||||
Flags = ImGuiTabBarFlags_None;
|
|
||||||
ReorderRequestTabId = 0;
|
ReorderRequestTabId = 0;
|
||||||
ReorderRequestDir = 0;
|
ReorderRequestDir = 0;
|
||||||
TabsActiveCount = 0;
|
TabsActiveCount = 0;
|
||||||
WantLayout = VisibleTabWasSubmitted = TabsAddedNew = false;
|
|
||||||
LastTabItemIdx = -1;
|
LastTabItemIdx = -1;
|
||||||
|
BeginCount = 0;
|
||||||
|
WantLayout = VisibleTabWasSubmitted = TabsAddedNew = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int IMGUI_CDECL TabItemComparerBySection(const void* lhs, const void* rhs)
|
static int IMGUI_CDECL TabItemComparerBySection(const void* lhs, const void* rhs)
|
||||||
@ -6878,9 +6879,11 @@ bool ImGui::BeginTabBarEx(ImGuiTabBar* tab_bar, const ImRect& tab_bar_bb, ImG
|
|||||||
g.CurrentTabBar = tab_bar;
|
g.CurrentTabBar = tab_bar;
|
||||||
|
|
||||||
// Append with multiple BeginTabBar()/EndTabBar() pairs.
|
// Append with multiple BeginTabBar()/EndTabBar() pairs.
|
||||||
|
tab_bar->BackupCursorPos = window->DC.CursorPos;
|
||||||
if (tab_bar->CurrFrameVisible == g.FrameCount)
|
if (tab_bar->CurrFrameVisible == g.FrameCount)
|
||||||
{
|
{
|
||||||
window->DC.CursorPos = tab_bar->TabsContentsMin;
|
window->DC.CursorPos = tab_bar->TabsContentsMin;
|
||||||
|
tab_bar->BeginCount++;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6903,6 +6906,7 @@ bool ImGui::BeginTabBarEx(ImGuiTabBar* tab_bar, const ImRect& tab_bar_bb, ImG
|
|||||||
tab_bar->CurrTabsContentsHeight = 0.0f;
|
tab_bar->CurrTabsContentsHeight = 0.0f;
|
||||||
tab_bar->FramePadding = g.Style.FramePadding;
|
tab_bar->FramePadding = g.Style.FramePadding;
|
||||||
tab_bar->TabsActiveCount = 0;
|
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
|
// 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;
|
tab_bar->TabsContentsMin.x = tab_bar->BarRect.Min.x;
|
||||||
@ -6949,6 +6953,8 @@ void ImGui::EndTabBar()
|
|||||||
{
|
{
|
||||||
window->DC.CursorPos.y = tab_bar->BarRect.Max.y + tab_bar->PrevTabsContentsHeight;
|
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)
|
if ((tab_bar->Flags & ImGuiTabBarFlags_DockNode) == 0)
|
||||||
PopID();
|
PopID();
|
||||||
@ -7543,7 +7549,7 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open,
|
|||||||
tab_bar->TabsAddedNew = true;
|
tab_bar->TabsAddedNew = true;
|
||||||
tab_is_new = 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->ContentWidth = size.x;
|
||||||
tab->BeginOrder = tab_bar->TabsActiveCount++;
|
tab->BeginOrder = tab_bar->TabsActiveCount++;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user