Skip to content

Commit 3d20da9

Browse files
committed
Userspace: Use Core::Object::add() when building interfaces
1 parent 7ec7587 commit 3d20da9

File tree

87 files changed

+403
-438
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+403
-438
lines changed

Applications/About/main.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ int main(int argc, char** argv)
6969
widget->layout()->set_margins({ 0, 8, 0, 8 });
7070
widget->layout()->set_spacing(8);
7171

72-
auto icon_label = GUI::Label::construct(widget);
72+
auto icon_label = widget->add<GUI::Label>();
7373
icon_label->set_icon(Gfx::Bitmap::load_from_file("/res/icons/serenity.png"));
7474
icon_label->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
7575
icon_label->set_preferred_size(icon_label->icon()->size());
7676

77-
auto label = GUI::Label::construct(widget);
77+
auto label = widget->add<GUI::Label>();
7878
label->set_font(Gfx::Font::default_bold_font());
7979
label->set_text("SerenityOS");
8080
label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
@@ -84,22 +84,22 @@ int main(int argc, char** argv)
8484
int rc = uname(&uts);
8585
ASSERT(rc == 0);
8686

87-
auto version_label = GUI::Label::construct(widget);
87+
auto version_label = widget->add<GUI::Label>();
8888
version_label->set_text(String::format("Version %s", uts.release));
8989
version_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
9090
version_label->set_preferred_size(0, 11);
9191

92-
auto git_info_label = GUI::Label::construct(widget);
92+
auto git_info_label = widget->add<GUI::Label>();
9393
git_info_label->set_text(String::format("Built on %s@%s", GIT_BRANCH, GIT_COMMIT));
9494
git_info_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
9595
git_info_label->set_preferred_size(0, 11);
9696

97-
auto git_changes_label = GUI::Label::construct(widget);
97+
auto git_changes_label = widget->add<GUI::Label>();
9898
git_changes_label->set_text(String::format("Changes: %s", GIT_CHANGES));
9999
git_changes_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
100100
git_changes_label->set_preferred_size(0, 11);
101101

102-
auto quit_button = GUI::Button::construct(widget);
102+
auto quit_button = widget->add<GUI::Button>();
103103
quit_button->set_text("Okay");
104104
quit_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
105105
quit_button->set_preferred_size(100, 20);

Applications/Browser/InspectorWidget.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ InspectorWidget::InspectorWidget(GUI::Widget* parent)
3939
: GUI::Widget(parent)
4040
{
4141
set_layout(make<GUI::VerticalBoxLayout>());
42-
auto splitter = GUI::VerticalSplitter::construct(this);
43-
m_dom_tree_view = GUI::TreeView::construct(splitter);
42+
auto splitter = add<GUI::VerticalSplitter>();
43+
m_dom_tree_view = splitter->add<GUI::TreeView>();
4444
m_dom_tree_view->on_selection = [this](auto& index) {
4545
auto* node = static_cast<Node*>(index.internal_data());
4646
node->document().set_inspected_node(node);
@@ -55,13 +55,13 @@ InspectorWidget::InspectorWidget(GUI::Widget* parent)
5555
m_computed_style_table_view->set_model(nullptr);
5656
}
5757
};
58-
m_style_table_view = GUI::TableView::construct(nullptr);
58+
m_style_table_view = GUI::TableView::construct();
5959
m_style_table_view->set_size_columns_to_fit_content(true);
6060

61-
m_computed_style_table_view = GUI::TableView::construct(nullptr);
61+
m_computed_style_table_view = GUI::TableView::construct();
6262
m_computed_style_table_view->set_size_columns_to_fit_content(true);
6363

64-
auto tabwidget = GUI::TabWidget::construct(splitter);
64+
auto tabwidget = splitter->add<GUI::TabWidget>();
6565
tabwidget->add_widget("Styles", m_style_table_view);
6666
tabwidget->add_widget("Computed", m_computed_style_table_view);
6767
}

Applications/Browser/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ int main(int argc, char** argv)
8080
widget->set_layout(make<GUI::VerticalBoxLayout>());
8181
widget->layout()->set_spacing(0);
8282

83-
auto toolbar = GUI::ToolBar::construct(widget);
84-
auto html_widget = HtmlView::construct(widget);
83+
auto toolbar = widget->add<GUI::ToolBar>();
84+
auto html_widget = widget->add<HtmlView>();
8585

