Userspace: Use Core::Object::add() when building interfaces

This commit is contained in:
Andreas Kling 2020-02-23 10:57:42 +01:00
parent 7ec758773c
commit 3d20da9ee4
Notes: sideshowbarker 2024-07-19 09:08:47 +09:00
87 changed files with 403 additions and 438 deletions

View file

@ -69,12 +69,12 @@ int main(int argc, char** argv)
widget->layout()->set_margins({ 0, 8, 0, 8 }); widget->layout()->set_margins({ 0, 8, 0, 8 });
widget->layout()->set_spacing(8); widget->layout()->set_spacing(8);
auto icon_label = GUI::Label::construct(widget); auto icon_label = widget->add<GUI::Label>();
icon_label->set_icon(Gfx::Bitmap::load_from_file("/res/icons/serenity.png")); icon_label->set_icon(Gfx::Bitmap::load_from_file("/res/icons/serenity.png"));
icon_label->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); icon_label->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
icon_label->set_preferred_size(icon_label->icon()->size()); icon_label->set_preferred_size(icon_label->icon()->size());
auto label = GUI::Label::construct(widget); auto label = widget->add<GUI::Label>();
label->set_font(Gfx::Font::default_bold_font()); label->set_font(Gfx::Font::default_bold_font());
label->set_text("SerenityOS"); label->set_text("SerenityOS");
label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
@ -84,22 +84,22 @@ int main(int argc, char** argv)
int rc = uname(&uts); int rc = uname(&uts);
ASSERT(rc == 0); ASSERT(rc == 0);
auto version_label = GUI::Label::construct(widget); auto version_label = widget->add<GUI::Label>();
version_label->set_text(String::format("Version %s", uts.release)); version_label->set_text(String::format("Version %s", uts.release));
version_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); version_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
version_label->set_preferred_size(0, 11); version_label->set_preferred_size(0, 11);
auto git_info_label = GUI::Label::construct(widget); auto git_info_label = widget->add<GUI::Label>();
git_info_label->set_text(String::format("Built on %s@%s", GIT_BRANCH, GIT_COMMIT)); git_info_label->set_text(String::format("Built on %s@%s", GIT_BRANCH, GIT_COMMIT));
git_info_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); git_info_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
git_info_label->set_preferred_size(0, 11); git_info_label->set_preferred_size(0, 11);
auto git_changes_label = GUI::Label::construct(widget); auto git_changes_label = widget->add<GUI::Label>();
git_changes_label->set_text(String::format("Changes: %s", GIT_CHANGES)); git_changes_label->set_text(String::format("Changes: %s", GIT_CHANGES));
git_changes_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); git_changes_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
git_changes_label->set_preferred_size(0, 11); git_changes_label->set_preferred_size(0, 11);
auto quit_button = GUI::Button::construct(widget); auto quit_button = widget->add<GUI::Button>();
quit_button->set_text("Okay"); quit_button->set_text("Okay");
quit_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); quit_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
quit_button->set_preferred_size(100, 20); quit_button->set_preferred_size(100, 20);

View file

@ -39,8 +39,8 @@ InspectorWidget::InspectorWidget(GUI::Widget* parent)
: GUI::Widget(parent) : GUI::Widget(parent)
{ {
set_layout(make<GUI::VerticalBoxLayout>()); set_layout(make<GUI::VerticalBoxLayout>());
auto splitter = GUI::VerticalSplitter::construct(this); auto splitter = add<GUI::VerticalSplitter>();
m_dom_tree_view = GUI::TreeView::construct(splitter); m_dom_tree_view = splitter->add<GUI::TreeView>();
m_dom_tree_view->on_selection = [this](auto& index) { m_dom_tree_view->on_selection = [this](auto& index) {
auto* node = static_cast<Node*>(index.internal_data()); auto* node = static_cast<Node*>(index.internal_data());
node->document().set_inspected_node(node); node->document().set_inspected_node(node);
@ -55,13 +55,13 @@ InspectorWidget::InspectorWidget(GUI::Widget* parent)
m_computed_style_table_view->set_model(nullptr); m_computed_style_table_view->set_model(nullptr);
} }
}; };
m_style_table_view = GUI::TableView::construct(nullptr); m_style_table_view = GUI::TableView::construct();
m_style_table_view->set_size_columns_to_fit_content(true); m_style_table_view->set_size_columns_to_fit_content(true);
m_computed_style_table_view = GUI::TableView::construct(nullptr); m_computed_style_table_view = GUI::TableView::construct();
m_computed_style_table_view->set_size_columns_to_fit_content(true); m_computed_style_table_view->set_size_columns_to_fit_content(true);
auto tabwidget = GUI::TabWidget::construct(splitter); auto tabwidget = splitter->add<GUI::TabWidget>();
tabwidget->add_widget("Styles", m_style_table_view); tabwidget->add_widget("Styles", m_style_table_view);
tabwidget->add_widget("Computed", m_computed_style_table_view); tabwidget->add_widget("Computed", m_computed_style_table_view);
} }

View file

@ -80,8 +80,8 @@ int main(int argc, char** argv)
widget->set_layout(make<GUI::VerticalBoxLayout>()); widget->set_layout(make<GUI::VerticalBoxLayout>());
widget->layout()->set_spacing(0); widget->layout()->set_spacing(0);
auto toolbar = GUI::ToolBar::construct(widget); auto toolbar = widget->add<GUI::ToolBar>();
auto html_widget = HtmlView::construct(widget); auto html_widget = widget->add<HtmlView>();
History<URL> history; History<URL> history;
@ -121,7 +121,7 @@ int main(int argc, char** argv)
html_widget->reload(); html_widget->reload();
})); }));
auto location_box = GUI::TextBox::construct(toolbar); auto location_box = toolbar->add<GUI::TextBox>();
location_box->on_return_pressed = [&] { location_box->on_return_pressed = [&] {
html_widget->load(location_box->text()); html_widget->load(location_box->text());
@ -151,7 +151,7 @@ int main(int argc, char** argv)
location_box->set_focus(true); location_box->set_focus(true);
}); });
auto statusbar = GUI::StatusBar::construct(widget); auto statusbar = widget->add<GUI::StatusBar>();
html_widget->on_link_hover = [&](auto& href) { html_widget->on_link_hover = [&](auto& href) {
statusbar->set_text(href); statusbar->set_text(href);

View file

@ -30,16 +30,15 @@
#include <LibGUI/Label.h> #include <LibGUI/Label.h>
#include <LibGUI/TextBox.h> #include <LibGUI/TextBox.h>
CalculatorWidget::CalculatorWidget(GUI::Widget* parent) CalculatorWidget::CalculatorWidget()
: GUI::Widget(parent)
{ {
set_fill_with_background_color(true); set_fill_with_background_color(true);
m_entry = GUI::TextBox::construct(this); m_entry = add<GUI::TextBox>();
m_entry->set_relative_rect(5, 5, 244, 26); m_entry->set_relative_rect(5, 5, 244, 26);
m_entry->set_text_alignment(Gfx::TextAlignment::CenterRight); m_entry->set_text_alignment(Gfx::TextAlignment::CenterRight);
m_label = GUI::Label::construct(this); m_label = add<GUI::Label>();
m_label->set_relative_rect(12, 42, 27, 27); m_label->set_relative_rect(12, 42, 27, 27);
m_label->set_foreground_color(Color::NamedColor::Red); m_label->set_foreground_color(Color::NamedColor::Red);
m_label->set_frame_shadow(Gfx::FrameShadow::Sunken); m_label->set_frame_shadow(Gfx::FrameShadow::Sunken);
@ -49,7 +48,7 @@ CalculatorWidget::CalculatorWidget(GUI::Widget* parent)
update_display(); update_display();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
m_digit_button[i] = GUI::Button::construct(this); m_digit_button[i] = add<GUI::Button>();
auto& button = *m_digit_button[i]; auto& button = *m_digit_button[i];
int p = i ? i + 2 : 0; int p = i ? i + 2 : 0;
int x = 55 + (p % 3) * 39; int x = 55 + (p % 3) * 39;
@ -59,31 +58,31 @@ CalculatorWidget::CalculatorWidget(GUI::Widget* parent)
add_button(button, i); add_button(button, i);
} }
m_mem_add_button = GUI::Button::construct(this); m_mem_add_button = add<GUI::Button>();
m_mem_add_button->move_to(9, 177); m_mem_add_button->move_to(9, 177);
m_mem_add_button->set_foreground_color(Color::NamedColor::Red); m_mem_add_button->set_foreground_color(Color::NamedColor::Red);
m_mem_add_button->set_text("M+"); m_mem_add_button->set_text("M+");
add_button(*m_mem_add_button, Calculator::Operation::MemAdd); add_button(*m_mem_add_button, Calculator::Operation::MemAdd);
m_mem_save_button = GUI::Button::construct(this); m_mem_save_button = add<GUI::Button>();
m_mem_save_button->move_to(9, 144); m_mem_save_button->move_to(9, 144);
m_mem_save_button->set_foreground_color(Color::NamedColor::Red); m_mem_save_button->set_foreground_color(Color::NamedColor::Red);
m_mem_save_button->set_text("MS"); m_mem_save_button->set_text("MS");
add_button(*m_mem_save_button, Calculator::Operation::MemSave); add_button(*m_mem_save_button, Calculator::Operation::MemSave);
m_mem_recall_button = GUI::Button::construct(this); m_mem_recall_button = add<GUI::Button>();
m_mem_recall_button->move_to(9, 111); m_mem_recall_button->move_to(9, 111);
m_mem_recall_button->set_foreground_color(Color::NamedColor::Red); m_mem_recall_button->set_foreground_color(Color::NamedColor::Red);
m_mem_recall_button->set_text("MR"); m_mem_recall_button->set_text("MR");
add_button(*m_mem_recall_button, Calculator::Operation::MemRecall); add_button(*m_mem_recall_button, Calculator::Operation::MemRecall);
m_mem_clear_button = GUI::Button::construct(this); m_mem_clear_button = add<GUI::Button>();
m_mem_clear_button->move_to(9, 78); m_mem_clear_button->move_to(9, 78);
m_mem_clear_button->set_foreground_color(Color::NamedColor::Red); m_mem_clear_button->set_foreground_color(Color::NamedColor::Red);
m_mem_clear_button->set_text("MC"); m_mem_clear_button->set_text("MC");
add_button(*m_mem_clear_button, Calculator::Operation::MemClear); add_button(*m_mem_clear_button, Calculator::Operation::MemClear);
m_clear_button = GUI::Button::construct(this); m_clear_button = add<GUI::Button>();
m_clear_button->set_foreground_color(Color::NamedColor::Red); m_clear_button->set_foreground_color(Color::NamedColor::Red);
m_clear_button->set_text("C"); m_clear_button->set_text("C");
m_clear_button->on_click = [this](GUI::Button&) { m_clear_button->on_click = [this](GUI::Button&) {
@ -94,7 +93,7 @@ CalculatorWidget::CalculatorWidget(GUI::Widget* parent)
add_button(*m_clear_button); add_button(*m_clear_button);
m_clear_button->set_relative_rect(187, 40, 60, 28); m_clear_button->set_relative_rect(187, 40, 60, 28);
m_clear_error_button = GUI::Button::construct(this); m_clear_error_button = add<GUI::Button>();
m_clear_error_button->set_foreground_color(Color::NamedColor::Red); m_clear_error_button->set_foreground_color(Color::NamedColor::Red);
m_clear_error_button->set_text("CE"); m_clear_error_button->set_text("CE");
m_clear_error_button->on_click = [this](GUI::Button&) { m_clear_error_button->on_click = [this](GUI::Button&) {
@ -104,7 +103,7 @@ CalculatorWidget::CalculatorWidget(GUI::Widget* parent)
add_button(*m_clear_error_button); add_button(*m_clear_error_button);
m_clear_error_button->set_relative_rect(124, 40, 59, 28); m_clear_error_button->set_relative_rect(124, 40, 59, 28);
m_backspace_button = GUI::Button::construct(this); m_backspace_button = add<GUI::Button>();
m_backspace_button->set_foreground_color(Color::NamedColor::Red); m_backspace_button->set_foreground_color(Color::NamedColor::Red);
m_backspace_button->set_text("Backspace"); m_backspace_button->set_text("Backspace");
m_backspace_button->on_click = [this](GUI::Button&) { m_backspace_button->on_click = [this](GUI::Button&) {
@ -114,7 +113,7 @@ CalculatorWidget::CalculatorWidget(GUI::Widget* parent)
add_button(*m_backspace_button); add_button(*m_backspace_button);
m_backspace_button->set_relative_rect(55, 40, 65, 28); m_backspace_button->set_relative_rect(55, 40, 65, 28);
m_decimal_point_button = GUI::Button::construct(this); m_decimal_point_button = add<GUI::Button>();
m_decimal_point_button->move_to(133, 177); m_decimal_point_button->move_to(133, 177);
m_decimal_point_button->set_foreground_color(Color::NamedColor::Blue); m_decimal_point_button->set_foreground_color(Color::NamedColor::Blue);
m_decimal_point_button->set_text("."); m_decimal_point_button->set_text(".");
@ -124,55 +123,55 @@ CalculatorWidget::CalculatorWidget(GUI::Widget* parent)
}; };
add_button(*m_decimal_point_button); add_button(*m_decimal_point_button);
m_sign_button = GUI::Button::construct(this); m_sign_button = add<GUI::Button>();
m_sign_button->move_to(94, 177); m_sign_button->move_to(94, 177);
m_sign_button->set_foreground_color(Color::NamedColor::Blue); m_sign_button->set_foreground_color(Color::NamedColor::Blue);
m_sign_button->set_text("+/-"); m_sign_button->set_text("+/-");
add_button(*m_sign_button, Calculator::Operation::ToggleSign); add_button(*m_sign_button, Calculator::Operation::ToggleSign);
m_add_button = GUI::Button::construct(this); m_add_button = add<GUI::Button>();
m_add_button->move_to(172, 177); m_add_button->move_to(172, 177);
m_add_button->set_foreground_color(Color::NamedColor::Red); m_add_button->set_foreground_color(Color::NamedColor::Red);
m_add_button->set_text("+"); m_add_button->set_text("+");
add_button(*m_add_button, Calculator::Operation::Add); add_button(*m_add_button, Calculator::Operation::Add);
m_subtract_button = GUI::Button::construct(this); m_subtract_button = add<GUI::Button>();
m_subtract_button->move_to(172, 144); m_subtract_button->move_to(172, 144);
m_subtract_button->set_foreground_color(Color::NamedColor::Red); m_subtract_button->set_foreground_color(Color::NamedColor::Red);
m_subtract_button->set_text("-"); m_subtract_button->set_text("-");
add_button(*m_subtract_button, Calculator::Operation::Subtract); add_button(*m_subtract_button, Calculator::Operation::Subtract);
m_multiply_button = GUI::Button::construct(this); m_multiply_button = add<GUI::Button>();
m_multiply_button->move_to(172, 111); m_multiply_button->move_to(172, 111);
m_multiply_button->set_foreground_color(Color::NamedColor::Red); m_multiply_button->set_foreground_color(Color::NamedColor::Red);
m_multiply_button->set_text("*"); m_multiply_button->set_text("*");
add_button(*m_multiply_button, Calculator::Operation::Multiply); add_button(*m_multiply_button, Calculator::Operation::Multiply);
m_divide_button = GUI::Button::construct(this); m_divide_button = add<GUI::Button>();
m_divide_button->move_to(172, 78); m_divide_button->move_to(172, 78);
m_divide_button->set_foreground_color(Color::NamedColor::Red); m_divide_button->set_foreground_color(Color::NamedColor::Red);
m_divide_button->set_text("/"); m_divide_button->set_text("/");
add_button(*m_divide_button, Calculator::Operation::Divide); add_button(*m_divide_button, Calculator::Operation::Divide);
m_sqrt_button = GUI::Button::construct(this); m_sqrt_button = add<GUI::Button>();
m_sqrt_button->move_to(211, 78); m_sqrt_button->move_to(211, 78);
m_sqrt_button->set_foreground_color(Color::NamedColor::Blue); m_sqrt_button->set_foreground_color(Color::NamedColor::Blue);
m_sqrt_button->set_text("sqrt"); m_sqrt_button->set_text("sqrt");
add_button(*m_sqrt_button, Calculator::Operation::Sqrt); add_button(*m_sqrt_button, Calculator::Operation::Sqrt);
m_inverse_button = GUI::Button::construct(this); m_inverse_button = add<GUI::Button>();
m_inverse_button->move_to(211, 144); m_inverse_button->move_to(211, 144);
m_inverse_button->set_foreground_color(Color::NamedColor::Blue); m_inverse_button->set_foreground_color(Color::NamedColor::Blue);
m_inverse_button->set_text("1/x"); m_inverse_button->set_text("1/x");
add_button(*m_inverse_button, Calculator::Operation::Inverse); add_button(*m_inverse_button, Calculator::Operation::Inverse);
m_percent_button = GUI::Button::construct(this); m_percent_button = add<GUI::Button>();
m_percent_button->move_to(211, 111); m_percent_button->move_to(211, 111);
m_percent_button->set_foreground_color(Color::NamedColor::Blue); m_percent_button->set_foreground_color(Color::NamedColor::Blue);
m_percent_button->set_text("%"); m_percent_button->set_text("%");
add_button(*m_percent_button, Calculator::Operation::Percent); add_button(*m_percent_button, Calculator::Operation::Percent);
m_equals_button = GUI::Button::construct(this); m_equals_button = add<GUI::Button>();
m_equals_button->move_to(211, 177); m_equals_button->move_to(211, 177);
m_equals_button->set_foreground_color(Color::NamedColor::Red); m_equals_button->set_foreground_color(Color::NamedColor::Red);
m_equals_button->set_text("="); m_equals_button->set_text("=");

View file

@ -37,7 +37,7 @@ public:
virtual ~CalculatorWidget() override; virtual ~CalculatorWidget() override;
private: private:
explicit CalculatorWidget(GUI::Widget*); CalculatorWidget();
void add_button(GUI::Button&, Calculator::Operation); void add_button(GUI::Button&, Calculator::Operation);
void add_button(GUI::Button&, int); void add_button(GUI::Button&, int);
void add_button(GUI::Button&); void add_button(GUI::Button&);

View file

@ -60,7 +60,7 @@ int main(int argc, char** argv)
window->set_resizable(false); window->set_resizable(false);
window->set_rect({ 300, 200, 254, 213 }); window->set_rect({ 300, 200, 254, 213 });
auto calc_widget = CalculatorWidget::construct(nullptr); auto calc_widget = CalculatorWidget::construct();
window->set_main_widget(calc_widget); window->set_main_widget(calc_widget);
window->show(); window->show();

View file

@ -62,17 +62,17 @@ int main(int argc, char** argv)
widget->set_fill_with_background_color(true); widget->set_fill_with_background_color(true);
widget->set_layout(make<GUI::VerticalBoxLayout>()); widget->set_layout(make<GUI::VerticalBoxLayout>());
auto board_combo = GUI::ComboBox::construct(widget); auto board_combo = widget->add<GUI::ComboBox>();
board_combo->set_only_allow_values_from_model(true); board_combo->set_only_allow_values_from_model(true);
board_combo->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); board_combo->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
board_combo->set_preferred_size(0, 20); board_combo->set_preferred_size(0, 20);
board_combo->set_model(BoardListModel::create()); board_combo->set_model(BoardListModel::create());
auto catalog_view = GUI::TableView::construct(widget); auto catalog_view = widget->add<GUI::TableView>();
catalog_view->set_model(ThreadCatalogModel::create()); catalog_view->set_model(ThreadCatalogModel::create());
auto& catalog_model = *static_cast<ThreadCatalogModel*>(catalog_view->model()); auto& catalog_model = *static_cast<ThreadCatalogModel*>(catalog_view->model());
auto statusbar = GUI::StatusBar::construct(widget); auto statusbar = widget->add<GUI::StatusBar>();
board_combo->on_change = [&] (auto&, const GUI::ModelIndex& index) { board_combo->on_change = [&] (auto&, const GUI::ModelIndex& index) {
auto selected_board = board_combo->model()->data(index, GUI::Model::Role::Custom); auto selected_board = board_combo->model()->data(index, GUI::Model::Role::Custom);

View file

@ -122,19 +122,19 @@ void DisplayPropertiesWidget::create_wallpaper_list()
void DisplayPropertiesWidget::create_frame() void DisplayPropertiesWidget::create_frame()
{ {
auto tab_widget = GUI::TabWidget::construct(m_root_widget); auto tab_widget = m_root_widget->add<GUI::TabWidget>();
// First, let's create the "Background" tab // First, let's create the "Background" tab
auto background_splitter = GUI::VerticalSplitter::construct(nullptr); auto background_splitter = GUI::VerticalSplitter::construct();
tab_widget->add_widget("Wallpaper", background_splitter); tab_widget->add_widget("Wallpaper", background_splitter);
auto background_content = GUI::Widget::construct(background_splitter.ptr()); auto background_content = background_splitter->add<GUI::Widget>();
background_content->set_layout(make<GUI::VerticalBoxLayout>()); background_content->set_layout(make<GUI::VerticalBoxLayout>());
background_content->layout()->set_margins({ 4, 4, 4, 4 }); background_content->layout()->set_margins({ 4, 4, 4, 4 });
m_wallpaper_preview = GUI::Label::construct(background_splitter); m_wallpaper_preview = background_splitter->add<GUI::Label>();
auto wallpaper_list = GUI::ListView::construct(background_content); auto wallpaper_list = background_content->add<GUI::ListView>();
wallpaper_list->set_background_color(Color::White); wallpaper_list->set_background_color(Color::White);
wallpaper_list->set_model(*ItemListModel<AK::String>::create(m_wallpapers)); wallpaper_list->set_model(*ItemListModel<AK::String>::create(m_wallpapers));
@ -155,14 +155,14 @@ void DisplayPropertiesWidget::create_frame()
}; };
// Let's add the settings tab // Let's add the settings tab
auto settings_splitter = GUI::VerticalSplitter::construct(nullptr); auto settings_splitter = GUI::VerticalSplitter::construct();
tab_widget->add_widget("Settings", settings_splitter); tab_widget->add_widget("Settings", settings_splitter);
auto settings_content = GUI::Widget::construct(settings_splitter.ptr()); auto settings_content = settings_splitter->add<GUI::Widget>();
settings_content->set_layout(make<GUI::VerticalBoxLayout>()); settings_content->set_layout(make<GUI::VerticalBoxLayout>());
settings_content->layout()->set_margins({ 4, 4, 4, 4 }); settings_content->layout()->set_margins({ 4, 4, 4, 4 });
auto resolution_list = GUI::ListView::construct(settings_content); auto resolution_list = settings_content->add<GUI::ListView>();
resolution_list->set_background_color(Color::White); resolution_list->set_background_color(Color::White);
resolution_list->set_model(*ItemListModel<Gfx::Size>::create(m_resolutions)); resolution_list->set_model(*ItemListModel<Gfx::Size>::create(m_resolutions));
@ -180,13 +180,13 @@ void DisplayPropertiesWidget::create_frame()
settings_content->layout()->add_spacer(); settings_content->layout()->add_spacer();
// Add the apply and cancel buttons // Add the apply and cancel buttons
auto bottom_widget = GUI::Widget::construct(m_root_widget.ptr()); auto bottom_widget = m_root_widget->add<GUI::Widget>();
bottom_widget->set_layout(make<GUI::HorizontalBoxLayout>()); bottom_widget->set_layout(make<GUI::HorizontalBoxLayout>());
bottom_widget->layout()->add_spacer(); bottom_widget->layout()->add_spacer();
bottom_widget->set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed); bottom_widget->set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed);
bottom_widget->set_preferred_size(1, 22); bottom_widget->set_preferred_size(1, 22);
auto apply_button = GUI::Button::construct(bottom_widget); auto apply_button = bottom_widget->add<GUI::Button>();
apply_button->set_text("Apply"); apply_button->set_text("Apply");
apply_button->set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed); apply_button->set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed);
apply_button->set_size_policy(Orientation::Horizontal, GUI::SizePolicy::Fixed); apply_button->set_size_policy(Orientation::Horizontal, GUI::SizePolicy::Fixed);
@ -195,7 +195,7 @@ void DisplayPropertiesWidget::create_frame()
send_settings_to_window_server(tab_widget->active_tab_index()); send_settings_to_window_server(tab_widget->active_tab_index());
}; };
auto ok_button = GUI::Button::construct(bottom_widget); auto ok_button = bottom_widget->add<GUI::Button>();
ok_button->set_text("OK"); ok_button->set_text("OK");
ok_button->set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed); ok_button->set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed);
ok_button->set_size_policy(Orientation::Horizontal, GUI::SizePolicy::Fixed); ok_button->set_size_policy(Orientation::Horizontal, GUI::SizePolicy::Fixed);
@ -205,7 +205,7 @@ void DisplayPropertiesWidget::create_frame()
GUI::Application::the().quit(); GUI::Application::the().quit();
}; };
auto cancel_button = GUI::Button::construct(bottom_widget); auto cancel_button = bottom_widget->add<GUI::Button>();
cancel_button->set_text("Cancel"); cancel_button->set_text("Cancel");
cancel_button->set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed); cancel_button->set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed);
cancel_button->set_size_policy(Orientation::Horizontal, GUI::SizePolicy::Fixed); cancel_button->set_size_policy(Orientation::Horizontal, GUI::SizePolicy::Fixed);

