LibGUI: Remove Layout::try_add_spacer()

And fall back to the infallible add_spacer().

Work towards #20557.
This commit is contained in:
Andreas Kling 2023-08-13 18:29:05 +02:00
parent 8322b31b97
commit 58e482a06d
Notes: sideshowbarker 2024-07-17 07:38:17 +09:00
22 changed files with 28 additions and 35 deletions

View file

@ -301,7 +301,7 @@ static ErrorOr<void> generate_loader_for_object(GUI::GML::Object const& gml_obje
TRY(gml_object.try_for_each_child_object([&](auto const& child) -> ErrorOr<void> {
// Spacer is a pseudo-class that insteads causes a call to `Widget::add_spacer` on the parent object.
if (child.name() == "GUI::Layout::Spacer"sv) {
TRY(append(generator, "TRY(@object_name@->add_spacer());"));
TRY(append(generator, "@object_name@->add_spacer();"));
return {};
}

View file

@ -69,7 +69,7 @@ DownloadWidget::DownloadWidget(const URL& url)
m_browser_image = animation_container.add<GUI::ImageWidget>();
m_browser_image->load_from_file("/res/graphics/download-animation.gif"sv);
animation_container.add_spacer().release_value_but_fixme_should_propagate_errors();
animation_container.add_spacer();
auto& source_label = add<GUI::Label>(String::formatted("File: {}", m_url.basename()).release_value_but_fixme_should_propagate_errors());
source_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
@ -102,7 +102,7 @@ DownloadWidget::DownloadWidget(const URL& url)
auto& button_container = add<GUI::Widget>();
button_container.set_layout<GUI::HorizontalBoxLayout>();
button_container.add_spacer().release_value_but_fixme_should_propagate_errors();
button_container.add_spacer();
m_cancel_button = button_container.add<GUI::Button>("Cancel"_string);
m_cancel_button->set_fixed_size(100, 22);
m_cancel_button->on_click = [this](auto) {

View file

@ -88,12 +88,12 @@ AddEventDialog::AddEventDialog(Core::DateTime date_time, EventManager& event_man
starting_meridiem_combo.set_model(MeridiemListModel::create());
starting_meridiem_combo.set_selected_index(0);
widget->add_spacer().release_value_but_fixme_should_propagate_errors();
widget->add_spacer();
auto& button_container = widget->add<GUI::Widget>();
button_container.set_fixed_height(20);
button_container.set_layout<GUI::HorizontalBoxLayout>();
button_container.add_spacer().release_value_but_fixme_should_propagate_errors();
button_container.add_spacer();
auto& ok_button = button_container.add<GUI::Button>("OK"_string);
ok_button.set_fixed_size(80, 20);
ok_button.on_click = [&](auto) {

View file

@ -82,7 +82,7 @@ ErrorOr<void> PropertiesWindow::create_widgets(bool disable_rename)
button_widget->set_layout<GUI::HorizontalBoxLayout>(GUI::Margins {}, 5);
button_widget->set_fixed_height(22);
TRY(button_widget->add_spacer());
button_widget->add_spacer();
auto ok_button = TRY(make_button("OK"_string, button_widget));
ok_button->on_click = [this](auto) {

View file

@ -94,7 +94,7 @@ void KeyboardMapperWidget::create_frame()
add_map_radio_button("alt_map"sv, "Alt"_string);
add_map_radio_button("shift_altgr_map"sv, "Shift+AltGr"_string);
bottom_widget.add_spacer().release_value_but_fixme_should_propagate_errors();
bottom_widget.add_spacer();
}
void KeyboardMapperWidget::add_map_radio_button(const StringView map_name, String button_text)

View file

@ -36,7 +36,7 @@ ErrorOr<NonnullRefPtr<TrackControlsWidget>> TrackControlsWidget::try_create(Weak
TRY(widget->m_processor_groups.try_append(mastering_parameters));
TRY(widget->add_spacer());
widget->add_spacer();
for (auto& processor : strong_track->processor_chain()) {
auto processor_parameters = TRY(widget->try_add<GUI::GroupBox>());

View file

@ -295,7 +295,7 @@ ErrorOr<GUI::Widget*> GradientTool::get_properties_widget()
auto button_container = TRY(properties_widget->try_add<GUI::Widget>());
button_container->set_fixed_height(22);
button_container->set_layout<GUI::HorizontalBoxLayout>();
button_container->add_spacer().release_value_but_fixme_should_propagate_errors();
button_container->add_spacer();
auto apply_button = TRY(button_container->try_add<GUI::DialogButton>("Apply"_string));
apply_button->on_click = [this](auto) {

View file

@ -55,7 +55,7 @@ CellTypeDialog::CellTypeDialog(Vector<Position> const& positions, Sheet& sheet,
auto& buttonbox = main_widget->add<GUI::Widget>();
buttonbox.set_shrink_to_fit(true);
buttonbox.set_layout<GUI::HorizontalBoxLayout>(GUI::Margins {}, 10);
buttonbox.add_spacer().release_value_but_fixme_should_propagate_errors();
buttonbox.add_spacer();
auto& ok_button = buttonbox.add<GUI::Button>("OK"_string);
ok_button.set_fixed_width(80);
ok_button.on_click = [&](auto) { done(ExecResult::OK); };

View file

@ -226,7 +226,7 @@ void ColorPicker::build_ui()
auto& button_container = root_container->add<Widget>();
button_container.set_preferred_height(GUI::SpecialDimension::Fit);
button_container.set_layout<HorizontalBoxLayout>(4);
button_container.add_spacer().release_value_but_fixme_should_propagate_errors();
button_container.add_spacer();
auto& ok_button = button_container.add<DialogButton>();
ok_button.set_text("OK"_string);
@ -327,7 +327,7 @@ void ColorPicker::build_ui_custom(Widget& root_container)
// Preview selected color
m_preview_widget = preview_container.add<ColorPreview>(m_color);
vertical_container.add_spacer().release_value_but_fixme_should_propagate_errors();
vertical_container.add_spacer();
// HTML
auto& html_container = vertical_container.add<GUI::Widget>();

View file

@ -159,7 +159,7 @@ ErrorOr<void> InputBox::build()
auto button_container = TRY(main_widget->try_add<Widget>());
button_container->set_layout<HorizontalBoxLayout>(0, 6);
TRY(button_container->add_spacer());
button_container->add_spacer();
m_ok_button = TRY(button_container->try_add<DialogButton>("OK"_string));
m_ok_button->on_click = [this](auto) {

View file

@ -73,15 +73,9 @@ void Layout::add_entry(Entry&& entry)
MUST(try_add_entry(move(entry)));
}
ErrorOr<void> Layout::try_add_spacer()
{
TRY(try_add_entry(Entry { .type = Entry::Type::Spacer }));
return {};
}
void Layout::add_spacer()
{
MUST(try_add_spacer());
add_entry(Entry { .type = Entry::Type::Spacer });
}
void Layout::add_layout(OwnPtr<Layout>&& layout)

View file

@ -40,7 +40,6 @@ public:
ErrorOr<void> try_add_widget(Widget&);
ErrorOr<void> try_insert_widget_before(Widget& widget, Widget& before_widget);
ErrorOr<void> try_add_spacer();
void remove_widget(Widget&);

View file

@ -179,7 +179,7 @@ ErrorOr<void> MessageBox::build()
return button;
};
TRY(button_container->add_spacer());
button_container->add_spacer();
if (should_include_ok_button())
m_ok_button = TRY(add_button("OK"_string, ExecResult::OK));
if (should_include_yes_button())
@ -188,7 +188,7 @@ ErrorOr<void> MessageBox::build()
m_no_button = TRY(add_button("No"_string, ExecResult::No));
if (should_include_cancel_button())
m_cancel_button = TRY(add_button("Cancel"_string, ExecResult::Cancel));
TRY(button_container->add_spacer());
button_container->add_spacer();
return {};
}

View file

@ -49,7 +49,7 @@ ProcessChooser::ProcessChooser(StringView window_title, String button_label, Gfx
auto& button_container = widget->add<GUI::Widget>();
button_container.set_fixed_height(30);
button_container.set_layout<GUI::HorizontalBoxLayout>(GUI::Margins { 0, 4, 0 });
button_container.add_spacer().release_value_but_fixme_should_propagate_errors();
button_container.add_spacer();
auto& select_button = button_container.add<GUI::Button>(m_button_label);
select_button.set_fixed_width(80);

View file

@ -49,7 +49,7 @@ ErrorOr<NonnullRefPtr<SettingsWindow>> SettingsWindow::create(DeprecatedString t
};
}
TRY(button_container->add_spacer());
button_container->add_spacer();
window->m_ok_button = TRY(button_container->try_add<GUI::DialogButton>("OK"_string));
window->m_ok_button->on_click = [window = window->make_weak_ptr<SettingsWindow>()](auto) {

View file

@ -174,7 +174,7 @@ ErrorOr<void> Toolbar::create_overflow_objects()
m_overflow_action->set_status_tip("Show hidden toolbar actions"_string);
m_overflow_action->set_enabled(false);
TRY(add_spacer());
add_spacer();
m_overflow_button = TRY(try_add_action(*m_overflow_action));
m_overflow_button->set_visible(false);

View file

@ -1199,7 +1199,7 @@ ErrorOr<void> Widget::load_from_gml_ast(NonnullRefPtr<GUI::GML::Node const> ast,
if (!this->layout()) {
return Error::from_string_literal("Specified GUI::Layout::Spacer in GML, but the parent has no Layout.");
}
this->layout()->add_spacer();
add_spacer();
} else {
RefPtr<Core::EventReceiver> child;
if (auto* registration = GUI::ObjectClassRegistration::find(class_name)) {
@ -1259,10 +1259,10 @@ bool Widget::is_visible_for_timer_purposes() const
return is_visible() && Object::is_visible_for_timer_purposes();
}
ErrorOr<void> Widget::add_spacer()
void Widget::add_spacer()
{
VERIFY(layout());
return layout()->try_add_spacer();
return layout()->add_spacer();
}
}

View file

@ -356,7 +356,7 @@ public:
// In order for others to be able to call this, it needs to be public.
virtual ErrorOr<void> load_from_gml_ast(NonnullRefPtr<GUI::GML::Node const> ast, UnregisteredChildHandler);
ErrorOr<void> add_spacer();
void add_spacer();
protected:
Widget();

View file

@ -39,7 +39,7 @@ ErrorOr<void> WizardDialog::build()
auto nav_container_widget = TRY(main_widget->try_add<Widget>());
nav_container_widget->set_layout<HorizontalBoxLayout>(Margins { 0, 10 }, 0);
nav_container_widget->set_fixed_height(42);
TRY(nav_container_widget->add_spacer());
nav_container_widget->add_spacer();
m_back_button = TRY(nav_container_widget->try_add<DialogButton>("< Back"_string));
m_back_button->on_click = [&](auto) {

View file

@ -39,7 +39,7 @@ ErrorOr<void> WizardPage::build(String title, String subtitle)
m_subtitle_label = TRY(header_widget->try_add<Label>(move(subtitle)));
m_subtitle_label->set_text_alignment(Gfx::TextAlignment::TopLeft);
m_subtitle_label->set_fixed_height(m_subtitle_label->font().pixel_size_rounded_up());
TRY(header_widget->add_spacer());
header_widget->add_spacer();
auto separator = TRY(try_add<SeparatorWidget>(Gfx::Orientation::Horizontal));
separator->set_fixed_height(2);

View file

@ -101,7 +101,7 @@ ClockWidget::ClockWidget()
auto& settings_container = root_container->add<GUI::Widget>();
settings_container.set_fixed_height(24);
settings_container.set_layout<GUI::HorizontalBoxLayout>(GUI::Margins { 2 });
settings_container.add_spacer().release_value_but_fixme_should_propagate_errors();
settings_container.add_spacer();
m_jump_to_button = settings_container.add<GUI::Button>();
m_jump_to_button->set_button_style(Gfx::ButtonStyle::Coolbar);

View file

@ -86,12 +86,12 @@ ShutdownDialog::ShutdownDialog()
}
}
right_container.add_spacer().release_value_but_fixme_should_propagate_errors();
right_container.add_spacer();
auto& button_container = right_container.add<GUI::Widget>();
button_container.set_fixed_height(23);
button_container.set_layout<GUI::HorizontalBoxLayout>(GUI::Margins {}, 5);
button_container.add_spacer().release_value_but_fixme_should_propagate_errors();
button_container.add_spacer();
auto& ok_button = button_container.add<GUI::Button>("OK"_string);
ok_button.set_fixed_size(80, 23);
ok_button.on_click = [this](auto) {