Smudge Strength: alert when a typed value is out of range (#12982)

* fix(ui): Sharpen Strength alerts when a typed value is out of range (#12949)

With the Sharpen tool, Strength now takes whole numbers 1 to 100 and a
value typed past either end becomes the closest one with the "Closest
value inserted" alert, as the Blur tool's does since #12650. Smudge keeps
its silent clamp. The field edits a copy, so showing the Sharpen bar does
not round a fraction already in the shared Strength.

* fix(ui): Smudge Strength alerts when a typed value is out of range (#12962)

With the Smudge tool, Strength now takes whole numbers 1 to 100 and a
value typed past either end becomes the closest one with the "Closest
value inserted" alert, as the Blur (#12650) and Sharpen (#12949) tools'
do. All three tools now share one path through the field, which edits a
copy, so showing the Smudge bar does not round a fraction already in the
shared Strength.
This commit is contained in:
RickiNano authored and GitHub committed 2026-11-10 20:07:25 +01:00
1 parent 0d08cb7dd6
commit 3e55928e63
4 files changed
+105 -21

No files matched your search

@@ -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 does the same since #12949; Smudge (not measured) keeps today's silent clamp.
//! OK says so. Sharpen (#12949) and Smudge (#12962) do the same.
use egui::accesskit::Role;
use egui::vec2;
@@ -83,14 +83,6 @@ fn a_caption_scrub_past_either_end_does_not_alert() {
}
}
#[test]
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]
fn opening_the_blur_bar_keeps_a_sharpen_fraction() {
let mut h = bar(Tool::Sharpen);
+4
View File
@@ -1022,3 +1022,7 @@ mod blur_strength_alert_tests;
#[cfg(test)]
#[path = "../sharpen_strength_alert_tests.rs"]
mod sharpen_strength_alert_tests;
#[cfg(test)]
#[path = "../smudge_strength_alert_tests.rs"]
mod smudge_strength_alert_tests;
@@ -0,0 +1,94 @@
//! #12962: the Smudge tool's Strength takes whole numbers 1..100, like Blur's (#12650) and Sharpen's
//! (#12949); 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 smudge_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::Smudge);
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 smudge_strength_in_range_stores_a_whole_number_without_an_alert() {
for (typed, want) in [("37", 37.0), ("33.6", 34.0), ("1", 1.0), ("100", 100.0)] {
let mut h = bar(Tool::Smudge);
type_into(&mut h, "Strength", typed);
assert_eq!(strength(&h), want, "{typed}");
assert!(alerts(&h).is_empty(), "{typed} is in range");
}
}
#[test]
fn smudge_strength_that_is_no_number_keeps_the_value_without_an_alert() {
let mut h = bar(Tool::Smudge);
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_smudge_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::Smudge);
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 showing_the_smudge_bar_keeps_a_shared_fraction() {
let mut h = bar(Tool::Blur);
h.state_mut().ui.tool_options.strength = 33.6;
h.state_mut().ui.tool = Tool::Smudge;
h.run_steps(4);
assert_eq!(strength(&h), 33.6, "the Smudge bar only shows the shared value");
assert!(alerts(&h).is_empty());
}
+6 -12
View File
@@ -943,18 +943,12 @@ 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);
// 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() {
o.strength = s;
}
alert
} else {
crate::widgets::value_field(ui, &mut o.strength, 1.0..=100.0, "%", 58.0);
false
};
// Measured for Blur (#12650), Sharpen (#12949) and Smudge (#12962); a copy, so a shared fraction is not rounded.
let mut s = o.strength;
let (r, out_of_range) = crate::widgets::value_field_whole_alerting(ui, label, &mut s, 1.0..=100.0, "%", 58.0);
if r.changed() {
o.strength = s;
}
if let Some(all) = o.sample_all.slot(tool) {
crate::widgets::checkbox(ui, all, tl!("Sample All Layers"));
}