From b15b25bccd108832aee7b8e75a53072830c353fe Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 6 Aug 2020 16:35:29 +0200 Subject: [PATCH] TabBar: made a change to that declared ideal width (for auto-resize) won't lag by an extra frame. Vaguely relate to underlying (uncommited) work for #3291 --- imgui_widgets.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 1d4362d0..1378613c 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -6657,9 +6657,9 @@ bool ImGui::BeginTabBarEx(ImGuiTabBar* tab_bar, const ImRect& tab_bar_bb, ImG tab_bar->CurrFrameVisible = g.FrameCount; tab_bar->FramePadding = g.Style.FramePadding; - // Layout - ItemSize(ImVec2(tab_bar->OffsetMaxIdeal, tab_bar->BarRect.GetHeight()), tab_bar->FramePadding.y); + // Set cursor pos in a way which only be used in the off-chance the user erroneously submits item before BeginTabItem(): items will overlap window->DC.CursorPos.x = tab_bar->BarRect.Min.x; + window->DC.CursorPos.y = tab_bar->BarRect.Max.y + g.Style.ItemSpacing.y; // Draw separator const ImU32 col = GetColorU32((flags & ImGuiTabBarFlags_IsFocused) ? ImGuiCol_TabActive : ImGuiCol_TabUnfocusedActive); @@ -6685,7 +6685,7 @@ void ImGui::EndTabBar() IM_ASSERT_USER_ERROR(tab_bar != NULL, "Mismatched BeginTabBar()/EndTabBar()!"); return; } - if (tab_bar->WantLayout) + if (tab_bar->WantLayout) // Fallback in case no TabItem have been submitted TabBarLayout(tab_bar); // Restore the last visible height if no tab is visible, this reduce vertical flicker/movement when a tabs gets removed without calling SetTabItemClosed(). @@ -6871,6 +6871,11 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) // Clear name buffers if ((tab_bar->Flags & ImGuiTabBarFlags_DockNode) == 0) tab_bar->TabsNames.Buf.resize(0); + + // Actual layout in host window (we don't do it in BeginTabBar() so as not to waste an extra frame) + ImGuiWindow* window = g.CurrentWindow; + window->DC.CursorPos = tab_bar->BarRect.Min; + ItemSize(ImVec2(tab_bar->OffsetMaxIdeal, tab_bar->BarRect.GetHeight()), tab_bar->FramePadding.y); } // Dockables uses Name/ID in the global namespace. Non-dockable items use the ID stack.