From bf4fca7232a8c95cba73fc17e0f360cafa131a7b Mon Sep 17 00:00:00 2001 From: qvest-ssels <214787280+qvest-ssels@users.noreply.github.com> Date: Sun, 22 Nov 2026 13:28:17 +0100 Subject: [PATCH] Paint Bucket: alert when a typed Tolerance fraction is rounded The reference application rounds a fractional Tolerance (12.7 becomes 13) and shows "An integer between 0 and 255 is required. Closest value inserted." (#12533). The Tolerance cell now commits the typed fraction, rounds it to the closest whole number and opens that alert. Opacity keeps rounding a typed fraction without an alert. --- .../src/paint_bucket_options_fields_tests.rs | 23 +++++++++- crates/ui-egui/src/panels/options_bar/fill.rs | 13 ++++-- crates/ui-egui/src/tools/option_cells.rs | 43 ++++++++++++++++--- 3 files changed, 70 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/paint_bucket_options_fields_tests.rs b/crates/ui-egui/src/paint_bucket_options_fields_tests.rs index d4957fb53a..4d0d34e3e9 100644 --- a/crates/ui-egui/src/paint_bucket_options_fields_tests.rs +++ b/crates/ui-egui/src/paint_bucket_options_fields_tests.rs @@ -1,6 +1,7 @@ //! #12533: the Paint Bucket's Tolerance takes whole numbers 0..255 and Opacity whole percents //! 1..100; a value typed past either range becomes the closest one with the reference's "Closest -//! value inserted" alert, and a typed fraction rounds without one. The seven controls carry the +//! value inserted" alert. A typed fraction rounds to the closest whole number: in Tolerance with +//! the same alert, in Opacity without one. The seven controls carry the //! reference's tooltips, and the Source dropdown has no "Fill" label. The Magic Wand and the Magic //! Eraser share Tolerance and keep their own behaviour. @@ -104,6 +105,26 @@ fn tolerance_is_a_whole_number() { } } +#[test] +fn a_fractional_tolerance_takes_the_closest_value_and_alerts() { + for (typed, want) in [("12.7", 13.0), ("12.4", 12.0), ("0.4", 0.0), ("254.6", 255.0)] { + let mut h = bar(Tool::PaintBucket); + type_into(&mut h, "Tolerance", typed); + assert_eq!(h.state().ui.tool_options.tolerance, want, "{typed}"); + assert_eq!(alerts(&h), vec![TOLERANCE_ALERT.to_string()], "{typed}: one alert"); + } +} + +#[test] +fn a_fractional_opacity_rounds_without_an_alert() { + for (typed, want) in [("50.5", 51.0), ("50.4", 50.0), ("1.4", 1.0), ("99.6", 100.0)] { + let mut h = bar(Tool::PaintBucket); + type_into(&mut h, "Opacity", typed); + assert_eq!(h.state().ui.tool_options.fill_opacity, want, "{typed}"); + assert!(alerts(&h).is_empty(), "{typed}: no alert, got {:?}", alerts(&h)); + } +} + #[test] fn opacity_past_1_100_takes_the_closest_value_and_alerts() { for (typed, want) in [("150", 100.0), ("0", 1.0), ("-3", 1.0)] { diff --git a/crates/ui-egui/src/panels/options_bar/fill.rs b/crates/ui-egui/src/panels/options_bar/fill.rs index ecc14de237..69d1f2b5fc 100644 --- a/crates/ui-egui/src/panels/options_bar/fill.rs +++ b/crates/ui-egui/src/panels/options_bar/fill.rs @@ -66,9 +66,14 @@ pub(crate) fn mode_select<'a>(mode: Bind<'a, PaintMode>, entries: &'a [Entry {} } let opacity = number(tl!("Opacity"), &mut o.fill_opacity, 1.0..=100.0).whole().unit("%").tooltip(tl!("Set opacity for fill")).show(ui).out_of_range; - let tolerance = number(tl!("Tolerance"), &mut o.tolerance, 0.0..=255.0).whole().tooltip(tl!("Range of colors to fill")).show(ui).out_of_range; + let tolerance = number(tl!("Tolerance"), &mut o.tolerance, 0.0..=255.0).whole_alerting_fractions().tooltip(tl!("Range of colors to fill")).show(ui); Checkbox::new(Bind::bound(&mut o.anti_alias)).label(tl!("Anti-alias").to_owned()).tooltip(tl!("Smoothes edge transition").to_owned()).show(ui); Checkbox::new(Bind::bound(&mut o.contiguous)).label(tl!("Contiguous").to_owned()).tooltip(tl!("Fill only contiguous pixels").to_owned()).show(ui); Checkbox::new(Bind::bound(&mut o.sample_all.paint_bucket)).label(tl!("All Layers").to_owned()).tooltip(tl!("Fill composite image").to_owned()).show(ui); if opacity.is_some() { let _ = crate::dialogs::alerts::alert(app, tl!(PAINT_BUCKET_OPACITY_ALERT)); - } else if let Some(alert) = tolerance { + } else if let Some(alert) = tolerance.out_of_range { // The framework words a whole-number field without a unit as the reference does: // "An integer between 0 and 255 is required. Closest value inserted." crate::tools::option_cells::range_alert(app, ui, &alert); + } else if tolerance.rounded { + let _ = crate::dialogs::alerts::alert(app, tl!(PAINT_BUCKET_TOLERANCE_ALERT)); } } diff --git a/crates/ui-egui/src/tools/option_cells.rs b/crates/ui-egui/src/tools/option_cells.rs index 159203d9c7..e76a56c288 100644 --- a/crates/ui-egui/src/tools/option_cells.rs +++ b/crates/ui-egui/src/tools/option_cells.rs @@ -22,6 +22,7 @@ pub(crate) struct NumberCell<'a> { range: RangeInclusive, unit: Option