diff --git a/Applications/FontEditor/main.cpp b/Applications/FontEditor/main.cpp index ff19eb45b7..92db3e2fc0 100644 --- a/Applications/FontEditor/main.cpp +++ b/Applications/FontEditor/main.cpp @@ -70,8 +70,7 @@ int main(int argc, char** argv) window->set_title("Font Editor"); window->set_rect({ 50, 50, 390, 342 }); - auto font_editor = FontEditorWidget::construct(path, move(edited_font)); - window->set_main_widget(font_editor); + window->set_main_widget(path, move(edited_font)); window->show(); window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-font-editor.png")); diff --git a/Applications/HexEditor/main.cpp b/Applications/HexEditor/main.cpp index ad5d44cef6..f20ade72e5 100644 --- a/Applications/HexEditor/main.cpp +++ b/Applications/HexEditor/main.cpp @@ -46,11 +46,10 @@ int main(int argc, char** argv) window->set_title("Hex Editor"); window->set_rect(20, 200, 640, 400); - auto hex_editor_widget = HexEditorWidget::construct(); - window->set_main_widget(hex_editor_widget); + auto& hex_editor_widget = window->set_main_widget(); window->on_close_request = [&]() -> GUI::Window::CloseRequestDecision { - if (hex_editor_widget->request_close()) + if (hex_editor_widget.request_close()) return GUI::Window::CloseRequestDecision::Close; return GUI::Window::CloseRequestDecision::StayOpen; }; @@ -59,7 +58,7 @@ int main(int argc, char** argv) window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-hexeditor.png")); if (argc >= 2) - hex_editor_widget->open_file(argv[1]); + hex_editor_widget.open_file(argv[1]); return app.exec(); } diff --git a/Applications/IRCClient/IRCAppWindow.cpp b/Applications/IRCClient/IRCAppWindow.cpp index e1ebe4d0b7..b3b22c6d16 100644 --- a/Applications/IRCClient/IRCAppWindow.cpp +++ b/Applications/IRCClient/IRCAppWindow.cpp @@ -179,13 +179,12 @@ void IRCAppWindow::setup_menus() void IRCAppWindow::setup_widgets() { - auto widget = GUI::Widget::construct(); - set_main_widget(widget); - widget->set_fill_with_background_color(true); - widget->set_layout(); - widget->layout()->set_spacing(0); + auto& widget = set_main_widget(); + widget.set_fill_with_background_color(true); + widget.set_layout(); + widget.layout()->set_spacing(0); - auto toolbar = widget->add(); + auto toolbar = widget.add(); toolbar->set_has_frame(false); toolbar->add_action(*m_change_nick_action); toolbar->add_separator(); @@ -196,7 +195,7 @@ void IRCAppWindow::setup_widgets() toolbar->add_action(*m_open_query_action); toolbar->add_action(*m_close_query_action); - auto outer_container = widget->add(); + auto outer_container = widget.add(); outer_container->set_layout(); outer_container->layout()->set_margins({ 2, 0, 2, 2 }); diff --git a/Applications/PaintBrush/main.cpp b/Applications/PaintBrush/main.cpp index 6e9b241db0..d79f2b83c6 100644 --- a/Applications/PaintBrush/main.cpp +++ b/Applications/PaintBrush/main.cpp @@ -58,14 +58,13 @@ int main(int argc, char** argv) window->set_rect(100, 100, 640, 480); window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-paintbrush.png")); - auto horizontal_container = GUI::Widget::construct(); - window->set_main_widget(horizontal_container); - horizontal_container->set_layout(); - horizontal_container->layout()->set_spacing(0); + auto& horizontal_container = window->set_main_widget(); + horizontal_container.set_layout(); + horizontal_container.layout()->set_spacing(0); - horizontal_container->add(); + horizontal_container.add(); - auto vertical_container = horizontal_container->add(); + auto vertical_container = horizontal_container.add(); vertical_container->set_layout(); vertical_container->layout()->set_spacing(0); diff --git a/Applications/Piano/main.cpp b/Applications/Piano/main.cpp index 13d1573422..9c396909a6 100644 --- a/Applications/Piano/main.cpp +++ b/Applications/Piano/main.cpp @@ -52,8 +52,7 @@ int main(int argc, char** argv) AudioEngine audio_engine; auto window = GUI::Window::construct(); - auto main_widget = MainWidget::construct(audio_engine); - window->set_main_widget(main_widget); + auto& main_widget = window->set_main_widget(audio_engine); window->set_title("Piano"); window->set_rect(90, 90, 840, 600); window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-piano.png")); @@ -74,7 +73,7 @@ int main(int argc, char** argv) for (;;) { audio_engine.fill_buffer(buffer); audio->write(reinterpret_cast(buffer.data()), buffer_size); - Core::EventLoop::current().post_event(*main_widget, make(0)); + Core::EventLoop::current().post_event(main_widget, make(0)); Core::EventLoop::wake(); if (need_to_write_wav) { diff --git a/Applications/QuickShow/main.cpp b/Applications/QuickShow/main.cpp index df90187b08..1233fe8209 100644 --- a/Applications/QuickShow/main.cpp +++ b/Applications/QuickShow/main.cpp @@ -87,22 +87,21 @@ int main(int argc, char** argv) } auto window = GUI::Window::construct(); - auto widget = QSWidget::construct(); - widget->set_path(path); - widget->set_bitmap(*bitmap); + auto& widget = window->set_main_widget(); + widget.set_path(path); + widget.set_bitmap(*bitmap); auto update_window_title = [&](int scale) { - window->set_title(String::format("QuickShow: %s %s %d%%", widget->path().characters(), widget->bitmap()->size().to_string().characters(), scale)); + window->set_title(String::format("QuickShow: %s %s %d%%", widget.path().characters(), widget.bitmap()->size().to_string().characters(), scale)); }; window->set_double_buffering_enabled(true); update_window_title(100); window->set_rect(200, 200, bitmap->width(), bitmap->height()); - widget->on_scale_change = [&](int scale) { + widget.on_scale_change = [&](int scale) { update_window_title(scale); }; - window->set_main_widget(widget); window->show(); diff --git a/Applications/SoundPlayer/main.cpp b/Applications/SoundPlayer/main.cpp index a6433e7395..5a4fe56edf 100644 --- a/Applications/SoundPlayer/main.cpp +++ b/Applications/SoundPlayer/main.cpp @@ -66,24 +66,24 @@ int main(int argc, char** argv) auto menubar = make(); auto app_menu = GUI::Menu::construct("SoundPlayer"); - auto player = SoundPlayerWidget::construct(window, audio_client); + auto& player = window->set_main_widget(window, audio_client); if (argc > 1) { String path = argv[1]; - player->open_file(path); - player->manager().play(); + player.open_file(path); + player.manager().play(); } auto hide_scope = GUI::Action::create("Hide scope", { Mod_Ctrl, Key_H }, [&](GUI::Action& action) { action.set_checked(!action.is_checked()); - player->hide_scope(action.is_checked()); + player.hide_scope(action.is_checked()); }); hide_scope->set_checkable(true); app_menu->add_action(GUI::CommonActions::make_open_action([&](auto&) { Optional path = GUI::FilePicker::get_open_filepath("Open wav file..."); if (path.has_value()) { - player->open_file(path.value()); + player.open_file(path.value()); } })); app_menu->add_action(move(hide_scope)); @@ -101,8 +101,6 @@ int main(int argc, char** argv) menubar->add_menu(move(help_menu)); app.set_menubar(move(menubar)); - window->set_main_widget(player); window->show(); - return app.exec(); } diff --git a/Applications/SystemMenu/PowerDialog.cpp b/Applications/SystemMenu/PowerDialog.cpp index c65f1495a2..1fe8fde82d 100644 --- a/Applications/SystemMenu/PowerDialog.cpp +++ b/Applications/SystemMenu/PowerDialog.cpp @@ -69,14 +69,13 @@ PowerDialog::PowerDialog() set_title("SerenityOS"); set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/power.png")); - auto main = GUI::Widget::construct(); - set_main_widget(main); - main->set_layout(); - main->layout()->set_margins({ 8, 8, 8, 8 }); - main->layout()->set_spacing(8); - main->set_fill_with_background_color(true); + auto& main = set_main_widget(); + main.set_layout(); + main.layout()->set_margins({ 8, 8, 8, 8 }); + main.layout()->set_spacing(8); + main.set_fill_with_background_color(true); - auto header = main->add(); + auto header = main.add(); header->set_text("What would you like to do?"); header->set_preferred_size(0, 16); header->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); @@ -84,7 +83,7 @@ PowerDialog::PowerDialog() for (size_t i = 0; i < options.size(); i++) { auto action = options[i]; - auto radio = main->add(); + auto radio = main.add(); radio->set_enabled(action.enabled); radio->set_text(action.title); @@ -98,7 +97,7 @@ PowerDialog::PowerDialog() } } - auto button_box = main->add(); + auto button_box = main.add(); button_box->set_layout(); button_box->layout()->set_spacing(8); diff --git a/Applications/SystemMonitor/main.cpp b/Applications/SystemMonitor/main.cpp index 736ffe8120..6965f5c49e 100644 --- a/Applications/SystemMonitor/main.cpp +++ b/Applications/SystemMonitor/main.cpp @@ -115,13 +115,12 @@ int main(int argc, char** argv) window->set_title("System Monitor"); window->set_rect(20, 200, 680, 400); - auto keeper = GUI::Widget::construct(); - window->set_main_widget(keeper); - keeper->set_layout(); - keeper->set_fill_with_background_color(true); - keeper->layout()->set_margins({ 4, 4, 4, 4 }); + auto& keeper = window->set_main_widget(); + keeper.set_layout(); + keeper.set_fill_with_background_color(true); + keeper.layout()->set_margins({ 4, 4, 4, 4 }); - auto tabwidget = keeper->add(); + auto tabwidget = keeper.add(); auto process_container_splitter = tabwidget->add_tab("Processes"); diff --git a/Applications/Taskbar/TaskbarWindow.cpp b/Applications/Taskbar/TaskbarWindow.cpp index f5ec210829..c4655a6b48 100644 --- a/Applications/Taskbar/TaskbarWindow.cpp +++ b/Applications/Taskbar/TaskbarWindow.cpp @@ -46,15 +46,14 @@ TaskbarWindow::TaskbarWindow() GUI::Desktop::the().on_rect_change = [this](const Gfx::Rect& rect) { on_screen_rect_change(rect); }; - auto widget = GUI::Frame::construct(); - widget->set_fill_with_background_color(true); - widget->set_layout(); - widget->layout()->set_margins({ 3, 2, 3, 2 }); - widget->layout()->set_spacing(3); - widget->set_frame_thickness(1); - widget->set_frame_shape(Gfx::FrameShape::Panel); - widget->set_frame_shadow(Gfx::FrameShadow::Raised); - set_main_widget(widget); + auto& widget = set_main_widget(); + widget.set_fill_with_background_color(true); + widget.set_layout(); + widget.layout()->set_margins({ 3, 2, 3, 2 }); + widget.layout()->set_spacing(3); + widget.set_frame_thickness(1); + widget.set_frame_shape(Gfx::FrameShape::Panel); + widget.set_frame_shadow(Gfx::FrameShadow::Raised); WindowList::the().aid_create_button = [this](auto& identifier) { return create_button(identifier); diff --git a/Applications/Terminal/main.cpp b/Applications/Terminal/main.cpp index 9f36dd439e..8f62196bb9 100644 --- a/Applications/Terminal/main.cpp +++ b/Applications/Terminal/main.cpp @@ -134,14 +134,13 @@ RefPtr create_settings_window(TerminalWidget& terminal) window->set_rect(50, 50, 200, 140); window->set_modal(true); - auto settings = GUI::Widget::construct(); - window->set_main_widget(settings); - settings->set_fill_with_background_color(true); - settings->set_background_role(ColorRole::Button); - settings->set_layout(); - settings->layout()->set_margins({ 4, 4, 4, 4 }); + auto& settings = window->set_main_widget(); + settings.set_fill_with_background_color(true); + settings.set_background_role(ColorRole::Button); + settings.set_layout(); + settings.layout()->set_margins({ 4, 4, 4, 4 }); - auto radio_container = settings->add("Bell Mode"); + auto radio_container = settings.add("Bell Mode"); radio_container->set_layout(); radio_container->layout()->set_margins({ 6, 16, 6, 6 }); radio_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); @@ -155,7 +154,7 @@ RefPtr create_settings_window(TerminalWidget& terminal) terminal.set_should_beep(checked); }; - auto slider_container = settings->add("Background Opacity"); + auto slider_container = settings.add("Background Opacity"); slider_container->set_layout(); slider_container->layout()->set_margins({ 6, 16, 6, 6 }); slider_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); @@ -227,24 +226,23 @@ int main(int argc, char** argv) window->set_double_buffering_enabled(false); RefPtr config = Core::ConfigFile::get_for_app("Terminal"); - auto terminal = TerminalWidget::construct(ptm_fd, true, config); - terminal->on_command_exit = [&] { + auto& terminal = window->set_main_widget(ptm_fd, true, config); + terminal.on_command_exit = [&] { app.quit(0); }; - terminal->on_title_change = [&](auto& title) { + terminal.on_title_change = [&](auto& title) { window->set_title(title); }; - window->set_main_widget(terminal); window->move_to(300, 300); - terminal->apply_size_increments_to_window(*window); + terminal.apply_size_increments_to_window(*window); window->show(); window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-terminal.png")); - terminal->set_should_beep(config->read_bool_entry("Window", "AudibleBeep", false)); + terminal.set_should_beep(config->read_bool_entry("Window", "AudibleBeep", false)); RefPtr settings_window; auto new_opacity = config->read_num_entry("Window", "Opacity", 255); - terminal->set_opacity(new_opacity); + terminal.set_opacity(new_opacity); window->set_has_alpha_channel(new_opacity < 255); auto menubar = make(); @@ -259,7 +257,7 @@ int main(int argc, char** argv) app_menu->add_action(GUI::Action::create("Settings...", Gfx::Bitmap::load_from_file("/res/icons/gear16.png"), [&](const GUI::Action&) { if (!settings_window) { - settings_window = create_settings_window(*terminal); + settings_window = create_settings_window(terminal); settings_window->on_close_request = [&] { settings_window = nullptr; return GUI::Window::CloseRequestDecision::Close; @@ -276,8 +274,8 @@ int main(int argc, char** argv) menubar->add_menu(move(app_menu)); auto edit_menu = GUI::Menu::construct("Edit"); - edit_menu->add_action(terminal->copy_action()); - edit_menu->add_action(terminal->paste_action()); + edit_menu->add_action(terminal.copy_action()); + edit_menu->add_action(terminal.paste_action()); menubar->add_menu(move(edit_menu)); GUI::ActionGroup font_action_group; @@ -286,16 +284,16 @@ int main(int argc, char** argv) GFontDatabase::the().for_each_fixed_width_font([&](const StringView& font_name) { auto action = GUI::Action::create(font_name, [&](GUI::Action& action) { action.set_checked(true); - terminal->set_font(GFontDatabase::the().get_by_name(action.text())); + terminal.set_font(GFontDatabase::the().get_by_name(action.text())); auto metadata = GFontDatabase::the().get_metadata_by_name(action.text()); ASSERT(metadata.has_value()); config->write_entry("Text", "Font", metadata.value().path); config->sync(); - terminal->force_repaint(); + terminal.force_repaint(); }); font_action_group.add_action(*action); action->set_checkable(true); - if (terminal->font().name() == font_name) + if (terminal.font().name() == font_name) action->set_checked(true); font_menu->add_action(*action); }); diff --git a/Applications/TextEditor/main.cpp b/Applications/TextEditor/main.cpp index 73e9ebb9fd..23d67ae586 100644 --- a/Applications/TextEditor/main.cpp +++ b/Applications/TextEditor/main.cpp @@ -46,19 +46,18 @@ int main(int argc, char** argv) window->set_title("Text Editor"); window->set_rect(20, 200, 640, 400); - auto text_widget = TextEditorWidget::construct(); - window->set_main_widget(text_widget); + auto& text_widget = window->set_main_widget(); - text_widget->editor().set_focus(true); + text_widget.editor().set_focus(true); window->on_close_request = [&]() -> GUI::Window::CloseRequestDecision { - if (text_widget->request_close()) + if (text_widget.request_close()) return GUI::Window::CloseRequestDecision::Close; return GUI::Window::CloseRequestDecision::StayOpen; }; if (argc >= 2) - text_widget->open_sesame(argv[1]); + text_widget.open_sesame(argv[1]); window->show(); window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/TextEditor16.png")); diff --git a/Applications/Welcome/main.cpp b/Applications/Welcome/main.cpp index d2544fb1a4..bf46960de1 100644 --- a/Applications/Welcome/main.cpp +++ b/Applications/Welcome/main.cpp @@ -161,19 +161,18 @@ int main(int argc, char** argv) window->set_resizable(true); window->set_rect(window_rect); - auto background = BackgroundWidget::construct(); - window->set_main_widget(background); - background->set_fill_with_background_color(false); - background->set_layout(); - background->layout()->set_margins({ 16, 8, 16, 8 }); - background->layout()->set_spacing(8); - background->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill); + auto& background = window->set_main_widget(); + background.set_fill_with_background_color(false); + background.set_layout(); + background.layout()->set_margins({ 16, 8, 16, 8 }); + background.layout()->set_spacing(8); + background.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill); // // header // - auto header = background->add(); + auto header = background.add(); header->set_font(Gfx::Font::load_from_file("/res/fonts/PebbletonBold11.font")); header->set_text("Welcome to SerenityOS!"); header->set_text_alignment(Gfx::TextAlignment::CenterLeft); @@ -184,7 +183,7 @@ int main(int argc, char** argv) // main section // - auto main_section = background->add(); + auto main_section = background.add(); main_section->set_layout(); main_section->layout()->set_margins({ 0, 0, 0, 0 }); main_section->layout()->set_spacing(8); diff --git a/Demos/Fire/Fire.cpp b/Demos/Fire/Fire.cpp index 67872f0505..f51c760eed 100644 --- a/Demos/Fire/Fire.cpp +++ b/Demos/Fire/Fire.cpp @@ -246,14 +246,13 @@ int main(int argc, char** argv) window->set_resizable(false); window->set_rect(100, 100, 640, 400); - auto fire = Fire::construct(); - window->set_main_widget(fire); + auto& fire = window->set_main_widget(); - auto time = fire->add(); + auto time = fire.add(); time->set_relative_rect({ 0, 4, 40, 10 }); time->move_by({ window->width() - time->width(), 0 }); time->set_foreground_color(Color::from_rgb(0x444444)); - fire->set_stat_label(time); + fire.set_stat_label(time); window->show(); window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-demo.png")); diff --git a/Demos/WidgetGallery/main.cpp b/Demos/WidgetGallery/main.cpp index d7936e437f..2da3b765f8 100644 --- a/Demos/WidgetGallery/main.cpp +++ b/Demos/WidgetGallery/main.cpp @@ -48,51 +48,50 @@ int main(int argc, char** argv) window->set_rect(100, 100, 320, 620); window->set_title("Widget Gallery"); - auto main_widget = GUI::Widget::construct(); - window->set_main_widget(main_widget); - main_widget->set_fill_with_background_color(true); - main_widget->set_layout(); - main_widget->layout()->set_margins({ 4, 4, 4, 4 }); + auto& main_widget = window->set_main_widget(); + main_widget.set_fill_with_background_color(true); + main_widget.set_layout(); + main_widget.layout()->set_margins({ 4, 4, 4, 4 }); - auto checkbox1 = main_widget->add("GCheckBox 1"); + auto checkbox1 = main_widget.add("GCheckBox 1"); (void)checkbox1; - auto checkbox2 = main_widget->add("GCheckBox 2"); + auto checkbox2 = main_widget.add("GCheckBox 2"); checkbox2->set_enabled(false); - auto radio1 = main_widget->add("GRadioButton 1"); + auto radio1 = main_widget.add("GRadioButton 1"); (void)radio1; - auto radio2 = main_widget->add("GRadioButton 2"); + auto radio2 = main_widget.add("GRadioButton 2"); radio2->set_enabled(false); - auto button1 = main_widget->add("GButton 1"); + auto button1 = main_widget.add("GButton 1"); (void)button1; - auto button2 = main_widget->add("GButton 2"); + auto button2 = main_widget.add("GButton 2"); button2->set_enabled(false); - auto progress1 = main_widget->add(); + auto progress1 = main_widget.add(); auto timer = progress1->add(100, [&] { progress1->set_value(progress1->value() + 1); if (progress1->value() == progress1->max()) progress1->set_value(progress1->min()); }); - auto label1 = main_widget->add("GLabel 1"); + auto label1 = main_widget.add("GLabel 1"); (void)label1; - auto label2 = main_widget->add("GLabel 2"); + auto label2 = main_widget.add("GLabel 2"); label2->set_enabled(false); - auto textbox1 = main_widget->add(); + auto textbox1 = main_widget.add(); textbox1->set_text("GTextBox 1"); - auto textbox2 = main_widget->add(); + auto textbox2 = main_widget.add(); textbox2->set_text("GTextBox 2"); textbox2->set_enabled(false); - auto spinbox1 = main_widget->add(); + auto spinbox1 = main_widget.add(); (void)spinbox1; - auto spinbox2 = main_widget->add(); + auto spinbox2 = main_widget.add(); spinbox2->set_enabled(false); - auto vertical_slider_container = main_widget->add(); + auto vertical_slider_container = main_widget.add(); vertical_slider_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); vertical_slider_container->set_preferred_size(0, 100); vertical_slider_container->set_layout(); @@ -104,21 +103,21 @@ int main(int argc, char** argv) vslider3->set_max(5); vslider3->set_knob_size_mode(GUI::Slider::KnobSizeMode::Proportional); - auto slider1 = main_widget->add(); + auto slider1 = main_widget.add(); (void)slider1; - auto slider2 = main_widget->add(); + auto slider2 = main_widget.add(); slider2->set_enabled(false); - auto slider3 = main_widget->add(); + auto slider3 = main_widget.add(); slider3->set_max(5); slider3->set_knob_size_mode(GUI::Slider::KnobSizeMode::Proportional); - auto scrollbar1 = main_widget->add(Orientation::Horizontal); + auto scrollbar1 = main_widget.add(Orientation::Horizontal); scrollbar1->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); scrollbar1->set_preferred_size(0, 16); scrollbar1->set_min(0); scrollbar1->set_max(100); scrollbar1->set_value(50); - auto scrollbar2 = main_widget->add(Orientation::Horizontal); + auto scrollbar2 = main_widget.add(Orientation::Horizontal); scrollbar2->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); scrollbar2->set_preferred_size(0, 16); scrollbar2->set_enabled(false); diff --git a/DevTools/HackStudio/Editor.cpp b/DevTools/HackStudio/Editor.cpp index d8f6a900dc..d43d0e5ede 100644 --- a/DevTools/HackStudio/Editor.cpp +++ b/DevTools/HackStudio/Editor.cpp @@ -48,9 +48,7 @@ Editor::Editor() m_documentation_tooltip_window = GUI::Window::construct(); m_documentation_tooltip_window->set_rect(0, 0, 500, 400); m_documentation_tooltip_window->set_window_type(GUI::WindowType::Tooltip); - - m_documentation_html_view = HtmlView::construct(); - m_documentation_tooltip_window->set_main_widget(m_documentation_html_view); + m_documentation_html_view = m_documentation_tooltip_window->set_main_widget(); } Editor::~Editor() diff --git a/DevTools/HackStudio/Locator.cpp b/DevTools/HackStudio/Locator.cpp index 5ea40170f9..1c9431b0c4 100644 --- a/DevTools/HackStudio/Locator.cpp +++ b/DevTools/HackStudio/Locator.cpp @@ -150,10 +150,9 @@ Locator::Locator() m_popup_window->set_window_type(GUI::WindowType::Tooltip); m_popup_window->set_rect(0, 0, 500, 200); - m_suggestion_view = GUI::TableView::construct(); + m_suggestion_view = m_popup_window->set_main_widget(); m_suggestion_view->set_size_columns_to_fit_content(true); m_suggestion_view->set_headers_visible(false); - m_popup_window->set_main_widget(m_suggestion_view); m_suggestion_view->on_activation = [this](auto& index) { open_suggestion(index); diff --git a/DevTools/HackStudio/main.cpp b/DevTools/HackStudio/main.cpp index 186f050474..778b242f56 100644 --- a/DevTools/HackStudio/main.cpp +++ b/DevTools/HackStudio/main.cpp @@ -141,12 +141,11 @@ int main(int argc, char** argv) g_window->set_rect(90, 90, 840, 600); g_window->set_title("HackStudio"); - auto widget = GUI::Widget::construct(); - g_window->set_main_widget(widget); + auto& widget = g_window->set_main_widget(); - widget->set_fill_with_background_color(true); - widget->set_layout(); - widget->layout()->set_spacing(0); + widget.set_fill_with_background_color(true); + widget.set_layout(); + widget.layout()->set_spacing(0); StringBuilder path; path.append(getenv("PATH")); @@ -165,7 +164,7 @@ int main(int argc, char** argv) g_project = Project::load_from_file("little.files"); ASSERT(g_project); - auto toolbar = widget->add(); + auto toolbar = widget.add(); auto selected_file_names = [&] { Vector files; @@ -247,7 +246,7 @@ int main(int argc, char** argv) project_tree_view_context_menu->add_action(add_existing_file_action); project_tree_view_context_menu->add_action(delete_action); - auto outer_splitter = widget->add(); + auto outer_splitter = widget.add(); g_project_tree_view = outer_splitter->add(); g_project_tree_view->set_model(g_project->model()); g_project_tree_view->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); @@ -448,7 +447,7 @@ int main(int argc, char** argv) auto find_in_files_widget = s_action_tab_widget->add_tab("Find in files"); auto terminal_wrapper = s_action_tab_widget->add_tab("Console"); - auto locator = widget->add(); + auto locator = widget.add(); auto open_locator_action = GUI::Action::create("Open Locator...", { Mod_Ctrl, Key_K }, [&](auto&) { locator->open(); diff --git a/DevTools/Inspector/main.cpp b/DevTools/Inspector/main.cpp index ffb1cf288b..1d7294b612 100644 --- a/DevTools/Inspector/main.cpp +++ b/DevTools/Inspector/main.cpp @@ -58,12 +58,11 @@ int main(int argc, char** argv) window->set_title("Inspector"); window->set_rect(150, 150, 300, 500); - auto widget = GUI::Widget::construct(); - window->set_main_widget(widget); - widget->set_fill_with_background_color(true); - widget->set_layout(); + auto& widget = window->set_main_widget(); + widget.set_fill_with_background_color(true); + widget.set_layout(); - auto splitter = widget->add(); + auto splitter = widget.add(); RemoteProcess remote_process(pid); diff --git a/DevTools/ProfileViewer/main.cpp b/DevTools/ProfileViewer/main.cpp index bdf9ae7020..93b5a17d29 100644 --- a/DevTools/ProfileViewer/main.cpp +++ b/DevTools/ProfileViewer/main.cpp @@ -57,14 +57,13 @@ int main(int argc, char** argv) window->set_title("ProfileViewer"); window->set_rect(100, 100, 800, 600); - auto main_widget = GUI::Widget::construct(); - window->set_main_widget(main_widget); - main_widget->set_fill_with_background_color(true); - main_widget->set_layout(); + auto& main_widget = window->set_main_widget(); + main_widget.set_fill_with_background_color(true); + main_widget.set_layout(); - auto timeline_widget = main_widget->add(*profile); + auto timeline_widget = main_widget.add(*profile); - auto tree_view = main_widget->add(); + auto tree_view = main_widget.add(); tree_view->set_headers_visible(true); tree_view->set_size_columns_to_fit_content(true); tree_view->set_model(profile->model()); diff --git a/DevTools/VisualBuilder/VBPropertiesWindow.cpp b/DevTools/VisualBuilder/VBPropertiesWindow.cpp index 350795adcf..0b6b1475a4 100644 --- a/DevTools/VisualBuilder/VBPropertiesWindow.cpp +++ b/DevTools/VisualBuilder/VBPropertiesWindow.cpp @@ -81,13 +81,12 @@ VBPropertiesWindow::VBPropertiesWindow() set_title("Properties"); set_rect(780, 200, 240, 280); - auto widget = GUI::Widget::construct(); - widget->set_fill_with_background_color(true); - widget->set_layout(); - widget->layout()->set_margins({ 2, 2, 2, 2 }); - set_main_widget(widget); + auto& widget = set_main_widget(); + widget.set_fill_with_background_color(true); + widget.set_layout(); + widget.layout()->set_margins({ 2, 2, 2, 2 }); - m_table_view = widget->add(); + m_table_view = widget.add(); m_table_view->set_headers_visible(false); m_table_view->set_editable(true); diff --git a/DevTools/VisualBuilder/main.cpp b/DevTools/VisualBuilder/main.cpp index 228a47d4d6..60bd53ad09 100644 --- a/DevTools/VisualBuilder/main.cpp +++ b/DevTools/VisualBuilder/main.cpp @@ -106,13 +106,12 @@ RefPtr make_toolbox_window() window->set_title("Widgets"); window->set_rect(20, 200, 80, 300); - auto widget = GUI::Widget::construct(); - widget->set_fill_with_background_color(true); - widget->set_layout(); - widget->layout()->set_spacing(0); - window->set_main_widget(widget); + auto& widget = window->set_main_widget(); + widget.set_fill_with_background_color(true); + widget.set_layout(); + widget.layout()->set_spacing(0); - auto label_button = widget->add(); + auto label_button = widget.add(); label_button->set_button_style(Gfx::ButtonStyle::CoolBar); label_button->set_tooltip("GLabel"); label_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/label.png")); @@ -121,7 +120,7 @@ RefPtr make_toolbox_window() form->insert_widget(VBWidgetType::GLabel); }; - auto button_button = widget->add(); + auto button_button = widget.add(); button_button->set_button_style(Gfx::ButtonStyle::CoolBar); button_button->set_tooltip("GButton"); button_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/button.png")); @@ -129,7 +128,7 @@ RefPtr make_toolbox_window() if (auto* form = VBForm::current()) form->insert_widget(VBWidgetType::GButton); }; - auto spinbox_button = widget->add(); + auto spinbox_button = widget.add(); spinbox_button->set_button_style(Gfx::ButtonStyle::CoolBar); spinbox_button->set_tooltip("GSpinBox"); spinbox_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/spinbox.png")); @@ -137,7 +136,7 @@ RefPtr make_toolbox_window() if (auto* form = VBForm::current()) form->insert_widget(VBWidgetType::GSpinBox); }; - auto editor_button = widget->add(); + auto editor_button = widget.add(); editor_button->set_button_style(Gfx::ButtonStyle::CoolBar); editor_button->set_tooltip("GTextEditor"); editor_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/textbox.png")); @@ -145,7 +144,7 @@ RefPtr make_toolbox_window() if (auto* form = VBForm::current()) form->insert_widget(VBWidgetType::GTextEditor); }; - auto progress_bar_button = widget->add(); + auto progress_bar_button = widget.add(); progress_bar_button->set_button_style(Gfx::ButtonStyle::CoolBar); progress_bar_button->set_tooltip("GProgressBar"); progress_bar_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/progressbar.png")); @@ -153,7 +152,7 @@ RefPtr make_toolbox_window() if (auto* form = VBForm::current()) form->insert_widget(VBWidgetType::GProgressBar); }; - auto slider_button = widget->add(); + auto slider_button = widget.add(); slider_button->set_button_style(Gfx::ButtonStyle::CoolBar); slider_button->set_tooltip("GSlider"); slider_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/slider.png")); @@ -161,7 +160,7 @@ RefPtr make_toolbox_window() if (auto* form = VBForm::current()) form->insert_widget(VBWidgetType::GSlider); }; - auto checkbox_button = widget->add(); + auto checkbox_button = widget.add(); checkbox_button->set_button_style(Gfx::ButtonStyle::CoolBar); checkbox_button->set_tooltip("GCheckBox"); checkbox_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/checkbox.png")); @@ -169,7 +168,7 @@ RefPtr make_toolbox_window() if (auto* form = VBForm::current()) form->insert_widget(VBWidgetType::GCheckBox); }; - auto radiobutton_button = widget->add(); + auto radiobutton_button = widget.add(); radiobutton_button->set_button_style(Gfx::ButtonStyle::CoolBar); radiobutton_button->set_tooltip("GRadioButton"); radiobutton_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/filled-radio-circle.png")); @@ -177,7 +176,7 @@ RefPtr make_toolbox_window() if (auto* form = VBForm::current()) form->insert_widget(VBWidgetType::GRadioButton); }; - auto scrollbar_button = widget->add(); + auto scrollbar_button = widget.add(); scrollbar_button->set_button_style(Gfx::ButtonStyle::CoolBar); scrollbar_button->set_tooltip("GScrollBar"); scrollbar_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/scrollbar.png")); @@ -185,7 +184,7 @@ RefPtr make_toolbox_window() if (auto* form = VBForm::current()) form->insert_widget(VBWidgetType::GScrollBar); }; - auto groupbox_button = widget->add(); + auto groupbox_button = widget.add(); groupbox_button->set_button_style(Gfx::ButtonStyle::CoolBar); groupbox_button->set_tooltip("GGroupBox"); groupbox_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/vbwidgets/groupbox.png")); diff --git a/Games/Minesweeper/main.cpp b/Games/Minesweeper/main.cpp index fa33033a31..a1cc2c3c45 100644 --- a/Games/Minesweeper/main.cpp +++ b/Games/Minesweeper/main.cpp @@ -57,12 +57,11 @@ int main(int argc, char** argv) window->set_title("Minesweeper"); window->set_rect(100, 100, 139, 175); - auto widget = GUI::Widget::construct(); - window->set_main_widget(widget); - widget->set_layout(); - widget->layout()->set_spacing(0); + auto& widget = window->set_main_widget(); + widget.set_layout(); + widget.layout()->set_spacing(0); - auto container = widget->add(); + auto container = widget.add(); container->set_fill_with_background_color(true); container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); container->set_preferred_size(0, 36); @@ -77,7 +76,7 @@ int main(int argc, char** argv) auto time_icon_label = container->add(); time_icon_label->set_icon(Gfx::Bitmap::load_from_file("/res/icons/minesweeper/timer.png")); auto time_label = container->add(); - auto field = widget->add(*flag_label, *time_label, *face_button, [&](auto size) { + auto field = widget.add(*flag_label, *time_label, *face_button, [&](auto size) { size.set_height(size.height() + container->preferred_size().height()); window->resize(size); }); diff --git a/Games/Snake/main.cpp b/Games/Snake/main.cpp index 39967a06f7..95dcb6a5af 100644 --- a/Games/Snake/main.cpp +++ b/Games/Snake/main.cpp @@ -55,15 +55,14 @@ int main(int argc, char** argv) window->set_title("Snake"); window->set_rect(100, 100, 320, 320); - auto game = SnakeGame::construct(); - window->set_main_widget(game); + auto& game = window->set_main_widget(); auto menubar = make(); auto app_menu = GUI::Menu::construct("Snake"); app_menu->add_action(GUI::Action::create("New game", { Mod_None, Key_F2 }, [&](const GUI::Action&) { - game->reset(); + game.reset(); })); app_menu->add_action(GUI::CommonActions::make_quit_action([](auto&) { GUI::Application::the().quit(0); diff --git a/Libraries/LibGUI/AboutDialog.cpp b/Libraries/LibGUI/AboutDialog.cpp index 1de49c2c3b..5b0f0a8cbc 100644 --- a/Libraries/LibGUI/AboutDialog.cpp +++ b/Libraries/LibGUI/AboutDialog.cpp @@ -42,12 +42,11 @@ AboutDialog::AboutDialog(const StringView& name, const Gfx::Bitmap* icon, Core:: set_title(String::format("About %s", m_name.characters())); set_resizable(false); - auto widget = Widget::construct(); - set_main_widget(widget); - widget->set_fill_with_background_color(true); - widget->set_layout(); + auto& widget = set_main_widget(); + widget.set_fill_with_background_color(true); + widget.set_layout(); - auto left_container = widget->add(); + auto left_container = widget.add(); left_container->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill); left_container->set_preferred_size(48, 0); left_container->set_layout(); @@ -57,7 +56,7 @@ AboutDialog::AboutDialog(const StringView& name, const Gfx::Bitmap* icon, Core:: icon_label->set_preferred_size(40, 40); left_container->layout()->add_spacer(); - auto right_container = widget->add(); + auto right_container = widget.add(); right_container->set_layout(); right_container->layout()->set_margins({ 0, 4, 4, 4 }); diff --git a/Libraries/LibGUI/Application.cpp b/Libraries/LibGUI/Application.cpp index 3e75168eb8..420a938711 100644 --- a/Libraries/LibGUI/Application.cpp +++ b/Libraries/LibGUI/Application.cpp @@ -122,13 +122,12 @@ private: TooltipWindow() { set_window_type(WindowType::Tooltip); - m_label = Label::construct(); + m_label = set_main_widget