mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:47:34 +00:00
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.
This commit is contained in:
parent
9c9a5c55cb
commit
e11d177618
101 changed files with 232 additions and 201 deletions
|
@ -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());
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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>();
|
||||
|
|
|
@ -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; \
|
||||
});
|
||||
|
|
|
@ -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>();
|
||||
|
|
|
@ -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>();
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
fill_with_background_color: true
|
||||
|
||||
layout: @GUI::HorizontalBoxLayout {
|
||||
margins: [8, 8, 8, 8]
|
||||
margins: [8]
|
||||
spacing: 8
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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>();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue