From 77ad0fdb0726aba2ecaf7ea9764a642671d1fd6f Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 16 Feb 2023 21:07:06 +0000 Subject: Userland: Specify margins and spacing in the GUI::Layout constructor --- Userland/Libraries/LibGUI/Breadcrumbbar.cpp | 3 +-- Userland/Libraries/LibGUI/ColorPicker.cpp | 23 +++++++--------------- Userland/Libraries/LibGUI/CommandPalette.cpp | 3 +-- Userland/Libraries/LibGUI/EmojiInputDialog.cpp | 4 +--- Userland/Libraries/LibGUI/InputBox.cpp | 8 ++------ Userland/Libraries/LibGUI/MessageBox.cpp | 11 +++-------- Userland/Libraries/LibGUI/ProcessChooser.cpp | 3 +-- Userland/Libraries/LibGUI/SettingsWindow.cpp | 7 ++----- Userland/Libraries/LibGUI/Statusbar.cpp | 4 +--- Userland/Libraries/LibGUI/Toolbar.cpp | 4 +--- Userland/Libraries/LibGUI/ToolbarContainer.cpp | 3 +-- .../Libraries/LibGUI/Wizards/CoverWizardPage.cpp | 3 +-- Userland/Libraries/LibGUI/Wizards/WizardDialog.cpp | 7 ++----- Userland/Libraries/LibGUI/Wizards/WizardPage.cpp | 9 +++------ 14 files changed, 27 insertions(+), 65 deletions(-) (limited to 'Userland/Libraries') diff --git a/Userland/Libraries/LibGUI/Breadcrumbbar.cpp b/Userland/Libraries/LibGUI/Breadcrumbbar.cpp index 79b83b3d43..a8db7bf70f 100644 --- a/Userland/Libraries/LibGUI/Breadcrumbbar.cpp +++ b/Userland/Libraries/LibGUI/Breadcrumbbar.cpp @@ -60,8 +60,7 @@ private: Breadcrumbbar::Breadcrumbbar() { - auto& layout = set_layout(); - layout.set_spacing(0); + set_layout(GUI::Margins {}, 0); } void Breadcrumbbar::clear_segments() diff --git a/Userland/Libraries/LibGUI/ColorPicker.cpp b/Userland/Libraries/LibGUI/ColorPicker.cpp index f481924c7f..b4d757e47b 100644 --- a/Userland/Libraries/LibGUI/ColorPicker.cpp +++ b/Userland/Libraries/LibGUI/ColorPicker.cpp @@ -207,31 +207,25 @@ void ColorPicker::set_color_has_alpha_channel(bool has_alpha) void ColorPicker::build_ui() { auto root_container = set_main_widget().release_value_but_fixme_should_propagate_errors(); - root_container->set_layout(); - root_container->layout()->set_margins(4); + root_container->set_layout(4); root_container->set_fill_with_background_color(true); auto& tab_widget = root_container->add(); auto& tab_palette = tab_widget.add_tab("Palette"); - tab_palette.set_layout(); - tab_palette.layout()->set_margins(4); - tab_palette.layout()->set_spacing(4); + tab_palette.set_layout(4, 4); build_ui_palette(tab_palette); auto& tab_custom_color = tab_widget.add_tab("Custom Color"); - tab_custom_color.set_layout(); - tab_custom_color.layout()->set_margins(4); - tab_custom_color.layout()->set_spacing(4); + tab_custom_color.set_layout(4, 4); build_ui_custom(tab_custom_color); auto& button_container = root_container->add(); button_container.set_preferred_height(GUI::SpecialDimension::Fit); - button_container.set_layout(); - button_container.layout()->set_spacing(4); - button_container.layout()->add_spacer(); + button_container.set_layout(4); + button_container.add_spacer().release_value_but_fixme_should_propagate_errors(); auto& ok_button = button_container.add(); ok_button.set_text(String::from_utf8_short_string("OK"sv)); @@ -315,14 +309,11 @@ void ColorPicker::build_ui_custom(Widget& root_container) // Right Side auto& vertical_container = horizontal_container.add(); - vertical_container.set_layout(); - vertical_container.layout()->set_margins({ 0, 0, 0, 8 }); + vertical_container.set_layout(GUI::Margins { 0, 0, 0, 8 }); vertical_container.set_min_width(120); auto& preview_container = vertical_container.add(); - preview_container.set_layout(); - preview_container.layout()->set_margins(2); - preview_container.layout()->set_spacing(0); + preview_container.set_layout(2, 0); preview_container.set_fixed_height(100); // Current color diff --git a/Userland/Libraries/LibGUI/CommandPalette.cpp b/Userland/Libraries/LibGUI/CommandPalette.cpp index 2d2ad31f7d..4bf7c9c5db 100644 --- a/Userland/Libraries/LibGUI/CommandPalette.cpp +++ b/Userland/Libraries/LibGUI/CommandPalette.cpp @@ -186,8 +186,7 @@ CommandPalette::CommandPalette(GUI::Window& parent_window, ScreenPosition screen main_widget->set_frame_shape(Gfx::FrameShape::Window); main_widget->set_fill_with_background_color(true); - auto& layout = main_widget->set_layout(); - layout.set_margins(4); + main_widget->set_layout(4); m_text_box = main_widget->add(); m_table_view = main_widget->add(); diff --git a/Userland/Libraries/LibGUI/EmojiInputDialog.cpp b/Userland/Libraries/LibGUI/EmojiInputDialog.cpp index 4d6ba70caf..b0a12d8777 100644 --- a/Userland/Libraries/LibGUI/EmojiInputDialog.cpp +++ b/Userland/Libraries/LibGUI/EmojiInputDialog.cpp @@ -219,9 +219,7 @@ void EmojiInputDialog::update_displayed_emoji() for (size_t row = 0; row < rows && index < m_emojis.size(); ++row) { auto& horizontal_container = m_emojis_widget->add(); horizontal_container.set_preferred_height(SpecialDimension::Fit); - - auto& horizontal_layout = horizontal_container.set_layout(); - horizontal_layout.set_spacing(0); + horizontal_container.set_layout(GUI::Margins {}, 0); for (size_t column = 0; column < columns; ++column) { bool found_match = false; diff --git a/Userland/Libraries/LibGUI/InputBox.cpp b/Userland/Libraries/LibGUI/InputBox.cpp index 1417727e23..834a0f09c9 100644 --- a/Userland/Libraries/LibGUI/InputBox.cpp +++ b/Userland/Libraries/LibGUI/InputBox.cpp @@ -67,13 +67,10 @@ void InputBox::build() int title_width = widget->font().width(title()) + 24 /* icon, plus a little padding -- not perfect */; int max_width = max(text_width, title_width); - widget->set_layout(); + widget->set_layout(6, 6); widget->set_fill_with_background_color(true); widget->set_preferred_height(SpecialDimension::Fit); - widget->layout()->set_margins(6); - widget->layout()->set_spacing(6); - auto& label_editor_container = widget->add(); label_editor_container.set_layout(); label_editor_container.set_preferred_height(SpecialDimension::Fit); @@ -101,9 +98,8 @@ void InputBox::build() button_container_outer.set_layout(); auto& button_container_inner = button_container_outer.add(); - button_container_inner.set_layout(); + button_container_inner.set_layout(GUI::Margins {}, 6); button_container_inner.set_preferred_height(SpecialDimension::Fit); - button_container_inner.layout()->set_spacing(6); button_container_inner.add_spacer().release_value_but_fixme_should_propagate_errors(); m_ok_button = button_container_inner.add(); diff --git a/Userland/Libraries/LibGUI/MessageBox.cpp b/Userland/Libraries/LibGUI/MessageBox.cpp index b76692407a..b056a03d10 100644 --- a/Userland/Libraries/LibGUI/MessageBox.cpp +++ b/Userland/Libraries/LibGUI/MessageBox.cpp @@ -121,15 +121,11 @@ void MessageBox::build() int total_text_height = number_of_lines * padded_text_height; int icon_width = 0; - widget->set_layout(); + widget->set_layout(8, 6); widget->set_fill_with_background_color(true); - widget->layout()->set_margins(8); - widget->layout()->set_spacing(6); - auto& message_container = widget->add(); - message_container.set_layout(); - message_container.layout()->set_spacing(8); + message_container.set_layout(GUI::Margins {}, 8); if (m_type != Type::None) { auto& icon_image = message_container.add(); @@ -147,9 +143,8 @@ void MessageBox::build() label.set_text_alignment(Gfx::TextAlignment::CenterLeft); auto& button_container = widget->add(); - button_container.set_layout(); + button_container.set_layout(GUI::Margins {}, 8); button_container.set_fixed_height(24); - button_container.layout()->set_spacing(8); constexpr int button_width = 80; int button_count = 0; diff --git a/Userland/Libraries/LibGUI/ProcessChooser.cpp b/Userland/Libraries/LibGUI/ProcessChooser.cpp index 58f6d545ac..bbf8db72f1 100644 --- a/Userland/Libraries/LibGUI/ProcessChooser.cpp +++ b/Userland/Libraries/LibGUI/ProcessChooser.cpp @@ -48,8 +48,7 @@ ProcessChooser::ProcessChooser(StringView window_title, String button_label, Gfx auto& button_container = widget->add(); button_container.set_fixed_height(30); - button_container.set_layout(); - button_container.layout()->set_margins({ 0, 4, 0 }); + button_container.set_layout(GUI::Margins { 0, 4, 0 }); button_container.add_spacer().release_value_but_fixme_should_propagate_errors(); auto& select_button = button_container.add(m_button_label); diff --git a/Userland/Libraries/LibGUI/SettingsWindow.cpp b/Userland/Libraries/LibGUI/SettingsWindow.cpp index 3e35e1d18d..95bf8a7235 100644 --- a/Userland/Libraries/LibGUI/SettingsWindow.cpp +++ b/Userland/Libraries/LibGUI/SettingsWindow.cpp @@ -34,16 +34,13 @@ ErrorOr> SettingsWindow::create(DeprecatedString t auto main_widget = TRY(window->set_main_widget()); main_widget->set_fill_with_background_color(true); - (void)TRY(main_widget->try_set_layout()); - main_widget->layout()->set_margins(4); - main_widget->layout()->set_spacing(6); + (void)TRY(main_widget->try_set_layout(4, 6)); window->m_tab_widget = TRY(main_widget->try_add()); auto button_container = TRY(main_widget->try_add()); button_container->set_preferred_size({ SpecialDimension::Grow, SpecialDimension::Fit }); - (void)TRY(button_container->try_set_layout()); - button_container->layout()->set_spacing(6); + (void)TRY(button_container->try_set_layout(GUI::Margins {}, 6)); if (show_defaults_button == ShowDefaultsButton::Yes) { window->m_reset_button = TRY(button_container->try_add(TRY(String::from_utf8("Defaults"sv)))); diff --git a/Userland/Libraries/LibGUI/Statusbar.cpp b/Userland/Libraries/LibGUI/Statusbar.cpp index 911c878d2c..3da3ef5423 100644 --- a/Userland/Libraries/LibGUI/Statusbar.cpp +++ b/Userland/Libraries/LibGUI/Statusbar.cpp @@ -20,9 +20,7 @@ namespace GUI { Statusbar::Statusbar(int count) { set_fixed_height(18); - set_layout(); - layout()->set_margins(0); - layout()->set_spacing(2); + set_layout(0, 2); m_corner = add(); set_segment_count(count); diff --git a/Userland/Libraries/LibGUI/Toolbar.cpp b/Userland/Libraries/LibGUI/Toolbar.cpp index d09306eb13..bf1ef4f83c 100644 --- a/Userland/Libraries/LibGUI/Toolbar.cpp +++ b/Userland/Libraries/LibGUI/Toolbar.cpp @@ -34,9 +34,7 @@ Toolbar::Toolbar(Orientation orientation, int button_size) else set_fixed_width(button_size); - set_layout(orientation); - layout()->set_spacing(0); - layout()->set_margins({ 2, 2, 2, 2 }); + set_layout(orientation, GUI::Margins { 2, 2, 2, 2 }, 0); } class ToolbarButton final : public Button { diff --git a/Userland/Libraries/LibGUI/ToolbarContainer.cpp b/Userland/Libraries/LibGUI/ToolbarContainer.cpp index a583bf593b..49c63b104b 100644 --- a/Userland/Libraries/LibGUI/ToolbarContainer.cpp +++ b/Userland/Libraries/LibGUI/ToolbarContainer.cpp @@ -23,8 +23,7 @@ ToolbarContainer::ToolbarContainer(Gfx::Orientation orientation) set_frame_shape(Gfx::FrameShape::Box); set_frame_shadow(Gfx::FrameShadow::Sunken); - auto& layout = set_layout(); - layout.set_spacing(2); + set_layout(GUI::Margins {}, 2); set_shrink_to_fit(true); } diff --git a/Userland/Libraries/LibGUI/Wizards/CoverWizardPage.cpp b/Userland/Libraries/LibGUI/Wizards/CoverWizardPage.cpp index 338ba3e27c..c054f7968e 100644 --- a/Userland/Libraries/LibGUI/Wizards/CoverWizardPage.cpp +++ b/Userland/Libraries/LibGUI/Wizards/CoverWizardPage.cpp @@ -24,8 +24,7 @@ CoverWizardPage::CoverWizardPage() m_banner_image_widget->load_from_file("/res/graphics/wizard-banner-simple.png"sv); m_content_widget = add(); - m_content_widget->set_layout(); - m_content_widget->layout()->set_margins(20); + m_content_widget->set_layout(20); m_header_label = m_content_widget->add