diff --git a/LibGUI/GBoxLayout.cpp b/LibGUI/GBoxLayout.cpp index 0f4e5265dd..6432e380d5 100644 --- a/LibGUI/GBoxLayout.cpp +++ b/LibGUI/GBoxLayout.cpp @@ -80,7 +80,12 @@ void GBoxLayout::run(GWidget& widget) if (entry.widget->size_policy(Orientation::Vertical) == SizePolicy::Fixed) rect.set_height(entry.widget->preferred_size().height()); if (entry.widget->size_policy(Orientation::Horizontal) == SizePolicy::Fixed) - rect.set_width(entry.widget->preferred_size().height()); + rect.set_width(entry.widget->preferred_size().width()); + + if (orientation() == Orientation::Horizontal) + rect.center_vertically_within(widget.rect()); + else + rect.center_horizontally_within(widget.rect()); #ifdef GBOXLAYOUT_DEBUG dbgprintf("GBoxLayout: apply, %s{%p} <- %s\n", entry.widget->class_name(), entry.widget.ptr(), rect.to_string().characters()); diff --git a/LibGUI/GToolBar.cpp b/LibGUI/GToolBar.cpp index b0de614c33..e052e5fd1c 100644 --- a/LibGUI/GToolBar.cpp +++ b/LibGUI/GToolBar.cpp @@ -41,10 +41,33 @@ void GToolBar::add_action(Retained&& action) m_items.append(move(item)); } +class SeparatorWidget final : public GWidget { +public: + SeparatorWidget(GWidget* parent) + : GWidget(parent) + { + set_fill_with_background_color(false); + set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); + set_background_color(Color::White); + set_preferred_size({ 8, 20 }); + } + virtual ~SeparatorWidget() override { } + + virtual void paint_event(GPaintEvent& event) override + { + Painter painter(*this); + painter.set_clip_rect(event.rect()); + painter.translate(rect().center().x() - 1, 0); + painter.draw_line({ 0, 0 }, { 0, rect().bottom() }, Color::DarkGray); + painter.draw_line({ 1, 0 }, { 1, rect().bottom() }, Color::White); + } +}; + void GToolBar::add_separator() { auto item = make(); item->type = Item::Separator; + new SeparatorWidget(this); m_items.append(move(item)); } diff --git a/SharedGraphics/Rect.h b/SharedGraphics/Rect.h index 86fc790a9e..e57d0e989b 100644 --- a/SharedGraphics/Rect.h +++ b/SharedGraphics/Rect.h @@ -197,8 +197,18 @@ public: Point bottom_right() const { return { right(), bottom() }; } void center_within(const Rect& other) + { + center_horizontally_within(other); + center_vertically_within(other); + } + + void center_horizontally_within(const Rect& other) { set_x(other.center().x() - width() / 2); + } + + void center_vertically_within(const Rect& other) + { set_y(other.center().y() - height() / 2); }