diff --git a/crates/ui-egui/src/color_replacement_tolerance_field_tests.rs b/crates/ui-egui/src/color_replacement_tolerance_field_tests.rs index 66080e54b1..7e237bcdfc 100644 --- a/crates/ui-egui/src/color_replacement_tolerance_field_tests.rs +++ b/crates/ui-egui/src/color_replacement_tolerance_field_tests.rs @@ -110,3 +110,15 @@ fn the_command_runs_tolerance_below_one_as_one() { let spec = photocraft_engine::command_specs().iter().find(|s| s.id == "paint.colorReplacement").unwrap(); assert!(spec.params.contains("\"tolerance\":1..100"), "{}", spec.params); } + +#[test] +fn a_restored_fraction_reaches_the_stroke_as_a_whole_number() { + // The options bar need not have drawn: the stroke's params round it themselves, so a stroke + // replaces the same pixels before and after the bar shows the setting. + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + for (saved, want) in [(12.5, 13.0), (23.4, 23.0), (0.0, 1.0), (150.0, 100.0)] { + app.ui.tool_options.cr_tolerance = saved; + let p = crate::retouch_ui::color_replacement_params(&app); + assert_eq!(p["tolerance"].as_f64(), Some(want), "{saved}"); + } +} diff --git a/crates/ui-egui/src/tools/eraser_ui.rs b/crates/ui-egui/src/tools/eraser_ui.rs index 730344cbf9..0902d74971 100644 --- a/crates/ui-egui/src/tools/eraser_ui.rs +++ b/crates/ui-egui/src/tools/eraser_ui.rs @@ -195,7 +195,7 @@ pub(crate) fn whole_tolerance_field(ui: &mut egui::Ui, value: &mut f32, draft: & /// A Tolerance as the field stores it: a whole number in 1..=100, the default 50 for a value /// that is no number. Strokes use it too, so a restored setting erases the same before and after /// the options bar shows it. -fn stored_tolerance(v: f32) -> f32 { +pub(crate) fn stored_tolerance(v: f32) -> f32 { if v.is_finite() { v.round().clamp(1.0, 100.0) } else { 50.0 } } diff --git a/crates/ui-egui/src/tools/retouch_ui.rs b/crates/ui-egui/src/tools/retouch_ui.rs index fa9f6d2e5c..eeea38e499 100644 --- a/crates/ui-egui/src/tools/retouch_ui.rs +++ b/crates/ui-egui/src/tools/retouch_ui.rs @@ -84,7 +84,9 @@ pub(crate) fn color_replacement_params(app: &PhotocraftApp) -> Value { "mode": o.cr_mode, "sampling": o.cr_sampling, "limits": o.cr_limits, - "tolerance": o.cr_tolerance, + // As the field stores it (#11930), so a restored fraction replaces the same pixels before + // and after the options bar shows it. + "tolerance": crate::eraser_ui::stored_tolerance(o.cr_tolerance), "antiAlias": o.cr_anti_alias, // A mask or channel target is refused: the tool recolours layer pixels only. "target": crate::canvas::paint_target(app),