diff options
author | Andreas Kling <kling@serenityos.org> | 2020-04-24 22:36:25 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-24 22:36:25 +0200 |
commit | d6bbf12b7c6b56e73408b6528dc4b49cf5b09e06 (patch) | |
tree | 6d1752fb979f1c404aa827937391dabc3bdce828 /Libraries/LibGUI/TabWidget.cpp | |
parent | 682f0ac93b91172e87d50bb65f3a7e4b7338de32 (diff) | |
download | serenity-d6bbf12b7c6b56e73408b6528dc4b49cf5b09e06.zip |
LibGUI: Add "uniform tabs" mode to TabWidget (all tabs have same width)
...and enable this in the main Browser UI. :^)
Diffstat (limited to 'Libraries/LibGUI/TabWidget.cpp')
-rw-r--r-- | Libraries/LibGUI/TabWidget.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/Libraries/LibGUI/TabWidget.cpp b/Libraries/LibGUI/TabWidget.cpp index 36bc3d91f0..6fa6a03a7e 100644 --- a/Libraries/LibGUI/TabWidget.cpp +++ b/Libraries/LibGUI/TabWidget.cpp @@ -178,7 +178,7 @@ void TabWidget::paint_event(PaintEvent& event) Gfx::StylePainter::paint_tab_button(painter, button_rect, palette(), false, hovered, m_tabs[i].widget->is_enabled()); auto text_rect = button_rect.translated(0, 1); paint_tab_icon_if_needed(m_tabs[i].icon, button_rect, text_rect); - painter.draw_text(text_rect, m_tabs[i].title, m_text_alignment, palette().button_text()); + painter.draw_text(text_rect, m_tabs[i].title, m_text_alignment, palette().button_text(), Gfx::TextElision::Right); } for (size_t i = 0; i < m_tabs.size(); ++i) { @@ -189,18 +189,25 @@ void TabWidget::paint_event(PaintEvent& event) Gfx::StylePainter::paint_tab_button(painter, button_rect, palette(), true, hovered, m_tabs[i].widget->is_enabled()); auto text_rect = button_rect.translated(0, 1); paint_tab_icon_if_needed(m_tabs[i].icon, button_rect, text_rect); - painter.draw_text(text_rect, m_tabs[i].title, m_text_alignment, palette().button_text()); + painter.draw_text(text_rect, m_tabs[i].title, m_text_alignment, palette().button_text(), Gfx::TextElision::Right); painter.draw_line(button_rect.bottom_left().translated(1, 1), button_rect.bottom_right().translated(-1, 1), palette().button()); break; } } +int TabWidget::uniform_tab_width() const +{ + return 160; +} + Gfx::Rect TabWidget::button_rect(int index) const { int x_offset = 2; - for (int i = 0; i < index; ++i) - x_offset += m_tabs[i].width(font()); - Gfx::Rect rect { x_offset, 0, m_tabs[index].width(font()), bar_height() }; + 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; + } + Gfx::Rect rect { x_offset, 0, m_uniform_tabs ? uniform_tab_width() : m_tabs[index].width(font()), bar_height() }; if (m_tabs[index].widget != m_active_widget) { rect.move_by(0, 2); rect.set_height(rect.height() - 2); |