From 4ea7a51ecdd1913698cb80f911301a3633f57781 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 4 Mar 2019 10:47:54 +0100 Subject: [PATCH] LibGUI: Improve GStatusBar and GToolBar and share some code via GStyle. --- LibGUI/GStatusBar.cpp | 9 ++++----- LibGUI/GStyle.cpp | 9 +++++++++ LibGUI/GStyle.h | 3 ++- LibGUI/GToolBar.cpp | 8 +++----- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/LibGUI/GStatusBar.cpp b/LibGUI/GStatusBar.cpp index 9b0e0d2034..a4b54f46ae 100644 --- a/LibGUI/GStatusBar.cpp +++ b/LibGUI/GStatusBar.cpp @@ -1,15 +1,16 @@ #include #include #include +#include #include GStatusBar::GStatusBar(GWidget* parent) : GWidget(parent) { set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); - set_preferred_size({ 0, 18 }); + set_preferred_size({ 0, 20 }); set_layout(make(Orientation::Horizontal)); - layout()->set_margins({ 1, 1, 1, 1 }); + layout()->set_margins({ 4, 2, 4, 2 }); m_label = new GLabel(this); m_label->set_text_alignment(TextAlignment::CenterLeft); m_label->set_fill_with_background_color(false); @@ -33,7 +34,5 @@ void GStatusBar::paint_event(GPaintEvent& event) { Painter painter(*this); painter.set_clip_rect(event.rect()); - painter.fill_rect({ 0, 1, width(), height() - 1 }, Color::LightGray); - painter.draw_line({ 0, 0 }, { width() - 1, 0 }, Color::White); - painter.draw_line({ 0, rect().bottom() }, { width() - 1, rect().bottom() }, Color::DarkGray); + GStyle::the().paint_surface(painter, rect()); } diff --git a/LibGUI/GStyle.cpp b/LibGUI/GStyle.cpp index e0fac12362..c74193d04a 100644 --- a/LibGUI/GStyle.cpp +++ b/LibGUI/GStyle.cpp @@ -51,3 +51,12 @@ void GStyle::paint_button(Painter& painter, const Rect& rect, GButtonStyle butto painter.translate(-rect.location().x(), -rect.location().y()); } + +void GStyle::paint_surface(Painter& painter, const Rect& rect) +{ + painter.fill_rect({ rect.x(), rect.y() + 1, rect.width(), rect.height() - 2 }, Color::LightGray); + painter.draw_line(rect.top_left(), rect.top_right(), Color::White); + painter.draw_line(rect.bottom_left(), rect.bottom_right(), Color::DarkGray); + painter.draw_line(rect.top_left().translated(0, 1), rect.bottom_left().translated(0, -1), Color::White); + painter.draw_line(rect.top_right(), rect.bottom_right().translated(0, -1), Color::DarkGray); +} diff --git a/LibGUI/GStyle.h b/LibGUI/GStyle.h index 2dc62c3d00..7e1f057ac2 100644 --- a/LibGUI/GStyle.h +++ b/LibGUI/GStyle.h @@ -9,7 +9,8 @@ class GStyle { public: static GStyle& the(); - void paint_button(Painter& painter, const Rect& rect, GButtonStyle, bool pressed, bool hovered = false); + void paint_button(Painter&, const Rect&, GButtonStyle, bool pressed, bool hovered = false); + void paint_surface(Painter&, const Rect&); private: GStyle(); diff --git a/LibGUI/GToolBar.cpp b/LibGUI/GToolBar.cpp index e8d6365493..b0de614c33 100644 --- a/LibGUI/GToolBar.cpp +++ b/LibGUI/GToolBar.cpp @@ -11,7 +11,7 @@ GToolBar::GToolBar(GWidget* parent) set_preferred_size({ 0, 30 }); set_layout(make(Orientation::Horizontal)); layout()->set_spacing(0); - layout()->set_margins({ 2, 2, 2, 2 }); + layout()->set_margins({ 3, 3, 3, 3 }); } GToolBar::~GToolBar() @@ -36,7 +36,7 @@ void GToolBar::add_action(Retained&& action) button->set_button_style(GButtonStyle::CoolBar); button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); - button->set_preferred_size({ 26, 26 }); + button->set_preferred_size({ 24, 24 }); m_items.append(move(item)); } @@ -52,7 +52,5 @@ void GToolBar::paint_event(GPaintEvent& event) { Painter painter(*this); painter.set_clip_rect(event.rect()); - painter.fill_rect({ 0, 0, width(), height() - 1 }, Color::LightGray); - painter.draw_line({ 0, 0 }, { width() - 1, 0 }, Color::White); - painter.draw_line({ 0, rect().bottom() }, { width() - 1, rect().bottom() }, Color::DarkGray); + GStyle::the().paint_surface(painter, rect()); }