diff --git a/crates/ui-egui/src/blur_strength_alert_tests.rs b/crates/ui-egui/src/blur_strength_alert_tests.rs index 66c4827c5d..0b923f1f4d 100644 --- a/crates/ui-egui/src/blur_strength_alert_tests.rs +++ b/crates/ui-egui/src/blur_strength_alert_tests.rs @@ -1,6 +1,6 @@ //! #12650: the Blur tool's Strength takes whole numbers 1..100; a value typed past the range becomes //! the closest one and, once the field is left, the reference's "Closest value inserted" alert with -//! OK says so. Sharpen and Smudge (not measured) keep today's silent clamp. +//! OK says so. Sharpen does the same since #12949; Smudge (not measured) keeps today's silent clamp. use egui::accesskit::Role; use egui::vec2; @@ -84,13 +84,11 @@ fn a_caption_scrub_past_either_end_does_not_alert() { } #[test] -fn sharpen_and_smudge_strength_keep_the_silent_clamp() { - for tool in [Tool::Sharpen, Tool::Smudge] { - let mut h = bar(tool); - type_into(&mut h, "Strength", "150"); - assert_eq!(strength(&h), 100.0, "{tool:?}"); - assert!(alerts(&h).is_empty(), "{tool:?}: not measured, so no alert"); - } +fn smudge_strength_keeps_the_silent_clamp() { + let mut h = bar(Tool::Smudge); + type_into(&mut h, "Strength", "150"); + assert_eq!(strength(&h), 100.0); + assert!(alerts(&h).is_empty(), "not measured, so no alert"); } #[test] diff --git a/crates/ui-egui/src/panels/options_bar.rs b/crates/ui-egui/src/panels/options_bar.rs index e375c8341a..7302d449fc 100644 --- a/crates/ui-egui/src/panels/options_bar.rs +++ b/crates/ui-egui/src/panels/options_bar.rs @@ -1018,3 +1018,7 @@ mod eraser_range_alert_tests; #[cfg(test)] #[path = "../blur_strength_alert_tests.rs"] mod blur_strength_alert_tests; + +#[cfg(test)] +#[path = "../sharpen_strength_alert_tests.rs"] +mod sharpen_strength_alert_tests; diff --git a/crates/ui-egui/src/sharpen_strength_alert_tests.rs b/crates/ui-egui/src/sharpen_strength_alert_tests.rs new file mode 100644 index 0000000000..3fed95e8e5 --- /dev/null +++ b/crates/ui-egui/src/sharpen_strength_alert_tests.rs @@ -0,0 +1,96 @@ +//! #12949: the Sharpen tool's Strength takes whole numbers 1..100, like Blur's (#12650); a value typed +//! past the range becomes the closest one and, once the field is left, the reference's "Closest value +//! inserted" alert with OK says so. Text that is no number and a scrub to either end stay silent. + +use egui::accesskit::Role; +use egui_kittest::Harness; +use egui_kittest::kittest::{NodeT, Queryable}; + +use super::eraser_range_alert_tests::{alerts, bar, ok, type_into}; +use crate::PhotocraftApp; +use crate::eraser_ui::TOLERANCE_RANGE_ALERT; +use crate::state::Tool; + +fn strength(h: &Harness<'static, PhotocraftApp>) -> f32 { + h.state().ui.tool_options.strength +} + +/// Drags the Strength caption by `dx` in six steps while the field holds the keyboard, then leaves it. +fn scrub_strength(h: &mut Harness<'static, PhotocraftApp>, dx: f32) { + let field = h.query_all_by_role(Role::SpinButton).find(|n| n.accesskit_node().label().as_deref() == Some("Strength:")).expect("the Strength field"); + let rect = field.rect(); + field.click(); + h.run_steps(1); + let primary = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }; + // The caption sits just left of the field. + let from = egui::pos2(rect.left() - 25.0, rect.center().y); + h.event(egui::Event::PointerMoved(from)); + h.run_steps(1); + h.event(primary(from, true)); + h.run_steps(1); + let mut at = from; + for _ in 0..6 { + at.x += dx; + h.event(egui::Event::PointerMoved(at)); + h.run_steps(1); + } + h.event(primary(at, false)); + h.run_steps(3); + h.key_press(egui::Key::Tab); + h.run_steps(3); +} + +#[test] +fn sharpen_strength_past_the_range_takes_the_closest_value_and_alerts() { + for (typed, want) in [("150", 100.0), ("0", 1.0)] { + let mut h = bar(Tool::Sharpen); + type_into(&mut h, "Strength", typed); + assert_eq!(strength(&h), want, "{typed}"); + assert_eq!(alerts(&h), vec![TOLERANCE_RANGE_ALERT.to_string()], "{typed}: one alert"); + ok(&mut h); + assert!(alerts(&h).is_empty(), "{typed}: OK closes the alert"); + assert_eq!(strength(&h), want, "{typed}: the closest value is kept"); + } +} + +#[test] +fn sharpen_strength_in_range_is_stored_without_an_alert() { + for (typed, want) in [("37", 37.0), ("1", 1.0), ("100", 100.0)] { + let mut h = bar(Tool::Sharpen); + type_into(&mut h, "Strength", typed); + assert_eq!(strength(&h), want, "{typed}"); + assert!(alerts(&h).is_empty(), "{typed} is in range"); + } +} + +#[test] +fn sharpen_strength_that_is_no_number_keeps_the_value_without_an_alert() { + let mut h = bar(Tool::Sharpen); + type_into(&mut h, "Strength", "abc"); + assert_eq!(strength(&h), 50.0, "the previous value stays"); + assert!(alerts(&h).is_empty(), "no number, no alert"); +} + +#[test] +fn a_sharpen_strength_scrub_past_either_end_does_not_alert() { + for (start, dx, want) in [("90", 50.0, 100.0), ("10", -50.0, 1.0)] { + let mut h = bar(Tool::Sharpen); + type_into(&mut h, "Strength", start); + scrub_strength(&mut h, dx); + assert_eq!(strength(&h), want, "{start}: the scrub reached the end"); + assert!(alerts(&h).is_empty(), "{start}: a scrub stops at the end without an alert"); + } +} + +#[test] +fn opening_the_sharpen_bar_keeps_a_smudge_fraction() { + let mut h = bar(Tool::Smudge); + h.state_mut().ui.tool_options.strength = 33.6; + h.run_steps(2); + h.state_mut().ui.tool = Tool::Sharpen; + h.run_steps(4); + h.state_mut().ui.tool = Tool::Smudge; + h.run_steps(2); + assert_eq!(strength(&h), 33.6, "the Sharpen bar only shows the shared value"); + assert!(alerts(&h).is_empty()); +} diff --git a/crates/ui-egui/src/tools/retouch_ui.rs b/crates/ui-egui/src/tools/retouch_ui.rs index 0e9dc2f3c7..6ece071520 100644 --- a/crates/ui-egui/src/tools/retouch_ui.rs +++ b/crates/ui-egui/src/tools/retouch_ui.rs @@ -943,8 +943,8 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bo Tool::Blur | Tool::Sharpen | Tool::Smudge => { let label = tl!("Strength:"); opt(ui, label); - // Only Blur's Strength is measured (#12650); a copy, so a shared fraction is not rounded. - let out_of_range = if tool == Tool::Blur { + // Blur's (#12650) and Sharpen's (#12949) Strength are measured; a copy, so a shared fraction is not rounded. + let out_of_range = if matches!(tool, Tool::Blur | Tool::Sharpen) { let mut s = o.strength; let (r, alert) = crate::widgets::value_field_whole_alerting(ui, label, &mut s, 1.0..=100.0, "%", 58.0); if r.changed() {