From 64c6d98421c6108a490a95ea5dd3ecb296590caf Mon Sep 17 00:00:00 2001 From: David Mann Date: Sun, 8 Nov 2026 15:30:38 +0100 Subject: [PATCH] Background Eraser: arrow steps past the Angle's ends no longer alert; more Angle tests The field consumes the arrow keys it steps with, so the step check now reads them before the field. New tests: arrow steps stop at +-180 without the alert, a click-away commits a typed 400 with one alert, a non-number keeps the angle, and the Magic Eraser check finds any field named Angle. Co-Authored-By: Claude Opus 5.5 --- .../src/background_eraser_bar_angle_tests.rs | 50 +++++++++++++++++++ crates/ui-egui/src/tools/eraser_ui.rs | 4 +- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/background_eraser_bar_angle_tests.rs b/crates/ui-egui/src/background_eraser_bar_angle_tests.rs index 3311742421..5d4eb7e164 100644 --- a/crates/ui-egui/src/background_eraser_bar_angle_tests.rs +++ b/crates/ui-egui/src/background_eraser_bar_angle_tests.rs @@ -143,7 +143,57 @@ fn the_field_shows_the_brush_settings_angle() { #[test] fn the_magic_eraser_has_neither() { + let bg = bar(Tool::BackgroundEraser); + assert!(bg.query_by_label("Angle").is_some(), "the Background Eraser's field is found by its name"); let h = bar(Tool::MagicEraser); assert!(angle_field(&h).is_none()); + assert!(h.query_by_label("Angle").is_none(), "no field named Angle, whatever its tooltip"); assert!(h.query_by_label(PRESSURE).is_none()); } + +/// Focus the field and press `key` `n` times, then Enter. +fn step_angle(h: &mut Harness<'static, PhotocraftApp>, key: egui::Key, n: usize) -> f32 { + angle_field(h).expect("the Angle field").click(); + h.run_steps(1); + for _ in 0..n { + h.key_press(key); + h.run_steps(1); + } + h.key_press(egui::Key::Enter); + h.run_steps(2); + h.state().session.tools.brush.angle +} + +#[test] +fn arrow_steps_stop_at_the_ends_without_the_alert() { + let mut h = bar(Tool::BackgroundEraser); + type_angle(&mut h, "178"); + assert_eq!(step_angle(&mut h, egui::Key::ArrowUp, 5), 180.0); + type_angle(&mut h, "-178"); + assert_eq!(step_angle(&mut h, egui::Key::ArrowDown, 5), -180.0); + assert!(alerts(&h).is_empty(), "stepping is not typing: {:?}", alerts(&h)); +} + +#[test] +fn a_click_away_commits_with_the_alert() { + let mut h = bar(Tool::BackgroundEraser); + angle_field(&h).expect("the Angle field").click(); + h.run_steps(1); + h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A); + h.event(egui::Event::Text("400".into())); + h.run_steps(1); + h.get_by_label(PRESSURE).click(); + h.run_steps(3); + assert_eq!(h.state().session.tools.brush.angle, 180.0); + assert_eq!(alerts(&h).len(), 1, "one alert on click-away: {:?}", alerts(&h)); +} + +#[test] +fn an_entry_that_is_not_a_number_keeps_the_angle_without_the_alert() { + let mut h = bar(Tool::BackgroundEraser); + type_angle(&mut h, "30"); + for text in ["", "abc", "inf", "NaN"] { + assert_eq!(type_angle(&mut h, text), 30.0, "{text:?}"); + } + assert!(alerts(&h).is_empty(), "{:?}", alerts(&h)); +} diff --git a/crates/ui-egui/src/tools/eraser_ui.rs b/crates/ui-egui/src/tools/eraser_ui.rs index 09d927ac7a..c390f24f55 100644 --- a/crates/ui-egui/src/tools/eraser_ui.rs +++ b/crates/ui-egui/src/tools/eraser_ui.rs @@ -102,6 +102,8 @@ fn angle_field(ui: &mut egui::Ui, b: &mut photocraft_engine::BrushSettings) -> b ui.add(icons::image("rotate-cw", 15.0, t.text_dim)).on_hover_text(tip); // A wider range than the angle's, so a typed 400 reaches us and can be told apart from 180. let mut a = b.angle; + // Read before the field: it consumes the arrow keys it steps with. + let arrow_or_wheel = ui.input(|i| i.key_pressed(egui::Key::ArrowUp) || i.key_pressed(egui::Key::ArrowDown) || i.smooth_scroll_delta.y != 0.0); let r = widgets::value_field_named(ui, tl!("Angle"), &mut a, -ANGLE_TYPED_MAX..=ANGLE_TYPED_MAX, "°", 52.0); let out_of_range = r.id.with("bg-eraser-angle-out-of-range"); // The flag lives only while an entry is being typed: drawn without the keyboard, the field @@ -114,7 +116,7 @@ fn angle_field(ui: &mut egui::Ui, b: &mut photocraft_engine::BrushSettings) -> b let clamped = whole.clamp(-180.0, 180.0); b.angle = clamped; // Only typing alerts: a scrub or an arrow-key step past the end just stops there. - let stepped = r.dragged() || ui.input(|i| i.key_pressed(egui::Key::ArrowUp) || i.key_pressed(egui::Key::ArrowDown) || i.smooth_scroll_delta.y != 0.0); + let stepped = r.dragged() || arrow_or_wheel; let typed_out = whole != clamped && !stepped; ui.data_mut(|d| d.insert_temp(out_of_range, typed_out)); }