Skip to content

Commit

Permalink
Userland+LibGUI: Add shorthand versions of the Margins constructor
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sin-ack authored and awesomekling committed Aug 18, 2021
1 parent 9c9a5c5 commit e11d177
Show file tree
Hide file tree
Showing 101 changed files with 232 additions and 201 deletions.
2 changes: 1 addition & 1 deletion Base/res/devel/templates/serenity-application/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int main(int argc, char** argv)
main_widget.set_fill_with_background_color(true);

auto& layout = main_widget.set_layout<GUI::VerticalBoxLayout>();
layout.set_margins({ 16, 16, 16, 16 });
layout.set_margins(16);

auto& button = main_widget.add<GUI::Button>("Click me!");
button.on_click = [&](auto) {
Expand Down
2 changes: 1 addition & 1 deletion Userland/Applets/Audio/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class AudioWidget final : public GUI::Widget {
m_root_container = m_slider_window->set_main_widget<GUI::Label>();
m_root_container->set_fill_with_background_color(true);
m_root_container->set_layout<GUI::VerticalBoxLayout>();
m_root_container->layout()->set_margins({ 4, 0, 4, 0 });
m_root_container->layout()->set_margins({ 4, 0 });
m_root_container->layout()->set_spacing(0);
m_root_container->set_frame_thickness(2);
m_root_container->set_frame_shape(Gfx::FrameShape::Container);
Expand Down
6 changes: 3 additions & 3 deletions Userland/Applications/Assistant/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ResultRow final : public GUI::Widget {
{
auto& layout = set_layout<GUI::HorizontalBoxLayout>();
layout.set_spacing(12);
layout.set_margins({ 4, 4, 4, 4 });
layout.set_margins(4);

m_image = add<GUI::ImageWidget>();

Expand Down Expand Up @@ -221,12 +221,12 @@ int main(int argc, char** argv)
container.set_fill_with_background_color(true);
container.set_frame_shadow(Gfx::FrameShadow::Raised);
auto& layout = container.set_layout<GUI::VerticalBoxLayout>();
layout.set_margins({ 8, 8, 0, 8 });
layout.set_margins({ 8, 8, 0 });

auto& text_box = container.add<GUI::TextBox>();
auto& results_container = container.add<GUI::Widget>();
auto& results_layout = results_container.set_layout<GUI::VerticalBoxLayout>();
results_layout.set_margins({ 10, 0, 10, 0 });
results_layout.set_margins({ 10, 0 });

auto mark_selected_item = [&]() {
for (size_t i = 0; i < app_state.visible_result_count; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion Userland/Applications/Browser/BrowserWindow.gml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@GUI::TabWidget {
name: "tab_widget"
container_margins: [0, 0, 0, 0]
container_margins: [0]
uniform_tabs: true
text_alignment: "CenterLeft"
}
Expand Down
2 changes: 1 addition & 1 deletion Userland/Applications/Browser/DownloadWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ DownloadWidget::DownloadWidget(const URL& url)

set_fill_with_background_color(true);
auto& layout = set_layout<GUI::VerticalBoxLayout>();
layout.set_margins({ 4, 4, 4, 4 });
layout.set_margins(4);

auto& animation_container = add<GUI::Widget>();
animation_container.set_fixed_height(32);
Expand Down
2 changes: 1 addition & 1 deletion Userland/Applications/Browser/EditBookmark.gml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
fill_with_background_color: true

layout: @GUI::VerticalBoxLayout {
margins: [4, 4, 4, 4]
margins: [4]
}


Expand Down
2 changes: 1 addition & 1 deletion Userland/Applications/Calculator/CalculatorWindow.gml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@GUI::Widget {
layout: @GUI::VerticalBoxLayout {
margins: [8, 8, 8, 8]
margins: [8]
}

@GUI::TextBox {
Expand Down
4 changes: 2 additions & 2 deletions Userland/Applications/Calendar/AddEventDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ AddEventDialog::AddEventDialog(Core::DateTime date_time, Window* parent_window)
auto& top_container = widget.add<GUI::Widget>();
top_container.set_layout<GUI::VerticalBoxLayout>();
top_container.set_fixed_height(45);
top_container.layout()->set_margins({ 4, 4, 4, 4 });
top_container.layout()->set_margins(4);

auto& add_label = top_container.add<GUI::Label>("Add title & date:");
add_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
Expand All @@ -52,7 +52,7 @@ AddEventDialog::AddEventDialog(Core::DateTime date_time, Window* parent_window)
auto& middle_container = widget.add<GUI::Widget>();
middle_container.set_layout<GUI::HorizontalBoxLayout>();
middle_container.set_fixed_height(25);
middle_container.layout()->set_margins({ 4, 4, 4, 4 });
middle_container.layout()->set_margins(4);

auto& starting_month_combo = middle_container.add<GUI::ComboBox>();
starting_month_combo.set_only_allow_values_from_model(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
fill_with_background_color: true

layout: @GUI::VerticalBoxLayout {
margins: [5, 5, 5, 5]
margins: [5]
}

@GUI::Widget {
Expand Down
10 changes: 5 additions & 5 deletions Userland/Applications/CrashReporter/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ int main(int argc, char** argv)

auto& backtrace_tab = tab_widget.add_tab<GUI::Widget>("Backtrace");
backtrace_tab.set_layout<GUI::VerticalBoxLayout>();
backtrace_tab.layout()->set_margins({ 4, 4, 4, 4 });
backtrace_tab.layout()->set_margins(4);

auto& backtrace_label = backtrace_tab.add<GUI::Label>("A backtrace for each thread alive during the crash is listed below:");
backtrace_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
Expand All @@ -236,15 +236,15 @@ int main(int argc, char** argv)
for (auto& backtrace : thread_backtraces) {
auto& backtrace_text_editor = backtrace_tab_widget.add_tab<GUI::TextEditor>(backtrace.title);
backtrace_text_editor.set_layout<GUI::VerticalBoxLayout>();
backtrace_text_editor.layout()->set_margins({ 4, 4, 4, 4 });
backtrace_text_editor.layout()->set_margins(4);
backtrace_text_editor.set_text(backtrace.text);
backtrace_text_editor.set_mode(GUI::TextEditor::Mode::ReadOnly);
backtrace_text_editor.set_should_hide_unnecessary_scrollbars(true);
}

auto& cpu_registers_tab = tab_widget.add_tab<GUI::Widget>("CPU Registers");
cpu_registers_tab.set_layout<GUI::VerticalBoxLayout>();
cpu_registers_tab.layout()->set_margins({ 4, 4, 4, 4 });
cpu_registers_tab.layout()->set_margins(4);

auto& cpu_registers_label = cpu_registers_tab.add<GUI::Label>("The CPU register state for each thread alive during the crash is listed below:");
cpu_registers_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
Expand All @@ -255,15 +255,15 @@ int main(int argc, char** argv)
for (auto& cpu_registers : thread_cpu_registers) {
auto& cpu_registers_text_editor = cpu_registers_tab_widget.add_tab<GUI::TextEditor>(cpu_registers.title);
cpu_registers_text_editor.set_layout<GUI::VerticalBoxLayout>();
cpu_registers_text_editor.layout()->set_margins({ 4, 4, 4, 4 });
cpu_registers_text_editor.layout()->set_margins(4);
cpu_registers_text_editor.set_text(cpu_registers.text);
cpu_registers_text_editor.set_mode(GUI::TextEditor::Mode::ReadOnly);
cpu_registers_text_editor.set_should_hide_unnecessary_scrollbars(true);
}

auto& environment_tab = tab_widget.add_tab<GUI::Widget>("Environment");
environment_tab.set_layout<GUI::VerticalBoxLayout>();
environment_tab.layout()->set_margins({ 4, 4, 4, 4 });
environment_tab.layout()->set_margins(4);

auto& environment_text_editor = environment_tab.add<GUI::TextEditor>();
environment_text_editor.set_text(String::join("\n", environment));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
fill_with_background_color: true

layout: @GUI::VerticalBoxLayout {
margins: [8, 8, 8, 8]
margins: [8]
}

@DisplaySettings::MonitorWidget {
Expand Down
8 changes: 4 additions & 4 deletions Userland/Applications/DisplaySettings/DesktopSettings.gml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
fill_with_background_color: true

layout: @GUI::VerticalBoxLayout {
margins: [8, 8, 8, 8]
margins: [8]
}

@GUI::GroupBox {
layout: @GUI::VerticalBoxLayout {
margins: [24, 16, 6, 16]
margins: [24, 16, 6]
}

title: "Workspaces"
Expand All @@ -17,7 +17,7 @@
fixed_height: 32

layout: @GUI::HorizontalBoxLayout {
margins: [6, 6, 6, 6]
margins: [6]
}

@GUI::Label {
Expand Down Expand Up @@ -57,7 +57,7 @@
}
@GUI::Widget {
layout: @GUI::VerticalBoxLayout {
margins: [6, 6, 6, 6]
margins: [6]
}
@GUI::Label {
text: "Use the Ctrl+Alt+Arrow hotkeys to move between workspaces."
Expand Down
2 changes: 1 addition & 1 deletion Userland/Applications/DisplaySettings/FontSettings.gml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
fill_with_background_color: true

layout: @GUI::VerticalBoxLayout {
margins: [8, 8, 8, 8]
margins: [8]
spacing: 8
}

Expand Down
4 changes: 2 additions & 2 deletions Userland/Applications/DisplaySettings/MonitorSettings.gml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
fill_with_background_color: true

layout: @GUI::VerticalBoxLayout {
margins: [8, 8, 8, 8]
margins: [8]
}

@DisplaySettings::MonitorWidget {
Expand Down Expand Up @@ -34,7 +34,7 @@

@GUI::GroupBox {
layout: @GUI::VerticalBoxLayout {
margins: [24, 16, 6, 16]
margins: [24, 16, 6]
}

title: "Screen settings"
Expand Down
2 changes: 1 addition & 1 deletion Userland/Applications/DisplaySettings/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int main(int argc, char** argv)
auto& main_widget = window->set_main_widget<GUI::Widget>();
main_widget.set_fill_with_background_color(true);
main_widget.set_layout<GUI::VerticalBoxLayout>();
main_widget.layout()->set_margins({ 4, 4, 4, 4 });
main_widget.layout()->set_margins(4);
main_widget.layout()->set_spacing(6);

auto& tab_widget = main_widget.add<GUI::TabWidget>();
Expand Down
2 changes: 1 addition & 1 deletion Userland/Applications/FileManager/DirectoryView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ DirectoryView::DirectoryView(Mode mode)
, m_sorting_model(GUI::SortingProxyModel::create(m_model))
{
set_active_widget(nullptr);
set_content_margins({ 2, 2, 2, 2 });
set_content_margins(2);

setup_actions();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
fill_with_background_color: true

layout: @GUI::VerticalBoxLayout {
margins: [4, 4, 4, 4]
margins: [4]
}

@GUI::Widget {
Expand Down
2 changes: 1 addition & 1 deletion Userland/Applications/FileManager/PropertiesWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ PropertiesWindow::PropertiesWindow(String const& path, bool disable_rename, Wind

auto& main_widget = set_main_widget<GUI::Widget>();
main_widget.set_layout<GUI::VerticalBoxLayout>();
main_widget.layout()->set_margins({ 4, 4, 4, 4 });
main_widget.layout()->set_margins(4);
main_widget.set_fill_with_background_color(true);

set_rect({ 0, 0, 360, 420 });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@GUI::Widget {
layout: @GUI::VerticalBoxLayout {
margins: [8, 12, 8, 12]
margins: [8, 12]
spacing: 10
}

Expand Down
4 changes: 2 additions & 2 deletions Userland/Applications/FileManager/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,12 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
auto& toolbar_container = *widget.find_descendant_of_type_named<GUI::ToolbarContainer>("toolbar_container");
auto& main_toolbar = *widget.find_descendant_of_type_named<GUI::Toolbar>("main_toolbar");
auto& location_toolbar = *widget.find_descendant_of_type_named<GUI::Toolbar>("location_toolbar");
location_toolbar.layout()->set_margins({ 3, 6, 3, 6 });
location_toolbar.layout()->set_margins({ 3, 6 });

auto& location_textbox = *widget.find_descendant_of_type_named<GUI::TextBox>("location_textbox");

auto& breadcrumb_toolbar = *widget.find_descendant_of_type_named<GUI::Toolbar>("breadcrumb_toolbar");
breadcrumb_toolbar.layout()->set_margins({ 0, 6, 0, 6 });
breadcrumb_toolbar.layout()->set_margins({ 0, 6 });
auto& breadcrumbbar = *widget.find_descendant_of_type_named<GUI::Breadcrumbbar>("breadcrumbbar");

auto& splitter = *widget.find_descendant_of_type_named<GUI::HorizontalSplitter>("splitter");
Expand Down
4 changes: 2 additions & 2 deletions Userland/Applications/FontEditor/FontEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ static RefPtr<GUI::Window> create_font_preview_window(FontEditorWidget& editor)
auto& main_widget = window->set_main_widget<GUI::Widget>();
main_widget.set_fill_with_background_color(true);
main_widget.set_layout<GUI::VerticalBoxLayout>();
main_widget.layout()->set_margins({ 2, 2, 2, 2 });
main_widget.layout()->set_margins(2);
main_widget.layout()->set_spacing(4);

auto& preview_box = main_widget.add<GUI::GroupBox>();
preview_box.set_layout<GUI::VerticalBoxLayout>();
preview_box.layout()->set_margins({ 8, 8, 8, 8 });
preview_box.layout()->set_margins(8);

auto& preview_label = preview_box.add<GUI::Label>();
preview_label.set_font(editor.edited_font());
Expand Down
2 changes: 1 addition & 1 deletion Userland/Applications/FontEditor/NewFontDialogPage1.gml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@GUI::Widget {
layout: @GUI::VerticalBoxLayout {
margins: [20, 20, 20, 20]
margins: [20]
}

@GUI::Widget {
Expand Down
6 changes: 3 additions & 3 deletions Userland/Applications/FontEditor/NewFontDialogPage2.gml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@GUI::Widget {
layout: @GUI::VerticalBoxLayout {
margins: [20, 20, 20, 20]
margins: [20]
}

@GUI::Widget {
Expand All @@ -11,7 +11,7 @@
title: "Metadata"
fixed_width: 200
layout: @GUI::VerticalBoxLayout {
margins: [16, 8, 8, 8]
margins: [16, 8, 8]
}

@GUI::Widget {
Expand Down Expand Up @@ -125,7 +125,7 @@
@GUI::Widget {
name: "glyph_editor_container"
layout: @GUI::VerticalBoxLayout {
margins: [5, 0, 0, 0]
margins: [5, 0, 0]
}
}

Expand Down
4 changes: 2 additions & 2 deletions Userland/Applications/Help/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ int main(int argc, char* argv[])
auto& left_tab_bar = splitter.add<GUI::TabWidget>();
auto& tree_view_container = left_tab_bar.add_tab<GUI::Widget>("Browse");
tree_view_container.set_layout<GUI::VerticalBoxLayout>();
tree_view_container.layout()->set_margins({ 4, 4, 4, 4 });
tree_view_container.layout()->set_margins(4);
auto& tree_view = tree_view_container.add<GUI::TreeView>();
auto& search_view = left_tab_bar.add_tab<GUI::Widget>("Search");
search_view.set_layout<GUI::VerticalBoxLayout>();
search_view.layout()->set_margins({ 4, 4, 4, 4 });
search_view.layout()->set_margins(4);
auto& search_box = search_view.add<GUI::TextBox>();
auto& search_list_view = search_view.add<GUI::ListView>();
search_box.set_fixed_height(20);
Expand Down
2 changes: 1 addition & 1 deletion Userland/Applications/HexEditor/FindDialog.gml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

layout: @GUI::VerticalBoxLayout {
spacing: 2
margins: [4, 4, 4, 4]
margins: [4]
}

@GUI::Widget {
Expand Down
6 changes: 3 additions & 3 deletions Userland/Applications/HexEditor/GoToOffsetDialog.gml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

layout: @GUI::VerticalBoxLayout {
spacing: 2
margins: [0, 0, 0, 0]
margins: [0]
}

@GUI::Widget {
layout: @GUI::HorizontalBoxLayout {
spacing: 2
margins: [2, 2, 2, 2]
margins: [2]
}

@GUI::Label {
Expand Down Expand Up @@ -41,7 +41,7 @@
@GUI::Widget {
layout: @GUI::HorizontalBoxLayout {
spacing: 2
margins: [2, 2, 2, 2]
margins: [2]
}

@GUI::Label {
Expand Down
2 changes: 1 addition & 1 deletion Userland/Applications/IRCClient/IRCAppWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ void IRCAppWindow::setup_widgets()

auto& outer_container = widget.add<GUI::Widget>();
outer_container.set_layout<GUI::VerticalBoxLayout>();
outer_container.layout()->set_margins({ 0, 2, 2, 2 });
outer_container.layout()->set_margins({ 0, 2, 2 });

auto& horizontal_container = outer_container.add<GUI::HorizontalSplitter>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void KeyboardMapperWidget::create_frame()
{
set_fill_with_background_color(true);
set_layout<GUI::VerticalBoxLayout>();
layout()->set_margins({ 4, 4, 4, 4 });
layout()->set_margins(4);

auto& main_widget = add<GUI::Widget>();
main_widget.set_relative_rect(0, 0, 200, 200);
Expand Down
Loading

0 comments on commit e11d177

Please sign in to comment.