1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:57:43 +00:00

PixelPaint: Propagate errors from making tool property widgets

This commit is contained in:
Karol Kosek 2023-02-12 00:04:02 +01:00 committed by Sam Atkins
parent b409a40377
commit be717edd33
41 changed files with 499 additions and 468 deletions

View file

@ -61,28 +61,29 @@ void BucketTool::on_mousedown(Layer* layer, MouseEvent& event)
m_editor->did_complete_action(tool_name());
}
GUI::Widget* BucketTool::get_properties_widget()
ErrorOr<GUI::Widget*> BucketTool::get_properties_widget()
{
if (!m_properties_widget) {
m_properties_widget = GUI::Widget::construct();
m_properties_widget->set_layout<GUI::VerticalBoxLayout>();
auto properties_widget = TRY(GUI::Widget::try_create());
(void)TRY(properties_widget->try_set_layout<GUI::VerticalBoxLayout>());
auto& threshold_container = m_properties_widget->add<GUI::Widget>();
threshold_container.set_fixed_height(20);
threshold_container.set_layout<GUI::HorizontalBoxLayout>();
auto threshold_container = TRY(properties_widget->try_add<GUI::Widget>());
threshold_container->set_fixed_height(20);
(void)TRY(threshold_container->try_set_layout<GUI::HorizontalBoxLayout>());
auto& threshold_label = threshold_container.add<GUI::Label>("Threshold:");
threshold_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
threshold_label.set_fixed_size(80, 20);
auto threshold_label = TRY(threshold_container->try_add<GUI::Label>("Threshold:"));
threshold_label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
threshold_label->set_fixed_size(80, 20);
auto& threshold_slider = threshold_container.add<GUI::ValueSlider>(Orientation::Horizontal, String::from_utf8_short_string("%"sv));
threshold_slider.set_range(0, 100);
threshold_slider.set_value(m_threshold);
auto threshold_slider = TRY(threshold_container->try_add<GUI::ValueSlider>(Orientation::Horizontal, String::from_utf8_short_string("%"sv)));
threshold_slider->set_range(0, 100);
threshold_slider->set_value(m_threshold);
threshold_slider.on_change = [&](int value) {
threshold_slider->on_change = [this](int value) {
m_threshold = value;
};
set_primary_slider(&threshold_slider);
set_primary_slider(threshold_slider);
m_properties_widget = properties_widget;
}
return m_properties_widget.ptr();