View file

@ -118,18 +118,17 @@ void DirectoryView::handle_activation(const GUI::ModelIndex& index)
} }
}; };
DirectoryView::DirectoryView(GUI::Widget* parent) DirectoryView::DirectoryView()
: GUI::StackWidget(parent) : m_model(GUI::FileSystemModel::create())
, m_model(GUI::FileSystemModel::create())
{ {
set_active_widget(nullptr); set_active_widget(nullptr);
m_item_view = GUI::ItemView::construct(this); m_item_view = add<GUI::ItemView>();
m_item_view->set_model(model()); m_item_view->set_model(model());
m_columns_view = GUI::ColumnsView::construct(this); m_columns_view = add<GUI::ColumnsView>();
m_columns_view->set_model(model()); m_columns_view->set_model(model());
m_table_view = GUI::TableView::construct(this); m_table_view = add<GUI::TableView>();
m_table_view->set_model(GUI::SortingProxyModel::create(m_model)); m_table_view->set_model(GUI::SortingProxyModel::create(m_model));
m_table_view->model()->set_key_column_and_sort_order(GUI::FileSystemModel::Column::Name, GUI::SortOrder::Ascending); m_table_view->model()->set_key_column_and_sort_order(GUI::FileSystemModel::Column::Name, GUI::SortOrder::Ascending);

View file

@ -90,7 +90,7 @@ public:
GUI::FileSystemModel& model() { return *m_model; } GUI::FileSystemModel& model() { return *m_model; }
private: private:
explicit DirectoryView(GUI::Widget* parent); DirectoryView();
const GUI::FileSystemModel& model() const { return *m_model; } const GUI::FileSystemModel& model() const { return *m_model; }
void handle_activation(const GUI::ModelIndex&); void handle_activation(const GUI::ModelIndex&);

View file

@ -52,9 +52,9 @@ PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, boo
set_rect({ 0, 0, 360, 420 }); set_rect({ 0, 0, 360, 420 });
set_resizable(false); set_resizable(false);
auto tab_widget = GUI::TabWidget::construct(main_widget); auto tab_widget = main_widget->add<GUI::TabWidget>();
auto general_tab = GUI::Widget::construct(tab_widget.ptr()); auto general_tab = tab_widget->add<GUI::Widget>();
general_tab->set_layout(make<GUI::VerticalBoxLayout>()); general_tab->set_layout(make<GUI::VerticalBoxLayout>());
general_tab->layout()->set_margins({ 12, 8, 12, 8 }); general_tab->layout()->set_margins({ 12, 8, 12, 8 });
general_tab->layout()->set_spacing(10); general_tab->layout()->set_spacing(10);
@ -62,19 +62,19 @@ PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, boo
general_tab->layout()->add_spacer(); general_tab->layout()->add_spacer();
auto file_container = GUI::Widget::construct(general_tab.ptr()); auto file_container = general_tab->add<GUI::Widget>();
file_container->set_layout(make<GUI::HorizontalBoxLayout>()); file_container->set_layout(make<GUI::HorizontalBoxLayout>());
file_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); file_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
file_container->layout()->set_spacing(20); file_container->layout()->set_spacing(20);
file_container->set_preferred_size(0, 34); file_container->set_preferred_size(0, 34);
m_icon = GUI::Label::construct(file_container); m_icon = file_container->add<GUI::Label>();
m_icon->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); m_icon->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
m_icon->set_preferred_size(32, 32); m_icon->set_preferred_size(32, 32);
m_name = file_path.basename(); m_name = file_path.basename();
m_name_box = GUI::TextBox::construct(file_container); m_name_box = file_container->add<GUI::TextBox>();
m_name_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); m_name_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_name_box->set_preferred_size({ 0, 22 }); m_name_box->set_preferred_size({ 0, 22 });
m_name_box->set_text(m_name); m_name_box->set_text(m_name);
@ -132,7 +132,7 @@ PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, boo
general_tab->layout()->add_spacer(); general_tab->layout()->add_spacer();
auto button_widget = GUI::Widget::construct(main_widget.ptr()); auto button_widget = main_widget->add<GUI::Widget>();
button_widget->set_layout(make<GUI::HorizontalBoxLayout>()); button_widget->set_layout(make<GUI::HorizontalBoxLayout>());
button_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); button_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
button_widget->set_preferred_size(0, 24); button_widget->set_preferred_size(0, 24);
@ -212,24 +212,24 @@ bool PropertiesDialog::apply_changes()
void PropertiesDialog::make_permission_checkboxes(NonnullRefPtr<GUI::Widget>& parent, PermissionMasks masks, String label_string, mode_t mode) void PropertiesDialog::make_permission_checkboxes(NonnullRefPtr<GUI::Widget>& parent, PermissionMasks masks, String label_string, mode_t mode)
{ {
auto widget = GUI::Widget::construct(parent.ptr()); auto widget = parent->add<GUI::Widget>();
widget->set_layout(make<GUI::HorizontalBoxLayout>()); widget->set_layout(make<GUI::HorizontalBoxLayout>());
widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
widget->set_preferred_size(0, 16); widget->set_preferred_size(0, 16);
widget->layout()->set_spacing(10); widget->layout()->set_spacing(10);
auto label = GUI::Label::construct(label_string, widget); auto label = widget->add<GUI::Label>(label_string);
label->set_text_alignment(Gfx::TextAlignment::CenterLeft); label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
auto box_read = GUI::CheckBox::construct("Read", widget); auto box_read = widget->add<GUI::CheckBox>("Read");
box_read->set_checked(mode & masks.read); box_read->set_checked(mode & masks.read);
box_read->on_checked = [&, masks](bool checked) { permission_changed(masks.read, checked); }; box_read->on_checked = [&, masks](bool checked) { permission_changed(masks.read, checked); };
auto box_write = GUI::CheckBox::construct("Write", widget); auto box_write = widget->add<GUI::CheckBox>("Write");
box_write->set_checked(mode & masks.write); box_write->set_checked(mode & masks.write);
box_write->on_checked = [&, masks](bool checked) { permission_changed(masks.write, checked); }; box_write->on_checked = [&, masks](bool checked) { permission_changed(masks.write, checked); };
auto box_execute = GUI::CheckBox::construct("Execute", widget); auto box_execute = widget->add<GUI::CheckBox>("Execute");
box_execute->set_checked(mode & masks.execute); box_execute->set_checked(mode & masks.execute);
box_execute->on_checked = [&, masks](bool checked) { permission_changed(masks.execute, checked); }; box_execute->on_checked = [&, masks](bool checked) { permission_changed(masks.execute, checked); };
} }
@ -241,17 +241,17 @@ void PropertiesDialog::make_property_value_pairs(const Vector<PropertyValuePair>
property_labels.ensure_capacity(pairs.size()); property_labels.ensure_capacity(pairs.size());
for (auto pair : pairs) { for (auto pair : pairs) {
auto label_container = GUI::Widget::construct(parent.ptr()); auto label_container = parent->add<GUI::Widget>();
label_container->set_layout(make<GUI::HorizontalBoxLayout>()); label_container->set_layout(make<GUI::HorizontalBoxLayout>());
label_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); label_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
label_container->set_preferred_size(0, 14); label_container->set_preferred_size(0, 14);
label_container->layout()->set_spacing(12); label_container->layout()->set_spacing(12);
auto label_property = GUI::Label::construct(pair.property, label_container); auto label_property = label_container->add<GUI::Label>(pair.property);
label_property->set_text_alignment(Gfx::TextAlignment::CenterLeft); label_property->set_text_alignment(Gfx::TextAlignment::CenterLeft);
label_property->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); label_property->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
GUI::Label::construct(pair.value, label_container)->set_text_alignment(Gfx::TextAlignment::CenterLeft); label_container->add<GUI::Label>(pair.value)->set_text_alignment(Gfx::TextAlignment::CenterLeft);
max_width = max(max_width, label_property->font().width(pair.property)); max_width = max(max_width, label_property->font().width(pair.property));
property_labels.append(label_property); property_labels.append(label_property);
@ -263,7 +263,7 @@ void PropertiesDialog::make_property_value_pairs(const Vector<PropertyValuePair>
NonnullRefPtr<GUI::Button> PropertiesDialog::make_button(String text, NonnullRefPtr<GUI::Widget>& parent) NonnullRefPtr<GUI::Button> PropertiesDialog::make_button(String text, NonnullRefPtr<GUI::Widget>& parent)
{ {
auto button = GUI::Button::construct(text, parent.ptr()); auto button = parent->add<GUI::Button>(text);
button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
button->set_preferred_size(70, 22); button->set_preferred_size(70, 22);
return button; return button;
@ -273,7 +273,7 @@ void PropertiesDialog::make_divider(NonnullRefPtr<GUI::Widget>& parent)
{ {
parent->layout()->add_spacer(); parent->layout()->add_spacer();
auto divider = GUI::Frame::construct(parent.ptr()); auto divider = parent->add<GUI::Frame>();
divider->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); divider->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
divider->set_preferred_size({ 0, 2 }); divider->set_preferred_size({ 0, 2 });
divider->set_frame_shape(Gfx::FrameShape::HorizontalLine); divider->set_frame_shape(Gfx::FrameShape::HorizontalLine);

View file

@ -96,18 +96,18 @@ int main(int argc, char** argv)
widget->set_layout(make<GUI::VerticalBoxLayout>()); widget->set_layout(make<GUI::VerticalBoxLayout>());
widget->layout()->set_spacing(0); widget->layout()->set_spacing(0);
auto main_toolbar = GUI::ToolBar::construct(widget); auto main_toolbar = widget->add<GUI::ToolBar>();
auto location_toolbar = GUI::ToolBar::construct(widget); auto location_toolbar = widget->add<GUI::ToolBar>();
location_toolbar->layout()->set_margins({ 6, 3, 6, 3 }); location_toolbar->layout()->set_margins({ 6, 3, 6, 3 });
location_toolbar->set_preferred_size(0, 25); location_toolbar->set_preferred_size(0, 25);
auto location_label = GUI::Label::construct("Location: ", location_toolbar); auto location_label = location_toolbar->add<GUI::Label>("Location: ");
location_label->size_to_fit(); location_label->size_to_fit();
auto location_textbox = GUI::TextEditor::construct(GUI::TextEditor::SingleLine, location_toolbar); auto location_textbox = location_toolbar->add<GUI::TextBox>();
auto splitter = GUI::HorizontalSplitter::construct(widget); auto splitter = widget->add<GUI::HorizontalSplitter>();
auto tree_view = GUI::TreeView::construct(splitter); auto tree_view = splitter->add<GUI::TreeView>();
auto directories_model = GUI::FileSystemModel::create("/", GUI::FileSystemModel::Mode::DirectoriesOnly); auto directories_model = GUI::FileSystemModel::create("/", GUI::FileSystemModel::Mode::DirectoriesOnly);
tree_view->set_model(directories_model); tree_view->set_model(directories_model);
tree_view->set_column_hidden(GUI::FileSystemModel::Column::Icon, true); tree_view->set_column_hidden(GUI::FileSystemModel::Column::Icon, true);
@ -120,11 +120,11 @@ int main(int argc, char** argv)
tree_view->set_column_hidden(GUI::FileSystemModel::Column::SymlinkTarget, true); tree_view->set_column_hidden(GUI::FileSystemModel::Column::SymlinkTarget, true);
tree_view->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); tree_view->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
tree_view->set_preferred_size(150, 0); tree_view->set_preferred_size(150, 0);
auto directory_view = DirectoryView::construct(splitter); auto directory_view = splitter->add<DirectoryView>();
auto statusbar = GUI::StatusBar::construct(widget); auto statusbar = widget->add<GUI::StatusBar>();
auto progressbar = GUI::ProgressBar::construct(statusbar); auto progressbar = statusbar->add<GUI::ProgressBar>();
progressbar->set_caption("Generating thumbnails: "); progressbar->set_caption("Generating thumbnails: ");
progressbar->set_format(GUI::ProgressBar::Format::ValueSlashMax); progressbar->set_format(GUI::ProgressBar::Format::ValueSlashMax);
progressbar->set_visible(false); progressbar->set_visible(false);
@ -171,7 +171,7 @@ int main(int argc, char** argv)
}); });
auto mkdir_action = GUI::Action::create("New directory...", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/mkdir.png"), [&](const GUI::Action&) { auto mkdir_action = GUI::Action::create("New directory...", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/mkdir.png"), [&](const GUI::Action&) {
auto input_box = GUI::InputBox::construct("Enter name:", "New directory", window); auto input_box = window->add<GUI::InputBox>("Enter name:", "New directory");
if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) { if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) {
auto new_dir_path = canonicalized_path( auto new_dir_path = canonicalized_path(
String::format("%s/%s", String::format("%s/%s",
@ -325,9 +325,9 @@ int main(int argc, char** argv)
RefPtr<PropertiesDialog> properties; RefPtr<PropertiesDialog> properties;
if (selected.is_empty()) { if (selected.is_empty()) {
properties = PropertiesDialog::construct(model, path, true, window); properties = window->add<PropertiesDialog>(model, path, true);
} else { } else {
properties = PropertiesDialog::construct(model, selected.first(), false, window); properties = window->add<PropertiesDialog>(model, selected.first(), false);
} }
properties->exec(); properties->exec();

View file

@ -50,10 +50,10 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::Font>&& edite
else else
m_path = path; m_path = path;
m_glyph_map_widget = GlyphMapWidget::construct(*m_edited_font, this); m_glyph_map_widget = add<GlyphMapWidget>(*m_edited_font);
m_glyph_map_widget->move_to({ 90, 5 }); m_glyph_map_widget->move_to({ 90, 5 });
m_glyph_editor_widget = GlyphEditorWidget::construct(*m_edited_font, this); m_glyph_editor_widget = add<GlyphEditorWidget>(*m_edited_font);
m_glyph_editor_widget->move_to({ 5, 5 }); m_glyph_editor_widget->move_to({ 5, 5 });
m_ui = make<UI_FontEditorBottom>(); m_ui = make<UI_FontEditorBottom>();

View file

@ -29,9 +29,8 @@
#include <LibGfx/Font.h> #include <LibGfx/Font.h>
#include <LibGfx/Palette.h> #include <LibGfx/Palette.h>
GlyphEditorWidget::GlyphEditorWidget(Gfx::Font& mutable_font, GUI::Widget* parent) GlyphEditorWidget::GlyphEditorWidget(Gfx::Font& mutable_font)
: GUI::Frame(parent) : m_font(mutable_font)
, m_font(mutable_font)
{ {
set_frame_thickness(2); set_frame_thickness(2);
set_frame_shadow(Gfx::FrameShadow::Sunken); set_frame_shadow(Gfx::FrameShadow::Sunken);

View file

@ -44,7 +44,7 @@ public:
Function<void(u8)> on_glyph_altered; Function<void(u8)> on_glyph_altered;
private: private:
GlyphEditorWidget(Gfx::Font&, GUI::Widget* parent); GlyphEditorWidget(Gfx::Font&);
virtual void paint_event(GUI::PaintEvent&) override; virtual void paint_event(GUI::PaintEvent&) override;
virtual void mousedown_event(GUI::MouseEvent&) override; virtual void mousedown_event(GUI::MouseEvent&) override;
virtual void mousemove_event(GUI::MouseEvent&) override; virtual void mousemove_event(GUI::MouseEvent&) override;

View file

@ -29,9 +29,8 @@
#include <LibGfx/Font.h> #include <LibGfx/Font.h>
#include <LibGfx/Palette.h> #include <LibGfx/Palette.h>
GlyphMapWidget::GlyphMapWidget(Gfx::Font& mutable_font, GUI::Widget* parent) GlyphMapWidget::GlyphMapWidget(Gfx::Font& mutable_font)
: GUI::Frame(parent) : m_font(mutable_font)
, m_font(mutable_font)
{ {
set_frame_thickness(2); set_frame_thickness(2);
set_frame_shape(Gfx::FrameShape::Container); set_frame_shape(Gfx::FrameShape::Container);

View file

@ -51,7 +51,7 @@ public:
Function<void(u8)> on_glyph_selected; Function<void(u8)> on_glyph_selected;
private: private:
GlyphMapWidget(Gfx::Font&, GUI::Widget* parent); explicit GlyphMapWidget(Gfx::Font&);
virtual void paint_event(GUI::PaintEvent&) override; virtual void paint_event(GUI::PaintEvent&) override;
virtual void mousedown_event(GUI::MouseEvent&) override; virtual void mousedown_event(GUI::MouseEvent&) override;

View file

@ -82,18 +82,18 @@ int main(int argc, char* argv[])
widget->set_layout(make<GUI::VerticalBoxLayout>()); widget->set_layout(make<GUI::VerticalBoxLayout>());
widget->layout()->set_spacing(0); widget->layout()->set_spacing(0);
auto toolbar = GUI::ToolBar::construct(widget); auto toolbar = widget->add<GUI::ToolBar>();
auto splitter = GUI::HorizontalSplitter::construct(widget); auto splitter = widget->add<GUI::HorizontalSplitter>();
auto model = ManualModel::create(); auto model = ManualModel::create();
auto tree_view = GUI::TreeView::construct(splitter); auto tree_view = splitter->add<GUI::TreeView>();
tree_view->set_model(model); tree_view->set_model(model);
tree_view->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); tree_view->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
tree_view->set_preferred_size(200, 500); tree_view->set_preferred_size(200, 500);
auto html_view = HtmlView::construct(splitter); auto html_view = splitter->add<HtmlView>();
History history; History history;

View file

@ -94,7 +94,7 @@ void IRCAppWindow::setup_client()
}; };
if (m_client->hostname().is_empty()) { if (m_client->hostname().is_empty()) {
auto input_box = GUI::InputBox::construct("Enter server:", "Connect to server", this); auto input_box = add<GUI::InputBox>("Enter server:", "Connect to server");
auto result = input_box->exec(); auto result = input_box->exec();
if (result == GUI::InputBox::ExecCancel) if (result == GUI::InputBox::ExecCancel)
::exit(0); ::exit(0);
@ -109,7 +109,7 @@ void IRCAppWindow::setup_client()
void IRCAppWindow::setup_actions() void IRCAppWindow::setup_actions()
{ {
m_join_action = GUI::Action::create("Join channel", { Mod_Ctrl, Key_J }, Gfx::Bitmap::load_from_file("/res/icons/16x16/irc-join.png"), [&](auto&) { m_join_action = GUI::Action::create("Join channel", { Mod_Ctrl, Key_J }, Gfx::Bitmap::load_from_file("/res/icons/16x16/irc-join.png"), [&](auto&) {
auto input_box = GUI::InputBox::construct("Enter channel name:", "Join channel", this); auto input_box = add<GUI::InputBox>("Enter channel name:", "Join channel");
if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty())
m_client->handle_join_action(input_box->text_value()); m_client->handle_join_action(input_box->text_value());
}); });
@ -185,7 +185,7 @@ void IRCAppWindow::setup_widgets()
widget->set_layout(make<GUI::VerticalBoxLayout>()); widget->set_layout(make<GUI::VerticalBoxLayout>());
widget->layout()->set_spacing(0); widget->layout()->set_spacing(0);
auto toolbar = GUI::ToolBar::construct(widget); auto toolbar = widget->add<GUI::ToolBar>();
toolbar->set_has_frame(false); toolbar->set_has_frame(false);
toolbar->add_action(*m_change_nick_action); toolbar->add_action(*m_change_nick_action);
toolbar->add_separator(); toolbar->add_separator();
@ -196,13 +196,13 @@ void IRCAppWindow::setup_widgets()
toolbar->add_action(*m_open_query_action); toolbar->add_action(*m_open_query_action);
toolbar->add_action(*m_close_query_action); toolbar->add_action(*m_close_query_action);
auto outer_container = GUI::Widget::construct(widget.ptr()); auto outer_container = widget->add<GUI::Widget>();
outer_container->set_layout(make<GUI::VerticalBoxLayout>()); outer_container->set_layout(make<GUI::VerticalBoxLayout>());
outer_container->layout()->set_margins({ 2, 0, 2, 2 }); outer_container->layout()->set_margins({ 2, 0, 2, 2 });
auto horizontal_container = GUI::HorizontalSplitter::construct(outer_container); auto horizontal_container = outer_container->add<GUI::HorizontalSplitter>();
m_window_list = GUI::TableView::construct(horizontal_container); m_window_list = horizontal_container->add<GUI::TableView>();
m_window_list->set_headers_visible(false); m_window_list->set_headers_visible(false);
m_window_list->set_alternating_row_colors(false); m_window_list->set_alternating_row_colors(false);
m_window_list->set_size_columns_to_fit_content(true); m_window_list->set_size_columns_to_fit_content(true);
@ -214,7 +214,7 @@ void IRCAppWindow::setup_widgets()
set_active_window(m_client->window_at(index.row())); set_active_window(m_client->window_at(index.row()));
}; };
m_container = GUI::StackWidget::construct(horizontal_container); m_container = horizontal_container->add<GUI::StackWidget>();
m_container->on_active_widget_change = [this](auto*) { m_container->on_active_widget_change = [this](auto*) {
update_part_action(); update_part_action();
}; };

View file

@ -45,12 +45,12 @@ IRCWindow::IRCWindow(IRCClient& client, void* owner, Type type, const String& na
set_layout(make<GUI::VerticalBoxLayout>()); set_layout(make<GUI::VerticalBoxLayout>());
// Make a container for the log buffer view + (optional) member list. // Make a container for the log buffer view + (optional) member list.
auto container = GUI::HorizontalSplitter::construct(this); auto container = add<GUI::HorizontalSplitter>();
m_html_view = HtmlView::construct(container); m_html_view = container->add<HtmlView>();
if (m_type == Channel) { if (m_type == Channel) {
auto member_view = GUI::TableView::construct(container); auto member_view = container->add<GUI::TableView>();
member_view->set_headers_visible(false); member_view->set_headers_visible(false);
member_view->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); member_view->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
member_view->set_preferred_size(100, 0); member_view->set_preferred_size(100, 0);
@ -59,7 +59,7 @@ IRCWindow::IRCWindow(IRCClient& client, void* owner, Type type, const String& na
member_view->set_activates_on_selection(true); member_view->set_activates_on_selection(true);
} }
m_text_editor = GUI::TextEditor::construct(GUI::TextEditor::SingleLine, this); m_text_editor = add<GUI::TextBox>();
m_text_editor->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); m_text_editor->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_text_editor->set_preferred_size(0, 19); m_text_editor->set_preferred_size(0, 19);
m_text_editor->on_return_pressed = [this] { m_text_editor->on_return_pressed = [this] {

View file

@ -37,8 +37,7 @@ PaintableWidget& PaintableWidget::the()
return *s_the; return *s_the;
} }
PaintableWidget::PaintableWidget(GUI::Widget* parent) PaintableWidget::PaintableWidget()
: GUI::Widget(parent)
{ {
ASSERT(!s_the); ASSERT(!s_the);
s_the = this; s_the = this;

View file

@ -34,7 +34,6 @@ class PaintableWidget final : public GUI::Widget {
public: public:
static PaintableWidget& the(); static PaintableWidget& the();
explicit PaintableWidget(GUI::Widget* parent);
virtual ~PaintableWidget() override; virtual ~PaintableWidget() override;
Color primary_color() const { return m_primary_color; } Color primary_color() const { return m_primary_color; }
@ -58,6 +57,8 @@ public:
Function<void(Color)> on_secondary_color_change; Function<void(Color)> on_secondary_color_change;
private: private:
PaintableWidget();
virtual bool accepts_focus() const override { return true; } virtual bool accepts_focus() const override { return true; }
virtual void paint_event(GUI::PaintEvent&) override; virtual void paint_event(GUI::PaintEvent&) override;
virtual void second_paint_event(GUI::PaintEvent&) override; virtual void second_paint_event(GUI::PaintEvent&) override;

View file

@ -33,9 +33,8 @@
class ColorWidget : public GUI::Frame { class ColorWidget : public GUI::Frame {
C_OBJECT(ColorWidget) C_OBJECT(ColorWidget)
public: public:
explicit ColorWidget(Color color, PaletteWidget& palette_widget, GUI::Widget* parent) explicit ColorWidget(Color color, PaletteWidget& palette_widget)
: GUI::Frame(parent) : m_palette_widget(palette_widget)
, m_palette_widget(palette_widget)
, m_color(color) , m_color(color)
{ {
set_frame_thickness(2); set_frame_thickness(2);
@ -72,9 +71,8 @@ private:
Color m_color; Color m_color;
}; };
PaletteWidget::PaletteWidget(PaintableWidget& paintable_widget, GUI::Widget* parent) PaletteWidget::PaletteWidget(PaintableWidget& paintable_widget)
: GUI::Frame(parent) : m_paintable_widget(paintable_widget)
, m_paintable_widget(paintable_widget)
{ {
set_frame_shape(Gfx::FrameShape::Panel); set_frame_shape(Gfx::FrameShape::Panel);
set_frame_shadow(Gfx::FrameShadow::Raised); set_frame_shadow(Gfx::FrameShadow::Raised);
@ -84,7 +82,7 @@ PaletteWidget::PaletteWidget(PaintableWidget& paintable_widget, GUI::Widget* par
set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
set_preferred_size(0, 34); set_preferred_size(0, 34);
m_secondary_color_widget = GUI::Frame::construct(this); m_secondary_color_widget = add<GUI::Frame>();
m_secondary_color_widget->set_frame_thickness(2); m_secondary_color_widget->set_frame_thickness(2);
m_secondary_color_widget->set_frame_shape(Gfx::FrameShape::Container); m_secondary_color_widget->set_frame_shape(Gfx::FrameShape::Container);
m_secondary_color_widget->set_frame_shadow(Gfx::FrameShadow::Sunken); m_secondary_color_widget->set_frame_shadow(Gfx::FrameShadow::Sunken);
@ -92,7 +90,7 @@ PaletteWidget::PaletteWidget(PaintableWidget& paintable_widget, GUI::Widget* par
m_secondary_color_widget->set_fill_with_background_color(true); m_secondary_color_widget->set_fill_with_background_color(true);
set_secondary_color(paintable_widget.secondary_color()); set_secondary_color(paintable_widget.secondary_color());
m_primary_color_widget = GUI::Frame::construct(this); m_primary_color_widget = add<GUI::Frame>();
m_primary_color_widget->set_frame_thickness(2); m_primary_color_widget->set_frame_thickness(2);
m_primary_color_widget->set_frame_shape(Gfx::FrameShape::Container); m_primary_color_widget->set_frame_shape(Gfx::FrameShape::Container);
m_primary_color_widget->set_frame_shadow(Gfx::FrameShadow::Sunken); m_primary_color_widget->set_frame_shadow(Gfx::FrameShadow::Sunken);
@ -110,21 +108,21 @@ PaletteWidget::PaletteWidget(PaintableWidget& paintable_widget, GUI::Widget* par
set_secondary_color(color); set_secondary_color(color);
}; };
auto color_container = GUI::Widget::construct(this); auto color_container = add<GUI::Widget>();
color_container->set_relative_rect(m_secondary_color_widget->relative_rect().right() + 2, 2, 500, 32); color_container->set_relative_rect(m_secondary_color_widget->relative_rect().right() + 2, 2, 500, 32);
color_container->set_layout(make<GUI::VerticalBoxLayout>()); color_container->set_layout(make<GUI::VerticalBoxLayout>());
color_container->layout()->set_spacing(1); color_container->layout()->set_spacing(1);
auto top_color_container = GUI::Widget::construct(color_container.ptr()); auto top_color_container = color_container->add<GUI::Widget>();
top_color_container->set_layout(make<GUI::HorizontalBoxLayout>()); top_color_container->set_layout(make<GUI::HorizontalBoxLayout>());
top_color_container->layout()->set_spacing(1); top_color_container->layout()->set_spacing(1);
auto bottom_color_container = GUI::Widget::construct(color_container.ptr()); auto bottom_color_container = color_container->add<GUI::Widget>();
bottom_color_container->set_layout(make<GUI::HorizontalBoxLayout>()); bottom_color_container->set_layout(make<GUI::HorizontalBoxLayout>());
bottom_color_container->layout()->set_spacing(1); bottom_color_container->layout()->set_spacing(1);
auto add_color_widget = [&](GUI::Widget* container, Color color) { auto add_color_widget = [&](GUI::Widget* container, Color color) {
auto color_widget = ColorWidget::construct(color, *this, container); auto color_widget = container->add<ColorWidget>(color, *this);
color_widget->set_fill_with_background_color(true); color_widget->set_fill_with_background_color(true);
auto pal = color_widget->palette(); auto pal = color_widget->palette();
pal.set_color(ColorRole::Background, color); pal.set_color(ColorRole::Background, color);

View file

@ -33,7 +33,7 @@ class PaintableWidget;
class PaletteWidget final : public GUI::Frame { class PaletteWidget final : public GUI::Frame {
C_OBJECT(PaletteWidget) C_OBJECT(PaletteWidget)
public: public:
explicit PaletteWidget(PaintableWidget&, GUI::Widget* parent); explicit PaletteWidget(PaintableWidget&);
virtual ~PaletteWidget() override; virtual ~PaletteWidget() override;
void set_primary_color(Color); void set_primary_color(Color);

View file

@ -40,9 +40,8 @@
class ToolButton final : public GUI::Button { class ToolButton final : public GUI::Button {
C_OBJECT(ToolButton) C_OBJECT(ToolButton)
public: public:
ToolButton(const String& name, GUI::Widget* parent, OwnPtr<Tool>&& tool) ToolButton(const String& name, OwnPtr<Tool>&& tool)
: GUI::Button(parent) : m_tool(move(tool))
, m_tool(move(tool))
{ {
set_tooltip(name); set_tooltip(name);
} }
@ -60,8 +59,7 @@ private:
OwnPtr<Tool> m_tool; OwnPtr<Tool> m_tool;
}; };
ToolboxWidget::ToolboxWidget(GUI::Widget* parent) ToolboxWidget::ToolboxWidget()
: GUI::Frame(parent)
{ {
set_fill_with_background_color(true); set_fill_with_background_color(true);
@ -76,7 +74,7 @@ ToolboxWidget::ToolboxWidget(GUI::Widget* parent)
layout()->set_margins({ 4, 4, 4, 4 }); layout()->set_margins({ 4, 4, 4, 4 });
auto add_tool = [&](const StringView& name, const StringView& icon_name, OwnPtr<Tool>&& tool) { auto add_tool = [&](const StringView& name, const StringView& icon_name, OwnPtr<Tool>&& tool) {
auto button = ToolButton::construct(name, this, move(tool)); auto button = add<ToolButton>(name, move(tool));
button->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); button->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
button->set_preferred_size(0, 32); button->set_preferred_size(0, 32);
button->set_checkable(true); button->set_checkable(true);

View file

@ -31,6 +31,6 @@
class ToolboxWidget final : public GUI::Frame { class ToolboxWidget final : public GUI::Frame {
C_OBJECT(ToolboxWidget) C_OBJECT(ToolboxWidget)
public: public:
explicit ToolboxWidget(GUI::Widget* parent); explicit ToolboxWidget();
virtual ~ToolboxWidget() override; virtual ~ToolboxWidget() override;
}; };

View file

@ -63,15 +63,15 @@ int main(int argc, char** argv)
horizontal_container->set_layout(make<GUI::HorizontalBoxLayout>()); horizontal_container->set_layout(make<GUI::HorizontalBoxLayout>());
horizontal_container->layout()->set_spacing(0); horizontal_container->layout()->set_spacing(0);
new ToolboxWidget(horizontal_container); horizontal_container->add<ToolboxWidget>();
auto vertical_container = GUI::Widget::construct(horizontal_container.ptr()); auto vertical_container = horizontal_container->add<GUI::Widget>();
vertical_container->set_layout(make<GUI::VerticalBoxLayout>()); vertical_container->set_layout(make<GUI::VerticalBoxLayout>());
vertical_container->layout()->set_spacing(0); vertical_container->layout()->set_spacing(0);
auto paintable_widget = PaintableWidget::construct(vertical_container); auto paintable_widget = vertical_container->add<PaintableWidget>();
paintable_widget->set_focus(true); paintable_widget->set_focus(true);
PaletteWidget::construct(*paintable_widget, vertical_container); vertical_container->add<PaletteWidget>(*paintable_widget);
window->show(); window->show();

View file

@ -29,9 +29,8 @@
#include "AudioEngine.h" #include "AudioEngine.h"
#include <LibGUI/Painter.h> #include <LibGUI/Painter.h>
KeysWidget::KeysWidget(GUI::Widget* parent, AudioEngine& audio_engine) KeysWidget::KeysWidget(AudioEngine& audio_engine)
: GUI::Frame(parent) : m_audio_engine(audio_engine)
, m_audio_engine(audio_engine)
{ {
set_frame_thickness(2); set_frame_thickness(2);
set_frame_shadow(Gfx::FrameShadow::Sunken); set_frame_shadow(Gfx::FrameShadow::Sunken);

View file

@ -43,7 +43,7 @@ public:
void set_key(int key, Switch); void set_key(int key, Switch);
private: private:
KeysWidget(GUI::Widget* parent, AudioEngine&); explicit KeysWidget(AudioEngine&);
virtual void paint_event(GUI::PaintEvent&) override; virtual void paint_event(GUI::PaintEvent&) override;
virtual void mousedown_event(GUI::MouseEvent&) override; virtual void mousedown_event(GUI::MouseEvent&) override;

View file

@ -32,9 +32,8 @@
#include <LibGUI/Label.h> #include <LibGUI/Label.h>
#include <LibGUI/Slider.h> #include <LibGUI/Slider.h>
KnobsWidget::KnobsWidget(GUI::Widget* parent, AudioEngine& audio_engine, MainWidget& main_widget) KnobsWidget::KnobsWidget(AudioEngine& audio_engine, MainWidget& main_widget)
: GUI::Frame(parent) : m_audio_engine(audio_engine)
, m_audio_engine(audio_engine)
, m_main_widget(main_widget) , m_main_widget(main_widget)
{ {
set_frame_thickness(2); set_frame_thickness(2);
@ -43,38 +42,38 @@ KnobsWidget::KnobsWidget(GUI::Widget* parent, AudioEngine& audio_engine, MainWid
set_layout(make<GUI::VerticalBoxLayout>()); set_layout(make<GUI::VerticalBoxLayout>());
set_fill_with_background_color(true); set_fill_with_background_color(true);
m_labels_container = GUI::Widget::construct(this); m_labels_container = add<GUI::Widget>();
m_labels_container->set_layout(make<GUI::HorizontalBoxLayout>()); m_labels_container->set_layout(make<GUI::HorizontalBoxLayout>());
m_labels_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); m_labels_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_labels_container->set_preferred_size(0, 20); m_labels_container->set_preferred_size(0, 20);
m_octave_label = GUI::Label::construct("Octave", m_labels_container); m_octave_label = m_labels_container->add<GUI::Label>("Octave");
m_wave_label = GUI::Label::construct("Wave", m_labels_container); m_wave_label = m_labels_container->add<GUI::Label>("Wave");
m_attack_label = GUI::Label::construct("Attack", m_labels_container); m_attack_label = m_labels_container->add<GUI::Label>("Attack");
m_decay_label = GUI::Label::construct("Decay", m_labels_container); m_decay_label = m_labels_container->add<GUI::Label>("Decay");
m_sustain_label = GUI::Label::construct("Sustain", m_labels_container); m_sustain_label = m_labels_container->add<GUI::Label>("Sustain");
m_release_label = GUI::Label::construct("Release", m_labels_container); m_release_label = m_labels_container->add<GUI::Label>("Release");
m_delay_label = GUI::Label::construct("Delay", m_labels_container); m_delay_label = m_labels_container->add<GUI::Label>("Delay");
m_values_container = GUI::Widget::construct(this); m_values_container = add<GUI::Widget>();
m_values_container->set_layout(make<GUI::HorizontalBoxLayout>()); m_values_container->set_layout(make<GUI::HorizontalBoxLayout>());
m_values_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); m_values_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_values_container->set_preferred_size(0, 10); m_values_container->set_preferred_size(0, 10);
m_octave_value = GUI::Label::construct(String::number(m_audio_engine.octave()), m_values_container); m_octave_value = m_values_container->add<GUI::Label>(String::number(m_audio_engine.octave()));
m_wave_value = GUI::Label::construct(wave_strings[m_audio_engine.wave()], m_values_container); m_wave_value = m_values_container->add<GUI::Label>(wave_strings[m_audio_engine.wave()]);
m_attack_value = GUI::Label::construct(String::number(m_audio_engine.attack()), m_values_container); m_attack_value = m_values_container->add<GUI::Label>(String::number(m_audio_engine.attack()));
m_decay_value = GUI::Label::construct(String::number(m_audio_engine.decay()), m_values_container); m_decay_value = m_values_container->add<GUI::Label>(String::number(m_audio_engine.decay()));
m_sustain_value = GUI::Label::construct(String::number(m_audio_engine.sustain()), m_values_container); m_sustain_value = m_values_container->add<GUI::Label>(String::number(m_audio_engine.sustain()));
m_release_value = GUI::Label::construct(String::number(m_audio_engine.release()), m_values_container); m_release_value = m_values_container->add<GUI::Label>(String::number(m_audio_engine.release()));
m_delay_value = GUI::Label::construct(String::number(m_audio_engine.delay() / m_audio_engine.tick()), m_values_container); m_delay_value = m_values_container->add<GUI::Label>(String::number(m_audio_engine.delay() / m_audio_engine.tick()));
m_knobs_container = GUI::Widget::construct(this); m_knobs_container = add<GUI::Widget>();
m_knobs_container->set_layout(make<GUI::HorizontalBoxLayout>()); m_knobs_container->set_layout(make<GUI::HorizontalBoxLayout>());
// FIXME: Implement vertical flipping in GSlider, not here. // FIXME: Implement vertical flipping in GSlider, not here.
m_octave_knob = GUI::VerticalSlider::construct(m_knobs_container); m_octave_knob = m_knobs_container->add<GUI::VerticalSlider>();
m_octave_knob->set_tooltip("Z: octave down, X: octave up"); m_octave_knob->set_tooltip("Z: octave down, X: octave up");
m_octave_knob->set_range(octave_min - 1, octave_max - 1); m_octave_knob->set_range(octave_min - 1, octave_max - 1);
m_octave_knob->set_value((octave_max - 1) - (m_audio_engine.octave() - 1)); m_octave_knob->set_value((octave_max - 1) - (m_audio_engine.octave() - 1));
@ -86,7 +85,7 @@ KnobsWidget::KnobsWidget(GUI::Widget* parent, AudioEngine& audio_engine, MainWid
m_octave_value->set_text(String::number(new_octave)); m_octave_value->set_text(String::number(new_octave));
}; };
m_wave_knob = GUI::VerticalSlider::construct(m_knobs_container); m_wave_knob = m_knobs_container->add<GUI::VerticalSlider>();
m_wave_knob->set_tooltip("C: cycle through waveforms"); m_wave_knob->set_tooltip("C: cycle through waveforms");
m_wave_knob->set_range(0, last_wave); m_wave_knob->set_range(0, last_wave);
m_wave_knob->set_value(last_wave - m_audio_engine.wave()); m_wave_knob->set_value(last_wave - m_audio_engine.wave());
@ -98,7 +97,7 @@ KnobsWidget::KnobsWidget(GUI::Widget* parent, AudioEngine& audio_engine, MainWid
}; };
constexpr int max_attack = 1000; constexpr int max_attack = 1000;
m_attack_knob = GUI::VerticalSlider::construct(m_knobs_container); m_attack_knob = m_knobs_container->add<GUI::VerticalSlider>();
m_attack_knob->set_range(0, max_attack); m_attack_knob->set_range(0, max_attack);
m_attack_knob->set_value(max_attack - m_audio_engine.attack()); m_attack_knob->set_value(max_attack - m_audio_engine.attack());
m_attack_knob->set_step(100); m_attack_knob->set_step(100);
@ -110,7 +109,7 @@ KnobsWidget::KnobsWidget(GUI::Widget* parent, AudioEngine& audio_engine, MainWid
}; };
constexpr int max_decay = 1000; constexpr int max_decay = 1000;
m_decay_knob = GUI::VerticalSlider::construct(m_knobs_container); m_decay_knob = m_knobs_container->add<GUI::VerticalSlider>();
m_decay_knob->set_range(0, max_decay); m_decay_knob->set_range(0, max_decay);
m_decay_knob->set_value(max_decay - m_audio_engine.decay()); m_decay_knob->set_value(max_decay - m_audio_engine.decay());
m_decay_knob->set_step(100); m_decay_knob->set_step(100);
@ -122,7 +121,7 @@ KnobsWidget::KnobsWidget(GUI::Widget* parent, AudioEngine& audio_engine, MainWid
}; };
constexpr int max_sustain = 1000; constexpr int max_sustain = 1000;
m_sustain_knob = GUI::VerticalSlider::construct(m_knobs_container); m_sustain_knob = m_knobs_container->add<GUI::VerticalSlider>();
m_sustain_knob->set_range(0, max_sustain); m_sustain_knob->set_range(0, max_sustain);
m_sustain_knob->set_value(max_sustain - m_audio_engine.sustain()); m_sustain_knob->set_value(max_sustain - m_audio_engine.sustain());
m_sustain_knob->set_step(100); m_sustain_knob->set_step(100);
@ -134,7 +133,7 @@ KnobsWidget::KnobsWidget(GUI::Widget* parent, AudioEngine& audio_engine, MainWid
}; };
constexpr int max_release = 1000; constexpr int max_release = 1000;
m_release_knob = GUI::VerticalSlider::construct(m_knobs_container); m_release_knob = m_knobs_container->add<GUI::VerticalSlider>();
m_release_knob->set_range(0, max_release); m_release_knob->set_range(0, max_release);
m_release_knob->set_value(max_release - m_audio_engine.release()); m_release_knob->set_value(max_release - m_audio_engine.release());
m_release_knob->set_step(100); m_release_knob->set_step(100);
@ -146,7 +145,7 @@ KnobsWidget::KnobsWidget(GUI::Widget* parent, AudioEngine& audio_engine, MainWid
}; };
constexpr int max_delay = 8; constexpr int max_delay = 8;
m_delay_knob = GUI::VerticalSlider::construct(m_knobs_container); m_delay_knob = m_knobs_container->add<GUI::VerticalSlider>();
m_delay_knob->set_range(0, max_delay); m_delay_knob->set_range(0, max_delay);
m_delay_knob->set_value(max_delay - (m_audio_engine.delay() / m_audio_engine.tick())); m_delay_knob->set_value(max_delay - (m_audio_engine.delay() / m_audio_engine.tick()));
m_delay_knob->on_value_changed = [this](int value) { m_delay_knob->on_value_changed = [this](int value) {

View file

@ -40,7 +40,7 @@ public:
void update_knobs(); void update_knobs();
private: private:
KnobsWidget(GUI::Widget* parent, AudioEngine&, MainWidget&); KnobsWidget(AudioEngine&, MainWidget&);
AudioEngine& m_audio_engine; AudioEngine& m_audio_engine;
MainWidget& m_main_widget; MainWidget& m_main_widget;

View file

@ -43,30 +43,30 @@ MainWidget::MainWidget(AudioEngine& audio_engine)
layout()->set_margins({ 2, 2, 2, 2 }); layout()->set_margins({ 2, 2, 2, 2 });
set_fill_with_background_color(true); set_fill_with_background_color(true);
m_wave_widget = WaveWidget::construct(this, audio_engine); m_wave_widget = add<WaveWidget>(audio_engine);
m_wave_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); m_wave_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_wave_widget->set_preferred_size(0, 100); m_wave_widget->set_preferred_size(0, 100);
m_roll_widget = RollWidget::construct(nullptr, audio_engine); m_roll_widget = RollWidget::construct(audio_engine);
m_roll_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill); m_roll_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill);
m_roll_widget->set_preferred_size(0, 300); m_roll_widget->set_preferred_size(0, 300);
m_sampler_widget = SamplerWidget::construct(nullptr, audio_engine); m_sampler_widget = SamplerWidget::construct(audio_engine);
m_tab_widget = GUI::TabWidget::construct(this); m_tab_widget = add<GUI::TabWidget>();
m_tab_widget->add_widget("Piano Roll", m_roll_widget); m_tab_widget->add_widget("Piano Roll", m_roll_widget);
m_tab_widget->add_widget("Sampler", m_sampler_widget); m_tab_widget->add_widget("Sampler", m_sampler_widget);
m_keys_and_knobs_container = GUI::Widget::construct(this); m_keys_and_knobs_container = add<GUI::Widget>();
m_keys_and_knobs_container->set_layout(make<GUI::HorizontalBoxLayout>()); m_keys_and_knobs_container->set_layout(make<GUI::HorizontalBoxLayout>());
m_keys_and_knobs_container->layout()->set_spacing(2); m_keys_and_knobs_container->layout()->set_spacing(2);
m_keys_and_knobs_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); m_keys_and_knobs_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_keys_and_knobs_container->set_preferred_size(0, 100); m_keys_and_knobs_container->set_preferred_size(0, 100);
m_keys_and_knobs_container->set_fill_with_background_color(true); m_keys_and_knobs_container->set_fill_with_background_color(true);
m_keys_widget = KeysWidget::construct(m_keys_and_knobs_container, audio_engine); m_keys_widget = m_keys_and_knobs_container->add<KeysWidget>(audio_engine);
m_knobs_widget = KnobsWidget::construct(m_keys_and_knobs_container, audio_engine, *this); m_knobs_widget = m_keys_and_knobs_container->add<KnobsWidget>(audio_engine, *this);
m_knobs_widget->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); m_knobs_widget->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
m_knobs_widget->set_preferred_size(350, 0); m_knobs_widget->set_preferred_size(350, 0);
} }

View file

@ -33,9 +33,8 @@
constexpr int note_height = 20; constexpr int note_height = 20;
constexpr int roll_height = note_count * note_height; constexpr int roll_height = note_count * note_height;
RollWidget::RollWidget(GUI::Widget* parent, AudioEngine& audio_engine) RollWidget::RollWidget(AudioEngine& audio_engine)
: ScrollableWidget(parent) : m_audio_engine(audio_engine)
, m_audio_engine(audio_engine)
{ {
set_frame_thickness(2); set_frame_thickness(2);
set_frame_shadow(Gfx::FrameShadow::Sunken); set_frame_shadow(Gfx::FrameShadow::Sunken);

View file

@ -38,7 +38,7 @@ public:
virtual ~RollWidget() override; virtual ~RollWidget() override;
private: private:
RollWidget(GUI::Widget* parent, AudioEngine&); explicit RollWidget(AudioEngine&);
virtual void paint_event(GUI::PaintEvent&) override; virtual void paint_event(GUI::PaintEvent&) override;
virtual void mousedown_event(GUI::MouseEvent& event) override; virtual void mousedown_event(GUI::MouseEvent& event) override;

View file

@ -33,9 +33,8 @@
#include <LibGUI/MessageBox.h> #include <LibGUI/MessageBox.h>
#include <LibGUI/Painter.h> #include <LibGUI/Painter.h>
WaveEditor::WaveEditor(GUI::Widget* parent, AudioEngine& audio_engine) WaveEditor::WaveEditor(AudioEngine& audio_engine)
: GUI::Frame(parent) : m_audio_engine(audio_engine)
, m_audio_engine(audio_engine)
{ {
set_frame_thickness(2); set_frame_thickness(2);
set_frame_shadow(Gfx::FrameShadow::Sunken); set_frame_shadow(Gfx::FrameShadow::Sunken);
@ -92,9 +91,8 @@ void WaveEditor::paint_event(GUI::PaintEvent& event)
} }
} }
SamplerWidget::SamplerWidget(GUI::Widget* parent, AudioEngine& audio_engine) SamplerWidget::SamplerWidget(AudioEngine& audio_engine)
: GUI::Frame(parent) : m_audio_engine(audio_engine)
, m_audio_engine(audio_engine)
{ {
set_frame_thickness(2); set_frame_thickness(2);
set_frame_shadow(Gfx::FrameShadow::Sunken); set_frame_shadow(Gfx::FrameShadow::Sunken);
@ -104,13 +102,13 @@ SamplerWidget::SamplerWidget(GUI::Widget* parent, AudioEngine& audio_engine)
layout()->set_spacing(10); layout()->set_spacing(10);
set_fill_with_background_color(true); set_fill_with_background_color(true);
m_open_button_and_recorded_sample_name_container = GUI::Widget::construct(this); m_open_button_and_recorded_sample_name_container = add<GUI::Widget>();
m_open_button_and_recorded_sample_name_container->set_layout(make<GUI::HorizontalBoxLayout>()); m_open_button_and_recorded_sample_name_container->set_layout(make<GUI::HorizontalBoxLayout>());
m_open_button_and_recorded_sample_name_container->layout()->set_spacing(10); m_open_button_and_recorded_sample_name_container->layout()->set_spacing(10);
m_open_button_and_recorded_sample_name_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); m_open_button_and_recorded_sample_name_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_open_button_and_recorded_sample_name_container->set_preferred_size(0, 24); m_open_button_and_recorded_sample_name_container->set_preferred_size(0, 24);
m_open_button = GUI::Button::construct(m_open_button_and_recorded_sample_name_container); m_open_button = m_open_button_and_recorded_sample_name_container->add<GUI::Button>();
m_open_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); m_open_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
m_open_button->set_preferred_size(24, 24); m_open_button->set_preferred_size(24, 24);
m_open_button->set_focusable(false); m_open_button->set_focusable(false);
@ -128,10 +126,10 @@ SamplerWidget::SamplerWidget(GUI::Widget* parent, AudioEngine& audio_engine)
m_wave_editor->update(); m_wave_editor->update();
}; };
m_recorded_sample_name = GUI::Label::construct("No sample loaded", m_open_button_and_recorded_sample_name_container); m_recorded_sample_name = m_open_button_and_recorded_sample_name_container->add<GUI::Label>("No sample loaded");
m_recorded_sample_name->set_text_alignment(Gfx::TextAlignment::CenterLeft); m_recorded_sample_name->set_text_alignment(Gfx::TextAlignment::CenterLeft);
m_wave_editor = WaveEditor::construct(this, m_audio_engine); m_wave_editor = add<WaveEditor>(m_audio_engine);
m_wave_editor->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); m_wave_editor->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_wave_editor->set_preferred_size(0, 100); m_wave_editor->set_preferred_size(0, 100);
} }

View file

@ -36,7 +36,7 @@ public:
virtual ~WaveEditor() override; virtual ~WaveEditor() override;
private: private:
WaveEditor(GUI::Widget* parent, AudioEngine&); explicit WaveEditor(AudioEngine&);
virtual void paint_event(GUI::PaintEvent&) override; virtual void paint_event(GUI::PaintEvent&) override;
@ -51,7 +51,7 @@ public:
virtual ~SamplerWidget() override; virtual ~SamplerWidget() override;
private: private:
SamplerWidget(GUI::Widget* parent, AudioEngine&); explicit SamplerWidget(AudioEngine&);
AudioEngine& m_audio_engine; AudioEngine& m_audio_engine;

View file

@ -30,9 +30,8 @@
#include <LibGUI/Painter.h> #include <LibGUI/Painter.h>
#include <limits> #include <limits>
WaveWidget::WaveWidget(GUI::Widget* parent, AudioEngine& audio_engine) WaveWidget::WaveWidget(AudioEngine& audio_engine)
: GUI::Frame(parent) : m_audio_engine(audio_engine)
, m_audio_engine(audio_engine)
{ {
set_frame_thickness(2); set_frame_thickness(2);
set_frame_shadow(Gfx::FrameShadow::Sunken); set_frame_shadow(Gfx::FrameShadow::Sunken);

View file

@ -37,7 +37,7 @@ public:
virtual ~WaveWidget() override; virtual ~WaveWidget() override;
private: private:
WaveWidget(GUI::Widget* parent, AudioEngine&); explicit WaveWidget(AudioEngine&);
virtual void paint_event(GUI::PaintEvent&) override; virtual void paint_event(GUI::PaintEvent&) override;

View file

@ -29,8 +29,7 @@
#include <LibGUI/Painter.h> #include <LibGUI/Painter.h>
#include <LibM/math.h> #include <LibM/math.h>
SampleWidget::SampleWidget(GUI::Widget* parent) SampleWidget::SampleWidget()
: GUI::Frame(parent)
{ {
set_frame_shape(Gfx::FrameShape::Container); set_frame_shape(Gfx::FrameShape::Container);
set_frame_shadow(Gfx::FrameShadow::Sunken); set_frame_shadow(Gfx::FrameShadow::Sunken);

View file

@ -39,7 +39,7 @@ public:
void set_buffer(Audio::Buffer*); void set_buffer(Audio::Buffer*);
private: private:
explicit SampleWidget(GUI::Widget* parent); SampleWidget();
virtual void paint_event(GUI::PaintEvent&) override; virtual void paint_event(GUI::PaintEvent&) override;
RefPtr<Audio::Buffer> m_buffer; RefPtr<Audio::Buffer> m_buffer;

View file

@ -41,36 +41,36 @@ SoundPlayerWidget::SoundPlayerWidget(GUI::Window& window, NonnullRefPtr<Audio::C
set_layout(make<GUI::VerticalBoxLayout>()); set_layout(make<GUI::VerticalBoxLayout>());
layout()->set_margins({ 2, 2, 2, 2 }); layout()->set_margins({ 2, 2, 2, 2 });
auto status_widget = GUI::Widget::construct(this); auto status_widget = add<GUI::Widget>();
status_widget->set_fill_with_background_color(true); status_widget->set_fill_with_background_color(true);
status_widget->set_layout(make<GUI::HorizontalBoxLayout>()); status_widget->set_layout(make<GUI::HorizontalBoxLayout>());
m_elapsed = GUI::Label::construct(status_widget); m_elapsed = status_widget->add<GUI::Label>();
m_elapsed->set_frame_shape(Gfx::FrameShape::Container); m_elapsed->set_frame_shape(Gfx::FrameShape::Container);
m_elapsed->set_frame_shadow(Gfx::FrameShadow::Sunken); m_elapsed->set_frame_shadow(Gfx::FrameShadow::Sunken);
m_elapsed->set_frame_thickness(2); m_elapsed->set_frame_thickness(2);
m_elapsed->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); m_elapsed->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
m_elapsed->set_preferred_size(80, 0); m_elapsed->set_preferred_size(80, 0);
auto sample_widget_container = GUI::Widget::construct(status_widget.ptr()); auto sample_widget_container = status_widget->add<GUI::Widget>();
sample_widget_container->set_layout(make<GUI::HorizontalBoxLayout>()); sample_widget_container->set_layout(make<GUI::HorizontalBoxLayout>());
sample_widget_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill); sample_widget_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill);
m_sample_widget = SampleWidget::construct(sample_widget_container); m_sample_widget = sample_widget_container->add<SampleWidget>();
m_remaining = GUI::Label::construct(status_widget); m_remaining = status_widget->add<GUI::Label>();
m_remaining->set_frame_shape(Gfx::FrameShape::Container); m_remaining->set_frame_shape(Gfx::FrameShape::Container);
m_remaining->set_frame_shadow(Gfx::FrameShadow::Sunken); m_remaining->set_frame_shadow(Gfx::FrameShadow::Sunken);
m_remaining->set_frame_thickness(2); m_remaining->set_frame_thickness(2);
m_remaining->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); m_remaining->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
m_remaining->set_preferred_size(80, 0); m_remaining->set_preferred_size(80, 0);
m_slider = Slider::construct(Orientation::Horizontal, this); m_slider = add<Slider>(Orientation::Horizontal);
m_slider->set_min(0); m_slider->set_min(0);
m_slider->set_enabled(false); m_slider->set_enabled(false);
m_slider->on_knob_released = [&](int value) { m_manager.seek(denormalize_rate(value)); }; m_slider->on_knob_released = [&](int value) { m_manager.seek(denormalize_rate(value)); };
auto control_widget = GUI::Widget::construct(this); auto control_widget = add<GUI::Widget>();
control_widget->set_fill_with_background_color(true); control_widget->set_fill_with_background_color(true);
control_widget->set_layout(make<GUI::HorizontalBoxLayout>()); control_widget->set_layout(make<GUI::HorizontalBoxLayout>());
control_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); control_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
@ -78,19 +78,19 @@ SoundPlayerWidget::SoundPlayerWidget(GUI::Window& window, NonnullRefPtr<Audio::C
control_widget->layout()->set_margins({ 10, 2, 10, 2 }); control_widget->layout()->set_margins({ 10, 2, 10, 2 });
control_widget->layout()->set_spacing(10); control_widget->layout()->set_spacing(10);
m_play = GUI::Button::construct(control_widget); m_play = control_widget->add<GUI::Button>();
m_play->set_icon(*m_pause_icon); m_play->set_icon(*m_pause_icon);
m_play->set_enabled(false); m_play->set_enabled(false);
m_play->on_click = [this](GUI::Button& button) { m_play->on_click = [this](GUI::Button& button) {
button.set_icon(m_manager.toggle_pause() ? *m_play_icon : *m_pause_icon); button.set_icon(m_manager.toggle_pause() ? *m_play_icon : *m_pause_icon);
}; };
m_stop = GUI::Button::construct(control_widget); m_stop = control_widget->add<GUI::Button>();
m_stop->set_enabled(false); m_stop->set_enabled(false);
m_stop->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/stop.png")); m_stop->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/stop.png"));
m_stop->on_click = [&](GUI::Button&) { m_manager.stop(); }; m_stop->on_click = [&](GUI::Button&) { m_manager.stop(); };
m_status = GUI::Label::construct(this); m_status = add<GUI::Label>();
m_status->set_frame_shape(Gfx::FrameShape::Box); m_status->set_frame_shape(Gfx::FrameShape::Box);
m_status->set_frame_shadow(Gfx::FrameShadow::Raised); m_status->set_frame_shadow(Gfx::FrameShadow::Raised);
m_status->set_frame_thickness(4); m_status->set_frame_thickness(4);

View file

@ -62,8 +62,8 @@ private:
} }
protected: protected:
Slider(Orientation orientation, GUI::Widget* parent) Slider(Orientation orientation)
: GUI::Slider(orientation, parent) : GUI::Slider(orientation)
{ {
} }

View file

@ -28,8 +28,7 @@
#include <LibGUI/Painter.h> #include <LibGUI/Painter.h>
#include <LibGfx/Font.h> #include <LibGfx/Font.h>
GraphWidget::GraphWidget(GUI::Widget* parent) GraphWidget::GraphWidget()
: GUI::Frame(parent)
{ {
set_frame_thickness(2); set_frame_thickness(2);
set_frame_shape(Gfx::FrameShape::Container); set_frame_shape(Gfx::FrameShape::Container);

View file

@ -41,7 +41,7 @@ public:
Function<String(int value, int max)> text_formatter; Function<String(int value, int max)> text_formatter;
private: private:
explicit GraphWidget(GUI::Widget* parent); explicit GraphWidget();
virtual void paint_event(GUI::PaintEvent&) override; virtual void paint_event(GUI::PaintEvent&) override;

View file

@ -43,9 +43,8 @@ MemoryStatsWidget* MemoryStatsWidget::the()
return s_the; return s_the;
} }
MemoryStatsWidget::MemoryStatsWidget(GraphWidget& graph, GUI::Widget* parent) MemoryStatsWidget::MemoryStatsWidget(GraphWidget& graph)
: GUI::Widget(parent) : m_graph(graph)
, m_graph(graph)
{ {
ASSERT(!s_the); ASSERT(!s_the);
s_the = this; s_the = this;
@ -58,14 +57,14 @@ MemoryStatsWidget::MemoryStatsWidget(GraphWidget& graph, GUI::Widget* parent)
layout()->set_spacing(3); layout()->set_spacing(3);
auto build_widgets_for_label = [this](const String& description) -> RefPtr<GUI::Label> { auto build_widgets_for_label = [this](const String& description) -> RefPtr<GUI::Label> {
auto container = GUI::Widget::construct(this); auto container = add<GUI::Widget>();
container->set_layout(make<GUI::HorizontalBoxLayout>()); container->set_layout(make<GUI::HorizontalBoxLayout>());
container->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); container->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
container->set_preferred_size(275, 12); container->set_preferred_size(275, 12);
auto description_label = GUI::Label::construct(description, container); auto description_label = container->add<GUI::Label>(description);
description_label->set_font(Gfx::Font::default_bold_font()); description_label->set_font(Gfx::Font::default_bold_font());
description_label->set_text_alignment(Gfx::TextAlignment::CenterLeft); description_label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
auto label = GUI::Label::construct(container); auto label = container->add<GUI::Label>();
label->set_text_alignment(Gfx::TextAlignment::CenterRight); label->set_text_alignment(Gfx::TextAlignment::CenterRight);
return label; return label;
}; };

View file

@ -40,7 +40,7 @@ public:
void refresh(); void refresh();
private: private:
MemoryStatsWidget(GraphWidget& graph, GUI::Widget* parent); MemoryStatsWidget(GraphWidget& graph);
GraphWidget& m_graph; GraphWidget& m_graph;
RefPtr<GUI::Label> m_user_physical_pages_label; RefPtr<GUI::Label> m_user_physical_pages_label;

View file

@ -38,13 +38,13 @@ NetworkStatisticsWidget::NetworkStatisticsWidget(GUI::Widget* parent)
layout()->set_margins({ 4, 4, 4, 4 }); layout()->set_margins({ 4, 4, 4, 4 });
set_fill_with_background_color(true); set_fill_with_background_color(true);
auto adapters_group_box = GUI::GroupBox::construct("Adapters", this); auto adapters_group_box = add<GUI::GroupBox>("Adapters");
adapters_group_box->set_layout(make<GUI::VerticalBoxLayout>()); adapters_group_box->set_layout(make<GUI::VerticalBoxLayout>());
adapters_group_box->layout()->set_margins({ 6, 16, 6, 6 }); adapters_group_box->layout()->set_margins({ 6, 16, 6, 6 });
adapters_group_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); adapters_group_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
adapters_group_box->set_preferred_size(0, 120); adapters_group_box->set_preferred_size(0, 120);
m_adapter_table_view = GUI::TableView::construct(adapters_group_box); m_adapter_table_view = adapters_group_box->add<GUI::TableView>();
m_adapter_table_view->set_size_columns_to_fit_content(true); m_adapter_table_view->set_size_columns_to_fit_content(true);
Vector<GUI::JsonArrayModel::FieldSpec> net_adapters_fields; Vector<GUI::JsonArrayModel::FieldSpec> net_adapters_fields;
@ -58,13 +58,13 @@ NetworkStatisticsWidget::NetworkStatisticsWidget(GUI::Widget* parent)
net_adapters_fields.empend("bytes_out", "Bytes Out", Gfx::TextAlignment::CenterRight); net_adapters_fields.empend("bytes_out", "Bytes Out", Gfx::TextAlignment::CenterRight);
m_adapter_table_view->set_model(GUI::JsonArrayModel::create("/proc/net/adapters", move(net_adapters_fields))); m_adapter_table_view->set_model(GUI::JsonArrayModel::create("/proc/net/adapters", move(net_adapters_fields)));
auto sockets_group_box = GUI::GroupBox::construct("Sockets", this); auto sockets_group_box = add<GUI::GroupBox>("Sockets");
sockets_group_box->set_layout(make<GUI::VerticalBoxLayout>()); sockets_group_box->set_layout(make<GUI::VerticalBoxLayout>());
sockets_group_box->layout()->set_margins({ 6, 16, 6, 6 }); sockets_group_box->layout()->set_margins({ 6, 16, 6, 6 });
sockets_group_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill); sockets_group_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill);
sockets_group_box->set_preferred_size(0, 0); sockets_group_box->set_preferred_size(0, 0);
m_socket_table_view = GUI::TableView::construct(sockets_group_box); m_socket_table_view = sockets_group_box->add<GUI::TableView>();
m_socket_table_view->set_size_columns_to_fit_content(true); m_socket_table_view->set_size_columns_to_fit_content(true);
Vector<GUI::JsonArrayModel::FieldSpec> net_tcp_fields; Vector<GUI::JsonArrayModel::FieldSpec> net_tcp_fields;
@ -81,11 +81,10 @@ NetworkStatisticsWidget::NetworkStatisticsWidget(GUI::Widget* parent)
net_tcp_fields.empend("bytes_out", "Bytes Out", Gfx::TextAlignment::CenterRight); net_tcp_fields.empend("bytes_out", "Bytes Out", Gfx::TextAlignment::CenterRight);
m_socket_table_view->set_model(GUI::JsonArrayModel::create("/proc/net/tcp", move(net_tcp_fields))); m_socket_table_view->set_model(GUI::JsonArrayModel::create("/proc/net/tcp", move(net_tcp_fields)));
m_update_timer = Core::Timer::construct( m_update_timer = add<Core::Timer>(
1000, [this] { 1000, [this] {
update_models(); update_models();
}, });
this);
update_models(); update_models();
}; };

View file

@ -36,7 +36,7 @@ ProcessMemoryMapWidget::ProcessMemoryMapWidget(GUI::Widget* parent)
{ {
set_layout(make<GUI::VerticalBoxLayout>()); set_layout(make<GUI::VerticalBoxLayout>());
layout()->set_margins({ 4, 4, 4, 4 }); layout()->set_margins({ 4, 4, 4, 4 });
m_table_view = GUI::TableView::construct(this); m_table_view = add<GUI::TableView>();
m_table_view->set_size_columns_to_fit_content(true); m_table_view->set_size_columns_to_fit_content(true);
Vector<GUI::JsonArrayModel::FieldSpec> pid_vm_fields; Vector<GUI::JsonArrayModel::FieldSpec> pid_vm_fields;
pid_vm_fields.empend("Address", Gfx::TextAlignment::CenterLeft, [](auto& object) { pid_vm_fields.empend("Address", Gfx::TextAlignment::CenterLeft, [](auto& object) {
@ -73,7 +73,7 @@ ProcessMemoryMapWidget::ProcessMemoryMapWidget(GUI::Widget* parent)
m_json_model = GUI::JsonArrayModel::create({}, move(pid_vm_fields)); m_json_model = GUI::JsonArrayModel::create({}, move(pid_vm_fields));
m_table_view->set_model(GUI::SortingProxyModel::create(*m_json_model)); m_table_view->set_model(GUI::SortingProxyModel::create(*m_json_model));
m_table_view->model()->set_key_column_and_sort_order(0, GUI::SortOrder::Ascending); m_table_view->model()->set_key_column_and_sort_order(0, GUI::SortOrder::Ascending);
m_timer = Core::Timer::construct(1000, [this] { refresh(); }, this); m_timer = add<Core::Timer>(1000, [this] { refresh(); });
} }
ProcessMemoryMapWidget::~ProcessMemoryMapWidget() ProcessMemoryMapWidget::~ProcessMemoryMapWidget()

View file

@ -35,10 +35,10 @@ ProcessStacksWidget::ProcessStacksWidget(GUI::Widget* parent)
{ {
set_layout(make<GUI::VerticalBoxLayout>()); set_layout(make<GUI::VerticalBoxLayout>());
layout()->set_margins({ 4, 4, 4, 4 }); layout()->set_margins({ 4, 4, 4, 4 });
m_stacks_editor = GUI::TextEditor::construct(GUI::TextEditor::Type::MultiLine, this); m_stacks_editor = add<GUI::TextEditor>();
m_stacks_editor->set_readonly(true); m_stacks_editor->set_readonly(true);
m_timer = Core::Timer::construct(1000, [this] { refresh(); }, this); m_timer = add<Core::Timer>(1000, [this] { refresh(); });
} }
ProcessStacksWidget::~ProcessStacksWidget() ProcessStacksWidget::~ProcessStacksWidget()

View file

@ -121,12 +121,12 @@ int main(int argc, char** argv)
keeper->set_fill_with_background_color(true); keeper->set_fill_with_background_color(true);
keeper->layout()->set_margins({ 4, 4, 4, 4 }); keeper->layout()->set_margins({ 4, 4, 4, 4 });
auto tabwidget = GUI::TabWidget::construct(keeper); auto tabwidget = keeper->add<GUI::TabWidget>();
auto process_container_splitter = GUI::VerticalSplitter::construct(nullptr); auto process_container_splitter = GUI::VerticalSplitter::construct(nullptr);
tabwidget->add_widget("Processes", process_container_splitter); tabwidget->add_widget("Processes", process_container_splitter);
auto process_table_container = GUI::Widget::construct(process_container_splitter.ptr()); auto process_table_container = process_container_splitter->add<GUI::Widget>();
tabwidget->add_widget("Graphs", build_graphs_tab()); tabwidget->add_widget("Graphs", build_graphs_tab());
@ -143,17 +143,16 @@ int main(int argc, char** argv)
process_table_container->layout()->set_margins({ 4, 0, 4, 0 }); process_table_container->layout()->set_margins({ 4, 0, 4, 0 });
process_table_container->layout()->set_spacing(0); process_table_container->layout()->set_spacing(0);
auto toolbar = GUI::ToolBar::construct(process_table_container); auto toolbar = process_table_container->add<GUI::ToolBar>();
toolbar->set_has_frame(false); toolbar->set_has_frame(false);
auto process_table_view = ProcessTableView::construct(process_table_container); auto process_table_view = process_table_container->add<ProcessTableView>();
auto refresh_timer = Core::Timer::construct( auto refresh_timer = window->add<Core::Timer>(
1000, [&] { 1000, [&] {
process_table_view->refresh(); process_table_view->refresh();
if (auto* memory_stats_widget = MemoryStatsWidget::the()) if (auto* memory_stats_widget = MemoryStatsWidget::the())
memory_stats_widget->refresh(); memory_stats_widget->refresh();
}, });
window);
auto kill_action = GUI::Action::create("Kill process", { Mod_Ctrl, Key_K }, Gfx::Bitmap::load_from_file("/res/icons/kill16.png"), [process_table_view](const GUI::Action&) { auto kill_action = GUI::Action::create("Kill process", { Mod_Ctrl, Key_K }, Gfx::Bitmap::load_from_file("/res/icons/kill16.png"), [process_table_view](const GUI::Action&) {
pid_t pid = process_table_view->selected_pid(); pid_t pid = process_table_view->selected_pid();
@ -231,7 +230,7 @@ int main(int argc, char** argv)
app.set_menubar(move(menubar)); app.set_menubar(move(menubar));
auto process_tab_widget = GUI::TabWidget::construct(process_container_splitter); auto process_tab_widget = process_container_splitter->add<GUI::TabWidget>();
auto memory_map_widget = ProcessMemoryMapWidget::construct(nullptr); auto memory_map_widget = ProcessMemoryMapWidget::construct(nullptr);
process_tab_widget->add_widget("Memory map", memory_map_widget); process_tab_widget->add_widget("Memory map", memory_map_widget);
@ -281,10 +280,10 @@ RefPtr<GUI::Widget> build_file_systems_tab()
{ {
auto fs_widget = GUI::LazyWidget::construct(); auto fs_widget = GUI::LazyWidget::construct();
fs_widget->on_first_show = [](auto& self) { fs_widget->on_first_show = [](GUI::LazyWidget& self) {
self.set_layout(make<GUI::VerticalBoxLayout>()); self.set_layout(make<GUI::VerticalBoxLayout>());
self.layout()->set_margins({ 4, 4, 4, 4 }); self.layout()->set_margins({ 4, 4, 4, 4 });
auto fs_table_view = GUI::TableView::construct(&self); auto fs_table_view = self.add<GUI::TableView>();
fs_table_view->set_size_columns_to_fit_content(true); fs_table_view->set_size_columns_to_fit_content(true);
Vector<GUI::JsonArrayModel::FieldSpec> df_fields; Vector<GUI::JsonArrayModel::FieldSpec> df_fields;
@ -374,10 +373,10 @@ RefPtr<GUI::Widget> build_pci_devices_tab()
{ {
auto pci_widget = GUI::LazyWidget::construct(); auto pci_widget = GUI::LazyWidget::construct();
pci_widget->on_first_show = [](auto& self) { pci_widget->on_first_show = [](GUI::LazyWidget& self) {
self.set_layout(make<GUI::VerticalBoxLayout>()); self.set_layout(make<GUI::VerticalBoxLayout>());
self.layout()->set_margins({ 4, 4, 4, 4 }); self.layout()->set_margins({ 4, 4, 4, 4 });
auto pci_table_view = GUI::TableView::construct(&self); auto pci_table_view = self.add<GUI::TableView>();
pci_table_view->set_size_columns_to_fit_content(true); pci_table_view->set_size_columns_to_fit_content(true);
auto db = PCIDB::Database::open(); auto db = PCIDB::Database::open();
@ -432,11 +431,11 @@ RefPtr<GUI::Widget> build_devices_tab()
{ {
auto devices_widget = GUI::LazyWidget::construct(); auto devices_widget = GUI::LazyWidget::construct();
devices_widget->on_first_show = [](auto& self) { devices_widget->on_first_show = [](GUI::LazyWidget& self) {
self.set_layout(make<GUI::VerticalBoxLayout>()); self.set_layout(make<GUI::VerticalBoxLayout>());
self.layout()->set_margins({ 4, 4, 4, 4 }); self.layout()->set_margins({ 4, 4, 4, 4 });
auto devices_table_view = GUI::TableView::construct(&self); auto devices_table_view = self.add<GUI::TableView>();
devices_table_view->set_size_columns_to_fit_content(true); devices_table_view->set_size_columns_to_fit_content(true);
devices_table_view->set_model(GUI::SortingProxyModel::create(DevicesModel::create())); devices_table_view->set_model(GUI::SortingProxyModel::create(DevicesModel::create()));
devices_table_view->model()->update(); devices_table_view->model()->update();
@ -449,18 +448,18 @@ NonnullRefPtr<GUI::Widget> build_graphs_tab()
{ {
auto graphs_container = GUI::LazyWidget::construct(); auto graphs_container = GUI::LazyWidget::construct();
graphs_container->on_first_show = [](auto& self) { graphs_container->on_first_show = [](GUI::LazyWidget& self) {
self.set_fill_with_background_color(true); self.set_fill_with_background_color(true);
self.set_background_role(ColorRole::Button); self.set_background_role(ColorRole::Button);
self.set_layout(make<GUI::VerticalBoxLayout>()); self.set_layout(make<GUI::VerticalBoxLayout>());
self.layout()->set_margins({ 4, 4, 4, 4 }); self.layout()->set_margins({ 4, 4, 4, 4 });
auto cpu_graph_group_box = GUI::GroupBox::construct("CPU usage", &self); auto cpu_graph_group_box = self.add<GUI::GroupBox>("CPU usage");
cpu_graph_group_box->set_layout(make<GUI::VerticalBoxLayout>()); cpu_graph_group_box->set_layout(make<GUI::VerticalBoxLayout>());
cpu_graph_group_box->layout()->set_margins({ 6, 16, 6, 6 }); cpu_graph_group_box->layout()->set_margins({ 6, 16, 6, 6 });
cpu_graph_group_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); cpu_graph_group_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
cpu_graph_group_box->set_preferred_size(0, 120); cpu_graph_group_box->set_preferred_size(0, 120);
auto cpu_graph = GraphWidget::construct(cpu_graph_group_box); auto cpu_graph = cpu_graph_group_box->add<GraphWidget>();
cpu_graph->set_max(100); cpu_graph->set_max(100);
cpu_graph->set_text_color(Color::Green); cpu_graph->set_text_color(Color::Green);
cpu_graph->set_graph_color(Color::from_rgb(0x00bb00)); cpu_graph->set_graph_color(Color::from_rgb(0x00bb00));
@ -472,19 +471,19 @@ NonnullRefPtr<GUI::Widget> build_graphs_tab()
graph->add_value(cpu_percent); graph->add_value(cpu_percent);
}; };
auto memory_graph_group_box = GUI::GroupBox::construct("Memory usage", &self); auto memory_graph_group_box = self.add<GUI::GroupBox>("Memory usage");
memory_graph_group_box->set_layout(make<GUI::VerticalBoxLayout>()); memory_graph_group_box->set_layout(make<GUI::VerticalBoxLayout>());
memory_graph_group_box->layout()->set_margins({ 6, 16, 6, 6 }); memory_graph_group_box->layout()->set_margins({ 6, 16, 6, 6 });
memory_graph_group_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); memory_graph_group_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
memory_graph_group_box->set_preferred_size(0, 120); memory_graph_group_box->set_preferred_size(0, 120);
auto memory_graph = GraphWidget::construct(memory_graph_group_box); auto memory_graph = memory_graph_group_box->add<GraphWidget>();
memory_graph->set_text_color(Color::Cyan); memory_graph->set_text_color(Color::Cyan);
memory_graph->set_graph_color(Color::from_rgb(0x00bbbb)); memory_graph->set_graph_color(Color::from_rgb(0x00bbbb));
memory_graph->text_formatter = [](int value, int max) { memory_graph->text_formatter = [](int value, int max) {
return String::format("%d / %d KB", value, max); return String::format("%d / %d KB", value, max);
}; };
auto memory_stats_widget = MemoryStatsWidget::construct(*memory_graph, &self); auto memory_stats_widget = self.add<MemoryStatsWidget>(*memory_graph);
}; };
return graphs_container; return graphs_container;
} }

View file

@ -28,9 +28,8 @@
#include <LibGUI/Action.h> #include <LibGUI/Action.h>
#include <LibGUI/WindowServerConnection.h> #include <LibGUI/WindowServerConnection.h>
TaskbarButton::TaskbarButton(const WindowIdentifier& identifier, GUI::Widget* parent) TaskbarButton::TaskbarButton(const WindowIdentifier& identifier)
: GUI::Button(parent) : m_identifier(identifier)
, m_identifier(identifier)
{ {
} }

View file

@ -32,10 +32,11 @@
class TaskbarButton final : public GUI::Button { class TaskbarButton final : public GUI::Button {
C_OBJECT(TaskbarButton) C_OBJECT(TaskbarButton)
public: public:
TaskbarButton(const WindowIdentifier&, GUI::Widget* parent);
virtual ~TaskbarButton() override; virtual ~TaskbarButton() override;
private: private:
explicit TaskbarButton(const WindowIdentifier&);
virtual void context_menu_event(GUI::ContextMenuEvent&) override; virtual void context_menu_event(GUI::ContextMenuEvent&) override;
virtual void resize_event(GUI::ResizeEvent&) override; virtual void resize_event(GUI::ResizeEvent&) override;

View file

@ -69,7 +69,7 @@ TaskbarWindow::~TaskbarWindow()
void TaskbarWindow::create_quick_launch_bar() void TaskbarWindow::create_quick_launch_bar()
{ {
auto quick_launch_bar = GUI::Frame::construct(main_widget()); auto quick_launch_bar = main_widget()->add<GUI::Frame>();
quick_launch_bar->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); quick_launch_bar->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
quick_launch_bar->set_layout(make<GUI::HorizontalBoxLayout>()); quick_launch_bar->set_layout(make<GUI::HorizontalBoxLayout>());
quick_launch_bar->layout()->set_spacing(3); quick_launch_bar->layout()->set_spacing(3);
@ -93,7 +93,7 @@ void TaskbarWindow::create_quick_launch_bar()
auto app_executable = af->read_entry("App", "Executable"); auto app_executable = af->read_entry("App", "Executable");
auto app_icon_path = af->read_entry("Icons", "16x16"); auto app_icon_path = af->read_entry("Icons", "16x16");
auto button = GUI::Button::construct(quick_launch_bar); auto button = quick_launch_bar->add<GUI::Button>();
button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
button->set_preferred_size(22, 22); button->set_preferred_size(22, 22);
button->set_button_style(Gfx::ButtonStyle::CoolBar); button->set_button_style(Gfx::ButtonStyle::CoolBar);
@ -129,7 +129,7 @@ void TaskbarWindow::on_screen_rect_change(const Gfx::Rect& rect)
NonnullRefPtr<GUI::Button> TaskbarWindow::create_button(const WindowIdentifier& identifier) NonnullRefPtr<GUI::Button> TaskbarWindow::create_button(const WindowIdentifier& identifier)
{ {
auto button = TaskbarButton::construct(identifier, main_widget()); auto button = main_widget()->add<TaskbarButton>(identifier);
button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
button->set_preferred_size(140, 22); button->set_preferred_size(140, 22);
button->set_checkable(true); button->set_checkable(true);

View file

@ -140,26 +140,26 @@ RefPtr<GUI::Window> create_settings_window(TerminalWidget& terminal)
settings->set_layout(make<GUI::VerticalBoxLayout>()); settings->set_layout(make<GUI::VerticalBoxLayout>());
settings->layout()->set_margins({ 4, 4, 4, 4 }); settings->layout()->set_margins({ 4, 4, 4, 4 });
auto radio_container = GUI::GroupBox::construct("Bell Mode", settings); auto radio_container = settings->add<GUI::GroupBox>("Bell Mode");
radio_container->set_layout(make<GUI::VerticalBoxLayout>()); radio_container->set_layout(make<GUI::VerticalBoxLayout>());
radio_container->layout()->set_margins({ 6, 16, 6, 6 }); radio_container->layout()->set_margins({ 6, 16, 6, 6 });
radio_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); radio_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
radio_container->set_preferred_size(100, 70); radio_container->set_preferred_size(100, 70);
auto sysbell_radio = GUI::RadioButton::construct("Use (Audible) System Bell", radio_container); auto sysbell_radio = radio_container->add<GUI::RadioButton>("Use (Audible) System Bell");
auto visbell_radio = GUI::RadioButton::construct("Use (Visual) Terminal Bell", radio_container); auto visbell_radio = radio_container->add<GUI::RadioButton>("Use (Visual) Terminal Bell");
sysbell_radio->set_checked(terminal.should_beep()); sysbell_radio->set_checked(terminal.should_beep());
visbell_radio->set_checked(!terminal.should_beep()); visbell_radio->set_checked(!terminal.should_beep());
sysbell_radio->on_checked = [&terminal](const bool checked) { sysbell_radio->on_checked = [&terminal](const bool checked) {
terminal.set_should_beep(checked); terminal.set_should_beep(checked);
}; };
auto slider_container = GUI::GroupBox::construct("Background Opacity", settings); auto slider_container = settings->add<GUI::GroupBox>("Background Opacity");
slider_container->set_layout(make<GUI::VerticalBoxLayout>()); slider_container->set_layout(make<GUI::VerticalBoxLayout>());
slider_container->layout()->set_margins({ 6, 16, 6, 6 }); slider_container->layout()->set_margins({ 6, 16, 6, 6 });
slider_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); slider_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
slider_container->set_preferred_size(100, 50); slider_container->set_preferred_size(100, 50);
auto slider = GUI::HorizontalSlider::construct(slider_container); auto slider = slider_container->add<GUI::HorizontalSlider>();
slider->on_value_changed = [&terminal](int value) { slider->on_value_changed = [&terminal](int value) {
terminal.set_opacity(value); terminal.set_opacity(value);

View file

@ -51,8 +51,8 @@ TextEditorWidget::TextEditorWidget()
set_layout(make<GUI::VerticalBoxLayout>()); set_layout(make<GUI::VerticalBoxLayout>());
layout()->set_spacing(0); layout()->set_spacing(0);
auto toolbar = GUI::ToolBar::construct(this); auto toolbar = add<GUI::ToolBar>();
m_editor = GUI::TextEditor::construct(GUI::TextEditor::MultiLine, this); m_editor = add<GUI::TextEditor>();
m_editor->set_ruler_visible(true); m_editor->set_ruler_visible(true);
m_editor->set_automatic_indentation_enabled(true); m_editor->set_automatic_indentation_enabled(true);
m_editor->set_line_wrapping_enabled(true); m_editor->set_line_wrapping_enabled(true);
@ -70,7 +70,7 @@ TextEditorWidget::TextEditorWidget()
update_title(); update_title();
}; };
m_find_replace_widget = GUI::Widget::construct(this); m_find_replace_widget = add<GUI::Widget>();
m_find_replace_widget->set_fill_with_background_color(true); m_find_replace_widget->set_fill_with_background_color(true);
m_find_replace_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); m_find_replace_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_find_replace_widget->set_preferred_size(0, 48); m_find_replace_widget->set_preferred_size(0, 48);
@ -78,22 +78,22 @@ TextEditorWidget::TextEditorWidget()
m_find_replace_widget->layout()->set_margins({ 2, 2, 2, 4 }); m_find_replace_widget->layout()->set_margins({ 2, 2, 2, 4 });
m_find_replace_widget->set_visible(false); m_find_replace_widget->set_visible(false);
m_find_widget = GUI::Widget::construct(m_find_replace_widget); m_find_widget = m_find_replace_widget->add<GUI::Widget>();
m_find_widget->set_fill_with_background_color(true); m_find_widget->set_fill_with_background_color(true);
m_find_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); m_find_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_find_widget->set_preferred_size(0, 22); m_find_widget->set_preferred_size(0, 22);
m_find_widget->set_layout(make<GUI::HorizontalBoxLayout>()); m_find_widget->set_layout(make<GUI::HorizontalBoxLayout>());
m_find_widget->set_visible(false); m_find_widget->set_visible(false);
m_replace_widget = GUI::Widget::construct(m_find_replace_widget); m_replace_widget = m_find_replace_widget->add<GUI::Widget>();
m_replace_widget->set_fill_with_background_color(true); m_replace_widget->set_fill_with_background_color(true);
m_replace_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); m_replace_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_replace_widget->set_preferred_size(0, 22); m_replace_widget->set_preferred_size(0, 22);
m_replace_widget->set_layout(make<GUI::HorizontalBoxLayout>()); m_replace_widget->set_layout(make<GUI::HorizontalBoxLayout>());
m_replace_widget->set_visible(false); m_replace_widget->set_visible(false);
m_find_textbox = GUI::TextBox::construct(m_find_widget); m_find_textbox = m_find_widget->add<GUI::TextBox>();
m_replace_textbox = GUI::TextBox::construct(m_replace_widget); m_replace_textbox = m_replace_widget->add<GUI::TextBox>();
m_find_next_action = GUI::Action::create("Find next", { Mod_Ctrl, Key_G }, [&](auto&) { m_find_next_action = GUI::Action::create("Find next", { Mod_Ctrl, Key_G }, [&](auto&) {
auto needle = m_find_textbox->text(); auto needle = m_find_textbox->text();
@ -202,12 +202,12 @@ TextEditorWidget::TextEditorWidget()
} }
}); });
m_find_previous_button = GUI::Button::construct("Find previous", m_find_widget); m_find_previous_button = m_find_widget->add<GUI::Button>("Find previous");
m_find_previous_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); m_find_previous_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
m_find_previous_button->set_preferred_size(150, 0); m_find_previous_button->set_preferred_size(150, 0);
m_find_previous_button->set_action(*m_find_previous_action); m_find_previous_button->set_action(*m_find_previous_action);
m_find_next_button = GUI::Button::construct("Find next", m_find_widget); m_find_next_button = m_find_widget->add<GUI::Button>("Find next");
m_find_next_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); m_find_next_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
m_find_next_button->set_preferred_size(150, 0); m_find_next_button->set_preferred_size(150, 0);
m_find_next_button->set_action(*m_find_next_action); m_find_next_button->set_action(*m_find_next_action);
@ -221,17 +221,17 @@ TextEditorWidget::TextEditorWidget()
m_editor->set_focus(true); m_editor->set_focus(true);
}; };
m_replace_previous_button = GUI::Button::construct("Replace previous", m_replace_widget); m_replace_previous_button = m_replace_widget->add<GUI::Button>("Replace previous");
m_replace_previous_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); m_replace_previous_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
m_replace_previous_button->set_preferred_size(100, 0); m_replace_previous_button->set_preferred_size(100, 0);
m_replace_previous_button->set_action(*m_replace_previous_action); m_replace_previous_button->set_action(*m_replace_previous_action);
m_replace_next_button = GUI::Button::construct("Replace next", m_replace_widget); m_replace_next_button = m_replace_widget->add<GUI::Button>("Replace next");
m_replace_next_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); m_replace_next_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
m_replace_next_button->set_preferred_size(100, 0); m_replace_next_button->set_preferred_size(100, 0);
m_replace_next_button->set_action(*m_replace_next_action); m_replace_next_button->set_action(*m_replace_next_action);
m_replace_all_button = GUI::Button::construct("Replace all", m_replace_widget); m_replace_all_button = m_replace_widget->add<GUI::Button>("Replace all");
m_replace_all_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); m_replace_all_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
m_replace_all_button->set_preferred_size(100, 0); m_replace_all_button->set_preferred_size(100, 0);
m_replace_all_button->set_action(*m_replace_all_action); m_replace_all_button->set_action(*m_replace_all_action);
@ -262,7 +262,7 @@ TextEditorWidget::TextEditorWidget()
m_editor->add_custom_context_menu_action(*m_find_next_action); m_editor->add_custom_context_menu_action(*m_find_next_action);
m_editor->add_custom_context_menu_action(*m_find_previous_action); m_editor->add_custom_context_menu_action(*m_find_previous_action);
m_statusbar = GUI::StatusBar::construct(this); m_statusbar = add<GUI::StatusBar>();
m_editor->on_cursor_change = [this] { m_editor->on_cursor_change = [this] {
StringBuilder builder; StringBuilder builder;
@ -272,7 +272,7 @@ TextEditorWidget::TextEditorWidget()
m_new_action = GUI::Action::create("New", { Mod_Ctrl, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"), [this](const GUI::Action&) { m_new_action = GUI::Action::create("New", { Mod_Ctrl, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"), [this](const GUI::Action&) {
if (m_document_dirty) { if (m_document_dirty) {
auto save_document_first_result = GUI::MessageBox::construct("Save Document First?", "Warning", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNoCancel, window())->exec(); auto save_document_first_result = GUI::MessageBox::show("Save Document First?", "Warning", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNoCancel);
if (save_document_first_result == GUI::Dialog::ExecResult::ExecYes) if (save_document_first_result == GUI::Dialog::ExecResult::ExecYes)
m_save_action->activate(); m_save_action->activate();
if (save_document_first_result == GUI::Dialog::ExecResult::ExecCancel) if (save_document_first_result == GUI::Dialog::ExecResult::ExecCancel)
@ -292,7 +292,7 @@ TextEditorWidget::TextEditorWidget()
return; return;
if (m_document_dirty) { if (m_document_dirty) {
auto save_document_first_result = GUI::MessageBox::construct("Save Document First?", "Warning", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNoCancel, window())->exec(); auto save_document_first_result = GUI::MessageBox::show("Save Document First?", "Warning", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNoCancel, window());
if (save_document_first_result == GUI::Dialog::ExecResult::ExecYes) if (save_document_first_result == GUI::Dialog::ExecResult::ExecYes)
m_save_action->activate(); m_save_action->activate();
if (save_document_first_result == GUI::Dialog::ExecResult::ExecCancel) if (save_document_first_result == GUI::Dialog::ExecResult::ExecCancel)

View file

@ -173,7 +173,7 @@ int main(int argc, char** argv)
// header // header
// //
auto header = GUI::Label::construct(background.ptr()); auto header = background->add<GUI::Label>();
header->set_font(Gfx::Font::load_from_file("/res/fonts/PebbletonBold11.font")); header->set_font(Gfx::Font::load_from_file("/res/fonts/PebbletonBold11.font"));
header->set_text("Welcome to SerenityOS!"); header->set_text("Welcome to SerenityOS!");
header->set_text_alignment(Gfx::TextAlignment::CenterLeft); header->set_text_alignment(Gfx::TextAlignment::CenterLeft);
@ -184,44 +184,44 @@ int main(int argc, char** argv)
// main section // main section
// //
auto main_section = GUI::Widget::construct(background.ptr()); auto main_section = background->add<GUI::Widget>();
main_section->set_layout(make<GUI::HorizontalBoxLayout>()); main_section->set_layout(make<GUI::HorizontalBoxLayout>());
main_section->layout()->set_margins({ 0, 0, 0, 0 }); main_section->layout()->set_margins({ 0, 0, 0, 0 });
main_section->layout()->set_spacing(8); main_section->layout()->set_spacing(8);
main_section->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill); main_section->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill);
auto menu = GUI::Widget::construct(main_section.ptr()); auto menu = main_section->add<GUI::Widget>();
menu->set_layout(make<GUI::VerticalBoxLayout>()); menu->set_layout(make<GUI::VerticalBoxLayout>());
menu->layout()->set_margins({ 0, 0, 0, 0 }); menu->layout()->set_margins({ 0, 0, 0, 0 });
menu->layout()->set_spacing(4); menu->layout()->set_spacing(4);
menu->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); menu->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
menu->set_preferred_size(100, 0); menu->set_preferred_size(100, 0);
auto stack = GUI::StackWidget::construct(main_section); auto stack = main_section->add<GUI::StackWidget>();
stack->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill); stack->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill);
bool first = true; bool first = true;
for (auto& page : pages) { for (auto& page : pages) {
auto content = GUI::Widget::construct(stack.ptr()); auto content = stack->add<GUI::Widget>();
content->set_layout(make<GUI::VerticalBoxLayout>()); content->set_layout(make<GUI::VerticalBoxLayout>());
content->layout()->set_margins({ 0, 0, 0, 0 }); content->layout()->set_margins({ 0, 0, 0, 0 });
content->layout()->set_spacing(8); content->layout()->set_spacing(8);
content->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill); content->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill);
auto title_box = GUI::Widget::construct(content.ptr()); auto title_box = content->add<GUI::Widget>();
title_box->set_layout(make<GUI::HorizontalBoxLayout>()); title_box->set_layout(make<GUI::HorizontalBoxLayout>());
title_box->layout()->set_spacing(4); title_box->layout()->set_spacing(4);
title_box->set_preferred_size(0, 16); title_box->set_preferred_size(0, 16);
title_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); title_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
if (!page.icon.is_empty()) { if (!page.icon.is_empty()) {
auto icon = GUI::Label::construct(title_box); auto icon = title_box->add<GUI::Label>();
icon->set_icon(Gfx::Bitmap::load_from_file(page.icon)); icon->set_icon(Gfx::Bitmap::load_from_file(page.icon));
icon->set_preferred_size(16, 16); icon->set_preferred_size(16, 16);
icon->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); icon->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
} }
auto content_title = GUI::Label::construct(title_box); auto content_title = title_box->add<GUI::Label>();
content_title->set_font(Gfx::Font::default_bold_font()); content_title->set_font(Gfx::Font::default_bold_font());
content_title->set_text(page.title); content_title->set_text(page.title);
content_title->set_text_alignment(Gfx::TextAlignment::CenterLeft); content_title->set_text_alignment(Gfx::TextAlignment::CenterLeft);
@ -229,7 +229,7 @@ int main(int argc, char** argv)
content_title->set_preferred_size(0, 10); content_title->set_preferred_size(0, 10);
for (auto& paragraph : page.content) { for (auto& paragraph : page.content) {
auto content_text = TextWidget::construct(content); auto content_text = content->add<TextWidget>();
content_text->set_font(Gfx::Font::default_font()); content_text->set_font(Gfx::Font::default_font());
content_text->set_text(paragraph); content_text->set_text(paragraph);
content_text->set_text_alignment(Gfx::TextAlignment::TopLeft); content_text->set_text_alignment(Gfx::TextAlignment::TopLeft);
@ -237,7 +237,7 @@ int main(int argc, char** argv)
content_text->wrap_and_set_height(); content_text->wrap_and_set_height();
} }
auto menu_option = UnuncheckableButton::construct(menu); auto menu_option = menu->add<UnuncheckableButton>();
menu_option->set_font(Gfx::Font::default_font()); menu_option->set_font(Gfx::Font::default_font());
menu_option->set_text(page.menu_name); menu_option->set_text(page.menu_name);
menu_option->set_text_alignment(Gfx::TextAlignment::CenterLeft); menu_option->set_text_alignment(Gfx::TextAlignment::CenterLeft);

View file

@ -96,7 +96,7 @@ public:
void set_stat_label(RefPtr<GUI::Label> l) { stats = l; }; void set_stat_label(RefPtr<GUI::Label> l) { stats = l; };
private: private:
explicit Fire(GUI::Widget* parent = nullptr); Fire();
RefPtr<Gfx::Bitmap> bitmap; RefPtr<Gfx::Bitmap> bitmap;
RefPtr<GUI::Label> stats; RefPtr<GUI::Label> stats;
@ -112,8 +112,7 @@ private:
int phase; int phase;
}; };
Fire::Fire(GUI::Widget* parent) Fire::Fire()
: GUI::Widget(parent)
{ {
bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::Indexed8, { 320, 200 }); bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::Indexed8, { 320, 200 });
@ -250,7 +249,7 @@ int main(int argc, char** argv)
auto fire = Fire::construct(); auto fire = Fire::construct();
window->set_main_widget(fire); window->set_main_widget(fire);
auto time = GUI::Label::construct(fire); auto time = fire->add<GUI::Label>();
time->set_relative_rect({ 0, 4, 40, 10 }); time->set_relative_rect({ 0, 4, 40, 10 });
time->move_by({ window->width() - time->width(), 0 }); time->move_by({ window->width() - time->width(), 0 });
time->set_foreground_color(Color::from_rgb(0x444444)); time->set_foreground_color(Color::from_rgb(0x444444));

View file

@ -46,10 +46,10 @@ int main(int argc, char** argv)
main_widget->set_layout(make<GUI::VerticalBoxLayout>()); main_widget->set_layout(make<GUI::VerticalBoxLayout>());
main_widget->layout()->set_margins({ 4, 4, 4, 4 }); main_widget->layout()->set_margins({ 4, 4, 4, 4 });
auto label = GUI::Label::construct(main_widget); auto label = main_widget->add<GUI::Label>();
label->set_text("Hello\nWorld!"); label->set_text("Hello\nWorld!");
auto button = GUI::Button::construct(main_widget); auto button = main_widget->add<GUI::Button>();
button->set_text("Good-bye"); button->set_text("Good-bye");
button->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); button->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
button->set_preferred_size(0, 20); button->set_preferred_size(0, 20);

View file

@ -54,71 +54,71 @@ int main(int argc, char** argv)
main_widget->set_layout(make<GUI::VerticalBoxLayout>()); main_widget->set_layout(make<GUI::VerticalBoxLayout>());
main_widget->layout()->set_margins({ 4, 4, 4, 4 }); main_widget->layout()->set_margins({ 4, 4, 4, 4 });
auto checkbox1 = GUI::CheckBox::construct("GCheckBox 1", main_widget); auto checkbox1 = main_widget->add<GUI::CheckBox>("GCheckBox 1");
(void)checkbox1; (void)checkbox1;
auto checkbox2 = GUI::CheckBox::construct("GCheckBox 2", main_widget); auto checkbox2 = main_widget->add<GUI::CheckBox>("GCheckBox 2");
checkbox2->set_enabled(false); checkbox2->set_enabled(false);
auto radio1 = GUI::RadioButton::construct("GRadioButton 1", main_widget); auto radio1 = main_widget->add<GUI::RadioButton>("GRadioButton 1");
(void)radio1; (void)radio1;
auto radio2 = GUI::RadioButton::construct("GRadioButton 2", main_widget); auto radio2 = main_widget->add<GUI::RadioButton>("GRadioButton 2");
radio2->set_enabled(false); radio2->set_enabled(false);
auto button1 = GUI::Button::construct("GButton 1", main_widget); auto button1 = main_widget->add<GUI::Button>("GButton 1");
(void)button1; (void)button1;
auto button2 = GUI::Button::construct("GButton 2", main_widget); auto button2 = main_widget->add<GUI::Button>("GButton 2");
button2->set_enabled(false); button2->set_enabled(false);
auto progress1 = GUI::ProgressBar::construct(main_widget); auto progress1 = main_widget->add<GUI::ProgressBar>();
auto timer = Core::Timer::construct(100, [&] { auto timer = progress1->add<Core::Timer>(100, [&] {
progress1->set_value(progress1->value() + 1); progress1->set_value(progress1->value() + 1);
if (progress1->value() == progress1->max()) if (progress1->value() == progress1->max())
progress1->set_value(progress1->min()); progress1->set_value(progress1->min());
}); });
auto label1 = GUI::Label::construct("GLabel 1", main_widget); auto label1 = main_widget->add<GUI::Label>("GLabel 1");
(void)label1; (void)label1;
auto label2 = GUI::Label::construct("GLabel 2", main_widget); auto label2 = main_widget->add<GUI::Label>("GLabel 2");
label2->set_enabled(false); label2->set_enabled(false);
auto textbox1 = GUI::TextBox::construct(main_widget); auto textbox1 = main_widget->add<GUI::TextBox>();
textbox1->set_text("GTextBox 1"); textbox1->set_text("GTextBox 1");
auto textbox2 = GUI::TextBox::construct(main_widget); auto textbox2 = main_widget->add<GUI::TextBox>();
textbox2->set_text("GTextBox 2"); textbox2->set_text("GTextBox 2");
textbox2->set_enabled(false); textbox2->set_enabled(false);
auto spinbox1 = GUI::SpinBox::construct(main_widget); auto spinbox1 = main_widget->add<GUI::SpinBox>();
(void)spinbox1; (void)spinbox1;
auto spinbox2 = GUI::SpinBox::construct(main_widget); auto spinbox2 = main_widget->add<GUI::SpinBox>();
spinbox2->set_enabled(false); spinbox2->set_enabled(false);
auto vertical_slider_container = GUI::Widget::construct(main_widget.ptr()); auto vertical_slider_container = main_widget->add<GUI::Widget>();
vertical_slider_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); vertical_slider_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
vertical_slider_container->set_preferred_size(0, 100); vertical_slider_container->set_preferred_size(0, 100);
vertical_slider_container->set_layout(make<GUI::HorizontalBoxLayout>()); vertical_slider_container->set_layout(make<GUI::HorizontalBoxLayout>());
auto vslider1 = GUI::VerticalSlider::construct(vertical_slider_container); auto vslider1 = vertical_slider_container->add<GUI::VerticalSlider>();
(void)vslider1; (void)vslider1;
auto vslider2 = GUI::VerticalSlider::construct(vertical_slider_container); auto vslider2 = vertical_slider_container->add<GUI::VerticalSlider>();
vslider2->set_enabled(false); vslider2->set_enabled(false);
auto vslider3 = GUI::VerticalSlider::construct(vertical_slider_container); auto vslider3 = vertical_slider_container->add<GUI::VerticalSlider>();
vslider3->set_max(5); vslider3->set_max(5);
vslider3->set_knob_size_mode(GUI::Slider::KnobSizeMode::Proportional); vslider3->set_knob_size_mode(GUI::Slider::KnobSizeMode::Proportional);
auto slider1 = GUI::HorizontalSlider::construct(main_widget); auto slider1 = main_widget->add<GUI::HorizontalSlider>();
(void)slider1; (void)slider1;
auto slider2 = GUI::HorizontalSlider::construct(main_widget); auto slider2 = main_widget->add<GUI::HorizontalSlider>();
slider2->set_enabled(false); slider2->set_enabled(false);
auto slider3 = GUI::HorizontalSlider::construct(main_widget); auto slider3 = main_widget->add<GUI::HorizontalSlider>();
slider3->set_max(5); slider3->set_max(5);
slider3->set_knob_size_mode(GUI::Slider::KnobSizeMode::Proportional); slider3->set_knob_size_mode(GUI::Slider::KnobSizeMode::Proportional);
auto scrollbar1 = GUI::ScrollBar::construct(Orientation::Horizontal, main_widget); auto scrollbar1 = main_widget->add<GUI::ScrollBar>(Orientation::Horizontal);
scrollbar1->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); scrollbar1->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
scrollbar1->set_preferred_size(0, 16); scrollbar1->set_preferred_size(0, 16);
scrollbar1->set_min(0); scrollbar1->set_min(0);
scrollbar1->set_max(100); scrollbar1->set_max(100);
scrollbar1->set_value(50); scrollbar1->set_value(50);
auto scrollbar2 = GUI::ScrollBar::construct(Orientation::Horizontal, main_widget); auto scrollbar2 = main_widget->add<GUI::ScrollBar>(Orientation::Horizontal);
scrollbar2->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); scrollbar2->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
scrollbar2->set_preferred_size(0, 16); scrollbar2->set_preferred_size(0, 16);
scrollbar2->set_enabled(false); scrollbar2->set_enabled(false);

View file

@ -43,14 +43,13 @@
//#define EDITOR_DEBUG //#define EDITOR_DEBUG
Editor::Editor(GUI::Widget* parent) Editor::Editor()
: TextEditor(GUI::TextEditor::MultiLine, parent)
{ {
m_documentation_tooltip_window = GUI::Window::construct(); m_documentation_tooltip_window = GUI::Window::construct();
m_documentation_tooltip_window->set_rect(0, 0, 500, 400); m_documentation_tooltip_window->set_rect(0, 0, 500, 400);
m_documentation_tooltip_window->set_window_type(GUI::WindowType::Tooltip); m_documentation_tooltip_window->set_window_type(GUI::WindowType::Tooltip);
m_documentation_html_view = HtmlView::construct(nullptr); m_documentation_html_view = HtmlView::construct();
m_documentation_tooltip_window->set_main_widget(m_documentation_html_view); m_documentation_tooltip_window->set_main_widget(m_documentation_html_view);
} }

View file

@ -49,7 +49,7 @@ private:
void show_documentation_tooltip_if_available(const String&, const Gfx::Point& screen_location); void show_documentation_tooltip_if_available(const String&, const Gfx::Point& screen_location);
explicit Editor(GUI::Widget* parent); explicit Editor();
RefPtr<GUI::Window> m_documentation_tooltip_window; RefPtr<GUI::Window> m_documentation_tooltip_window;
RefPtr<HtmlView> m_documentation_html_view; RefPtr<HtmlView> m_documentation_html_view;

View file

@ -34,29 +34,28 @@
extern RefPtr<EditorWrapper> g_current_editor_wrapper; extern RefPtr<EditorWrapper> g_current_editor_wrapper;
EditorWrapper::EditorWrapper(GUI::Widget* parent) EditorWrapper::EditorWrapper()
: GUI::Widget(parent)
{ {
set_layout(make<GUI::VerticalBoxLayout>()); set_layout(make<GUI::VerticalBoxLayout>());
auto label_wrapper = GUI::Widget::construct(this); auto label_wrapper = add<GUI::Widget>();
label_wrapper->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); label_wrapper->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
label_wrapper->set_preferred_size(0, 14); label_wrapper->set_preferred_size(0, 14);
label_wrapper->set_fill_with_background_color(true); label_wrapper->set_fill_with_background_color(true);
label_wrapper->set_layout(make<GUI::HorizontalBoxLayout>()); label_wrapper->set_layout(make<GUI::HorizontalBoxLayout>());
label_wrapper->layout()->set_margins({ 2, 0, 2, 0 }); label_wrapper->layout()->set_margins({ 2, 0, 2, 0 });
m_filename_label = GUI::Label::construct("(Untitled)", label_wrapper); m_filename_label = label_wrapper->add<GUI::Label>("(Untitled)");
m_filename_label->set_text_alignment(Gfx::TextAlignment::CenterLeft); m_filename_label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
m_filename_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); m_filename_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_filename_label->set_preferred_size(0, 14); m_filename_label->set_preferred_size(0, 14);
m_cursor_label = GUI::Label::construct("(Cursor)", label_wrapper); m_cursor_label = label_wrapper->add<GUI::Label>("(Cursor)");
m_cursor_label->set_text_alignment(Gfx::TextAlignment::CenterRight); m_cursor_label->set_text_alignment(Gfx::TextAlignment::CenterRight);
m_cursor_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); m_cursor_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_cursor_label->set_preferred_size(0, 14); m_cursor_label->set_preferred_size(0, 14);
m_editor = Editor::construct(this); m_editor = add<Editor>();
m_editor->set_ruler_visible(true); m_editor->set_ruler_visible(true);
m_editor->set_line_wrapping_enabled(true); m_editor->set_line_wrapping_enabled(true);
m_editor->set_automatic_indentation_enabled(true); m_editor->set_automatic_indentation_enabled(true);

View file

@ -43,7 +43,7 @@ public:
void set_editor_has_focus(Badge<Editor>, bool); void set_editor_has_focus(Badge<Editor>, bool);
private: private:
explicit EditorWrapper(GUI::Widget* parent = nullptr); explicit EditorWrapper();
RefPtr<GUI::Label> m_filename_label; RefPtr<GUI::Label> m_filename_label;
RefPtr<GUI::Label> m_cursor_label; RefPtr<GUI::Label> m_cursor_label;

View file

@ -127,18 +127,17 @@ static RefPtr<SearchResultsModel> find_in_files(const StringView& text)
return adopt(*new SearchResultsModel(move(matches))); return adopt(*new SearchResultsModel(move(matches)));
} }
FindInFilesWidget::FindInFilesWidget(GUI::Widget* parent) FindInFilesWidget::FindInFilesWidget()
: GUI::Widget(parent)
{ {
set_layout(make<GUI::VerticalBoxLayout>()); set_layout(make<GUI::VerticalBoxLayout>());
m_textbox = GUI::TextBox::construct(this); m_textbox = add<GUI::TextBox>();
m_textbox->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); m_textbox->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_textbox->set_preferred_size(0, 20); m_textbox->set_preferred_size(0, 20);
m_button = GUI::Button::construct("Find in files", this); m_button = add<GUI::Button>("Find in files");
m_button->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); m_button->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_button->set_preferred_size(0, 20); m_button->set_preferred_size(0, 20);
m_result_view = GUI::TableView::construct(this); m_result_view = add<GUI::TableView>();
m_result_view->set_size_columns_to_fit_content(true); m_result_view->set_size_columns_to_fit_content(true);
m_result_view->on_activation = [](auto& index) { m_result_view->on_activation = [](auto& index) {

View file

@ -36,7 +36,7 @@ public:
void focus_textbox_and_select_all(); void focus_textbox_and_select_all();
private: private:
explicit FindInFilesWidget(GUI::Widget* parent); explicit FindInFilesWidget();
RefPtr<GUI::TextBox> m_textbox; RefPtr<GUI::TextBox> m_textbox;
RefPtr<GUI::Button> m_button; RefPtr<GUI::Button> m_button;

View file

@ -30,9 +30,8 @@
#include "WidgetTreeModel.h" #include "WidgetTreeModel.h"
#include <LibGUI/Painter.h> #include <LibGUI/Painter.h>
FormEditorWidget::FormEditorWidget(GUI::Widget* parent) FormEditorWidget::FormEditorWidget()
: ScrollableWidget(parent) : m_tool(make<CursorTool>(*this))
, m_tool(make<CursorTool>(*this))
{ {
set_fill_with_background_color(true); set_fill_with_background_color(true);
set_background_color(Color::MidGray); set_background_color(Color::MidGray);
@ -41,7 +40,7 @@ FormEditorWidget::FormEditorWidget(GUI::Widget* parent)
set_frame_shadow(Gfx::FrameShadow::Sunken); set_frame_shadow(Gfx::FrameShadow::Sunken);
set_frame_thickness(2); set_frame_thickness(2);
m_form_widget = FormWidget::construct(*this); m_form_widget = add<FormWidget>();
m_widget_tree_model = WidgetTreeModel::create(*m_form_widget); m_widget_tree_model = WidgetTreeModel::create(*m_form_widget);
} }

View file

@ -124,7 +124,7 @@ public:
private: private:
virtual void paint_event(GUI::PaintEvent&) override; virtual void paint_event(GUI::PaintEvent&) override;
explicit FormEditorWidget(GUI::Widget* parent); FormEditorWidget();
RefPtr<FormWidget> m_form_widget; RefPtr<FormWidget> m_form_widget;
RefPtr<WidgetTreeModel> m_widget_tree_model; RefPtr<WidgetTreeModel> m_widget_tree_model;

View file

@ -29,8 +29,7 @@
#include "Tool.h" #include "Tool.h"
#include <LibGUI/Painter.h> #include <LibGUI/Painter.h>
FormWidget::FormWidget(FormEditorWidget& parent) FormWidget::FormWidget()
: GUI::Widget(&parent)
{ {
set_fill_with_background_color(true); set_fill_with_background_color(true);
set_relative_rect(5, 5, 400, 300); set_relative_rect(5, 5, 400, 300);

View file

@ -53,7 +53,7 @@ private:
virtual void mousemove_event(GUI::MouseEvent&) override; virtual void mousemove_event(GUI::MouseEvent&) override;
virtual void keydown_event(GUI::KeyEvent&) override; virtual void keydown_event(GUI::KeyEvent&) override;
explicit FormWidget(FormEditorWidget& parent); FormWidget();
int m_grid_size { 5 }; int m_grid_size { 5 };
}; };

View file

@ -92,14 +92,10 @@ public:
} }
private: private:
LocatorTextBox(GUI::Widget* parent) LocatorTextBox() {}
: GUI::TextBox(parent)
{
}
}; };
Locator::Locator(GUI::Widget* parent) Locator::Locator()
: GUI::Widget(parent)
{ {
if (!s_cplusplus_icon) { if (!s_cplusplus_icon) {
s_file_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-unknown.png"); s_file_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-unknown.png");
@ -110,7 +106,7 @@ Locator::Locator(GUI::Widget* parent)
set_layout(make<GUI::VerticalBoxLayout>()); set_layout(make<GUI::VerticalBoxLayout>());
set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
set_preferred_size(0, 20); set_preferred_size(0, 20);
m_textbox = LocatorTextBox::construct(this); m_textbox = add<LocatorTextBox>();
m_textbox->on_change = [this] { m_textbox->on_change = [this] {
update_suggestions(); update_suggestions();
}; };
@ -154,7 +150,7 @@ Locator::Locator(GUI::Widget* parent)
m_popup_window->set_window_type(GUI::WindowType::Tooltip); m_popup_window->set_window_type(GUI::WindowType::Tooltip);
m_popup_window->set_rect(0, 0, 500, 200); m_popup_window->set_rect(0, 0, 500, 200);
m_suggestion_view = GUI::TableView::construct(nullptr); m_suggestion_view = GUI::TableView::construct();
m_suggestion_view->set_size_columns_to_fit_content(true); m_suggestion_view->set_size_columns_to_fit_content(true);
m_suggestion_view->set_headers_visible(false); m_suggestion_view->set_headers_visible(false);
m_popup_window->set_main_widget(m_suggestion_view); m_popup_window->set_main_widget(m_suggestion_view);

View file

@ -42,7 +42,7 @@ private:
void update_suggestions(); void update_suggestions();
void open_suggestion(const GUI::ModelIndex&); void open_suggestion(const GUI::ModelIndex&);
explicit Locator(GUI::Widget* parent); Locator();
RefPtr<LocatorTextBox> m_textbox; RefPtr<LocatorTextBox> m_textbox;
RefPtr<GUI::Window> m_popup_window; RefPtr<GUI::Window> m_popup_window;

View file

@ -32,8 +32,7 @@
#include <LibGfx/Font.h> #include <LibGfx/Font.h>
#include <unistd.h> #include <unistd.h>
ProcessStateWidget::ProcessStateWidget(GUI::Widget* parent) ProcessStateWidget::ProcessStateWidget()
: GUI::Widget(parent)
{ {
set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
set_preferred_size(0, 20); set_preferred_size(0, 20);
@ -41,24 +40,24 @@ ProcessStateWidget::ProcessStateWidget(GUI::Widget* parent)
set_layout(make<GUI::HorizontalBoxLayout>()); set_layout(make<GUI::HorizontalBoxLayout>());
auto pid_label_label = GUI::Label::construct("Process:", this); auto pid_label_label = add<GUI::Label>("Process:");
pid_label_label->set_font(Gfx::Font::default_bold_font()); pid_label_label->set_font(Gfx::Font::default_bold_font());
m_pid_label = GUI::Label::construct("", this); m_pid_label = add<GUI::Label>("");
auto state_label_label = GUI::Label::construct("State:", this); auto state_label_label = add<GUI::Label>("State:");
state_label_label->set_font(Gfx::Font::default_bold_font()); state_label_label->set_font(Gfx::Font::default_bold_font());
m_state_label = GUI::Label::construct("", this); m_state_label = add<GUI::Label>("");
// FIXME: This should show CPU% instead. // FIXME: This should show CPU% instead.
auto cpu_label_label = GUI::Label::construct("Times scheduled:", this); auto cpu_label_label = add<GUI::Label>("Times scheduled:");
cpu_label_label->set_font(Gfx::Font::default_bold_font()); cpu_label_label->set_font(Gfx::Font::default_bold_font());
m_cpu_label = GUI::Label::construct("", this); m_cpu_label = add<GUI::Label>("");
auto memory_label_label = GUI::Label::construct("Memory (resident):", this); auto memory_label_label = add<GUI::Label>("Memory (resident):");
memory_label_label->set_font(Gfx::Font::default_bold_font()); memory_label_label->set_font(Gfx::Font::default_bold_font());
m_memory_label = GUI::Label::construct("", this); m_memory_label = add<GUI::Label>("");
m_timer = Core::Timer::construct(500, [this] { m_timer = add<Core::Timer>(500, [this] {
refresh(); refresh();
}); });
} }

View file

@ -36,7 +36,7 @@ public:
void set_tty_fd(int); void set_tty_fd(int);
private: private:
explicit ProcessStateWidget(GUI::Widget* parent); explicit ProcessStateWidget();
void refresh(); void refresh();

View file

@ -166,16 +166,13 @@ void TerminalWrapper::kill_running_command()
(void)killpg(m_pid, SIGTERM); (void)killpg(m_pid, SIGTERM);
} }
TerminalWrapper::TerminalWrapper(GUI::Widget* parent) TerminalWrapper::TerminalWrapper()
: GUI::Widget(parent)
{ {
set_layout(make<GUI::VerticalBoxLayout>()); set_layout(make<GUI::VerticalBoxLayout>());
RefPtr<Core::ConfigFile> config = Core::ConfigFile::get_for_app("Terminal"); RefPtr<Core::ConfigFile> config = Core::ConfigFile::get_for_app("Terminal");
m_terminal_widget = TerminalWidget::construct(-1, false, config); m_terminal_widget = add<TerminalWidget>(-1, false, config);
add_child(*m_terminal_widget); m_process_state_widget = add<ProcessStateWidget>();
m_process_state_widget = ProcessStateWidget::construct(this);
} }
TerminalWrapper::~TerminalWrapper() TerminalWrapper::~TerminalWrapper()

View file

@ -42,7 +42,7 @@ public:
Function<void()> on_command_exit; Function<void()> on_command_exit;
private: private:
explicit TerminalWrapper(GUI::Widget* parent); explicit TerminalWrapper();
RefPtr<ProcessStateWidget> m_process_state_widget; RefPtr<ProcessStateWidget> m_process_state_widget;
RefPtr<TerminalWidget> m_terminal_widget; RefPtr<TerminalWidget> m_terminal_widget;

View file

@ -80,7 +80,7 @@ static RefPtr<GUI::TabWidget> s_action_tab_widget;
void add_new_editor(GUI::Widget& parent) void add_new_editor(GUI::Widget& parent)
{ {
auto wrapper = EditorWrapper::construct(nullptr); auto wrapper = EditorWrapper::construct();
if (s_action_tab_widget) { if (s_action_tab_widget) {
parent.insert_child_before(wrapper, *s_action_tab_widget); parent.insert_child_before(wrapper, *s_action_tab_widget);
} else { } else {
@ -165,7 +165,7 @@ int main(int argc, char** argv)
g_project = Project::load_from_file("little.files"); g_project = Project::load_from_file("little.files");
ASSERT(g_project); ASSERT(g_project);
auto toolbar = GUI::ToolBar::construct(widget); auto toolbar = widget->add<GUI::ToolBar>();
auto selected_file_names = [&] { auto selected_file_names = [&] {
Vector<String> files; Vector<String> files;
@ -176,7 +176,7 @@ int main(int argc, char** argv)
}; };
auto new_action = GUI::Action::create("Add new file to project...", { Mod_Ctrl, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"), [&](const GUI::Action&) { auto new_action = GUI::Action::create("Add new file to project...", { Mod_Ctrl, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"), [&](const GUI::Action&) {
auto input_box = GUI::InputBox::construct("Enter name of new file:", "Add new file to project", g_window); auto input_box = g_window->add<GUI::InputBox>("Enter name of new file:", "Add new file to project");
if (input_box->exec() == GUI::InputBox::ExecCancel) if (input_box->exec() == GUI::InputBox::ExecCancel)
return; return;
auto filename = input_box->text_value(); auto filename = input_box->text_value();
@ -247,8 +247,8 @@ int main(int argc, char** argv)
project_tree_view_context_menu->add_action(add_existing_file_action); project_tree_view_context_menu->add_action(add_existing_file_action);
project_tree_view_context_menu->add_action(delete_action); project_tree_view_context_menu->add_action(delete_action);
auto outer_splitter = GUI::HorizontalSplitter::construct(widget); auto outer_splitter = widget->add<GUI::HorizontalSplitter>();
g_project_tree_view = GUI::TreeView::construct(outer_splitter); g_project_tree_view = outer_splitter->add<GUI::TreeView>();
g_project_tree_view->set_model(g_project->model()); g_project_tree_view->set_model(g_project->model());
g_project_tree_view->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); g_project_tree_view->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
g_project_tree_view->set_preferred_size(140, 0); g_project_tree_view->set_preferred_size(140, 0);
@ -263,11 +263,11 @@ int main(int argc, char** argv)
delete_action->set_enabled(!g_project_tree_view->selection().is_empty()); delete_action->set_enabled(!g_project_tree_view->selection().is_empty());
}; };
g_right_hand_stack = GUI::StackWidget::construct(outer_splitter); g_right_hand_stack = outer_splitter->add<GUI::StackWidget>();
g_form_inner_container = GUI::Widget::construct(g_right_hand_stack); g_form_inner_container = g_right_hand_stack->add<GUI::Widget>();
g_form_inner_container->set_layout(make<GUI::HorizontalBoxLayout>()); g_form_inner_container->set_layout(make<GUI::HorizontalBoxLayout>());
auto form_widgets_toolbar = GUI::ToolBar::construct(Orientation::Vertical, 26, g_form_inner_container); auto form_widgets_toolbar = g_form_inner_container->add<GUI::ToolBar>(Orientation::Vertical, 26);
form_widgets_toolbar->set_preferred_size(38, 0); form_widgets_toolbar->set_preferred_size(38, 0);
GUI::ActionGroup tool_actions; GUI::ActionGroup tool_actions;
@ -296,19 +296,19 @@ int main(int argc, char** argv)
form_widgets_toolbar->add_action(move(action)); form_widgets_toolbar->add_action(move(action));
}); });
auto form_editor_inner_splitter = GUI::HorizontalSplitter::construct(g_form_inner_container); auto form_editor_inner_splitter = g_form_inner_container->add<GUI::HorizontalSplitter>();
g_form_editor_widget = FormEditorWidget::construct(form_editor_inner_splitter); g_form_editor_widget = form_editor_inner_splitter->add<FormEditorWidget>();
auto form_editing_pane_container = GUI::VerticalSplitter::construct(form_editor_inner_splitter); auto form_editing_pane_container = form_editor_inner_splitter->add<GUI::VerticalSplitter>();
form_editing_pane_container->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); form_editing_pane_container->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
form_editing_pane_container->set_preferred_size(190, 0); form_editing_pane_container->set_preferred_size(190, 0);
form_editing_pane_container->set_layout(make<GUI::VerticalBoxLayout>()); form_editing_pane_container->set_layout(make<GUI::VerticalBoxLayout>());
auto add_properties_pane = [&](auto& text, auto pane_widget) { auto add_properties_pane = [&](auto& text, auto pane_widget) {
auto wrapper = GUI::Widget::construct(form_editing_pane_container.ptr()); auto wrapper = form_editing_pane_container->add<GUI::Widget>();
wrapper->set_layout(make<GUI::VerticalBoxLayout>()); wrapper->set_layout(make<GUI::VerticalBoxLayout>());
auto label = GUI::Label::construct(text, wrapper); auto label = wrapper->add<GUI::Label>(text);
label->set_fill_with_background_color(true); label->set_fill_with_background_color(true);
label->set_text_alignment(Gfx::TextAlignment::CenterLeft); label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
label->set_font(Gfx::Font::default_bold_font()); label->set_font(Gfx::Font::default_bold_font());
@ -317,7 +317,7 @@ int main(int argc, char** argv)
wrapper->add_child(pane_widget); wrapper->add_child(pane_widget);
}; };
auto form_widget_tree_view = GUI::TreeView::construct(nullptr); auto form_widget_tree_view = GUI::TreeView::construct();
form_widget_tree_view->set_model(g_form_editor_widget->model()); form_widget_tree_view->set_model(g_form_editor_widget->model());
form_widget_tree_view->on_selection_change = [&] { form_widget_tree_view->on_selection_change = [&] {
g_form_editor_widget->selection().disable_hooks(); g_form_editor_widget->selection().disable_hooks();
@ -343,9 +343,9 @@ int main(int argc, char** argv)
}; };
add_properties_pane("Form widget tree:", form_widget_tree_view); add_properties_pane("Form widget tree:", form_widget_tree_view);
add_properties_pane("Widget properties:", GUI::TableView::construct(nullptr)); add_properties_pane("Widget properties:", GUI::TableView::construct());
g_text_inner_splitter = GUI::VerticalSplitter::construct(g_right_hand_stack); g_text_inner_splitter = g_right_hand_stack->add<GUI::VerticalSplitter>();
g_text_inner_splitter->layout()->set_margins({ 0, 3, 0, 0 }); g_text_inner_splitter->layout()->set_margins({ 0, 3, 0, 0 });
add_new_editor(*g_text_inner_splitter); add_new_editor(*g_text_inner_splitter);
@ -420,7 +420,7 @@ int main(int argc, char** argv)
open_file(filename); open_file(filename);
}; };
s_action_tab_widget = GUI::TabWidget::construct(g_text_inner_splitter); s_action_tab_widget = g_text_inner_splitter->add<GUI::TabWidget>();
s_action_tab_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); s_action_tab_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
s_action_tab_widget->set_preferred_size(0, 24); s_action_tab_widget->set_preferred_size(0, 24);
@ -444,13 +444,13 @@ int main(int argc, char** argv)
update_actions(); update_actions();
}); });
auto find_in_files_widget = FindInFilesWidget::construct(nullptr); auto find_in_files_widget = FindInFilesWidget::construct();
s_action_tab_widget->add_widget("Find in files", find_in_files_widget); s_action_tab_widget->add_widget("Find in files", find_in_files_widget);
auto terminal_wrapper = TerminalWrapper::construct(nullptr); auto terminal_wrapper = TerminalWrapper::construct();
s_action_tab_widget->add_widget("Console", terminal_wrapper); s_action_tab_widget->add_widget("Console", terminal_wrapper);
auto locator = Locator::construct(widget); auto locator = widget->add<Locator>();
auto open_locator_action = GUI::Action::create("Open Locator...", { Mod_Ctrl, Key_K }, [&](auto&) { auto open_locator_action = GUI::Action::create("Open Locator...", { Mod_Ctrl, Key_K }, [&](auto&) {
locator->open(); locator->open();

View file

@ -98,53 +98,53 @@ static RefPtr<GUI::Widget> build_gwidget(VBWidgetType type, GUI::Widget* parent)
{ {
switch (type) { switch (type) {
case VBWidgetType::GWidget: case VBWidgetType::GWidget:
return GUI::Widget::construct(parent); return parent->add<GUI::Widget>();
case VBWidgetType::GScrollBar: case VBWidgetType::GScrollBar:
return GUI::ScrollBar::construct(Orientation::Vertical, parent); return parent->add<GUI::ScrollBar>(Orientation::Vertical);
case VBWidgetType::GGroupBox: case VBWidgetType::GGroupBox:
return GUI::GroupBox::construct("groupbox_1", parent); return parent->add<GUI::GroupBox>("groupbox_1");
case VBWidgetType::GLabel: { case VBWidgetType::GLabel: {
auto label = GUI::Label::construct(parent); auto label = parent->add<GUI::Label>();
label->set_fill_with_background_color(true); label->set_fill_with_background_color(true);
label->set_text("label_1"); label->set_text("label_1");
return label; return label;
} }
case VBWidgetType::GButton: { case VBWidgetType::GButton: {
auto button = GUI::Button::construct(parent); auto button = parent->add<GUI::Button>();
button->set_text("button_1"); button->set_text("button_1");
return button; return button;
} }
case VBWidgetType::GSpinBox: { case VBWidgetType::GSpinBox: {
auto box = GUI::SpinBox::construct(parent); auto box = parent->add<GUI::SpinBox>();
box->set_range(0, 100); box->set_range(0, 100);
box->set_value(0); box->set_value(0);
return box; return box;
} }
case VBWidgetType::GTextEditor: { case VBWidgetType::GTextEditor: {
auto editor = GUI::TextEditor::construct(GUI::TextEditor::Type::MultiLine, parent); auto editor = parent->add<GUI::TextEditor>();
editor->set_ruler_visible(false); editor->set_ruler_visible(false);
return editor; return editor;
} }
case VBWidgetType::GProgressBar: { case VBWidgetType::GProgressBar: {
auto bar = GUI::ProgressBar::construct(parent); auto bar = parent->add<GUI::ProgressBar>();
bar->set_format(GUI::ProgressBar::Format::NoText); bar->set_format(GUI::ProgressBar::Format::NoText);
bar->set_range(0, 100); bar->set_range(0, 100);
bar->set_value(50); bar->set_value(50);
return bar; return bar;
} }
case VBWidgetType::GSlider: { case VBWidgetType::GSlider: {
auto slider = GUI::HorizontalSlider::construct(parent); auto slider = parent->add<GUI::HorizontalSlider>();
slider->set_range(0, 100); slider->set_range(0, 100);
slider->set_value(50); slider->set_value(50);
return slider; return slider;
} }
case VBWidgetType::GCheckBox: { case VBWidgetType::GCheckBox: {
auto box = GUI::CheckBox::construct(parent); auto box = parent->add<GUI::CheckBox>();
box->set_text("checkbox_1"); box->set_text("checkbox_1");
return box; return box;
} }
case VBWidgetType::GRadioButton: case VBWidgetType::GRadioButton:
return GUI::RadioButton::construct("radio_1", parent); return parent->add<GUI::RadioButton>("radio_1");
default: default:
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
return nullptr; return nullptr;

View file

@ -28,10 +28,10 @@
#include <AK/HashTable.h> #include <AK/HashTable.h>
#include <AK/Queue.h> #include <AK/Queue.h>
#include <LibCore/ConfigFile.h> #include <LibCore/ConfigFile.h>
#include <LibGfx/Palette.h>
#include <LibGUI/Button.h> #include <LibGUI/Button.h>
#include <LibGUI/Label.h> #include <LibGUI/Label.h>
#include <LibGUI/Painter.h> #include <LibGUI/Painter.h>
#include <LibGfx/Palette.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
@ -72,8 +72,7 @@ public:
virtual void mousedown_event(GUI::MouseEvent& event) override virtual void mousedown_event(GUI::MouseEvent& event) override
{ {
if (event.button() == GUI::MouseButton::Right || event.button() == GUI::MouseButton::Left) { if (event.button() == GUI::MouseButton::Right || event.button() == GUI::MouseButton::Left) {
if (event.buttons() == (GUI::MouseButton::Right | GUI::MouseButton::Left) || if (event.buttons() == (GUI::MouseButton::Right | GUI::MouseButton::Left) || m_square.field->is_single_chording()) {
m_square.field->is_single_chording()) {
m_chord = true; m_chord = true;
m_square.field->set_chord_preview(m_square, true); m_square.field->set_chord_preview(m_square, true);
} }
@ -120,15 +119,14 @@ public:
bool m_chord { false }; bool m_chord { false };
}; };
Field::Field(GUI::Label& flag_label, GUI::Label& time_label, GUI::Button& face_button, GUI::Widget* parent, Function<void(Gfx::Size)> on_size_changed) Field::Field(GUI::Label& flag_label, GUI::Label& time_label, GUI::Button& face_button, Function<void(Gfx::Size)> on_size_changed)
: GUI::Frame(parent) : m_face_button(face_button)
, m_face_button(face_button)
, m_flag_label(flag_label) , m_flag_label(flag_label)
, m_time_label(time_label) , m_time_label(time_label)
, m_on_size_changed(move(on_size_changed)) , m_on_size_changed(move(on_size_changed))
{ {
srand(time(nullptr)); srand(time(nullptr));
m_timer = Core::Timer::construct(); m_timer = add<Core::Timer>();
m_timer->on_timeout = [this] { m_timer->on_timeout = [this] {
++m_time_elapsed; ++m_time_elapsed;
m_time_label.set_text(String::format("%u.%u", m_time_elapsed / 10, m_time_elapsed % 10)); m_time_label.set_text(String::format("%u.%u", m_time_elapsed / 10, m_time_elapsed % 10));
@ -511,7 +509,8 @@ void Field::set_field_size(int rows, int columns, int mine_count)
m_on_size_changed(preferred_size()); m_on_size_changed(preferred_size());
} }
void Field::set_single_chording(bool enabled) { void Field::set_single_chording(bool enabled)
{
auto config = Core::ConfigFile::get_for_app("Minesweeper"); auto config = Core::ConfigFile::get_for_app("Minesweeper");
m_single_chording = enabled; m_single_chording = enabled;
config->write_bool_entry("Minesweeper", "SingleChording", m_single_chording); config->write_bool_entry("Minesweeper", "SingleChording", m_single_chording);

View file

@ -60,7 +60,7 @@ class Field final : public GUI::Frame {
friend class Square; friend class Square;
friend class SquareLabel; friend class SquareLabel;
public: public:
Field(GUI::Label& flag_label, GUI::Label& time_label, GUI::Button& face_button, GUI::Widget* parent, Function<void(Gfx::Size)> on_size_changed); Field(GUI::Label& flag_label, GUI::Label& time_label, GUI::Button& face_button, Function<void(Gfx::Size)> on_size_changed);
virtual ~Field() override; virtual ~Field() override;
int rows() const { return m_rows; } int rows() const { return m_rows; }

View file

@ -62,22 +62,22 @@ int main(int argc, char** argv)
widget->set_layout(make<GUI::VerticalBoxLayout>()); widget->set_layout(make<GUI::VerticalBoxLayout>());
widget->layout()->set_spacing(0); widget->layout()->set_spacing(0);
auto container = GUI::Widget::construct(widget.ptr()); auto container = widget->add<GUI::Widget>();
container->set_fill_with_background_color(true); container->set_fill_with_background_color(true);
container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
container->set_preferred_size(0, 36); container->set_preferred_size(0, 36);
container->set_layout(make<GUI::HorizontalBoxLayout>()); container->set_layout(make<GUI::HorizontalBoxLayout>());
auto flag_icon_label = GUI::Label::construct(container); auto flag_icon_label = container->add<GUI::Label>();
flag_icon_label->set_icon(Gfx::Bitmap::load_from_file("/res/icons/minesweeper/flag.png")); flag_icon_label->set_icon(Gfx::Bitmap::load_from_file("/res/icons/minesweeper/flag.png"));
auto flag_label = GUI::Label::construct(container); auto flag_label = container->add<GUI::Label>();
auto face_button = GUI::Button::construct(container); auto face_button = container->add<GUI::Button>();
face_button->set_button_style(Gfx::ButtonStyle::CoolBar); face_button->set_button_style(Gfx::ButtonStyle::CoolBar);
face_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); face_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
face_button->set_preferred_size(36, 0); face_button->set_preferred_size(36, 0);
auto time_icon_label = GUI::Label::construct(container); auto time_icon_label = container->add<GUI::Label>();
time_icon_label->set_icon(Gfx::Bitmap::load_from_file("/res/icons/minesweeper/timer.png")); time_icon_label->set_icon(Gfx::Bitmap::load_from_file("/res/icons/minesweeper/timer.png"));
auto time_label = GUI::Label::construct(container); auto time_label = container->add<GUI::Label>();
auto field = Field::construct(*flag_label, *time_label, *face_button, widget, [&](auto size) { auto field = widget->add<Field>(*flag_label, *time_label, *face_button, [&](auto size) {
size.set_height(size.height() + container->preferred_size().height()); size.set_height(size.height() + container->preferred_size().height());
window->resize(size); window->resize(size);
}); });

View file

@ -52,7 +52,7 @@ RefPtr<LayoutNode> HTMLInputElement::create_layout_node(const StyleProperties*)
RefPtr<GUI::Widget> widget; RefPtr<GUI::Widget> widget;
if (type() == "submit") { if (type() == "submit") {
auto button = GUI::Button::construct(value(), &html_view); auto button = html_view.add<GUI::Button>(value());
int text_width = Gfx::Font::default_font().width(value()); int text_width = Gfx::Font::default_font().width(value());
button->set_relative_rect(0, 0, text_width + 20, 20); button->set_relative_rect(0, 0, text_width + 20, 20);
button->on_click = [this](auto&) { button->on_click = [this](auto&) {

View file

@ -46,9 +46,8 @@
#include <LibHTML/ResourceLoader.h> #include <LibHTML/ResourceLoader.h>
#include <stdio.h> #include <stdio.h>
HtmlView::HtmlView(GUI::Widget* parent) HtmlView::HtmlView()
: GUI::ScrollableWidget(parent) : m_main_frame(::Frame::create(*this))
, m_main_frame(::Frame::create(*this))
{ {
main_frame().on_set_needs_display = [this](auto& content_rect) { main_frame().on_set_needs_display = [this](auto& content_rect) {
if (content_rect.is_empty()) { if (content_rect.is_empty()) {

View file

@ -62,7 +62,7 @@ public:
virtual bool accepts_focus() const override { return true; } virtual bool accepts_focus() const override { return true; }
protected: protected:
HtmlView(GUI::Widget* parent = nullptr); HtmlView();
virtual void resize_event(GUI::ResizeEvent&) override; virtual void resize_event(GUI::ResizeEvent&) override;
virtual void paint_event(GUI::PaintEvent&) override; virtual void paint_event(GUI::PaintEvent&) override;

View file

@ -89,14 +89,14 @@ TerminalWidget::TerminalWidget(int ptm_fd, bool automatic_size_policy, RefPtr<Co
, m_config(move(config)) , m_config(move(config))
{ {
set_pty_master_fd(ptm_fd); set_pty_master_fd(ptm_fd);
m_cursor_blink_timer = Core::Timer::construct(); m_cursor_blink_timer = add<Core::Timer>();
m_visual_beep_timer = Core::Timer::construct(); m_visual_beep_timer = add<Core::Timer>();
set_frame_shape(Gfx::FrameShape::Container); set_frame_shape(Gfx::FrameShape::Container);
set_frame_shadow(Gfx::FrameShadow::Sunken); set_frame_shadow(Gfx::FrameShadow::Sunken);
set_frame_thickness(2); set_frame_thickness(2);
m_scrollbar = GUI::ScrollBar::construct(Orientation::Vertical, this); m_scrollbar = add<GUI::ScrollBar>(Orientation::Vertical);
m_scrollbar->set_relative_rect(0, 0, 16, 0); m_scrollbar->set_relative_rect(0, 0, 16, 0);
m_scrollbar->on_change = [this](int) { m_scrollbar->on_change = [this](int) {
force_repaint(); force_repaint();

View file

@ -42,7 +42,7 @@ public:
{ {
m_time_width = Gfx::Font::default_bold_font().width("2222-22-22 22:22:22"); m_time_width = Gfx::Font::default_bold_font().width("2222-22-22 22:22:22");
m_timer = Core::Timer::construct(1000, [this] { m_timer = add<Core::Timer>(1000, [this] {
static time_t last_update_time; static time_t last_update_time;
time_t now = time(nullptr); time_t now = time(nullptr);
if (now != last_update_time) { if (now != last_update_time) {

View file

@ -68,21 +68,21 @@ NotificationWindow::NotificationWindow(const String& text, const String& title)
widget->layout()->set_margins({ 4, 4, 4, 4 }); widget->layout()->set_margins({ 4, 4, 4, 4 });
widget->layout()->set_spacing(4); widget->layout()->set_spacing(4);
auto left_container = GUI::Widget::construct(widget.ptr()); auto left_container = widget->add<GUI::Widget>();
left_container->set_layout(make<GUI::VerticalBoxLayout>()); left_container->set_layout(make<GUI::VerticalBoxLayout>());
auto title_label = GUI::Label::construct(title, left_container); auto title_label = left_container->add<GUI::Label>(title);
title_label->set_font(Gfx::Font::default_bold_font()); title_label->set_font(Gfx::Font::default_bold_font());
title_label->set_text_alignment(Gfx::TextAlignment::CenterLeft); title_label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
auto text_label = GUI::Label::construct(text, left_container); auto text_label = left_container->add<GUI::Label>(text);
text_label->set_text_alignment(Gfx::TextAlignment::CenterLeft); text_label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
auto right_container = GUI::Widget::construct(widget.ptr()); auto right_container = widget->add<GUI::Widget>();
right_container->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); right_container->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
right_container->set_preferred_size(40, 0); right_container->set_preferred_size(40, 0);
right_container->set_layout(make<GUI::HorizontalBoxLayout>()); right_container->set_layout(make<GUI::HorizontalBoxLayout>());
auto button = GUI::Button::construct("Okay", right_container); auto button = right_container->add<GUI::Button>("Okay");
button->on_click = [this](auto&) { button->on_click = [this](auto&) {
s_windows.remove(this); s_windows.remove(this);
close(); close();

View file

@ -60,8 +60,8 @@ WallpaperMode mode_to_enum(const String& name)
Compositor::Compositor() Compositor::Compositor()
{ {
m_compose_timer = Core::Timer::construct(this); m_compose_timer = add<Core::Timer>();
m_immediate_compose_timer = Core::Timer::construct(this); m_immediate_compose_timer = add<Core::Timer>();
m_screen_can_set_buffer = Screen::the().can_set_buffer(); m_screen_can_set_buffer = Screen::the().can_set_buffer();