From 1b63ded8fad7ab2e41468d485160b416383e0646 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 7 Feb 2019 12:06:48 +0100 Subject: [PATCH] Tabs: Fixed border (when enabled) so it is aligned correctly mid-pixel and appears as bright as other borders. --- docs/CHANGELOG.txt | 1 + imgui_widgets.cpp | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 9f7f2109..81c7eb5f 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -50,6 +50,7 @@ Other Changes: - Tabs: Added ImGuiTabBarFlags_TabListPopupButton flag to show a popup button on manual tab bars. (#261, #351) - Tabs: Removed ImGuiTabBarFlags_NoTabListPopupButton which was available in 1.67 but actually had zero use. - Tabs: Fixed a minor clipping glitch when changing style's FramePadding from frame to frame. +- Tabs: Fixed border (when enabled) so it is aligned correctly mid-pixel and appears as bright as other borders. - Menus: Tweaked horizontal overlap between parent and child menu (to help convey relative depth) from using style.ItemSpacing.x to style.ItemInnerSpacing.x, the later being expected to be smaller. (#1086) - RadioButton: Fixed label horizontal alignment to precisely match Checkbox(). diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 565dbe1a..667cf3c4 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -6281,7 +6281,7 @@ static ImGuiTabItem* ImGui::TabBarTabListPopupButton(ImGuiTabBar* tab_bar) // - TabItemEx() [Internal] // - SetTabItemClosed() // - TabItemCalcSize() [Internal] -// - TabItemRenderBackground() [Internal] +// - TabItemBackground() [Internal] // - TabItemLabelAndCloseButton() [Internal] //------------------------------------------------------------------------- @@ -6465,7 +6465,7 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, // Enlarge tab display when hovering bb.Max.x = bb.Min.x + (float)(int)ImLerp(bb.GetWidth(), tab->WidthContents, ImSaturate((g.HoveredIdNotActiveTimer - 0.40f) * 6.0f)); display_draw_list = GetOverlayDrawList(window); - TabItemRenderBackground(display_draw_list, bb, flags, GetColorU32(ImGuiCol_TitleBgActive)); + TabItemBackground(display_draw_list, bb, flags, GetColorU32(ImGuiCol_TitleBgActive)); } #endif @@ -6540,16 +6540,21 @@ void ImGui::TabItemBackground(ImDrawList* draw_list, const ImRect& bb, ImGuiTabI IM_UNUSED(flags); IM_ASSERT(width > 0.0f); const float rounding = ImMax(0.0f, ImMin(g.Style.TabRounding, width * 0.5f - 1.0f)); - float y1 = bb.Min.y + 1.0f; - float y2 = bb.Max.y - 1.0f; + const float y1 = bb.Min.y + 1.0f; + const float y2 = bb.Max.y - 1.0f; draw_list->PathLineTo(ImVec2(bb.Min.x, y2)); draw_list->PathArcToFast(ImVec2(bb.Min.x + rounding, y1 + rounding), rounding, 6, 9); draw_list->PathArcToFast(ImVec2(bb.Max.x - rounding, y1 + rounding), rounding, 9, 12); draw_list->PathLineTo(ImVec2(bb.Max.x, y2)); - draw_list->AddConvexPolyFilled(draw_list->_Path.Data, draw_list->_Path.Size, col); + draw_list->PathFillConvex(col); if (g.Style.TabBorderSize > 0.0f) - draw_list->AddPolyline(draw_list->_Path.Data, draw_list->_Path.Size, GetColorU32(ImGuiCol_Border), false, g.Style.TabBorderSize); - draw_list->PathClear(); + { + draw_list->PathLineTo(ImVec2(bb.Min.x + 0.5f, y2)); + draw_list->PathArcToFast(ImVec2(bb.Min.x + rounding + 0.5f, y1 + rounding + 0.5f), rounding, 6, 9); + draw_list->PathArcToFast(ImVec2(bb.Max.x - rounding - 0.5f, y1 + rounding + 0.5f), rounding, 9, 12); + draw_list->PathLineTo(ImVec2(bb.Max.x - 0.5f, y2)); + draw_list->PathStroke(GetColorU32(ImGuiCol_Border), false, g.Style.TabBorderSize); + } } // Render text label (with custom clipping) + Unsaved Document marker + Close Button logic