Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request (patch included): add ImGuiTabBarFlags_X option to remove separator line under tab-bar #4859

Closed
nobody-special666 opened this issue Jan 4, 2022 · 3 comments
Labels
style tabs tab bars, tabs

Comments

@nobody-special666
Copy link

Version: latest
Branch: docking

Back-ends: any
Compiler: any
Operating System: any

This is a follow-up to my previous issue #4850.
Attached is a patch to prevent the separator line under the tab-bar from being drawn in case the user doesn't want it.
And also adds the option to the imgui_demo.

Please consider for inclusion.
Thanks for ImGui!
Regards.

image

diff --git a/imgui.h b/imgui.h
index ceb3b086d..ace89ebc1 100644
--- a/imgui.h
+++ b/imgui.h
@@ -1144,6 +1144,7 @@ enum ImGuiTabBarFlags_
     ImGuiTabBarFlags_NoTooltip                      = 1 << 5,   // Disable tooltips when hovering a tab
     ImGuiTabBarFlags_FittingPolicyResizeDown        = 1 << 6,   // Resize tabs when they don't fit
     ImGuiTabBarFlags_FittingPolicyScroll            = 1 << 7,   // Add scroll buttons when tabs don't fit
+    ImGuiTabBarFlags_NoBaseSeparator                = 1 << 8,   // Disable drawing the separator line at the base of tabs
     ImGuiTabBarFlags_FittingPolicyMask_             = ImGuiTabBarFlags_FittingPolicyResizeDown | ImGuiTabBarFlags_FittingPolicyScroll,
     ImGuiTabBarFlags_FittingPolicyDefault_          = ImGuiTabBarFlags_FittingPolicyResizeDown
 };
diff --git a/imgui_demo.cpp b/imgui_demo.cpp
index 5d6779e9a..24b4c6e30 100644
--- a/imgui_demo.cpp
+++ b/imgui_demo.cpp
@@ -1592,6 +1592,7 @@ static void ShowDemoWindowWidgets()
                 tab_bar_flags &= ~(ImGuiTabBarFlags_FittingPolicyMask_ ^ ImGuiTabBarFlags_FittingPolicyResizeDown);
             if (ImGui::CheckboxFlags("ImGuiTabBarFlags_FittingPolicyScroll", &tab_bar_flags, ImGuiTabBarFlags_FittingPolicyScroll))
                 tab_bar_flags &= ~(ImGuiTabBarFlags_FittingPolicyMask_ ^ ImGuiTabBarFlags_FittingPolicyScroll);
+            ImGui::CheckboxFlags("ImGuiTabBarFlags_NoBaseSeparator", &tab_bar_flags, ImGuiTabBarFlags_NoBaseSeparator);
 
             // Tab Bar
             const char* names[4] = { "Artichoke", "Beetroot", "Celery", "Daikon" };
@@ -1644,6 +1645,7 @@ static void ShowDemoWindowWidgets()
                 tab_bar_flags &= ~(ImGuiTabBarFlags_FittingPolicyMask_ ^ ImGuiTabBarFlags_FittingPolicyResizeDown);
             if (ImGui::CheckboxFlags("ImGuiTabBarFlags_FittingPolicyScroll", &tab_bar_flags, ImGuiTabBarFlags_FittingPolicyScroll))
                 tab_bar_flags &= ~(ImGuiTabBarFlags_FittingPolicyMask_ ^ ImGuiTabBarFlags_FittingPolicyScroll);
