1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:57:44 +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

@ -64,71 +64,72 @@ void WandSelectTool::on_mousedown(Layer* layer, MouseEvent& event)
m_editor->did_complete_action(tool_name());
}
GUI::Widget* WandSelectTool::get_properties_widget()
ErrorOr<GUI::Widget*> WandSelectTool::get_properties_widget()
{
if (m_properties_widget) {
return m_properties_widget.ptr();
}
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);
auto& mode_container = m_properties_widget->add<GUI::Widget>();
mode_container.set_fixed_height(20);
mode_container.set_layout<GUI::HorizontalBoxLayout>();
auto mode_container = TRY(properties_widget->try_add<GUI::Widget>());
mode_container->set_fixed_height(20);
(void)TRY(mode_container->try_set_layout<GUI::HorizontalBoxLayout>());
auto& mode_label = mode_container.add<GUI::Label>();
mode_label.set_text("Mode:");
mode_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
mode_label.set_fixed_size(80, 20);
auto mode_label = TRY(mode_container->try_add<GUI::Label>());
mode_label->set_text("Mode:");
mode_label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
mode_label->set_fixed_size(80, 20);
for (int i = 0; i < (int)Selection::MergeMode::__Count; i++) {
switch ((Selection::MergeMode)i) {
case Selection::MergeMode::Set:
m_merge_mode_names.append("Set");
TRY(m_merge_mode_names.try_append("Set"));
break;
case Selection::MergeMode::Add:
m_merge_mode_names.append("Add");
TRY(m_merge_mode_names.try_append("Add"));
break;
case Selection::MergeMode::Subtract:
m_merge_mode_names.append("Subtract");
TRY(m_merge_mode_names.try_append("Subtract"));
break;
case Selection::MergeMode::Intersect:
m_merge_mode_names.append("Intersect");
TRY(m_merge_mode_names.try_append("Intersect"));
break;
default:
VERIFY_NOT_REACHED();
}
}
auto& mode_combo = mode_container.add<GUI::ComboBox>();
mode_combo.set_only_allow_values_from_model(true);
mode_combo.set_model(*GUI::ItemListModel<DeprecatedString>::create(m_merge_mode_names));
mode_combo.set_selected_index((int)m_merge_mode);
mode_combo.on_change = [this](auto&&, GUI::ModelIndex const& index) {
auto mode_combo = TRY(mode_container->try_add<GUI::ComboBox>());
mode_combo->set_only_allow_values_from_model(true);
mode_combo->set_model(*GUI::ItemListModel<DeprecatedString>::create(m_merge_mode_names));
mode_combo->set_selected_index((int)m_merge_mode);
mode_combo->on_change = [this](auto&&, GUI::ModelIndex const& index) {
VERIFY(index.row() >= 0);
VERIFY(index.row() < (int)Selection::MergeMode::__Count);
m_merge_mode = (Selection::MergeMode)index.row();
};
m_properties_widget = properties_widget;
return m_properties_widget.ptr();
}