diff --git a/Userland/Demos/WidgetGallery/DemoWizardDialog.cpp b/Userland/Demos/WidgetGallery/DemoWizardDialog.cpp index e00dd7de8a..1b118e8acd 100644 --- a/Userland/Demos/WidgetGallery/DemoWizardDialog.cpp +++ b/Userland/Demos/WidgetGallery/DemoWizardDialog.cpp @@ -16,7 +16,7 @@ DemoWizardDialog::DemoWizardDialog(GUI::Window* parent_window) : GUI::WizardDialog(parent_window) { // Create the front cover - m_front_page = GUI::CoverWizardPage::construct(); + m_front_page = GUI::CoverWizardPage::try_create().release_value_but_fixme_should_propagate_errors(); m_front_page->set_header_text("Welcome to the SerenityOS demo wizard!"); m_front_page->set_body_text("This wizard demonstrates the amazing wizardry\ncapabilities of LibGUI :^)"); m_front_page->on_next_page = [&]() { @@ -24,9 +24,10 @@ DemoWizardDialog::DemoWizardDialog(GUI::Window* parent_window) }; // Create Page 1 - m_page_1 = GUI::WizardPage::construct( + m_page_1 = GUI::WizardPage::try_create( "Installation location", - "Choose where Demo Application is installed on your computer."); + "Choose where Demo Application is installed on your computer.") + .release_value_but_fixme_should_propagate_errors(); m_page_1->body_widget().load_from_gml(demo_wizard_page_1_gml); m_page_1_location_text_box = m_page_1->body_widget().find_descendant_of_type_named("page_1_location_text_box"); m_page_1->on_next_page = [&]() { @@ -34,12 +35,13 @@ DemoWizardDialog::DemoWizardDialog(GUI::Window* parent_window) }; // Create Page 2 with a progress bar :^) - m_page_2 = GUI::WizardPage::construct( + m_page_2 = GUI::WizardPage::try_create( "Installation in progress...", - "Please wait. Do not turn off your computer."); + "Please wait. Do not turn off your computer.") + .release_value_but_fixme_should_propagate_errors(); m_page_2->body_widget().load_from_gml(demo_wizard_page_2_gml); m_page_2_progressbar = m_page_2->body_widget().find_descendant_of_type_named("page_2_progressbar"); - m_page_2_timer = Core::Timer::construct(this); + m_page_2_timer = Core::Timer::try_create(this).release_value_but_fixme_should_propagate_errors(); m_page_2->on_page_enter = [&]() { m_page_2_progress_value = 0; m_page_2_timer->restart(100); @@ -62,7 +64,7 @@ DemoWizardDialog::DemoWizardDialog(GUI::Window* parent_window) // Don't set a on_next_page handler for page 2 as we automatically navigate to the final page on progress completion // Create the back cover - m_back_page = GUI::CoverWizardPage::construct(); + m_back_page = GUI::CoverWizardPage::try_create().release_value_but_fixme_should_propagate_errors(); m_back_page->set_header_text("Wizard complete."); m_back_page->set_body_text("That concludes the SerenityOS demo wizard :^)"); m_back_page->set_is_final_page(true); diff --git a/Userland/Demos/WidgetGallery/GalleryWidget.cpp b/Userland/Demos/WidgetGallery/GalleryWidget.cpp index a45a892541..5f631e4164 100644 --- a/Userland/Demos/WidgetGallery/GalleryWidget.cpp +++ b/Userland/Demos/WidgetGallery/GalleryWidget.cpp @@ -36,11 +36,11 @@ GalleryWidget::GalleryWidget() auto& tab_widget = *find_descendant_of_type_named("tab_widget"); tab_widget.set_reorder_allowed(true); - auto& basics_tab = tab_widget.add_tab("Basics"); - basics_tab.load_from_gml(basics_tab_gml); + auto basics_tab = tab_widget.try_add_tab("Basics").release_value_but_fixme_should_propagate_errors(); + basics_tab->load_from_gml(basics_tab_gml); - m_enabled_label = basics_tab.find_descendant_of_type_named("enabled_label"); - m_label_frame = basics_tab.find_descendant_of_type_named("label_frame"); + m_enabled_label = basics_tab->find_descendant_of_type_named("enabled_label"); + m_label_frame = basics_tab->find_descendant_of_type_named("label_frame"); m_frame_shapes.append("No Frame"); m_frame_shapes.append("Plain Box"); @@ -53,7 +53,7 @@ GalleryWidget::GalleryWidget() m_frame_shapes.append("Sunken Container"); m_frame_shapes.append("Sunken Panel"); - m_frame_shape_combobox = basics_tab.find_descendant_of_type_named("frame_shape_combobox"); + m_frame_shape_combobox = basics_tab->find_descendant_of_type_named("frame_shape_combobox"); m_frame_shape_combobox->set_model(*GUI::ItemListModel::create(m_frame_shapes)); m_frame_shape_combobox->on_change = [&](auto&, const auto& index) { @@ -66,7 +66,7 @@ GalleryWidget::GalleryWidget() m_enabled_label->set_text(m_frame_shape_combobox->text()); }; - m_thickness_spinbox = basics_tab.find_descendant_of_type_named("thickness_spinbox"); + m_thickness_spinbox = basics_tab->find_descendant_of_type_named("thickness_spinbox"); m_thickness_spinbox->set_value(1); m_thickness_spinbox->on_change = [&](auto value) { @@ -77,10 +77,10 @@ GalleryWidget::GalleryWidget() m_button_icons.append(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/inspector-object.png").release_value_but_fixme_should_propagate_errors()); m_button_icons.append(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/ladybug.png").release_value_but_fixme_should_propagate_errors()); - m_icon_button = basics_tab.find_descendant_of_type_named("icon_button"); + m_icon_button = basics_tab->find_descendant_of_type_named("icon_button"); m_icon_button->set_icon(*m_button_icons[2]); - m_disabled_icon_button = basics_tab.find_descendant_of_type_named("disabled_icon_button"); + m_disabled_icon_button = basics_tab->find_descendant_of_type_named("disabled_icon_button"); m_disabled_icon_button->set_icon(*m_button_icons[2]); m_icon_button->on_click = [&](auto) { @@ -92,19 +92,19 @@ GalleryWidget::GalleryWidget() i++; }; - m_text_editor = basics_tab.find_descendant_of_type_named("text_editor"); + m_text_editor = basics_tab->find_descendant_of_type_named("text_editor"); - m_font_button = basics_tab.find_descendant_of_type_named("font_button"); + m_font_button = basics_tab->find_descendant_of_type_named("font_button"); m_font_button->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-font-editor.png").release_value_but_fixme_should_propagate_errors()); m_font_button->on_click = [&](auto) { - auto picker = GUI::FontPicker::construct(window(), &m_text_editor->font(), false); + auto picker = GUI::FontPicker::try_create(window(), &m_text_editor->font(), false).release_value_but_fixme_should_propagate_errors(); if (picker->exec() == GUI::Dialog::ExecOK) { m_text_editor->set_font(picker->font()); } }; - m_file_button = basics_tab.find_descendant_of_type_named("file_button"); + m_file_button = basics_tab->find_descendant_of_type_named("file_button"); m_file_button->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/open.png").release_value_but_fixme_should_propagate_errors()); m_file_button->on_click = [&](auto) { @@ -114,7 +114,7 @@ GalleryWidget::GalleryWidget() m_text_editor->set_text(open_path.value()); }; - m_input_button = basics_tab.find_descendant_of_type_named("input_button"); + m_input_button = basics_tab->find_descendant_of_type_named("input_button"); m_input_button->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/properties.png").release_value_but_fixme_should_propagate_errors()); m_input_button->on_click = [&](auto) { @@ -123,7 +123,7 @@ GalleryWidget::GalleryWidget() m_text_editor->set_text(value); }; - m_font_colorinput = basics_tab.find_descendant_of_type_named("font_colorinput"); + m_font_colorinput = basics_tab->find_descendant_of_type_named("font_colorinput"); m_font_colorinput->on_change = [&]() { auto palette = m_text_editor->palette(); @@ -132,7 +132,7 @@ GalleryWidget::GalleryWidget() m_text_editor->update(); }; - m_msgbox_button = basics_tab.find_descendant_of_type_named("msgbox_button"); + m_msgbox_button = basics_tab->find_descendant_of_type_named("msgbox_button"); m_msgbox_button->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-browser.png").release_value_but_fixme_should_propagate_errors()); m_msgbox_type = GUI::MessageBox::Type::None; @@ -149,7 +149,7 @@ GalleryWidget::GalleryWidget() m_msgbox_buttons.append("Yes No"); m_msgbox_buttons.append("Yes No Cancel"); - m_msgbox_icon_combobox = basics_tab.find_descendant_of_type_named("msgbox_icon_combobox"); + m_msgbox_icon_combobox = basics_tab->find_descendant_of_type_named("msgbox_icon_combobox"); m_msgbox_icon_combobox->set_model(*GUI::ItemListModel::create(m_msgbox_icons)); m_msgbox_icon_combobox->set_selected_index(0); @@ -157,7 +157,7 @@ GalleryWidget::GalleryWidget() m_msgbox_type = static_cast(index.row()); }; - m_msgbox_buttons_combobox = basics_tab.find_descendant_of_type_named("msgbox_buttons_combobox"); + m_msgbox_buttons_combobox = basics_tab->find_descendant_of_type_named("msgbox_buttons_combobox"); m_msgbox_buttons_combobox->set_model(*GUI::ItemListModel::create(m_msgbox_buttons)); m_msgbox_buttons_combobox->set_selected_index(0); @@ -169,17 +169,17 @@ GalleryWidget::GalleryWidget() GUI::MessageBox::show(window(), m_text_editor->text(), "Message", m_msgbox_type, m_msgbox_input_type); }; - auto& sliders_tab = tab_widget.add_tab("Sliders"); - sliders_tab.load_from_gml(sliders_tab_gml); + auto sliders_tab = tab_widget.try_add_tab("Sliders").release_value_but_fixme_should_propagate_errors(); + sliders_tab->load_from_gml(sliders_tab_gml); - m_vertical_progressbar_left = sliders_tab.find_descendant_of_type_named("vertical_progressbar_left"); + m_vertical_progressbar_left = sliders_tab->find_descendant_of_type_named("vertical_progressbar_left"); m_vertical_progressbar_left->set_value(0); - m_vertical_progressbar_right = sliders_tab.find_descendant_of_type_named("vertical_progressbar_right"); + m_vertical_progressbar_right = sliders_tab->find_descendant_of_type_named("vertical_progressbar_right"); m_vertical_progressbar_right->set_value(100); - m_vertical_slider_left = sliders_tab.find_descendant_of_type_named("vertical_slider_left"); - m_vertical_slider_right = sliders_tab.find_descendant_of_type_named("vertical_slider_right"); + m_vertical_slider_left = sliders_tab->find_descendant_of_type_named("vertical_slider_left"); + m_vertical_slider_right = sliders_tab->find_descendant_of_type_named("vertical_slider_right"); m_vertical_slider_left->on_change = [&](auto value) { m_vertical_progressbar_left->set_value(m_vertical_slider_left->max() - value); @@ -189,11 +189,11 @@ GalleryWidget::GalleryWidget() m_vertical_progressbar_right->set_value((100 / m_vertical_slider_right->max()) * (m_vertical_slider_right->max() - value)); }; - m_horizontal_progressbar = sliders_tab.find_descendant_of_type_named("horizontal_progressbar"); + m_horizontal_progressbar = sliders_tab->find_descendant_of_type_named("horizontal_progressbar"); m_horizontal_progressbar->set_value(0); - m_horizontal_slider_left = sliders_tab.find_descendant_of_type_named("horizontal_slider_left"); - m_horizontal_slider_right = sliders_tab.find_descendant_of_type_named("horizontal_slider_right"); + m_horizontal_slider_left = sliders_tab->find_descendant_of_type_named("horizontal_slider_left"); + m_horizontal_slider_right = sliders_tab->find_descendant_of_type_named("horizontal_slider_right"); m_horizontal_slider_left->on_change = [&](auto value) { m_horizontal_progressbar->set_value(value); @@ -206,23 +206,23 @@ GalleryWidget::GalleryWidget() m_horizontal_slider_left->set_value((value * 100) / m_horizontal_slider_right->max()); }; - m_enabled_scrollbar = sliders_tab.find_descendant_of_type_named("enabled_scrollbar"); + m_enabled_scrollbar = sliders_tab->find_descendant_of_type_named("enabled_scrollbar"); m_enabled_scrollbar->set_orientation(Orientation::Horizontal); - m_disabled_scrollbar = sliders_tab.find_descendant_of_type_named("disabled_scrollbar"); + m_disabled_scrollbar = sliders_tab->find_descendant_of_type_named("disabled_scrollbar"); m_disabled_scrollbar->set_orientation(Orientation::Horizontal); - m_opacity_imagewidget = sliders_tab.find_descendant_of_type_named("opacity_imagewidget"); + m_opacity_imagewidget = sliders_tab->find_descendant_of_type_named("opacity_imagewidget"); m_opacity_imagewidget->load_from_file("/res/graphics/brand-banner.png"); - m_opacity_slider = sliders_tab.find_descendant_of_type_named("opacity_slider"); + m_opacity_slider = sliders_tab->find_descendant_of_type_named("opacity_slider"); m_opacity_slider->on_change = [&](auto percent) { m_opacity_imagewidget->set_opacity_percent(percent); m_opacity_value_slider->set_value(percent); }; - m_opacity_value_slider = sliders_tab.find_descendant_of_type_named("opacity_value_slider"); + m_opacity_value_slider = sliders_tab->find_descendant_of_type_named("opacity_value_slider"); m_opacity_value_slider->set_range(0, 100); m_opacity_value_slider->on_change = [&](auto percent) { @@ -230,11 +230,11 @@ GalleryWidget::GalleryWidget() m_opacity_slider->set_value(percent); }; - auto& wizards_tab = tab_widget.add_tab("Wizards"); - wizards_tab.load_from_gml(wizards_tab_gml); + auto wizards_tab = tab_widget.try_add_tab("Wizards").release_value_but_fixme_should_propagate_errors(); + wizards_tab->load_from_gml(wizards_tab_gml); - m_wizard_button = wizards_tab.find_descendant_of_type_named("wizard_button"); - m_wizard_output = wizards_tab.find_descendant_of_type_named("wizard_output"); + m_wizard_button = wizards_tab->find_descendant_of_type_named("wizard_button"); + m_wizard_output = wizards_tab->find_descendant_of_type_named("wizard_output"); m_wizard_output->set_should_hide_unnecessary_scrollbars(true); const char* serenityos_ascii = { @@ -277,7 +277,7 @@ GalleryWidget::GalleryWidget() sb.append("\nWizard started."); m_wizard_output->set_text(sb.to_string()); - auto wizard = DemoWizardDialog::construct(window()); + auto wizard = DemoWizardDialog::try_create(window()).release_value_but_fixme_should_propagate_errors(); int result = wizard->exec(); sb.append(String::formatted("\nWizard execution complete.\nDialog ExecResult code: {}", result)); @@ -286,10 +286,10 @@ GalleryWidget::GalleryWidget() m_wizard_output->set_text(sb.string_view()); }; - auto& cursors_tab = tab_widget.add_tab("Cursors"); - cursors_tab.load_from_gml(cursors_tab_gml); + auto cursors_tab = tab_widget.try_add_tab("Cursors").release_value_but_fixme_should_propagate_errors(); + cursors_tab->load_from_gml(cursors_tab_gml); - m_cursors_tableview = cursors_tab.find_descendant_of_type_named("cursors_tableview"); + m_cursors_tableview = cursors_tab->find_descendant_of_type_named("cursors_tableview"); m_cursors_tableview->set_highlight_selected_rows(true); m_cursors_tableview->set_alternating_row_colors(false); m_cursors_tableview->set_vertical_padding(16); @@ -309,10 +309,10 @@ GalleryWidget::GalleryWidget() m_cursors_tableview->set_override_cursor(NonnullRefPtr(icon_index.data().as_bitmap())); }; - auto& icons_tab = tab_widget.add_tab("Icons"); - icons_tab.load_from_gml(icons_tab_gml); + auto icons_tab = tab_widget.try_add_tab("Icons").release_value_but_fixme_should_propagate_errors(); + icons_tab->load_from_gml(icons_tab_gml); - m_icons_tableview = icons_tab.find_descendant_of_type_named("icons_tableview"); + m_icons_tableview = icons_tab->find_descendant_of_type_named("icons_tableview"); m_icons_tableview->set_highlight_selected_rows(true); m_icons_tableview->set_alternating_row_colors(false); m_icons_tableview->set_vertical_padding(24); diff --git a/Userland/Demos/WidgetGallery/main.cpp b/Userland/Demos/WidgetGallery/main.cpp index 539dbd3a32..4484312577 100644 --- a/Userland/Demos/WidgetGallery/main.cpp +++ b/Userland/Demos/WidgetGallery/main.cpp @@ -28,7 +28,7 @@ ErrorOr serenity_main(Main::Arguments arguments) window->resize(430, 480); window->set_title("Widget Gallery"); window->set_icon(app_icon.bitmap_for_size(16)); - window->set_main_widget(); + TRY(window->try_set_main_widget()); window->show(); return app->exec();