mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +00:00
GButton: Convert most code to using ObjectPtr for GButton
This commit is contained in:
parent
55a6e4ac0b
commit
45cfd57f6e
Notes:
sideshowbarker
2024-07-19 12:01:11 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/45cfd57f6ed
20 changed files with 38 additions and 38 deletions
|
@ -44,7 +44,7 @@ int main(int argc, char** argv)
|
|||
version_label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
version_label->set_preferred_size(0, 11);
|
||||
|
||||
auto* quit_button = new GButton(widget);
|
||||
auto quit_button = GButton::construct(widget);
|
||||
quit_button->set_text("Okay");
|
||||
quit_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
||||
quit_button->set_preferred_size(100, 20);
|
||||
|
|
|
@ -39,13 +39,13 @@ void ColorDialog::build()
|
|||
m_preview_widget->set_background_color(m_color);
|
||||
m_preview_widget->set_fill_with_background_color(true);
|
||||
right_vertical_container->layout()->add_spacer();
|
||||
auto* cancel_button = new GButton("Cancel", right_vertical_container);
|
||||
auto cancel_button = GButton::construct("Cancel", right_vertical_container);
|
||||
cancel_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
cancel_button->set_preferred_size(0, 20);
|
||||
cancel_button->on_click = [&](auto&) {
|
||||
done(GDialog::ExecCancel);
|
||||
};
|
||||
auto* ok_button = new GButton("Okay", right_vertical_container);
|
||||
auto ok_button = GButton::construct("Okay", right_vertical_container);
|
||||
ok_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
ok_button->set_preferred_size(0, 20);
|
||||
ok_button->on_click = [&](auto&) {
|
||||
|
|
|
@ -43,7 +43,7 @@ int main(int argc, char** argv)
|
|||
|
||||
auto* sample_widget = new SampleWidget(widget);
|
||||
|
||||
auto* button = new GButton("Quit", widget);
|
||||
auto button = GButton::construct("Quit", widget);
|
||||
button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
button->set_preferred_size(0, 20);
|
||||
button->on_click = [&](auto&) {
|
||||
|
|
|
@ -79,12 +79,12 @@ TextEditorWidget::TextEditorWidget()
|
|||
}
|
||||
});
|
||||
|
||||
m_find_previous_button = new GButton("Previous", m_find_widget);
|
||||
m_find_previous_button = GButton::construct("Previous", m_find_widget);
|
||||
m_find_previous_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||
m_find_previous_button->set_preferred_size(64, 0);
|
||||
m_find_previous_button->set_action(*m_find_previous_action);
|
||||
|
||||
m_find_next_button = new GButton("Next", m_find_widget);
|
||||
m_find_next_button = GButton::construct("Next", m_find_widget);
|
||||
m_find_next_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||
m_find_next_button->set_preferred_size(64, 0);
|
||||
m_find_next_button->set_action(*m_find_next_action);
|
||||
|
|
|
@ -133,7 +133,7 @@ int main(int argc, char** argv)
|
|||
content_text->wrap_and_set_height();
|
||||
}
|
||||
|
||||
auto* menu_option = new GButton(menu);
|
||||
auto menu_option = GButton::construct(menu);
|
||||
menu_option->set_font(Font::default_font());
|
||||
menu_option->set_text(page.menu_name);
|
||||
menu_option->set_text_alignment(TextAlignment::CenterLeft);
|
||||
|
|
|
@ -23,7 +23,7 @@ int main(int argc, char** argv)
|
|||
auto label = GLabel::construct(main_widget);
|
||||
label->set_text("Hello\nWorld!");
|
||||
|
||||
auto* button = new GButton(main_widget);
|
||||
auto button = GButton::construct(main_widget);
|
||||
button->set_text("Good-bye");
|
||||
button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
button->set_preferred_size(0, 20);
|
||||
|
|
|
@ -38,9 +38,9 @@ int main(int argc, char** argv)
|
|||
auto radio2 = GRadioButton::construct("GRadioButton 2", main_widget);
|
||||
radio2->set_enabled(false);
|
||||
|
||||
auto* button1 = new GButton("GButton 1", main_widget);
|
||||
auto button1 = GButton::construct("GButton 1", main_widget);
|
||||
(void)button1;
|
||||
auto* button2 = new GButton("GButton 2", main_widget);
|
||||
auto button2 = GButton::construct("GButton 2", main_widget);
|
||||
button2->set_enabled(false);
|
||||
|
||||
auto progress1 = GProgressBar::construct(main_widget);
|
||||
|
|
|
@ -84,7 +84,7 @@ static ObjectPtr<GWidget> build_gwidget(VBWidgetType type, GWidget* parent)
|
|||
return label;
|
||||
}
|
||||
case VBWidgetType::GButton: {
|
||||
auto* button = new GButton(parent);
|
||||
auto button = GButton::construct(parent);
|
||||
button->set_text("button_1");
|
||||
return button;
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ ObjectPtr<GWindow> make_toolbox_window()
|
|||
widget->layout()->set_spacing(0);
|
||||
window->set_main_widget(widget);
|
||||
|
||||
auto* label_button = new GButton(widget);
|
||||
auto label_button = GButton::construct(widget);
|
||||
label_button->set_button_style(ButtonStyle::CoolBar);
|
||||
label_button->set_tooltip("GLabel");
|
||||
label_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/label.png"));
|
||||
|
@ -95,7 +95,7 @@ ObjectPtr<GWindow> make_toolbox_window()
|
|||
form->insert_widget(VBWidgetType::GLabel);
|
||||
};
|
||||
|
||||
auto* button_button = new GButton(widget);
|
||||
auto button_button = GButton::construct(widget);
|
||||
button_button->set_button_style(ButtonStyle::CoolBar);
|
||||
button_button->set_tooltip("GButton");
|
||||
button_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/button.png"));
|
||||
|
@ -103,7 +103,7 @@ ObjectPtr<GWindow> make_toolbox_window()
|
|||
if (auto* form = VBForm::current())
|
||||
form->insert_widget(VBWidgetType::GButton);
|
||||
};
|
||||
auto* spinbox_button = new GButton(widget);
|
||||
auto spinbox_button = GButton::construct(widget);
|
||||
spinbox_button->set_button_style(ButtonStyle::CoolBar);
|
||||
spinbox_button->set_tooltip("GSpinBox");
|
||||
spinbox_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/spinbox.png"));
|
||||
|
@ -111,7 +111,7 @@ ObjectPtr<GWindow> make_toolbox_window()
|
|||
if (auto* form = VBForm::current())
|
||||
form->insert_widget(VBWidgetType::GSpinBox);
|
||||
};
|
||||
auto* editor_button = new GButton(widget);
|
||||
auto editor_button = GButton::construct(widget);
|
||||
editor_button->set_button_style(ButtonStyle::CoolBar);
|
||||
editor_button->set_tooltip("GTextEditor");
|
||||
editor_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/textbox.png"));
|
||||
|
@ -119,7 +119,7 @@ ObjectPtr<GWindow> make_toolbox_window()
|
|||
if (auto* form = VBForm::current())
|
||||
form->insert_widget(VBWidgetType::GTextEditor);
|
||||
};
|
||||
auto* progress_bar_button = new GButton(widget);
|
||||
auto progress_bar_button = GButton::construct(widget);
|
||||
progress_bar_button->set_button_style(ButtonStyle::CoolBar);
|
||||
progress_bar_button->set_tooltip("GProgressBar");
|
||||
progress_bar_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/progressbar.png"));
|
||||
|
@ -127,7 +127,7 @@ ObjectPtr<GWindow> make_toolbox_window()
|
|||
if (auto* form = VBForm::current())
|
||||
form->insert_widget(VBWidgetType::GProgressBar);
|
||||
};
|
||||
auto* slider_button = new GButton(widget);
|
||||
auto slider_button = GButton::construct(widget);
|
||||
slider_button->set_button_style(ButtonStyle::CoolBar);
|
||||
slider_button->set_tooltip("GSlider");
|
||||
slider_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/slider.png"));
|
||||
|
@ -135,7 +135,7 @@ ObjectPtr<GWindow> make_toolbox_window()
|
|||
if (auto* form = VBForm::current())
|
||||
form->insert_widget(VBWidgetType::GSlider);
|
||||
};
|
||||
auto* checkbox_button = new GButton(widget);
|
||||
auto checkbox_button = GButton::construct(widget);
|
||||
checkbox_button->set_button_style(ButtonStyle::CoolBar);
|
||||
checkbox_button->set_tooltip("GCheckBox");
|
||||
checkbox_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/checkbox.png"));
|
||||
|
@ -143,7 +143,7 @@ ObjectPtr<GWindow> make_toolbox_window()
|
|||
if (auto* form = VBForm::current())
|
||||
form->insert_widget(VBWidgetType::GCheckBox);
|
||||
};
|
||||
auto* radiobutton_button = new GButton(widget);
|
||||
auto radiobutton_button = GButton::construct(widget);
|
||||
radiobutton_button->set_button_style(ButtonStyle::CoolBar);
|
||||
radiobutton_button->set_tooltip("GRadioButton");
|
||||
radiobutton_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/filled-radio-circle.png"));
|
||||
|
@ -151,7 +151,7 @@ ObjectPtr<GWindow> make_toolbox_window()
|
|||
if (auto* form = VBForm::current())
|
||||
form->insert_widget(VBWidgetType::GRadioButton);
|
||||
};
|
||||
auto* scrollbar_button = new GButton(widget);
|
||||
auto scrollbar_button = GButton::construct(widget);
|
||||
scrollbar_button->set_button_style(ButtonStyle::CoolBar);
|
||||
scrollbar_button->set_tooltip("GScrollBar");
|
||||
scrollbar_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/scrollbar.png"));
|
||||
|
@ -159,7 +159,7 @@ ObjectPtr<GWindow> make_toolbox_window()
|
|||
if (auto* form = VBForm::current())
|
||||
form->insert_widget(VBWidgetType::GScrollBar);
|
||||
};
|
||||
auto* groupbox_button = new GButton(widget);
|
||||
auto groupbox_button = GButton::construct(widget);
|
||||
groupbox_button->set_button_style(ButtonStyle::CoolBar);
|
||||
groupbox_button->set_tooltip("GGroupBox");
|
||||
groupbox_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/groupbox.png"));
|
||||
|
|
|
@ -32,7 +32,7 @@ int main(int argc, char** argv)
|
|||
auto flag_icon_label = GLabel::construct(container);
|
||||
flag_icon_label->set_icon(GraphicsBitmap::load_from_file("/res/icons/minesweeper/flag.png"));
|
||||
auto flag_label = GLabel::construct(container);
|
||||
auto* face_button = new GButton(container);
|
||||
auto face_button = GButton::construct(container);
|
||||
face_button->set_button_style(ButtonStyle::CoolBar);
|
||||
face_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||
face_button->set_preferred_size(36, 0);
|
||||
|
|
|
@ -51,7 +51,7 @@ GAboutDialog::GAboutDialog(const StringView& name, const GraphicsBitmap* icon, C
|
|||
button_container->set_preferred_size(0, 20);
|
||||
button_container->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||
button_container->layout()->add_spacer();
|
||||
auto* ok_button = new GButton("OK", button_container);
|
||||
auto ok_button = GButton::construct("OK", button_container);
|
||||
ok_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
||||
ok_button->set_preferred_size(80, 20);
|
||||
ok_button->on_click = [this](auto&) {
|
||||
|
|
|
@ -18,7 +18,7 @@ GComboBox::GComboBox(GWidget* parent)
|
|||
if (on_return_pressed)
|
||||
on_return_pressed();
|
||||
};
|
||||
m_open_button = new GButton(this);
|
||||
m_open_button = GButton::construct(this);
|
||||
m_open_button->set_focusable(false);
|
||||
m_open_button->set_text("\xc3\xb7");
|
||||
m_open_button->on_click = [this](auto&) {
|
||||
|
|
|
@ -37,7 +37,7 @@ protected:
|
|||
|
||||
private:
|
||||
ObjectPtr<GTextEditor> m_editor;
|
||||
GButton* m_open_button { nullptr };
|
||||
ObjectPtr<GButton> m_open_button;
|
||||
ObjectPtr<GWindow> m_list_window;
|
||||
ObjectPtr<GListView> m_list_view;
|
||||
bool m_only_allow_values_from_model { false };
|
||||
|
|
|
@ -162,7 +162,7 @@ GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringVie
|
|||
button_container->layout()->set_spacing(4);
|
||||
button_container->layout()->add_spacer();
|
||||
|
||||
auto* cancel_button = new GButton(button_container);
|
||||
auto cancel_button = GButton::construct(button_container);
|
||||
cancel_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||
cancel_button->set_preferred_size(80, 0);
|
||||
cancel_button->set_text("Cancel");
|
||||
|
@ -170,7 +170,7 @@ GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringVie
|
|||
done(ExecCancel);
|
||||
};
|
||||
|
||||
auto* ok_button = new GButton(button_container);
|
||||
auto ok_button = GButton::construct(button_container);
|
||||
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));
|
||||
|
|
|
@ -51,7 +51,7 @@ void GInputBox::build()
|
|||
button_container_inner->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||
button_container_inner->layout()->set_spacing(8);
|
||||
|
||||
m_cancel_button = new GButton(button_container_inner);
|
||||
m_cancel_button = GButton::construct(button_container_inner);
|
||||
m_cancel_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
m_cancel_button->set_preferred_size(0, 20);
|
||||
m_cancel_button->set_text("Cancel");
|
||||
|
@ -60,7 +60,7 @@ void GInputBox::build()
|
|||
done(ExecCancel);
|
||||
};
|
||||
|
||||
m_ok_button = new GButton(button_container_inner);
|
||||
m_ok_button = GButton::construct(button_container_inner);
|
||||
m_ok_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
m_ok_button->set_preferred_size(0, 20);
|
||||
m_ok_button->set_text("OK");
|
||||
|
|
|
@ -18,7 +18,7 @@ private:
|
|||
String m_prompt;
|
||||
String m_text_value;
|
||||
|
||||
GButton* m_ok_button { nullptr };
|
||||
GButton* m_cancel_button { nullptr };
|
||||
ObjectPtr<GButton> m_ok_button;
|
||||
ObjectPtr<GButton> m_cancel_button;
|
||||
ObjectPtr<GTextEditor> m_text_editor;
|
||||
};
|
||||
|
|
|
@ -86,7 +86,7 @@ void GMessageBox::build()
|
|||
button_container->layout()->set_margins({ 15, 0, 15, 0 });
|
||||
|
||||
if (should_include_ok_button()) {
|
||||
auto* ok_button = new GButton(button_container);
|
||||
auto ok_button = GButton::construct(button_container);
|
||||
ok_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
ok_button->set_preferred_size(0, 20);
|
||||
ok_button->set_text("OK");
|
||||
|
@ -97,7 +97,7 @@ void GMessageBox::build()
|
|||
}
|
||||
|
||||
if (should_include_cancel_button()) {
|
||||
auto* cancel_button = new GButton(button_container);
|
||||
auto cancel_button = GButton::construct(button_container);
|
||||
cancel_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
cancel_button->set_preferred_size(0, 20);
|
||||
cancel_button->set_text("Cancel");
|
||||
|
|
|
@ -15,12 +15,12 @@ GSpinBox::GSpinBox(GWidget* parent)
|
|||
else
|
||||
m_editor->set_text(String::number(m_value));
|
||||
};
|
||||
m_increment_button = new GButton(this);
|
||||
m_increment_button = GButton::construct(this);
|
||||
m_increment_button->set_focusable(false);
|
||||
m_increment_button->set_text("\xc3\xb6");
|
||||
m_increment_button->on_click = [this](GButton&) { set_value(m_value + 1); };
|
||||
m_increment_button->set_auto_repeat_interval(150);
|
||||
m_decrement_button = new GButton(this);
|
||||
m_decrement_button = GButton::construct(this);
|
||||
m_decrement_button->set_focusable(false);
|
||||
m_decrement_button->set_text("\xc3\xb7");
|
||||
m_decrement_button->on_click = [this](GButton&) { set_value(m_value - 1); };
|
||||
|
|
|
@ -28,8 +28,8 @@ protected:
|
|||
|
||||
private:
|
||||
ObjectPtr<GTextEditor> m_editor;
|
||||
GButton* m_increment_button { nullptr };
|
||||
GButton* m_decrement_button { nullptr };
|
||||
ObjectPtr<GButton> m_increment_button;
|
||||
ObjectPtr<GButton> m_decrement_button;
|
||||
|
||||
int m_min { 0 };
|
||||
int m_max { 100 };
|
||||
|
|
|
@ -24,7 +24,7 @@ void GToolBar::add_action(GAction& action)
|
|||
item->type = Item::Action;
|
||||
item->action = action;
|
||||
|
||||
auto* button = new GButton(this);
|
||||
auto button = GButton::construct(this);
|
||||
button->set_action(*item->action);
|
||||
button->set_tooltip(item->action->text());
|
||||
if (item->action->icon())
|
||||
|
|
Loading…
Add table
Reference in a new issue