8686
History<URL> history;
8787

@@ -121,7 +121,7 @@ int main(int argc, char** argv)
121121
html_widget->reload();
122122
}));
123123

124-
auto location_box = GUI::TextBox::construct(toolbar);
124+
auto location_box = toolbar->add<GUI::TextBox>();
125125

126126
location_box->on_return_pressed = [&] {
127127
html_widget->load(location_box->text());
@@ -151,7 +151,7 @@ int main(int argc, char** argv)
151151
location_box->set_focus(true);
152152
});
153153

154-
auto statusbar = GUI::StatusBar::construct(widget);
154+
auto statusbar = widget->add<GUI::StatusBar>();
155155

156156
html_widget->on_link_hover = [&](auto& href) {
157157
statusbar->set_text(href);

Applications/Calculator/CalculatorWidget.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,15 @@
3030
#include <LibGUI/Label.h>
3131
#include <LibGUI/TextBox.h>
3232

33-
CalculatorWidget::CalculatorWidget(GUI::Widget* parent)
34-
: GUI::Widget(parent)
33+
CalculatorWidget::CalculatorWidget()
3534
{
3635
set_fill_with_background_color(true);
3736

38-
m_entry = GUI::TextBox::construct(this);
37+
m_entry = add<GUI::TextBox>();
3938
m_entry->set_relative_rect(5, 5, 244, 26);
4039
m_entry->set_text_alignment(Gfx::TextAlignment::CenterRight);
4140

42-
m_label = GUI::Label::construct(this);
41+
m_label = add<GUI::Label>();
4342
m_label->set_relative_rect(12, 42, 27, 27);
4443
m_label->set_foreground_color(Color::NamedColor::Red);
4544
m_label->set_frame_shadow(Gfx::FrameShadow::Sunken);
@@ -49,7 +48,7 @@ CalculatorWidget::CalculatorWidget(GUI::Widget* parent)
4948
update_display();
5049

5150
for (int i = 0; i < 10; i++) {
52-
m_digit_button[i] = GUI::Button::construct(this);
51+
m_digit_button[i] = add<GUI::Button>();
5352
auto& button = *m_digit_button[i];
5453
int p = i ? i + 2 : 0;
5554
int x = 55 + (p % 3) * 39;
@@ -59,31 +58,31 @@ CalculatorWidget::CalculatorWidget(GUI::Widget* parent)
5958
add_button(button, i);
6059
}
6160

62-
m_mem_add_button = GUI::Button::construct(this);
61+
m_mem_add_button = add<GUI::Button>();
6362
m_mem_add_button->move_to(9, 177);
6463
m_mem_add_button->set_foreground_color(Color::NamedColor::Red);
6564
m_mem_add_button->set_text("M+");
6665
add_button(*m_mem_add_button, Calculator::Operation::MemAdd);
6766

68-
m_mem_save_button = GUI::Button::construct(this);
67+
m_mem_save_button = add<GUI::Button>();
6968
m_mem_save_button->move_to(9, 144);
7069
m_mem_save_button->set_foreground_color(Color::NamedColor::Red);
7170
m_mem_save_button->set_text("MS");
7271
add_button(*m_mem_save_button, Calculator::Operation::MemSave);
7372

74-
m_mem_recall_button = GUI::Button::construct(this);
73+
m_mem_recall_button = add<GUI::Button>();
7574
m_mem_recall_button->move_to(9, 111);
7675
m_mem_recall_button->set_foreground_color(Color::NamedColor::Red);
7776
m_mem_recall_button->set_text("MR");
7877
add_button(*m_mem_recall_button, Calculator::Operation::MemRecall);
7978

80-
m_mem_clear_button = GUI::Button::construct(this);
79+
m_mem_clear_button = add<GUI::Button>();
8180
m_mem_clear_button->move_to(9, 78);
8281
m_mem_clear_button->set_foreground_color(Color::NamedColor::Red);
8382
m_mem_clear_button->set_text("MC");
8483
add_button(*m_mem_clear_button, Calculator::Operation::MemClear);
8584

86-
m_clear_button = GUI::Button::construct(this);
85+
m_clear_button = add<GUI::Button>();
8786
m_clear_button->set_foreground_color(Color::NamedColor::Red);
8887
m_clear_button->set_text("C");
8988
m_clear_button->on_click = [this](GUI::Button&) {
@@ -94,7 +93,7 @@ CalculatorWidget::CalculatorWidget(GUI::Widget* parent)
9493
add_button(*m_clear_button);
9594
m_clear_button->set_relative_rect(187, 40, 60, 28);
9695

97-
m_clear_error_button = GUI::Button::construct(this);
96+
m_clear_error_button = add<GUI::Button>();
9897
m_clear_error_button->set_foreground_color(Color::NamedColor::Red);
9998
m_clear_error_button->set_text("CE");
10099
m_clear_error_button->on_click = [this](GUI::Button&) {
@@ -104,7 +103,7 @@ CalculatorWidget::CalculatorWidget(GUI::Widget* parent)
104103
add_button(*m_clear_error_button);
105104
m_clear_error_button->set_relative_rect(124, 40, 59, 28);
106105

107-
m_backspace_button = GUI::Button::construct(this);
106+
m_backspace_button = add<GUI::Button>();
108107
m_backspace_button->set_foreground_color(Color::NamedColor::Red);
109108
m_backspace_button->set_text("Backspace");
110109
m_backspace_button->on_click = [this](GUI::Button&) {
@@ -114,7 +113,7 @@ CalculatorWidget::CalculatorWidget(GUI::Widget* parent)
114113
add_button(*m_backspace_button);
115114
m_backspace_button->set_relative_rect(55, 40, 65, 28);
116115

117-
m_decimal_point_button = GUI::Button::construct(this);
116+
m_decimal_point_button = add<GUI::Button>();
118117
m_decimal_point_button->move_to(133, 177);
119118
m_decimal_point_button->set_foreground_color(Color::NamedColor::Blue);
120119
m_decimal_point_button->set_text(".");
@@ -124,55 +123,55 @@ CalculatorWidget::CalculatorWidget(GUI::Widget* parent)
124123
};
125124
add_button(*m_decimal_point_button);
126125

127-
m_sign_button = GUI::Button::construct(this);
126+
m_sign_button = add<GUI::Button>();
128127
m_sign_button->move_to(94, 177);
129128
m_sign_button->set_foreground_color(Color::NamedColor::Blue);
130129
m_sign_button->set_text("+/-");
131130
add_button(*m_sign_button, Calculator::Operation::ToggleSign);
132131

133-
m_add_button = GUI::Button::construct(this);
132+
m_add_button = add<GUI::Button>();
134133
m_add_button->move_to(172, 177);
135134
m_add_button->set_foreground_color(Color::NamedColor::Red);
136135
m_add_button->set_text("+");
137136
add_button(*m_add_button, Calculator::Operation::Add);
138137

139-
m_subtract_button = GUI::Button::construct(this);
138+
m_subtract_button = add<GUI::Button>();
140139
m_subtract_button->move_to(172, 144);
141140
m_subtract_button->set_foreground_color(Color::NamedColor::Red);
142141
m_subtract_button->set_text("-");
143142
add_button(*m_subtract_button, Calculator::Operation::Subtract);
144143

145-
m_multiply_button = GUI::Button::construct(this);
144+
m_multiply_button = add<GUI::Button>();
146145
m_multiply_button->move_to(172, 111);
147146
m_multiply_button->set_foreground_color(Color::NamedColor::Red);
148147
m_multiply_button->set_text("*");
149148
add_button(*m_multiply_button, Calculator::Operation::Multiply);
150149

151-
m_divide_button = GUI::Button::construct(this);
150+
m_divide_button = add<GUI::Button>();
152151
m_divide_button->move_to(172, 78);
153152
m_divide_button->set_foreground_color(Color::NamedColor::Red);
154153
m_divide_button->set_text("/");
155154
add_button(*m_divide_button, Calculator::Operation::Divide);
156155

157-
m_sqrt_button = GUI::Button::construct(this);
156+
m_sqrt_button = add<GUI::Button>();
158157
m_sqrt_button->move_to(211, 78);
159158
m_sqrt_button->set_foreground_color(Color::NamedColor::Blue);
160159
m_sqrt_button->set_text("sqrt");
161160
add_button(*m_sqrt_button, Calculator::Operation::Sqrt);
162161

163-
m_inverse_button = GUI::Button::construct(this);
162+
m_inverse_button = add<GUI::Button>();
164163
m_inverse_button->move_to(211, 144);
165164
m_inverse_button->set_foreground_color(Color::NamedColor::Blue);
166165
m_inverse_button->set_text("1/x");
167166
add_button(*m_inverse_button, Calculator::Operation::Inverse);
168167

169-
m_percent_button = GUI::Button::construct(this);
168+
m_percent_button = add<GUI::Button>();
170169
m_percent_button->move_to(211, 111);
171170
m_percent_button->set_foreground_color(Color::NamedColor::Blue);
172171
m_percent_button->set_text("%");
173172
add_button(*m_percent_button, Calculator::Operation::Percent);
174173

175-
m_equals_button = GUI::Button::construct(this);
174+
m_equals_button = add<GUI::Button>();
176175
m_equals_button->move_to(211, 177);
177176
m_equals_button->set_foreground_color(Color::NamedColor::Red);
178177
m_equals_button->set_text("=");

Applications/Calculator/CalculatorWidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class CalculatorWidget final : public GUI::Widget {
3737
virtual ~CalculatorWidget() override;
3838

3939
private:
40-
explicit CalculatorWidget(GUI::Widget*);
40+
CalculatorWidget();
4141
void add_button(GUI::Button&, Calculator::Operation);
4242
void add_button(GUI::Button&, int);
4343
void add_button(GUI::Button&);

Applications/Calculator/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ int main(int argc, char** argv)
6060
window->set_resizable(false);
6161
window->set_rect({ 300, 200, 254, 213 });
6262

63-
auto calc_widget = CalculatorWidget::construct(nullptr);
63+
auto calc_widget = CalculatorWidget::construct();
6464
window->set_main_widget(calc_widget);
6565

6666
window->show();

Applications/ChanViewer/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@ int main(int argc, char** argv)
6262
widget->set_fill_with_background_color(true);
6363
widget->set_layout(make<GUI::VerticalBoxLayout>());
6464

65-
auto board_combo = GUI::ComboBox::construct(widget);
65+
auto board_combo = widget->add<GUI::ComboBox>();
6666
board_combo->set_only_allow_values_from_model(true);
6767
board_combo->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
6868
board_combo->set_preferred_size(0, 20);
6969
board_combo->set_model(BoardListModel::create());
7070

71-
auto catalog_view = GUI::TableView::construct(widget);
71+
auto catalog_view = widget->add<GUI::TableView>();
7272
catalog_view->set_model(ThreadCatalogModel::create());
7373
auto& catalog_model = *static_cast<ThreadCatalogModel*>(catalog_view->model());
7474

75-
auto statusbar = GUI::StatusBar::construct(widget);
75+
auto statusbar = widget->add<GUI::StatusBar>();
7676

7777
board_combo->on_change = [&] (auto&, const GUI::ModelIndex& index) {
7878
auto selected_board = board_combo->model()->data(index, GUI::Model::Role::Custom);

Applications/DisplayProperties/DisplayProperties.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,19 @@ void DisplayPropertiesWidget::create_wallpaper_list()
122122

123123
void DisplayPropertiesWidget::create_frame()
124124
{
125-
auto tab_widget = GUI::TabWidget::construct(m_root_widget);
125+
auto tab_widget = m_root_widget->add<GUI::TabWidget>();
126126

127127
// First, let's create the "Background" tab
128-
auto background_splitter = GUI::VerticalSplitter::construct(nullptr);
128+
auto background_splitter = GUI::VerticalSplitter::construct();
129129
tab_widget->add_widget("Wallpaper", background_splitter);
130130

131-
auto background_content = GUI::Widget::construct(background_splitter.ptr());
131+
auto background_content = background_splitter->add<GUI::Widget>();
132132
background_content->set_layout(make<GUI::VerticalBoxLayout>());
133133
background_content->layout()->set_margins({ 4, 4, 4, 4 });
134134

135-
m_wallpaper_preview = GUI::Label::construct(background_splitter);
135+
m_wallpaper_preview = background_splitter->add<GUI::Label>();
136136

137-
auto wallpaper_list = GUI::ListView::construct(background_content);
137+
auto wallpaper_list = background_content->add<GUI::ListView>();
138138
wallpaper_list->set_background_color(Color::White);
139139
wallpaper_list->set_model(*ItemListModel<AK::String>::create(m_wallpapers));
140140

@@ -155,14 +155,14 @@ void DisplayPropertiesWidget::create_frame()
155155
};
156156

157157
// Let's add the settings tab
158-
auto settings_splitter = GUI::VerticalSplitter::construct(nullptr);
158+
auto settings_splitter = GUI::VerticalSplitter::construct();
159159
tab_widget->add_widget("Settings", settings_splitter);
160160

161-
auto settings_content = GUI::Widget::construct(settings_splitter.ptr());
161+
auto settings_content = settings_splitter->add<GUI::Widget>();
162162
settings_content->set_layout(make<GUI::VerticalBoxLayout>());
163163
settings_content->layout()->set_margins({ 4, 4, 4, 4 });
164164

165-
auto resolution_list = GUI::ListView::construct(settings_content);
165+
auto resolution_list = settings_content->add<GUI::ListView>();
166166
resolution_list->set_background_color(Color::White);
167167
resolution_list->set_model(*ItemListModel<Gfx::Size>::create(m_resolutions));
168168

@@ -180,13 +180,13 @@ void DisplayPropertiesWidget::create_frame()
180180
settings_content->layout()->add_spacer();
181181

182182
// Add the apply and cancel buttons
183-
auto bottom_widget = GUI::Widget::construct(m_root_widget.ptr());
183+
auto bottom_widget = m_root_widget->add<GUI::Widget>();
184184
bottom_widget->set_layout(make<GUI::HorizontalBoxLayout>());
185185
bottom_widget->layout()->add_spacer();
186186
bottom_widget->set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed);
187187
bottom_widget->set_preferred_size(1, 22);
188188

189-
auto apply_button = GUI::Button::construct(bottom_widget);
189+
auto apply_button = bottom_widget->add<GUI::Button>();
190190
apply_button->set_text("Apply");
191191
apply_button->set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed);
192192
apply_button->set_size_policy(Orientation::Horizontal, GUI::SizePolicy::Fixed);
@@ -195,7 +195,7 @@ void DisplayPropertiesWidget::create_frame()
195195
send_settings_to_window_server(tab_widget->active_tab_index());
196196
};
197197

198-
auto ok_button = GUI::Button::construct(bottom_widget);
198+
auto ok_button = bottom_widget->add<GUI::Button>();
199199
ok_button->set_text("OK");
200200
ok_button->set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed);
201201
ok_button->set_size_policy(Orientation::Horizontal, GUI::SizePolicy::Fixed);
@@ -205,7 +205,7 @@ void DisplayPropertiesWidget::create_frame()
205205
GUI::Application::the().quit();
206206
};
207207

208-
auto cancel_button = GUI::Button::construct(bottom_widget);
208+
auto cancel_button = bottom_widget->add<GUI::Button>();
209209
cancel_button->set_text("Cancel");
210210
cancel_button->set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed);
211211
cancel_button->set_size_policy(Orientation::Horizontal, GUI::SizePolicy::Fixed);

Applications/FileManager/DirectoryView.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,17 @@ void DirectoryView::handle_activation(const GUI::ModelIndex& index)
118118
}
119119
};
120120

121-
DirectoryView::DirectoryView(GUI::Widget* parent)
122-
: GUI::StackWidget(parent)
123-
, m_model(GUI::FileSystemModel::create())
121+
DirectoryView::DirectoryView()
122+
: m_model(GUI::FileSystemModel::create())
124123
{
125124
set_active_widget(nullptr);
126-
m_item_view = GUI::ItemView::construct(this);
125+
m_item_view = add<GUI::ItemView>();
127126
m_item_view->set_model(model());
128127

129-
m_columns_view = GUI::ColumnsView::construct(this);
128+
m_columns_view = add<GUI::ColumnsView>();
130129
m_columns_view->set_model(model());
131130

132-
m_table_view = GUI::TableView::construct(this);
131+
m_table_view = add<GUI::TableView>();
133132
m_table_view->set_model(GUI::SortingProxyModel::create(m_model));
134133

135134
m_table_view->model()->set_key_column_and_sort_order(GUI::FileSystemModel::Column::Name, GUI::SortOrder::Ascending);

0 commit comments

Comments
 (0)