diff --git a/crates/ui-egui/src/panels/art_history_bar_controls_tests.rs b/crates/ui-egui/src/panels/art_history_bar_controls_tests.rs index fc8e6b9e11..0aa7f6d6cc 100644 --- a/crates/ui-egui/src/panels/art_history_bar_controls_tests.rs +++ b/crates/ui-egui/src/panels/art_history_bar_controls_tests.rs @@ -1,7 +1,8 @@ //! #12629: the Art History Brush's options bar has a Pressure for Opacity toggle right after //! Opacity, and an Angle field and a Pressure for Size toggle after Tolerance, with the reference -//! application's tooltips, off / 0° by default and after Reset Tool. They edit the tool's own -//! brush, not the History Brush's or the Brush's, and the bar has no Flow and no Airbrush. +//! application's tooltips. The toggles start off and keep their state after Reset Tool (#18335), +//! which restores the angle to 0°. The controls belong to the Art History Brush, and the bar has +//! no Flow or Airbrush. use egui::accesskit::Role; use egui::{Modifiers, Rect, vec2}; @@ -99,7 +100,7 @@ fn the_controls_carry_the_reference_tooltips() { } #[test] -fn the_controls_are_off_and_0_by_default_and_after_reset_tool() { +fn reset_tool_restores_the_angle_and_keeps_pressure_toggles() { let mut h = bar(Tool::ArtHistoryBrush); assert_eq!(controls(h.state()), (false, 0.0, false)); assert!(angle_field(&h).and_then(|n| n.accesskit_node().numeric_value()) == Some(0.0), "the field shows 0°"); @@ -112,7 +113,7 @@ fn the_controls_are_off_and_0_by_default_and_after_reset_tool() { let ctx = h.ctx.clone(); crate::menus::invoke(h.state_mut(), &ctx, "tool.reset", json!({})).unwrap(); h.run_steps(3); - assert_eq!(controls(h.state()), (false, 0.0, false)); + assert_eq!(controls(h.state()), (true, 0.0, true)); } #[test] diff --git a/crates/ui-egui/src/tools/art_history_reset_keeps_pressure_tests.rs b/crates/ui-egui/src/tools/art_history_reset_keeps_pressure_tests.rs new file mode 100644 index 0000000000..26c6cbd15a --- /dev/null +++ b/crates/ui-egui/src/tools/art_history_reset_keeps_pressure_tests.rs @@ -0,0 +1,48 @@ +use serde_json::json; + +use super::{RESET, RESET_ALL, invoke}; +use crate::PhotocraftApp; +use crate::state::{Tool, ToolOptions}; + +fn art_history_brush(pressure_size: bool, pressure_opacity: bool) -> Box { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 200, "height": 200})).unwrap(); + app.ui.tool = Tool::ArtHistoryBrush; + crate::paint_mouse::sync_tool_brush(&mut app); + app.run("tools.setBrush", json!({"brush": {"pressureSize": pressure_size, "pressureOpacity": pressure_opacity}})).unwrap(); + app +} + +fn pressure(app: &PhotocraftApp) -> (bool, bool) { + let brush = &app.session.tools.brush; + (brush.pressure_size, brush.pressure_opacity) +} + +#[test] +fn reset_tool_keeps_each_art_history_brush_pressure_toggle() { + let defaults = ToolOptions::default(); + for toggles in [(true, false), (false, true), (true, true), (false, false)] { + let mut app = art_history_brush(toggles.0, toggles.1); + assert_eq!(pressure(&app), toggles); + app.ui.tool_options.art_history_style = "dab".into(); + app.ui.tool_options.art_history_area = 120.0; + app.ui.tool_options.art_history_tolerance = 25.0; + + invoke(&mut app, RESET, &json!({})).unwrap().unwrap(); + + assert_eq!(pressure(&app), toggles); + assert_eq!(app.ui.tool_options.art_history_style, defaults.art_history_style); + assert_eq!(app.ui.tool_options.art_history_area, defaults.art_history_area); + assert_eq!(app.ui.tool_options.art_history_tolerance, defaults.art_history_tolerance); + } +} + +#[test] +fn reset_all_tools_clears_the_art_history_brush_pressure_toggles() { + let mut app = art_history_brush(true, true); + assert_eq!(pressure(&app), (true, true)); + + invoke(&mut app, RESET_ALL, &json!({"confirmed": true})).unwrap().unwrap(); + + assert_eq!(pressure(&app), (false, false)); +} diff --git a/crates/ui-egui/src/tools/tool_reset.rs b/crates/ui-egui/src/tools/tool_reset.rs index 55ea6ef18f..4e9bf5a5be 100644 --- a/crates/ui-egui/src/tools/tool_reset.rs +++ b/crates/ui-egui/src/tools/tool_reset.rs @@ -90,11 +90,12 @@ fn reset_tool(app: &mut PhotocraftApp, tool: Tool) { // The session brush is the options bar's tool's: make sure it is `tool`'s before resetting. crate::paint_mouse::sync_tool_brush(app); app.ui.tool_brushes.retain(|(t, _)| *t != tool); - // The Eraser's Reset Tool resets the tip but keeps Pressure for Size and Pressure for - // Opacity as they were (#17700). The Background Eraser's keeps Pressure for Size (#18058). + // Reset the tip but keep Pressure for Size and Pressure for Opacity for the Eraser + // (#17700) and Art History Brush (#18335). Background Eraser keeps only Size (#18058). let brush = &app.session.tools.brush; - let size = matches!(tool, Tool::Eraser | Tool::BackgroundEraser).then_some(brush.pressure_size); - let opacity = (tool == Tool::Eraser).then_some(brush.pressure_opacity); + let keep_opacity = matches!(tool, Tool::Eraser | Tool::ArtHistoryBrush); + let size = (keep_opacity || tool == Tool::BackgroundEraser).then_some(brush.pressure_size); + let opacity = keep_opacity.then_some(brush.pressure_opacity); reset_session_brush(app); if size.is_some() || opacity.is_some() { let brush = &mut app.session.tools.brush; @@ -486,6 +487,10 @@ mod patch_sample_all_default_tests; #[path = "eraser_reset_keeps_pressure_tests.rs"] mod eraser_reset_keeps_pressure_tests; +#[cfg(test)] +#[path = "art_history_reset_keeps_pressure_tests.rs"] +mod art_history_reset_keeps_pressure_tests; + #[cfg(test)] #[path = "bg_eraser_reset_pressure_tests.rs"] mod bg_eraser_reset_pressure_tests;