mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:37:43 +00:00
LibGUI: Implement GToolbar separators.
This commit is contained in:
parent
054e4caf49
commit
949c98c5af
3 changed files with 39 additions and 1 deletions
|
@ -80,7 +80,12 @@ void GBoxLayout::run(GWidget& widget)
|
||||||
if (entry.widget->size_policy(Orientation::Vertical) == SizePolicy::Fixed)
|
if (entry.widget->size_policy(Orientation::Vertical) == SizePolicy::Fixed)
|
||||||
rect.set_height(entry.widget->preferred_size().height());
|
rect.set_height(entry.widget->preferred_size().height());
|
||||||
if (entry.widget->size_policy(Orientation::Horizontal) == SizePolicy::Fixed)
|
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
|
#ifdef GBOXLAYOUT_DEBUG
|
||||||
dbgprintf("GBoxLayout: apply, %s{%p} <- %s\n", entry.widget->class_name(), entry.widget.ptr(), rect.to_string().characters());
|
dbgprintf("GBoxLayout: apply, %s{%p} <- %s\n", entry.widget->class_name(), entry.widget.ptr(), rect.to_string().characters());
|
||||||
|
|
|
@ -41,10 +41,33 @@ void GToolBar::add_action(Retained<GAction>&& action)
|
||||||
m_items.append(move(item));
|
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()
|
void GToolBar::add_separator()
|
||||||
{
|
{
|
||||||
auto item = make<Item>();
|
auto item = make<Item>();
|
||||||
item->type = Item::Separator;
|
item->type = Item::Separator;
|
||||||
|
new SeparatorWidget(this);
|
||||||
m_items.append(move(item));
|
m_items.append(move(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -197,8 +197,18 @@ public:
|
||||||
Point bottom_right() const { return { right(), bottom() }; }
|
Point bottom_right() const { return { right(), bottom() }; }
|
||||||
|
|
||||||
void center_within(const Rect& other)
|
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);
|
set_x(other.center().x() - width() / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void center_vertically_within(const Rect& other)
|
||||||
|
{
|
||||||
set_y(other.center().y() - height() / 2);
|
set_y(other.center().y() - height() / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue