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.
This commit is contained in:
RickiNano committed 2026-11-10 16:38:36 +01:00
1 parent 3af373a82f
commit 4ed948b01e
4 files changed
+108 -10

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 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]
+4
View File
@@ -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;
@@ -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());
}
+2 -2
View File
@@ -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() {