Skip to content

Commit 7ae7c90

Browse files
committed
Tabs, Style: reworked selected overline rendering to better accommodate for rounded tabs. (ocornut#8334)
1 parent e8779a6 commit 7ae7c90

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

docs/CHANGELOG.txt

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ Other changes:
5454
- Windows: legacy SetWindowFontScale() is properly inherited by nested child
5555
windows. Note that an upcoming major release should make this obsolete,
5656
but in the meanwhile it works better now. (#2701, #8138, #1018)
57+
- Tabs, Style: reworked selected overline rendering to better accommodate
58+
for rounded tabs. Reduced default thickness (style.TabBarOverlineSize),
59+
increased default rounding (style.TabRounding). (#8334) [@Kian738, @ocornut]
60+
styles as the current look is not right (but ImGuiCol_TabSelectedOverline stays the same).
5761
- Examples: DirectX12: Reduced number of frame in flight from 3 to 2 in
5862
provided example, to reduce latency.
5963
- Examples: Vulkan: better handle VK_SUBOPTIMAL_KHR being returned by

imgui.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1334,11 +1334,11 @@ ImGuiStyle::ImGuiStyle()
13341334
GrabMinSize = 12.0f; // Minimum width/height of a grab box for slider/scrollbar
13351335
GrabRounding = 0.0f; // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs.
13361336
LogSliderDeadzone = 4.0f; // The size in pixels of the dead-zone around zero on logarithmic sliders that cross zero.
1337-
TabRounding = 4.0f; // Radius of upper corners of a tab. Set to 0.0f to have rectangular tabs.
1337+
TabRounding = 5.0f; // Radius of upper corners of a tab. Set to 0.0f to have rectangular tabs.
13381338
TabBorderSize = 0.0f; // Thickness of border around tabs.
13391339
TabMinWidthForCloseButton = 0.0f; // Minimum width for close button to appear on an unselected tab when hovered. Set to 0.0f to always show when hovering, set to FLT_MAX to never show close button unless selected.
13401340
TabBarBorderSize = 1.0f; // Thickness of tab-bar separator, which takes on the tab active color to denote focus.
1341-
TabBarOverlineSize = 2.0f; // Thickness of tab-bar overline, which highlights the selected tab-bar.
1341+
TabBarOverlineSize = 1.0f; // Thickness of tab-bar overline, which highlights the selected tab-bar.
13421342
TableAngledHeadersAngle = 35.0f * (IM_PI / 180.0f); // Angle of angled headers (supported values range from -50 degrees to +50 degrees).
13431343
TableAngledHeadersTextAlign = ImVec2(0.5f,0.0f);// Alignment of angled headers within the cell
13441344
ColorButtonPosition = ImGuiDir_Right; // Side of the color button in the ColorEdit4 widget (left/right). Defaults to ImGuiDir_Right.

imgui_demo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7966,7 +7966,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
79667966
ImGui::SliderFloat("FrameBorderSize", &style.FrameBorderSize, 0.0f, 1.0f, "%.0f");
79677967
ImGui::SliderFloat("TabBorderSize", &style.TabBorderSize, 0.0f, 1.0f, "%.0f");
79687968
ImGui::SliderFloat("TabBarBorderSize", &style.TabBarBorderSize, 0.0f, 2.0f, "%.0f");
7969-
ImGui::SliderFloat("TabBarOverlineSize", &style.TabBarOverlineSize, 0.0f, 2.0f, "%.0f");
7969+
ImGui::SliderFloat("TabBarOverlineSize", &style.TabBarOverlineSize, 0.0f, 3.0f, "%.0f");
79707970
ImGui::SameLine(); HelpMarker("Overline is only drawn over the selected tab when ImGuiTabBarFlags_DrawSelectedOverline is set.");
79717971

79727972
ImGui::SeparatorText("Rounding");

imgui_widgets.cpp

+15-5
Original file line numberDiff line numberDiff line change
@@ -10150,11 +10150,21 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open,
1015010150
TabItemBackground(display_draw_list, bb, flags, tab_col);
1015110151
if (tab_contents_visible && (tab_bar->Flags & ImGuiTabBarFlags_DrawSelectedOverline) && style.TabBarOverlineSize > 0.0f)
1015210152
{
10153-
float x_offset = IM_TRUNC(0.4f * style.TabRounding);
10154-
if (x_offset < 2.0f * g.CurrentDpiScale)
10155-
x_offset = 0.0f;
10156-
float y_offset = 1.0f * g.CurrentDpiScale;
10157-
display_draw_list->AddLine(bb.GetTL() + ImVec2(x_offset, y_offset), bb.GetTR() + ImVec2(-x_offset, y_offset), GetColorU32(tab_bar_focused ? ImGuiCol_TabSelectedOverline : ImGuiCol_TabDimmedSelectedOverline), style.TabBarOverlineSize);
10153+
// Might be moved to TabItemBackground() ?
10154+
ImVec2 tl = bb.GetTL() + ImVec2(0, 1.0f * g.CurrentDpiScale);
10155+
ImVec2 tr = bb.GetTR() + ImVec2(0, 1.0f * g.CurrentDpiScale);
10156+
ImU32 overline_col = GetColorU32(tab_bar_focused ? ImGuiCol_TabSelectedOverline : ImGuiCol_TabDimmedSelectedOverline);
10157+
if (style.TabRounding > 0.0f)
10158+
{
10159+
float rounding = style.TabRounding;
10160+
display_draw_list->PathArcToFast(tl + ImVec2(+rounding, +rounding), rounding, 7, 9);
10161+
display_draw_list->PathArcToFast(tr + ImVec2(-rounding, +rounding), rounding, 9, 11);
10162+
display_draw_list->PathStroke(overline_col, 0, style.TabBarOverlineSize);
10163+
}
10164+
else
10165+
{
10166+
display_draw_list->AddLine(tl - ImVec2(0.5f, 0.5f), tr - ImVec2(0.5f, 0.5f), overline_col, style.TabBarOverlineSize);
10167+
}
1015810168
}
1015910169
RenderNavCursor(bb, id);
1016010170

0 commit comments

Comments
 (0)