2019-02-10 13:07:13 +03:00
|
|
|
#include <LibGUI/GLayout.h>
|
|
|
|
#include <LibGUI/GWidget.h>
|
|
|
|
|
|
|
|
GLayout::GLayout()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GLayout::~GLayout()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLayout::notify_adopted(Badge<GWidget>, GWidget& widget)
|
|
|
|
{
|
2019-04-14 03:36:06 +03:00
|
|
|
if (m_owner == &widget)
|
2019-02-10 13:07:13 +03:00
|
|
|
return;
|
|
|
|
m_owner = widget.make_weak_ptr();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLayout::notify_disowned(Badge<GWidget>, GWidget& widget)
|
|
|
|
{
|
2019-04-14 03:36:06 +03:00
|
|
|
ASSERT(m_owner == &widget);
|
2019-02-10 13:07:13 +03:00
|
|
|
m_owner.clear();
|
|
|
|
}
|
|
|
|
|
2019-05-09 04:06:20 +03:00
|
|
|
void GLayout::add_entry(Entry&& entry)
|
2019-02-10 13:07:13 +03:00
|
|
|
{
|
|
|
|
m_entries.append(move(entry));
|
|
|
|
if (m_owner)
|
2019-05-31 16:44:04 +03:00
|
|
|
m_owner->notify_layout_changed({});
|
2019-02-10 13:07:13 +03:00
|
|
|
}
|
|
|
|
|
2019-05-09 04:06:20 +03:00
|
|
|
void GLayout::add_spacer()
|
|
|
|
{
|
|
|
|
Entry entry;
|
|
|
|
entry.type = Entry::Type::Spacer;
|
|
|
|
add_entry(move(entry));
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLayout::add_layout(OwnPtr<GLayout>&& layout)
|
|
|
|
{
|
|
|
|
Entry entry;
|
|
|
|
entry.type = Entry::Type::Layout;
|
|
|
|
entry.layout = move(layout);
|
|
|
|
add_entry(move(entry));
|
|
|
|
}
|
|
|
|
|
2019-02-10 13:07:13 +03:00
|
|
|
void GLayout::add_widget(GWidget& widget)
|
|
|
|
{
|
|
|
|
Entry entry;
|
2019-05-09 04:06:20 +03:00
|
|
|
entry.type = Entry::Type::Widget;
|
2019-02-10 13:07:13 +03:00
|
|
|
entry.widget = widget.make_weak_ptr();
|
2019-05-09 04:06:20 +03:00
|
|
|
add_entry(move(entry));
|
2019-02-10 13:07:13 +03:00
|
|
|
}
|
2019-02-20 11:04:28 +03:00
|
|
|
|
2019-04-04 02:44:35 +03:00
|
|
|
void GLayout::remove_widget(GWidget& widget)
|
|
|
|
{
|
2019-06-07 12:46:02 +03:00
|
|
|
m_entries.remove_first_matching([&](auto& entry) {
|
2019-04-14 03:36:06 +03:00
|
|
|
return entry.widget == &widget;
|
2019-04-04 02:44:35 +03:00
|
|
|
});
|
|
|
|
if (m_owner)
|
2019-05-31 16:44:04 +03:00
|
|
|
m_owner->notify_layout_changed({});
|
2019-04-04 02:44:35 +03:00
|
|
|
}
|
|
|
|
|
2019-02-20 11:04:28 +03:00
|
|
|
void GLayout::set_spacing(int spacing)
|
|
|
|
{
|
|
|
|
if (m_spacing == spacing)
|
|
|
|
return;
|
|
|
|
m_spacing = spacing;
|
|
|
|
if (m_owner)
|
2019-05-31 16:44:04 +03:00
|
|
|
m_owner->notify_layout_changed({});
|
2019-02-20 11:04:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLayout::set_margins(const GMargins& margins)
|
|
|
|
{
|
|
|
|
if (m_margins == margins)
|
|
|
|
return;
|
|
|
|
m_margins = margins;
|
|
|
|
if (m_owner)
|
2019-05-31 16:44:04 +03:00
|
|
|
m_owner->notify_layout_changed({});
|
2019-02-20 11:04:28 +03:00
|
|
|
}
|