diff options
author | sin-ack <sin-ack@users.noreply.github.com> | 2021-08-17 00:11:38 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-18 10:30:50 +0200 |
commit | e11d17761846b04c8cd3d0fe1254f0a19bd3ae0e (patch) | |
tree | c3ca91cfec0f742ba96df36dde3daa32e28373fa /Userland/Libraries/LibGUI | |
parent | 9c9a5c55cb34c63f3b6d3bf36dcbc6c37a429677 (diff) | |
download | serenity-e11d17761846b04c8cd3d0fe1254f0a19bd3ae0e.zip |
Userland+LibGUI: Add shorthand versions of the Margins constructor
This allows for typing [8] instead of [8, 8, 8, 8] to specify the same
margin on all edges, for example. The constructors follow CSS' style of
specifying margins. The added constructors are:
- Margins(int all): Sets the same margin on all edges.
- Margins(int vertical, int horizontal): Sets the first argument to top
and bottom margins, and the second argument to left and right margins.
- Margins(int top, int vertical, int bottom): Sets the first argument to
the top margin, the second argument to the left and right margins,
and the third argument to the bottom margin.
Diffstat (limited to 'Userland/Libraries/LibGUI')
-rw-r--r-- | Userland/Libraries/LibGUI/AboutDialog.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/ColorPicker.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/EmojiInputDialog.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/FilePickerDialog.gml | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Frame.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/InputBox.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Margins.h | 53 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/MessageBox.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/MultiView.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/PasswordInputDialog.gml | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/ProcessChooser.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Statusbar.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/ToolbarContainer.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Wizards/CoverWizardPage.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Wizards/WizardDialog.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Wizards/WizardPage.cpp | 4 |
16 files changed, 65 insertions, 34 deletions
diff --git a/Userland/Libraries/LibGUI/AboutDialog.cpp b/Userland/Libraries/LibGUI/AboutDialog.cpp index ef2c855e5b..8af316bd0e 100644 --- a/Userland/Libraries/LibGUI/AboutDialog.cpp +++ b/Userland/Libraries/LibGUI/AboutDialog.cpp @@ -43,7 +43,7 @@ AboutDialog::AboutDialog(const StringView& name, const Gfx::Bitmap* icon, Window auto& left_container = content_container.add<Widget>(); left_container.set_fixed_width(60); left_container.set_layout<VerticalBoxLayout>(); - left_container.layout()->set_margins({ 12, 0, 0, 0 }); + left_container.layout()->set_margins({ 12, 0, 0 }); if (icon) { auto& icon_wrapper = left_container.add<Widget>(); @@ -62,7 +62,7 @@ AboutDialog::AboutDialog(const StringView& name, const Gfx::Bitmap* icon, Window auto& label = right_container.add<Label>(text); label.set_text_alignment(Gfx::TextAlignment::CenterLeft); label.set_fixed_height(14); - label.set_content_margins({ 0, 8, 0, 0 }); + label.set_content_margins({ 0, 8, 0 }); if (bold) label.set_font(Gfx::FontDatabase::default_font().bold_variant()); }; diff --git a/Userland/Libraries/LibGUI/ColorPicker.cpp b/Userland/Libraries/LibGUI/ColorPicker.cpp index 04d50af117..50be4baaa7 100644 --- a/Userland/Libraries/LibGUI/ColorPicker.cpp +++ b/Userland/Libraries/LibGUI/ColorPicker.cpp @@ -154,21 +154,21 @@ void ColorPicker::build_ui() { auto& root_container = set_main_widget<Widget>(); root_container.set_layout<VerticalBoxLayout>(); - root_container.layout()->set_margins({ 4, 4, 4, 4 }); + root_container.layout()->set_margins(4); root_container.set_fill_with_background_color(true); auto& tab_widget = root_container.add<GUI::TabWidget>(); auto& tab_palette = tab_widget.add_tab<Widget>("Palette"); tab_palette.set_layout<VerticalBoxLayout>(); - tab_palette.layout()->set_margins({ 4, 4, 4, 4 }); + tab_palette.layout()->set_margins(4); tab_palette.layout()->set_spacing(4); build_ui_palette(tab_palette); auto& tab_custom_color = tab_widget.add_tab<Widget>("Custom Color"); tab_custom_color.set_layout<VerticalBoxLayout>(); - tab_custom_color.layout()->set_margins({ 4, 4, 4, 4 }); + tab_custom_color.layout()->set_margins(4); tab_custom_color.layout()->set_spacing(4); build_ui_custom(tab_custom_color); @@ -245,7 +245,7 @@ void ColorPicker::build_ui_custom(Widget& root_container) auto& preview_container = vertical_container.add<Frame>(); preview_container.set_layout<VerticalBoxLayout>(); - preview_container.layout()->set_margins({ 2, 2, 2, 2 }); + preview_container.layout()->set_margins(2); preview_container.layout()->set_spacing(0); preview_container.set_fixed_height(128); diff --git a/Userland/Libraries/LibGUI/EmojiInputDialog.cpp b/Userland/Libraries/LibGUI/EmojiInputDialog.cpp index 7a25e701c3..b1ec3267c1 100644 --- a/Userland/Libraries/LibGUI/EmojiInputDialog.cpp +++ b/Userland/Libraries/LibGUI/EmojiInputDialog.cpp @@ -45,7 +45,7 @@ EmojiInputDialog::EmojiInputDialog(Window* parent_window) main_widget.set_frame_shadow(Gfx::FrameShadow::Raised); main_widget.set_fill_with_background_color(true); auto& main_layout = main_widget.set_layout<VerticalBoxLayout>(); - main_layout.set_margins({ 1, 1, 1, 1 }); + main_layout.set_margins(1); main_layout.set_spacing(0); auto code_points = supported_emoji_code_points(); diff --git a/Userland/Libraries/LibGUI/FilePickerDialog.gml b/Userland/Libraries/LibGUI/FilePickerDialog.gml index aaa8c25bec..e775bb10bc 100644 --- a/Userland/Libraries/LibGUI/FilePickerDialog.gml +++ b/Userland/Libraries/LibGUI/FilePickerDialog.gml @@ -2,14 +2,14 @@ fill_with_background_color: true layout: @GUI::HorizontalBoxLayout { - margins: [4, 4, 4, 4] + margins: [4] spacing: 3 } @GUI::Widget { shrink_to_fit: true layout: @GUI::VerticalBoxLayout { - margins: [0, 4, 0, 4] + margins: [0, 4] } @GUI::Label { @@ -24,7 +24,7 @@ fill_with_background_color: true layout: @GUI::VerticalBoxLayout { - margins: [2, 2, 2, 2] + margins: [2] spacing: 0 } } diff --git a/Userland/Libraries/LibGUI/Frame.cpp b/Userland/Libraries/LibGUI/Frame.cpp index fc2dfbadba..5e0d93688b 100644 --- a/Userland/Libraries/LibGUI/Frame.cpp +++ b/Userland/Libraries/LibGUI/Frame.cpp @@ -42,7 +42,7 @@ void Frame::set_frame_thickness(int thickness) if (m_thickness == thickness) return; m_thickness = thickness; - set_content_margins({ thickness, thickness, thickness, thickness }); + set_content_margins(thickness); } void Frame::paint_event(PaintEvent& event) diff --git a/Userland/Libraries/LibGUI/InputBox.cpp b/Userland/Libraries/LibGUI/InputBox.cpp index 0996bb3568..abb39e4cbc 100644 --- a/Userland/Libraries/LibGUI/InputBox.cpp +++ b/Userland/Libraries/LibGUI/InputBox.cpp @@ -52,7 +52,7 @@ void InputBox::build(InputType input_type) widget.set_layout<VerticalBoxLayout>(); widget.set_fill_with_background_color(true); - widget.layout()->set_margins({ 6, 6, 6, 6 }); + widget.layout()->set_margins(6); widget.layout()->set_spacing(6); auto& label_editor_container = widget.add<Widget>(); diff --git a/Userland/Libraries/LibGUI/Margins.h b/Userland/Libraries/LibGUI/Margins.h index 7e10fd5239..f51fb82d03 100644 --- a/Userland/Libraries/LibGUI/Margins.h +++ b/Userland/Libraries/LibGUI/Margins.h @@ -11,6 +11,27 @@ namespace GUI { class Margins { public: Margins() { } + Margins(int all) + : m_top(all) + , m_right(all) + , m_bottom(all) + , m_left(all) + { + } + Margins(int vertical, int horizontal) + : m_top(vertical) + , m_right(horizontal) + , m_bottom(vertical) + , m_left(horizontal) + { + } + Margins(int top, int horizontal, int bottom) + : m_top(top) + , m_right(horizontal) + , m_bottom(bottom) + , m_left(horizontal) + { + } Margins(int top, int right, int bottom, int left) : m_top(top) , m_right(right) @@ -49,8 +70,8 @@ private: } -#define REGISTER_MARGINS_PROPERTY(property_name, getter, setter) \ - register_property( \ +#define REGISTER_MARGINS_PROPERTY(property_name, getter, setter) \ + register_property( \ property_name, [this]() { \ auto m = getter(); \ JsonObject margins_object; \ @@ -58,13 +79,23 @@ private: margins_object.set("right", m.right()); \ margins_object.set("top", m.top()); \ margins_object.set("bottom", m.bottom()); \ - return margins_object; }, \ - [this](auto& value) { \ - if (!value.is_array() || value.as_array().size() != 4) \ - return false; \ - int m[4]; \ - for (size_t i = 0; i < 4; ++i) \ - m[i] = value.as_array().at(i).to_i32(); \ - setter({ m[0], m[1], m[2], m[3] }); \ - return true; \ + return margins_object; }, \ + [this](auto& value) { \ + if (!value.is_array()) \ + return false; \ + auto size = value.as_array().size(); \ + if (size == 0 || size > 4) \ + return false; \ + int m[4]; \ + for (size_t i = 0; i < size; ++i) \ + m[i] = value.as_array().at(i).to_i32(); \ + if (size == 1) \ + setter({ m[0] }); \ + else if (size == 2) \ + setter({ m[0], m[1] }); \ + else if (size == 3) \ + setter({ m[0], m[1], m[2] }); \ + else \ + setter({ m[0], m[1], m[2], m[3] }); \ + return true; \ }); diff --git a/Userland/Libraries/LibGUI/MessageBox.cpp b/Userland/Libraries/LibGUI/MessageBox.cpp index 20d28450a2..7414bb67c2 100644 --- a/Userland/Libraries/LibGUI/MessageBox.cpp +++ b/Userland/Libraries/LibGUI/MessageBox.cpp @@ -89,7 +89,7 @@ void MessageBox::build() widget.set_layout<VerticalBoxLayout>(); widget.set_fill_with_background_color(true); - widget.layout()->set_margins({ 8, 8, 8, 8 }); + widget.layout()->set_margins(8); widget.layout()->set_spacing(6); auto& message_container = widget.add<Widget>(); diff --git a/Userland/Libraries/LibGUI/MultiView.cpp b/Userland/Libraries/LibGUI/MultiView.cpp index a7c8ffa09e..2fa22b1cc2 100644 --- a/Userland/Libraries/LibGUI/MultiView.cpp +++ b/Userland/Libraries/LibGUI/MultiView.cpp @@ -20,7 +20,7 @@ namespace GUI { MultiView::MultiView() { set_active_widget(nullptr); - set_content_margins({ 2, 2, 2, 2 }); + set_content_margins(2); m_icon_view = add<IconView>(); m_table_view = add<TableView>(); m_columns_view = add<ColumnsView>(); diff --git a/Userland/Libraries/LibGUI/PasswordInputDialog.gml b/Userland/Libraries/LibGUI/PasswordInputDialog.gml index cc31100c8e..2c8a1d8cfd 100644 --- a/Userland/Libraries/LibGUI/PasswordInputDialog.gml +++ b/Userland/Libraries/LibGUI/PasswordInputDialog.gml @@ -2,7 +2,7 @@ fill_with_background_color: true layout: @GUI::HorizontalBoxLayout { - margins: [8, 8, 8, 8] + margins: [8] spacing: 8 } diff --git a/Userland/Libraries/LibGUI/ProcessChooser.cpp b/Userland/Libraries/LibGUI/ProcessChooser.cpp index 0333431c8a..e9a2afadec 100644 --- a/Userland/Libraries/LibGUI/ProcessChooser.cpp +++ b/Userland/Libraries/LibGUI/ProcessChooser.cpp @@ -48,8 +48,8 @@ ProcessChooser::ProcessChooser(const StringView& window_title, const StringView& auto& button_container = widget.add<GUI::Widget>(); button_container.set_fixed_height(30); button_container.set_layout<GUI::HorizontalBoxLayout>(); - button_container.set_content_margins({ 4, 0, 4, 0 }); - button_container.layout()->set_margins({ 0, 4, 0, 0 }); + button_container.set_content_margins({ 4, 0 }); + button_container.layout()->set_margins({ 0, 4, 0 }); button_container.layout()->add_spacer(); auto& select_button = button_container.add<GUI::Button>(m_button_label); diff --git a/Userland/Libraries/LibGUI/Statusbar.cpp b/Userland/Libraries/LibGUI/Statusbar.cpp index bdb09983e4..cc66795e81 100644 --- a/Userland/Libraries/LibGUI/Statusbar.cpp +++ b/Userland/Libraries/LibGUI/Statusbar.cpp @@ -21,7 +21,7 @@ Statusbar::Statusbar(int label_count) { set_fixed_height(18); set_layout<HorizontalBoxLayout>(); - layout()->set_margins({ 0, 0, 0, 0 }); + layout()->set_margins(0); layout()->set_spacing(2); m_corner = add<ResizeCorner>(); diff --git a/Userland/Libraries/LibGUI/ToolbarContainer.cpp b/Userland/Libraries/LibGUI/ToolbarContainer.cpp index a2c8545030..9125df1b8c 100644 --- a/Userland/Libraries/LibGUI/ToolbarContainer.cpp +++ b/Userland/Libraries/LibGUI/ToolbarContainer.cpp @@ -25,7 +25,7 @@ ToolbarContainer::ToolbarContainer(Gfx::Orientation orientation) auto& layout = set_layout<VerticalBoxLayout>(); layout.set_spacing(2); - layout.set_margins({ 2, 2, 2, 2 }); + layout.set_margins(2); set_shrink_to_fit(true); } diff --git a/Userland/Libraries/LibGUI/Wizards/CoverWizardPage.cpp b/Userland/Libraries/LibGUI/Wizards/CoverWizardPage.cpp index 0a1d3a6a79..cbc5f69427 100644 --- a/Userland/Libraries/LibGUI/Wizards/CoverWizardPage.cpp +++ b/Userland/Libraries/LibGUI/Wizards/CoverWizardPage.cpp @@ -25,7 +25,7 @@ CoverWizardPage::CoverWizardPage() m_content_widget = add<Widget>(); m_content_widget->set_layout<VerticalBoxLayout>(); - m_content_widget->layout()->set_margins({ 20, 20, 20, 20 }); + m_content_widget->layout()->set_margins(20); m_header_label = m_content_widget->add<Label>(); m_header_label->set_font(Gfx::FontDatabase::the().get("Pebbleton", 14, 700)); diff --git a/Userland/Libraries/LibGUI/Wizards/WizardDialog.cpp b/Userland/Libraries/LibGUI/Wizards/WizardDialog.cpp index 5f8ae88bd2..a1978fd511 100644 --- a/Userland/Libraries/LibGUI/Wizards/WizardDialog.cpp +++ b/Userland/Libraries/LibGUI/Wizards/WizardDialog.cpp @@ -41,7 +41,7 @@ WizardDialog::WizardDialog(Window* parent_window) auto& nav_container_widget = main_widget.add<Widget>(); nav_container_widget.set_layout<HorizontalBoxLayout>(); nav_container_widget.set_fixed_height(42); - nav_container_widget.layout()->set_margins({ 0, 10, 0, 10 }); + nav_container_widget.layout()->set_margins({ 0, 10 }); nav_container_widget.layout()->set_spacing(0); nav_container_widget.layout()->add_spacer(); diff --git a/Userland/Libraries/LibGUI/Wizards/WizardPage.cpp b/Userland/Libraries/LibGUI/Wizards/WizardPage.cpp index 9f9286c68e..a08f5e879f 100644 --- a/Userland/Libraries/LibGUI/Wizards/WizardPage.cpp +++ b/Userland/Libraries/LibGUI/Wizards/WizardPage.cpp @@ -26,7 +26,7 @@ WizardPage::WizardPage(const String& title_text, const String& subtitle_text) header_widget.set_fixed_height(58); header_widget.set_layout<VerticalBoxLayout>(); - header_widget.layout()->set_margins({ 15, 30, 0, 30 }); + header_widget.layout()->set_margins({ 15, 30, 0 }); m_title_label = header_widget.add<Label>(title_text); m_title_label->set_font(Gfx::FontDatabase::default_font().bold_variant()); m_title_label->set_fixed_height(m_title_label->font().glyph_height() + 2); @@ -41,7 +41,7 @@ WizardPage::WizardPage(const String& title_text, const String& subtitle_text) m_body_widget = add<Widget>(); m_body_widget->set_layout<VerticalBoxLayout>(); - m_body_widget->layout()->set_margins({ 20, 20, 20, 20 }); + m_body_widget->layout()->set_margins(20); } void WizardPage::set_page_title(const String& text) |