diff options
author | Andreas Kling <kling@serenityos.org> | 2020-03-04 19:07:55 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-03-04 21:04:06 +0100 |
commit | 028c011760b5b665fc2a72bb3c11fd3a6ca60d2c (patch) | |
tree | a961293992de78ebac5c3ffec864179d661dcc09 /Libraries | |
parent | fb09b6a8cec02cc473b3fed326d99055d80a60ba (diff) | |
download | serenity-028c011760b5b665fc2a72bb3c11fd3a6ca60d2c.zip |
LibCore: Make Core::Object::add<ChildType> return a ChildType&
Since the returned object is now owned by the callee object, we can
simply vend a ChildType&. This allows us to use "." instead of "->"
at the call site, which is quite nice. :^)
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibCore/Object.h | 8 | ||||
-rw-r--r-- | Libraries/LibGUI/AboutDialog.cpp | 54 | ||||
-rw-r--r-- | Libraries/LibGUI/ColorPicker.cpp | 43 | ||||
-rw-r--r-- | Libraries/LibGUI/FilePicker.cpp | 146 | ||||
-rw-r--r-- | Libraries/LibGUI/InputBox.cpp | 24 | ||||
-rw-r--r-- | Libraries/LibGUI/MessageBox.cpp | 34 | ||||
-rw-r--r-- | Libraries/LibGUI/StatusBar.cpp | 10 | ||||
-rw-r--r-- | Libraries/LibGUI/ToolBar.cpp | 22 | ||||
-rw-r--r-- | Libraries/LibHTML/DOM/HTMLInputElement.cpp | 14 |
9 files changed, 177 insertions, 178 deletions
diff --git a/Libraries/LibCore/Object.h b/Libraries/LibCore/Object.h index d007818b0e..6f4a106a4f 100644 --- a/Libraries/LibCore/Object.h +++ b/Libraries/LibCore/Object.h @@ -121,11 +121,11 @@ public: } template<class T, class... Args> - inline NonnullRefPtr<T> add(Args&&... args) + inline T& add(Args&&... args) { - auto t = T::construct(forward<Args>(args)...); - add_child(*t); - return t; + auto child = T::construct(forward<Args>(args)...); + add_child(*child); + return child; } virtual bool is_visible_for_timer_purposes() const; diff --git a/Libraries/LibGUI/AboutDialog.cpp b/Libraries/LibGUI/AboutDialog.cpp index 5b0f0a8cbc..12b43c3f40 100644 --- a/Libraries/LibGUI/AboutDialog.cpp +++ b/Libraries/LibGUI/AboutDialog.cpp @@ -46,43 +46,43 @@ AboutDialog::AboutDialog(const StringView& name, const Gfx::Bitmap* icon, Core:: widget.set_fill_with_background_color(true); widget.set_layout<HorizontalBoxLayout>(); - 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<VerticalBoxLayout>(); - 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& 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<VerticalBoxLayout>(); + 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.add<Widget>(); - right_container->set_layout<VerticalBoxLayout>(); - right_container->layout()->set_margins({ 0, 4, 4, 4 }); + auto& right_container = widget.add<Widget>(); + right_container.set_layout<VerticalBoxLayout>(); + right_container.layout()->set_margins({ 0, 4, 4, 4 }); auto make_label = [&](const StringView& text, bool bold = false) { - 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); + 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); if (bold) - label->set_font(Gfx::Font::default_bold_font()); + label.set_font(Gfx::Font::default_bold_font()); }; make_label(m_name, true); make_label("SerenityOS"); make_label("(C) The SerenityOS developers"); - right_container->layout()->add_spacer(); + right_container.layout()->add_spacer(); - 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<HorizontalBoxLayout>(); - button_container->layout()->add_spacer(); - 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& 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<HorizontalBoxLayout>(); + button_container.layout()->add_spacer(); + 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] { done(Dialog::ExecOK); }; } diff --git a/Libraries/LibGUI/ColorPicker.cpp b/Libraries/LibGUI/ColorPicker.cpp index e5d2df6eb1..7640812a5b 100644 --- a/Libraries/LibGUI/ColorPicker.cpp +++ b/Libraries/LibGUI/ColorPicker.cpp @@ -53,11 +53,11 @@ void ColorPicker::build() horizontal_container.set_layout<HorizontalBoxLayout>(); horizontal_container.layout()->set_margins({ 4, 4, 4, 4 }); - auto left_vertical_container = horizontal_container.add<Widget>(); - left_vertical_container->set_layout<VerticalBoxLayout>(); + auto& left_vertical_container = horizontal_container.add<Widget>(); + left_vertical_container.set_layout<VerticalBoxLayout>(); - auto right_vertical_container = horizontal_container.add<Widget>(); - right_vertical_container->set_layout<VerticalBoxLayout>(); + auto& right_vertical_container = horizontal_container.add<Widget>(); + right_vertical_container.set_layout<VerticalBoxLayout>(); enum RGBComponent { Red, @@ -65,34 +65,34 @@ void ColorPicker::build() Blue }; - m_preview_widget = right_vertical_container->add<Frame>(); + 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 = 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 = [&] { + right_vertical_container.layout()->add_spacer(); + 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 = [&] { done(Dialog::ExecCancel); }; - 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& 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 = [&] { done(Dialog::ExecOK); }; auto make_spinbox = [&](RGBComponent component, int initial_value) { - 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); - spinbox->set_max(255); - spinbox->set_value(initial_value); + 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); + spinbox.set_max(255); + spinbox.set_value(initial_value); - spinbox->on_change = [this, component](auto value) { + spinbox.on_change = [this, component](auto value) { if (component == Red) m_color.set_red(value); if (component == Green) @@ -105,7 +105,6 @@ void ColorPicker::build() m_preview_widget->set_palette(pal); m_preview_widget->update(); }; - return spinbox; }; make_spinbox(Red, m_color.red()); diff --git a/Libraries/LibGUI/FilePicker.cpp b/Libraries/LibGUI/FilePicker.cpp index 7d0abcdb84..3936f038fe 100644 --- a/Libraries/LibGUI/FilePicker.cpp +++ b/Libraries/LibGUI/FilePicker.cpp @@ -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 = horizontal_container.add<Widget>(); - vertical_container->set_layout<VerticalBoxLayout>(); - vertical_container->layout()->set_spacing(4); - - auto upper_container = vertical_container->add<Widget>(); - upper_container->set_layout<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 = upper_container->add<ToolBar>(); - toolbar->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill); - toolbar->set_preferred_size(165, 0); - toolbar->set_has_frame(false); - - 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 = vertical_container->add<MultiView>(); + auto& vertical_container = horizontal_container.add<Widget>(); + vertical_container.set_layout<VerticalBoxLayout>(); + vertical_container.layout()->set_spacing(4); + + auto& upper_container = vertical_container.add<Widget>(); + upper_container.set_layout<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 = upper_container.add<ToolBar>(); + toolbar.set_size_policy(SizePolicy::Fixed, SizePolicy::Fill); + toolbar.set_preferred_size(165, 0); + toolbar.set_has_frame(false); + + 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 = vertical_container.add<MultiView>(); m_view->set_model(SortingProxyModel::create(*m_model)); m_view->set_model_column(FileSystemModel::Column::Name); m_view->set_column_hidden(FileSystemModel::Column::Owner, true); @@ -115,8 +115,8 @@ FilePicker::FilePicker(Mode mode, const StringView& file_name, const StringView& m_view->set_column_hidden(FileSystemModel::Column::SymlinkTarget, true); m_model->set_root_path(path); - location_textbox->on_return_pressed = [&] { - m_model->set_root_path(location_textbox->text()); + location_textbox.on_return_pressed = [&] { + m_model->set_root_path(location_textbox.text()); clear_preview(); }; @@ -124,20 +124,20 @@ FilePicker::FilePicker(Mode mode, const StringView& file_name, const StringView& m_model->set_root_path(String::format("%s/..", m_model->root_path().characters())); clear_preview(); }); - toolbar->add_action(*open_parent_directory_action); + toolbar.add_action(*open_parent_directory_action); auto go_home_action = CommonActions::make_go_home_action([this](auto&) { m_model->set_root_path(get_current_user_home_path()); }); - toolbar->add_action(go_home_action); - toolbar->add_separator(); + toolbar.add_action(go_home_action); + 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 = add<InputBox>("Enter name:", "New directory"); - if (input_box->exec() == InputBox::ExecOK && !input_box->text_value().is_empty()) { + 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(), - input_box->text_value().characters())) + input_box.text_value().characters())) .string(); int rc = mkdir(new_dir_path.characters(), 0777); if (rc < 0) { @@ -148,33 +148,33 @@ FilePicker::FilePicker(Mode mode, const StringView& file_name, const StringView& } }); - toolbar->add_action(*mkdir_action); + toolbar.add_action(*mkdir_action); - toolbar->add_separator(); + toolbar.add_separator(); - toolbar->add_action(m_view->view_as_icons_action()); - toolbar->add_action(m_view->view_as_table_action()); + toolbar.add_action(m_view->view_as_icons_action()); + toolbar.add_action(m_view->view_as_table_action()); #ifdef MULTIVIEW_WITH_COLUMNSVIEW m_view->view_as_columns_action().set_enabled(false); - toolbar->add_action(m_view->view_as_columns_action()); + toolbar.add_action(m_view->view_as_columns_action()); #endif - auto lower_container = vertical_container->add<Widget>(); - lower_container->set_layout<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 = lower_container->add<Widget>(); - filename_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); - filename_container->set_preferred_size(0, 20); - filename_container->set_layout<HorizontalBoxLayout>(); - 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 = filename_container->add<TextBox>(); + auto& lower_container = vertical_container.add<Widget>(); + lower_container.set_layout<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 = lower_container.add<Widget>(); + filename_container.set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); + filename_container.set_preferred_size(0, 20); + filename_container.set_layout<HorizontalBoxLayout>(); + 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 = filename_container.add<TextBox>(); if (m_mode == Mode::Save) { m_filename_textbox->set_text(file_name); m_filename_textbox->set_focus(true); @@ -198,26 +198,26 @@ FilePicker::FilePicker(Mode mode, const StringView& file_name, const StringView& set_preview(path); }; - 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<HorizontalBoxLayout>(); - button_container->layout()->set_spacing(4); - button_container->layout()->add_spacer(); - - 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"); - cancel_button->on_click = [this] { + 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<HorizontalBoxLayout>(); + button_container.layout()->set_spacing(4); + button_container.layout()->add_spacer(); + + 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"); + cancel_button.on_click = [this] { done(ExecCancel); }; - 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)); - ok_button->on_click = [this] { + 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)); + ok_button.on_click = [this] { on_file_return(); }; @@ -235,23 +235,23 @@ FilePicker::FilePicker(Mode mode, const StringView& file_name, const StringView& } }; - 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_layout<VerticalBoxLayout>(); - preview_container->layout()->set_margins({ 8, 8, 8, 8 }); + 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_layout<VerticalBoxLayout>(); + preview_container.layout()->set_margins({ 8, 8, 8, 8 }); - m_preview_image_label = preview_container->add<Label>(); + 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 = preview_container->add<Label>(); + 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 = preview_container->add<Label>(); + 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()); } diff --git a/Libraries/LibGUI/InputBox.cpp b/Libraries/LibGUI/InputBox.cpp index aca0d182b8..aada52ddcb 100644 --- a/Libraries/LibGUI/InputBox.cpp +++ b/Libraries/LibGUI/InputBox.cpp @@ -62,24 +62,24 @@ void InputBox::build() widget.layout()->set_margins({ 8, 8, 8, 8 }); widget.layout()->set_spacing(8); - auto label = widget.add<Label>(m_prompt); - label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); - label->set_preferred_size(text_width, 16); + 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 = 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.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<VerticalBoxLayout>(); + 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<VerticalBoxLayout>(); - auto button_container_inner = button_container_outer->add<Widget>(); - button_container_inner->set_layout<HorizontalBoxLayout>(); - button_container_inner->layout()->set_spacing(8); + auto& button_container_inner = button_container_outer.add<Widget>(); + button_container_inner.set_layout<HorizontalBoxLayout>(); + button_container_inner.layout()->set_spacing(8); - m_cancel_button = button_container_inner->add<Button>(); + 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"); @@ -88,7 +88,7 @@ void InputBox::build() done(ExecCancel); }; - m_ok_button = button_container_inner->add<Button>(); + 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"); diff --git a/Libraries/LibGUI/MessageBox.cpp b/Libraries/LibGUI/MessageBox.cpp index bd8a0bb447..952ace264c 100644 --- a/Libraries/LibGUI/MessageBox.cpp +++ b/Libraries/LibGUI/MessageBox.cpp @@ -109,28 +109,28 @@ void MessageBox::build() message_container->layout()->set_margins({ 8, 0, 8, 0 }); message_container->layout()->set_spacing(8); - 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& 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 = message_container->add<Label>(m_text); - label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); - label->set_preferred_size(text_width, 16); + 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.add<Widget>(); - button_container->set_layout<HorizontalBoxLayout>(); - button_container->layout()->set_spacing(5); - button_container->layout()->set_margins({ 15, 0, 15, 0 }); + auto& button_container = widget.add<Widget>(); + button_container.set_layout<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_container->add<Button>(); - button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); - button->set_preferred_size(0, 20); - button->set_text(label); - button->on_click = [this, label, result] { + auto& button = button_container.add<Button>(); + button.set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); + button.set_preferred_size(0, 20); + button.set_text(label); + button.on_click = [this, label, result] { dbg() << "GUI::MessageBox: '" << label << "' button clicked"; done(result); }; diff --git a/Libraries/LibGUI/StatusBar.cpp b/Libraries/LibGUI/StatusBar.cpp index 1217d764bf..0e05aef4b6 100644 --- a/Libraries/LibGUI/StatusBar.cpp +++ b/Libraries/LibGUI/StatusBar.cpp @@ -57,11 +57,11 @@ StatusBar::~StatusBar() NonnullRefPtr<Label> StatusBar::create_label() { - auto label = add<Label>(); - label->set_frame_shadow(Gfx::FrameShadow::Sunken); - label->set_frame_shape(Gfx::FrameShape::Panel); - label->set_frame_thickness(1); - label->set_text_alignment(Gfx::TextAlignment::CenterLeft); + auto& label = add<Label>(); + label.set_frame_shadow(Gfx::FrameShadow::Sunken); + label.set_frame_shape(Gfx::FrameShape::Panel); + label.set_frame_thickness(1); + label.set_text_alignment(Gfx::TextAlignment::CenterLeft); return label; } diff --git a/Libraries/LibGUI/ToolBar.cpp b/Libraries/LibGUI/ToolBar.cpp index 922f944954..fb56811211 100644 --- a/Libraries/LibGUI/ToolBar.cpp +++ b/Libraries/LibGUI/ToolBar.cpp @@ -59,21 +59,21 @@ void ToolBar::add_action(Action& action) item->type = Item::Type::Action; item->action = action; - auto button = add<Button>(); + auto& button = add<Button>(); if (action.group() && action.group()->is_exclusive()) - button->set_exclusive(true); - button->set_action(*item->action); - button->set_tooltip(item->action->text()); + button.set_exclusive(true); + button.set_action(*item->action); + button.set_tooltip(item->action->text()); if (item->action->icon()) - button->set_icon(item->action->icon()); + button.set_icon(item->action->icon()); else - button->set_text(item->action->text()); + button.set_text(item->action->text()); - button->set_button_style(Gfx::ButtonStyle::CoolBar); - button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); - ASSERT(button->size_policy(Orientation::Horizontal) == SizePolicy::Fixed); - ASSERT(button->size_policy(Orientation::Vertical) == SizePolicy::Fixed); - button->set_preferred_size(m_button_size + 8, m_button_size + 8); + button.set_button_style(Gfx::ButtonStyle::CoolBar); + button.set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); + ASSERT(button.size_policy(Orientation::Horizontal) == SizePolicy::Fixed); + ASSERT(button.size_policy(Orientation::Vertical) == SizePolicy::Fixed); + button.set_preferred_size(m_button_size + 8, m_button_size + 8); m_items.append(move(item)); } diff --git a/Libraries/LibHTML/DOM/HTMLInputElement.cpp b/Libraries/LibHTML/DOM/HTMLInputElement.cpp index c22c694fde..67753e3aea 100644 --- a/Libraries/LibHTML/DOM/HTMLInputElement.cpp +++ b/Libraries/LibHTML/DOM/HTMLInputElement.cpp @@ -52,10 +52,10 @@ RefPtr<LayoutNode> HTMLInputElement::create_layout_node(const StyleProperties*) RefPtr<GUI::Widget> widget; if (type() == "submit") { - auto button = html_view.add<GUI::Button>(value()); + auto& button = html_view.add<GUI::Button>(value()); int text_width = Gfx::Font::default_font().width(value()); - button->set_relative_rect(0, 0, text_width + 20, 20); - button->on_click = [this] { + button.set_relative_rect(0, 0, text_width + 20, 20); + button.on_click = [this] { if (auto* form = first_ancestor_of_type<HTMLFormElement>()) { // FIXME: Remove this const_cast once we have a non-const first_ancestor_of_type. const_cast<HTMLFormElement*>(form)->submit(); @@ -63,14 +63,14 @@ RefPtr<LayoutNode> HTMLInputElement::create_layout_node(const StyleProperties*) }; widget = button; } else { - auto text_box = html_view.add<GUI::TextBox>(); - text_box->set_text(value()); - text_box->on_change = [this] { + auto& text_box = html_view.add<GUI::TextBox>(); + text_box.set_text(value()); + text_box.on_change = [this] { auto& widget = to<LayoutWidget>(layout_node())->widget(); const_cast<HTMLInputElement*>(this)->set_attribute("value", static_cast<const GUI::TextBox&>(widget).text()); }; int text_width = Gfx::Font::default_font().width(value()); - text_box->set_relative_rect(0, 0, text_width + 20, 20); + text_box.set_relative_rect(0, 0, text_width + 20, 20); widget = text_box; } |