diff --git a/LibGUI/GBoxLayout.cpp b/LibGUI/GBoxLayout.cpp index 7296bac0be..669a21b641 100644 --- a/LibGUI/GBoxLayout.cpp +++ b/LibGUI/GBoxLayout.cpp @@ -34,6 +34,9 @@ void GBoxLayout::run(GWidget& widget) dbgprintf("GBoxLayout: Starting with available size: %s\n", available_size.to_string().characters()); for (auto& entry : m_entries) { + if (entry.type == Entry::Type::Spacer) { + ++number_of_visible_entries; + } if (!entry.widget) continue; @@ -84,6 +87,11 @@ void GBoxLayout::run(GWidget& widget) int current_y = margins().top(); for (auto& entry : m_entries) { + if (entry.type == Entry::Type::Spacer) { + current_x += automatic_size.width(); + current_y += automatic_size.height(); + } + if (!entry.widget) continue; if (!entry.widget->is_visible()) diff --git a/LibGUI/GFilePicker.cpp b/LibGUI/GFilePicker.cpp index bf4c61c41d..8686997bf0 100644 --- a/LibGUI/GFilePicker.cpp +++ b/LibGUI/GFilePicker.cpp @@ -13,7 +13,7 @@ GFilePicker::GFilePicker(const String& path, CObject* parent) set_rect(200, 200, 400, 300); set_main_widget(new GWidget); main_widget()->set_layout(make(Orientation::Vertical)); - main_widget()->layout()->set_margins({ 4, 0, 4, 0 }); + main_widget()->layout()->set_margins({ 4, 4, 4, 4 }); main_widget()->layout()->set_spacing(4); main_widget()->set_fill_with_background_color(true); main_widget()->set_background_color(Color::LightGray); @@ -42,6 +42,7 @@ GFilePicker::GFilePicker(const String& path, CObject* parent) button_container->set_preferred_size({ 0, 20 }); button_container->set_layout(make(Orientation::Horizontal)); button_container->layout()->set_spacing(4); + button_container->layout()->add_spacer(); auto* cancel_button = new GButton(button_container); cancel_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill); diff --git a/LibGUI/GLayout.cpp b/LibGUI/GLayout.cpp index 93fa45ab9e..207ad7883d 100644 --- a/LibGUI/GLayout.cpp +++ b/LibGUI/GLayout.cpp @@ -22,22 +22,34 @@ void GLayout::notify_disowned(Badge, GWidget& widget) m_owner.clear(); } -void GLayout::add_layout(OwnPtr&& layout) +void GLayout::add_entry(Entry&& entry) { - Entry entry; - entry.layout = move(layout); m_entries.append(move(entry)); if (m_owner) m_owner->notify_layout_changed(Badge()); } +void GLayout::add_spacer() +{ + Entry entry; + entry.type = Entry::Type::Spacer; + add_entry(move(entry)); +} + +void GLayout::add_layout(OwnPtr&& layout) +{ + Entry entry; + entry.type = Entry::Type::Layout; + entry.layout = move(layout); + add_entry(move(entry)); +} + void GLayout::add_widget(GWidget& widget) { Entry entry; + entry.type = Entry::Type::Widget; entry.widget = widget.make_weak_ptr(); - m_entries.append(move(entry)); - if (m_owner) - m_owner->notify_layout_changed(Badge()); + add_entry(move(entry)); } void GLayout::remove_widget(GWidget& widget) diff --git a/LibGUI/GLayout.h b/LibGUI/GLayout.h index 599ad6248c..765e6fb070 100644 --- a/LibGUI/GLayout.h +++ b/LibGUI/GLayout.h @@ -15,6 +15,7 @@ public: void add_widget(GWidget&); void add_layout(OwnPtr&&); + void add_spacer(); void remove_widget(GWidget&); @@ -31,9 +32,19 @@ public: protected: struct Entry { + enum class Type { + Invalid = 0, + Widget, + Layout, + Spacer, + }; + + Type type { Type::Invalid }; WeakPtr widget; OwnPtr layout; }; + void add_entry(Entry&&); + WeakPtr m_owner; Vector m_entries;