summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-04-09 22:30:41 +0200
committerAndreas Kling <kling@serenityos.org>2021-04-09 22:30:41 +0200
commitbcd05e199b165594bdde6bf477f01fa4047d289a (patch)
tree810233aa8848809070261fedcd19976e5297a495
parent1029069ad62904ec1e4709b49f5eb69efe8c2b80 (diff)
downloadserenity-bcd05e199b165594bdde6bf477f01fa4047d289a.zip
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.
-rw-r--r--Userland/Libraries/LibGUI/TabWidget.cpp7
-rw-r--r--Userland/Libraries/LibGUI/TabWidget.h1
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<Widget> m_active_widget;