+            ImGui::CheckboxFlags("ImGuiTabBarFlags_NoBaseSeparator", &tab_bar_flags, ImGuiTabBarFlags_NoBaseSeparator);
 
             if (ImGui::BeginTabBar("MyTabBar", tab_bar_flags))
             {
diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp
index 89e3681e4..213b26632 100644
--- a/imgui_widgets.cpp
+++ b/imgui_widgets.cpp
@@ -7333,20 +7333,24 @@ bool    ImGui::BeginTabBarEx(ImGuiTabBar* tab_bar, const ImRect& tab_bar_bb, ImG
     window->DC.CursorPos = ImVec2(tab_bar->BarRect.Min.x, tab_bar->BarRect.Max.y + tab_bar->ItemSpacingY);
 
     // Draw separator
-    const ImU32 col = GetColorU32((flags & ImGuiTabBarFlags_IsFocused) ? ImGuiCol_TabActive : ImGuiCol_TabUnfocusedActive);
-    const float y = tab_bar->BarRect.Max.y - 1.0f;
-    if (dock_node != NULL)
+    if ((flags & ImGuiTabBarFlags_NoBaseSeparator) == 0)
     {
-        const float separator_min_x = dock_node->Pos.x + window->WindowBorderSize;
-        const float separator_max_x = dock_node->Pos.x + dock_node->Size.x - window->WindowBorderSize;
-        window->DrawList->AddLine(ImVec2(separator_min_x, y), ImVec2(separator_max_x, y), col, 1.0f);
-    }
-    else
-    {
-        const float separator_min_x = tab_bar->BarRect.Min.x - IM_FLOOR(window->WindowPadding.x * 0.5f);
-        const float separator_max_x = tab_bar->BarRect.Max.x + IM_FLOOR(window->WindowPadding.x * 0.5f);
-        window->DrawList->AddLine(ImVec2(separator_min_x, y), ImVec2(separator_max_x, y), col, 1.0f);
+        const ImU32 col = GetColorU32((flags & ImGuiTabBarFlags_IsFocused) ? ImGuiCol_TabActive : ImGuiCol_TabUnfocusedActive);
+        const float y = tab_bar->BarRect.Max.y - 1.0f;
+        if (dock_node != NULL)
+        {
+            const float separator_min_x = dock_node->Pos.x + window->WindowBorderSize;
+            const float separator_max_x = dock_node->Pos.x + dock_node->Size.x - window->WindowBorderSize;
+            window->DrawList->AddLine(ImVec2(separator_min_x, y), ImVec2(separator_max_x, y), col, 1.0f);
+        }
+        else
+        {
+            const float separator_min_x = tab_bar->BarRect.Min.x - IM_FLOOR(window->WindowPadding.x * 0.5f);
+            const float separator_max_x = tab_bar->BarRect.Max.x + IM_FLOOR(window->WindowPadding.x * 0.5f);
+            window->DrawList->AddLine(ImVec2(separator_min_x, y), ImVec2(separator_max_x, y), col, 1.0f);
+        }
     }
+
     return true;
 }
@ocornut
Copy link
Owner

ocornut commented Jan 4, 2022

You can surround BeginTabBar() with a PushStyleColor/PopStyleColor() call to make those colors 0 then restore it to render tabs?

@ocornut ocornut added style tabs tab bars, tabs labels Jan 4, 2022
@nobody-special666
Copy link
Author

nobody-special666 commented Jan 4, 2022

Thanks for quick response.
I did not know about PushStyleColor().
You are correct, closing ticket.

ImGui::PushStyleColor(ImGuiCol_TabActive, IM_COL32(0,0,0,0));
ImGui::PushStyleColor(ImGuiCol_TabUnfocusedActive, IM_COL32(0,0,0,0));

bool bTabBar= ImGui::BeginTabBar("MyTabBar", tab_bar_flags);

ImGui::PopStyleColor();
ImGui::PopStyleColor();

ocornut added a commit that referenced this issue Sep 18, 2023
…Var_TabBarBorderSize. (#6820, #4859, #5022, #5239)

Removed ImGuiTabItemFlags_Preview. Will need cherry-picking in master.
ocornut added a commit that referenced this issue Sep 18, 2023
@ocornut
Copy link
Owner

ocornut commented Sep 18, 2023

FYI
Now added a style.TabBarBorderSize variable,
So ImGui::PushStyleVar(ImGuiStyleVar_TabBarBorderSize, 0.0f) will also work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
style tabs tab bars, tabs
Projects
None yet
Development

No branches or pull requests

2 participants