mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:37:35 +00:00
LibGUI: Improve GStatusBar and GToolBar and share some code via GStyle.
This commit is contained in:
parent
ac2a3f7fdf
commit
4ea7a51ecd
4 changed files with 18 additions and 11 deletions
|
@ -1,15 +1,16 @@
|
|||
#include <LibGUI/GStatusBar.h>
|
||||
#include <LibGUI/GLabel.h>
|
||||
#include <LibGUI/GBoxLayout.h>
|
||||
#include <LibGUI/GStyle.h>
|
||||
#include <SharedGraphics/Painter.h>
|
||||
|
||||
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<GBoxLayout>(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());
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -11,7 +11,7 @@ GToolBar::GToolBar(GWidget* parent)
|
|||
set_preferred_size({ 0, 30 });
|
||||
set_layout(make<GBoxLayout>(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<GAction>&& 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());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue