From 1195fb971a1a0fb1c031889346bcd8b89ae2d55b Mon Sep 17 00:00:00 2001 From: rmsff <17902130+rmsff@users.noreply.github.com> Date: Tue, 10 Nov 2026 14:20:33 +0300 Subject: [PATCH 1/2] Blur Strength: alert when a typed value is out of range Typing a Blur Strength past 1..100 now stores the closest whole number and shows the reference's "Closest value inserted" alert once the field is left, as the Eraser's fields do. Sharpen and Smudge share the field but were not measured, so they keep the silent clamp. --- crates/ui-egui/src/tools/retouch_ui.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/tools/retouch_ui.rs b/crates/ui-egui/src/tools/retouch_ui.rs index ea79767e30..fc720fc2f5 100644 --- a/crates/ui-egui/src/tools/retouch_ui.rs +++ b/crates/ui-egui/src/tools/retouch_ui.rs @@ -613,11 +613,6 @@ fn opt(ui: &mut egui::Ui, text: &str) { crate::widgets::scrub_option_label(ui, &label); } -fn pct(ui: &mut egui::Ui, label: &str, v: &mut f32) { - opt(ui, label); - crate::widgets::value_field(ui, v, 1.0..=100.0, "%", 58.0); -} - const STRUCTURE_RANGE_ALERT: &str = "An integer between 1 and 7 is required. Closest value inserted."; const COLOR_RANGE_ALERT: &str = "An integer between 0 and 10 is required. Closest value inserted."; const STRUCTURE_TIP: &str = "Adjust how strictly the source structure is preserved"; @@ -899,7 +894,20 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bo crate::widgets::checkbox(ui, &mut o.vibrance, tl!("Vibrance")); } Tool::Blur | Tool::Sharpen | Tool::Smudge => { - pct(ui, tl!("Strength:"), &mut o.strength); + 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 { + 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() { + o.strength = s; + } + alert + } else { + crate::widgets::value_field(ui, &mut o.strength, 1.0..=100.0, "%", 58.0); + false + }; if let Some(all) = o.sample_all.slot(tool) { crate::widgets::checkbox(ui, all, tl!("Sample All Layers")); } @@ -909,6 +917,9 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bo if tool == Tool::Smudge { crate::widgets::checkbox(ui, &mut o.finger_painting, tl!("Finger Painting")); } + if out_of_range { + crate::eraser_ui::open_range_alert(app); + } } Tool::ColorReplacement => { // Photoshop's options bar: Mode, Sampling (three icon toggles), Limits, Tolerance, Anti-alias. From be83ed2182c43631efe5becefac1d52b1e38fd4b Mon Sep 17 00:00:00 2001 From: rmsff <17902130+rmsff@users.noreply.github.com> Date: Tue, 10 Nov 2026 14:20:33 +0300 Subject: [PATCH 2/2] Test the Blur Strength range alert --- .../ui-egui/src/blur_strength_alert_tests.rs | 107 ++++++++++++++++++ .../ui-egui/src/eraser_range_alert_tests.rs | 8 +- crates/ui-egui/src/panels/options_bar.rs | 4 + 3 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 crates/ui-egui/src/blur_strength_alert_tests.rs diff --git a/crates/ui-egui/src/blur_strength_alert_tests.rs b/crates/ui-egui/src/blur_strength_alert_tests.rs new file mode 100644 index 0000000000..66c4827c5d --- /dev/null +++ b/crates/ui-egui/src/blur_strength_alert_tests.rs @@ -0,0 +1,107 @@ +//! #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. + +use egui::accesskit::Role; +use egui::vec2; +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; + +/// Clicks into Strength and gives back where it sits. +fn click_strength(h: &mut Harness<'static, PhotocraftApp>) -> egui::Rect { + 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); + rect +} + +fn strength(h: &Harness<'static, PhotocraftApp>) -> f32 { + h.state().ui.tool_options.strength +} + +#[test] +fn blur_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::Blur); + 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 blur_strength_in_range_stores_a_whole_number_without_an_alert() { + for (typed, want) in [("40", 40.0), ("33.6", 34.0), ("1", 1.0), ("100", 100.0)] { + let mut h = bar(Tool::Blur); + type_into(&mut h, "Strength", typed); + assert_eq!(strength(&h), want, "{typed}"); + assert!(alerts(&h).is_empty(), "{typed} is in range"); + } +} + +#[test] +fn blur_strength_that_is_no_number_keeps_the_value_without_an_alert() { + let mut h = bar(Tool::Blur); + 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_caption_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::Blur); + type_into(&mut h, "Strength", start); + // The field keeps the keyboard while its caption is scrubbed past the end. + let rect = click_strength(&mut h); + // 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(egui::Event::PointerButton { pos: from, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); + h.run_steps(1); + for k in 1..=6 { + h.event(egui::Event::PointerMoved(from + vec2(dx * k as f32, 0.0))); + h.run_steps(1); + } + let to = from + vec2(dx * 6.0, 0.0); + h.event(egui::Event::PointerButton { pos: to, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() }); + h.run_steps(3); + h.key_press(egui::Key::Tab); + h.run_steps(3); + 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 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"); + } +} + +#[test] +fn opening_the_blur_bar_keeps_a_sharpen_fraction() { + let mut h = bar(Tool::Sharpen); + h.state_mut().ui.tool_options.strength = 33.6; + h.run_steps(2); + h.state_mut().ui.tool = Tool::Blur; + h.run_steps(4); + h.state_mut().ui.tool = Tool::Sharpen; + h.run_steps(2); + assert_eq!(strength(&h), 33.6, "the Blur bar only shows the shared value"); + assert!(alerts(&h).is_empty()); +} diff --git a/crates/ui-egui/src/eraser_range_alert_tests.rs b/crates/ui-egui/src/eraser_range_alert_tests.rs index 8450145a80..6abcbbc919 100644 --- a/crates/ui-egui/src/eraser_range_alert_tests.rs +++ b/crates/ui-egui/src/eraser_range_alert_tests.rs @@ -12,7 +12,7 @@ use super::{ONE_TO_100, ZERO_TO_100}; use crate::PhotocraftApp; use crate::state::{DialogKind, Tool}; -fn bar(tool: Tool) -> Harness<'static, PhotocraftApp> { +pub(super) fn bar(tool: Tool) -> Harness<'static, PhotocraftApp> { let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); app.run("file.new", json!({"width": 80, "height": 80})).unwrap(); app.ui.tool = tool; @@ -23,7 +23,7 @@ fn bar(tool: Tool) -> Harness<'static, PhotocraftApp> { } /// Types `text` into the field named `label`, then Tabs out of it. -fn type_into(h: &mut Harness<'static, PhotocraftApp>, label: &str, text: &str) { +pub(super) fn type_into(h: &mut Harness<'static, PhotocraftApp>, label: &str, text: &str) { // The fields take their captions' names ("Opacity:"). let label = &format!("{label}:"); h.query_all_by_role(Role::SpinButton) @@ -38,12 +38,12 @@ fn type_into(h: &mut Harness<'static, PhotocraftApp>, label: &str, text: &str) { h.run_steps(3); } -fn alerts(h: &Harness<'static, PhotocraftApp>) -> Vec { +pub(super) fn alerts(h: &Harness<'static, PhotocraftApp>) -> Vec { h.state().ui.dialogs.iter().filter(|d| d.kind == DialogKind::Error).filter_map(|d| d.fields.get("message")?.as_str().map(str::to_owned)).collect() } /// OK on the alert, as `ui.dialog.confirm` presses it (this harness draws only the bar). -fn ok(h: &mut Harness<'static, PhotocraftApp>) { +pub(super) fn ok(h: &mut Harness<'static, PhotocraftApp>) { let id = h.state().ui.dialogs.iter().find(|d| d.kind == DialogKind::Error).map(|d| d.id).expect("an alert"); crate::dialogs::confirm(h.state_mut(), id).unwrap(); h.run_steps(3); diff --git a/crates/ui-egui/src/panels/options_bar.rs b/crates/ui-egui/src/panels/options_bar.rs index 158657aa5a..0e8c481cc6 100644 --- a/crates/ui-egui/src/panels/options_bar.rs +++ b/crates/ui-egui/src/panels/options_bar.rs @@ -928,3 +928,7 @@ fn hint(ui: &mut egui::Ui, s: &str) { #[cfg(test)] #[path = "../eraser_range_alert_tests.rs"] mod eraser_range_alert_tests; + +#[cfg(test)] +#[path = "../blur_strength_alert_tests.rs"] +mod blur_strength_alert_tests;