LibGUI: Use Core::Object::add() a whole bunch

This commit is contained in:
Andreas Kling 2020-02-23 10:31:26 +01:00
parent 8efafdfc12
commit 45c25ffecd
Notes: sideshowbarker 2024-07-19 09:08:55 +09:00
11 changed files with 52 additions and 52 deletions

View file

@ -47,22 +47,22 @@ AboutDialog::AboutDialog(const StringView& name, const Gfx::Bitmap* icon, Core::
widget->set_fill_with_background_color(true);
widget->set_layout(make<HorizontalBoxLayout>());
auto left_container = Widget::construct(widget.ptr());
auto left_container = widget->add<Widget>();
left_container->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
left_container->set_preferred_size(48, 0);
left_container->set_layout(make<VerticalBoxLayout>());
auto icon_label = Label::construct(left_container);
auto icon_label = left_container->add<Label>();
icon_label->set_icon(m_icon);
icon_label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
icon_label->set_preferred_size(40, 40);
left_container->layout()->add_spacer();
auto right_container = Widget::construct(widget.ptr());
auto right_container = widget->add<Widget>();
right_container->set_layout(make<VerticalBoxLayout>());
right_container->layout()->set_margins({ 0, 4, 4, 4 });
auto make_label = [&](const StringView& text, bool bold = false) {
auto label = Label::construct(text, right_container);
auto label = right_container->add<Label>(text);
label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
label->set_preferred_size(0, 14);
@ -75,12 +75,12 @@ AboutDialog::AboutDialog(const StringView& name, const Gfx::Bitmap* icon, Core::
right_container->layout()->add_spacer();
auto button_container = Widget::construct(right_container.ptr());
auto button_container = right_container->add<Widget>();
button_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
button_container->set_preferred_size(0, 20);
button_container->set_layout(make<HorizontalBoxLayout>());
button_container->layout()->add_spacer();
auto ok_button = Button::construct("OK", button_container);
auto ok_button = button_container->add<Button>("OK");
ok_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
ok_button->set_preferred_size(80, 20);
ok_button->on_click = [this](auto&) {

View file

@ -40,7 +40,7 @@ AbstractButton::AbstractButton(const StringView& text, Widget* parent)
: Widget(parent)
, m_text(text)
{
m_auto_repeat_timer = Core::Timer::construct(this);
m_auto_repeat_timer = add<Core::Timer>();
m_auto_repeat_timer->on_timeout = [this] {
click();
};

View file

@ -54,10 +54,10 @@ void ColorPicker::build()
horizontal_container->layout()->set_margins({ 4, 4, 4, 4 });
set_main_widget(horizontal_container);
auto left_vertical_container = Widget::construct(horizontal_container.ptr());
auto left_vertical_container = horizontal_container->add<Widget>();
left_vertical_container->set_layout(make<VerticalBoxLayout>());
auto right_vertical_container = Widget::construct(horizontal_container.ptr());
auto right_vertical_container = horizontal_container->add<Widget>();
right_vertical_container->set_layout(make<VerticalBoxLayout>());
enum RGBComponent {
@ -66,19 +66,19 @@ void ColorPicker::build()
Blue
};
m_preview_widget = Frame::construct(right_vertical_container);
m_preview_widget = right_vertical_container->add<Frame>();
auto pal = m_preview_widget->palette();
pal.set_color(ColorRole::Background, m_color);
m_preview_widget->set_fill_with_background_color(true);
m_preview_widget->set_palette(pal);
right_vertical_container->layout()->add_spacer();
auto cancel_button = Button::construct("Cancel", right_vertical_container);
auto cancel_button = right_vertical_container->add<Button>("Cancel");
cancel_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
cancel_button->set_preferred_size(0, 20);
cancel_button->on_click = [&](auto&) {
done(Dialog::ExecCancel);
};
auto ok_button = Button::construct("Okay", right_vertical_container);
auto ok_button = right_vertical_container->add<Button>("Okay");
ok_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
ok_button->set_preferred_size(0, 20);
ok_button->on_click = [&](auto&) {
@ -86,7 +86,7 @@ void ColorPicker::build()
};
auto make_spinbox = [&](RGBComponent component, int initial_value) {
auto spinbox = SpinBox::construct(left_vertical_container);
auto spinbox = left_vertical_container->add<SpinBox>();
spinbox->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
spinbox->set_preferred_size(0, 20);
spinbox->set_min(0);

View file

@ -47,7 +47,7 @@ ComboBox::ComboBox(Widget* parent)
if (on_return_pressed)
on_return_pressed();
};
m_open_button = Button::construct(this);
m_open_button = add<Button>();
m_open_button->set_focusable(false);
m_open_button->set_text("\xc3\xb7");
m_open_button->on_click = [this](auto&) {

View file

@ -86,26 +86,26 @@ FilePicker::FilePicker(Mode mode, const StringView& file_name, const StringView&
horizontal_container->layout()->set_margins({ 4, 4, 4, 4 });
horizontal_container->set_fill_with_background_color(true);
auto vertical_container = Widget::construct(horizontal_container.ptr());
auto vertical_container = horizontal_container->add<Widget>();
vertical_container->set_layout(make<VerticalBoxLayout>());
vertical_container->layout()->set_spacing(4);
auto upper_container = Widget::construct(vertical_container.ptr());
auto upper_container = vertical_container->add<Widget>();
upper_container->set_layout(make<HorizontalBoxLayout>());
upper_container->layout()->set_spacing(4);
upper_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
upper_container->set_preferred_size(0, 26);
auto toolbar = ToolBar::construct(upper_container);
auto toolbar = upper_container->add<ToolBar>();
toolbar->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
toolbar->set_preferred_size(85, 0);
toolbar->set_has_frame(false);
auto location_textbox = TextBox::construct(upper_container);
auto location_textbox = upper_container->add<TextBox>();
location_textbox->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
location_textbox->set_preferred_size(0, 20);
m_view = TableView::construct(vertical_container);
m_view = vertical_container->add<TableView>();
m_view->set_model(SortingProxyModel::create(*m_model));
m_view->set_column_hidden(FileSystemModel::Column::Owner, true);
m_view->set_column_hidden(FileSystemModel::Column::Group, true);
@ -132,7 +132,7 @@ FilePicker::FilePicker(Mode mode, const StringView& file_name, const StringView&
toolbar->add_separator();
auto mkdir_action = Action::create("New directory...", Gfx::Bitmap::load_from_file("/res/icons/16x16/mkdir.png"), [this](const Action&) {
auto input_box = InputBox::construct("Enter name:", "New directory", this);
auto input_box = add<InputBox>("Enter name:", "New directory");
if (input_box->exec() == InputBox::ExecOK && !input_box->text_value().is_empty()) {
auto new_dir_path = FileSystemPath(String::format("%s/%s",
m_model->root_path().characters(),
@ -148,21 +148,21 @@ FilePicker::FilePicker(Mode mode, const StringView& file_name, const StringView&
});
toolbar->add_action(*mkdir_action);
auto lower_container = Widget::construct(vertical_container.ptr());
auto lower_container = vertical_container->add<Widget>();
lower_container->set_layout(make<VerticalBoxLayout>());
lower_container->layout()->set_spacing(4);
lower_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
lower_container->set_preferred_size(0, 60);
auto filename_container = Widget::construct(lower_container.ptr());
auto filename_container = lower_container->add<Widget>();
filename_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
filename_container->set_preferred_size(0, 20);
filename_container->set_layout(make<HorizontalBoxLayout>());
auto filename_label = Label::construct("File name:", filename_container);
auto filename_label = filename_container->add<Label>("File name:");
filename_label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
filename_label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
filename_label->set_preferred_size(60, 0);
m_filename_textbox = TextBox::construct(filename_container.ptr());
m_filename_textbox = filename_container->add<TextBox>();
if (m_mode == Mode::Save) {
m_filename_textbox->set_text(file_name);
m_filename_textbox->set_focus(true);
@ -185,14 +185,14 @@ FilePicker::FilePicker(Mode mode, const StringView& file_name, const StringView&
set_preview(path);
};
auto button_container = Widget::construct(lower_container.ptr());
auto button_container = lower_container->add<Widget>();
button_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
button_container->set_preferred_size(0, 20);
button_container->set_layout(make<HorizontalBoxLayout>());
button_container->layout()->set_spacing(4);
button_container->layout()->add_spacer();
auto cancel_button = Button::construct(button_container);
auto cancel_button = button_container->add<Button>();
cancel_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
cancel_button->set_preferred_size(80, 0);
cancel_button->set_text("Cancel");
@ -200,7 +200,7 @@ FilePicker::FilePicker(Mode mode, const StringView& file_name, const StringView&
done(ExecCancel);
};
auto ok_button = Button::construct(button_container);
auto ok_button = button_container->add<Button>();
ok_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
ok_button->set_preferred_size(80, 0);
ok_button->set_text(ok_button_name(m_mode));
@ -222,7 +222,7 @@ FilePicker::FilePicker(Mode mode, const StringView& file_name, const StringView&
}
};
auto preview_container = Frame::construct(horizontal_container);
auto preview_container = horizontal_container->add<Frame>();
preview_container->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
preview_container->set_preferred_size(180, 0);
preview_container->set_frame_shape(Gfx::FrameShape::Container);
@ -231,17 +231,17 @@ FilePicker::FilePicker(Mode mode, const StringView& file_name, const StringView&
preview_container->set_layout(make<VerticalBoxLayout>());
preview_container->layout()->set_margins({ 8, 8, 8, 8 });
m_preview_image_label = Label::construct(preview_container);
m_preview_image_label = preview_container->add<Label>();
m_preview_image_label->set_should_stretch_icon(true);
m_preview_image_label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
m_preview_image_label->set_preferred_size(160, 160);
m_preview_name_label = Label::construct(preview_container);
m_preview_name_label = preview_container->add<Label>();
m_preview_name_label->set_font(Gfx::Font::default_bold_font());
m_preview_name_label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
m_preview_name_label->set_preferred_size(0, m_preview_name_label->font().glyph_height());
m_preview_geometry_label = Label::construct(preview_container);
m_preview_geometry_label = preview_container->add<Label>();
m_preview_geometry_label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
m_preview_geometry_label->set_preferred_size(0, m_preview_name_label->font().glyph_height());
}

View file

@ -28,7 +28,7 @@
#include <LibGUI/Button.h>
#include <LibGUI/InputBox.h>
#include <LibGUI/Label.h>
#include <LibGUI/TextEditor.h>
#include <LibGUI/TextBox.h>
#include <LibGfx/Font.h>
#include <stdio.h>
@ -63,24 +63,24 @@ void InputBox::build()
widget->layout()->set_margins({ 8, 8, 8, 8 });
widget->layout()->set_spacing(8);
auto label = Label::construct(m_prompt, widget);
auto label = widget->add<Label>(m_prompt);
label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
label->set_preferred_size(text_width, 16);
m_text_editor = TextEditor::construct(TextEditor::SingleLine, widget);
m_text_editor = widget->add<TextBox>();
m_text_editor->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
m_text_editor->set_preferred_size(0, 19);
auto button_container_outer = Widget::construct(widget.ptr());
auto button_container_outer = widget->add<Widget>();
button_container_outer->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
button_container_outer->set_preferred_size(0, 20);
button_container_outer->set_layout(make<VerticalBoxLayout>());
auto button_container_inner = Widget::construct(button_container_outer.ptr());
auto button_container_inner = button_container_outer->add<Widget>();
button_container_inner->set_layout(make<HorizontalBoxLayout>());
button_container_inner->layout()->set_spacing(8);
m_cancel_button = Button::construct(button_container_inner);
m_cancel_button = button_container_inner->add<Button>();
m_cancel_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
m_cancel_button->set_preferred_size(0, 20);
m_cancel_button->set_text("Cancel");
@ -89,7 +89,7 @@ void InputBox::build()
done(ExecCancel);
};
m_ok_button = Button::construct(button_container_inner);
m_ok_button = button_container_inner->add<Button>();
m_ok_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
m_ok_button->set_preferred_size(0, 20);
m_ok_button->set_text("OK");

View file

@ -35,7 +35,7 @@ namespace GUI {
int MessageBox::show(const StringView& text, const StringView& title, Type type, InputType input_type, Core::Object* parent)
{
auto box = MessageBox::construct(text, title, type, input_type, parent);
auto box = parent->add<MessageBox>(text, title, type, input_type);
return box->exec();
}
@ -103,29 +103,29 @@ void MessageBox::build()
RefPtr<Widget> message_container = widget;
if (m_type != Type::None) {
message_container = Widget::construct(widget.ptr());
message_container = widget->add<Widget>();
message_container->set_layout(make<HorizontalBoxLayout>());
message_container->layout()->set_margins({ 8, 0, 8, 0 });
message_container->layout()->set_spacing(8);
auto icon_label = Label::construct(message_container);
auto icon_label = message_container->add<Label>();
icon_label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
icon_label->set_preferred_size(32, 32);
icon_label->set_icon(icon());
icon_width = icon_label->icon()->width();
}
auto label = Label::construct(m_text, message_container);
auto label = message_container->add<Label>(m_text);
label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
label->set_preferred_size(text_width, 16);
auto button_container = Widget::construct(widget.ptr());
auto button_container = widget->add<Widget>();
button_container->set_layout(make<HorizontalBoxLayout>());
button_container->layout()->set_spacing(5);
button_container->layout()->set_margins({ 15, 0, 15, 0 });
auto add_button = [&](String label, Dialog::ExecResult result) {
auto button = Button::construct(button_container);
auto button = button_container->add<Button>();
button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
button->set_preferred_size(0, 20);
button->set_text(label);

View file

@ -95,7 +95,7 @@ ScrollBar::ScrollBar(Orientation orientation, Widget* parent)
: Widget(parent)
, m_orientation(orientation)
{
m_automatic_scrolling_timer = Core::Timer::construct(this);
m_automatic_scrolling_timer = add<Core::Timer>();
if (!s_up_arrow_bitmap)
s_up_arrow_bitmap = &Gfx::CharacterBitmap::create_from_ascii(s_up_arrow_bitmap_data, 9, 9).leak_ref();
if (!s_down_arrow_bitmap)

View file

@ -74,8 +74,8 @@ public:
Function<void(int)> on_value_changed;
protected:
explicit Slider(Widget*);
explicit Slider(Orientation, Widget*);
explicit Slider(Widget* = nullptr);
explicit Slider(Orientation, Widget* = nullptr);
virtual void paint_event(PaintEvent&) override;
virtual void mousedown_event(MouseEvent&) override;

View file

@ -26,14 +26,14 @@
#include <LibGUI/Button.h>
#include <LibGUI/SpinBox.h>
#include <LibGUI/TextEditor.h>
#include <LibGUI/TextBox.h>
namespace GUI {
SpinBox::SpinBox(Widget* parent)
: Widget(parent)
{
m_editor = TextEditor::construct(TextEditor::Type::SingleLine, this);
m_editor = add<TextBox>();
m_editor->set_text("0");
m_editor->on_change = [this] {
bool ok;
@ -43,12 +43,12 @@ SpinBox::SpinBox(Widget* parent)
else
m_editor->set_text(String::number(m_value));
};
m_increment_button = Button::construct(this);
m_increment_button = add<Button>();
m_increment_button->set_focusable(false);
m_increment_button->set_text("\xc3\xb6");
m_increment_button->on_click = [this](auto&) { set_value(m_value + 1); };
m_increment_button->set_auto_repeat_interval(150);
m_decrement_button = Button::construct(this);
m_decrement_button = add<Button>();
m_decrement_button->set_focusable(false);
m_decrement_button->set_text("\xc3\xb7");
m_decrement_button->on_click = [this](auto&) { set_value(m_value - 1); };

View file

@ -65,7 +65,7 @@ void ToolBar::add_action(Action& action)
item->type = Item::Type::Action;
item->action = action;
auto button = Button::construct(this);
auto button = add<Button>();
if (action.group() && action.group()->is_exclusive())
button->set_exclusive(true);
button->set_action(*item->action);