From bcd05e199b165594bdde6bf477f01fa4047d289a Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 9 Apr 2021 22:30:41 +0200 Subject: LibGUI: Fix uniform TabWidget tabs bleeding outside the widget The last uniform-sized tab button would bleed outside the tab bar area due to us not taking the bar margin into account. --- Userland/Libraries/LibGUI/TabWidget.cpp | 7 ++++--- Userland/Libraries/LibGUI/TabWidget.h | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibGUI/TabWidget.cpp b/Userland/Libraries/LibGUI/TabWidget.cpp index 6e680b38ff..588c468868 100644 --- a/Userland/Libraries/LibGUI/TabWidget.cpp +++ b/Userland/Libraries/LibGUI/TabWidget.cpp @@ -278,8 +278,9 @@ int TabWidget::uniform_tab_width() const int maximum_tab_width = 160; int total_tab_width = m_tabs.size() * maximum_tab_width; int tab_width = maximum_tab_width; - if (total_tab_width > width()) - tab_width = width() / m_tabs.size(); + int available_width = width() - bar_margin() * 2; + if (total_tab_width > available_width) + tab_width = available_width / m_tabs.size(); return max(tab_width, minimum_tab_width); } @@ -293,7 +294,7 @@ void TabWidget::set_bar_visible(bool bar_visible) Gfx::IntRect TabWidget::button_rect(int index) const { - int x_offset = 2; + int x_offset = bar_margin(); for (int i = 0; i < index; ++i) { auto tab_width = m_uniform_tabs ? uniform_tab_width() : m_tabs[i].width(font()); x_offset += tab_width; diff --git a/Userland/Libraries/LibGUI/TabWidget.h b/Userland/Libraries/LibGUI/TabWidget.h index d8f078c75c..9d111dc49b 100644 --- a/Userland/Libraries/LibGUI/TabWidget.h +++ b/Userland/Libraries/LibGUI/TabWidget.h @@ -108,6 +108,7 @@ private: Gfx::IntRect container_rect() const; void update_bar(); void update_focus_policy(); + int bar_margin() const { return 2; } RefPtr m_active_widget; -- cgit v1.2.3