From f74722b6022e06e774d537041046751409926747 Mon Sep 17 00:00:00 2001 From: "Eng. Mahmoud Bek ElNemer" Date: Mon, 9 Nov 2026 06:43:59 +0200 Subject: [PATCH 1/3] fix(ui): give the Pencil tool a 1 px hard tip on start and Reset Tool Fixes #12200 --- crates/ui-egui/src/canvas/paint_mouse.rs | 14 +- crates/ui-egui/src/control/dispatch.rs | 3 + crates/ui-egui/src/input/hold_keys/tests.rs | 5 +- crates/ui-egui/src/menus/invoke.rs | 6 + .../src/pencil_reset_defaults_tests.rs | 140 ++++++++++++++++++ crates/ui-egui/src/pencil_tests.rs | 5 +- .../tests/it/background_eraser_reset_tip.rs | 2 +- .../ui-egui/tests/it/brush_reset_defaults.rs | 4 +- 8 files changed, 171 insertions(+), 8 deletions(-) create mode 100644 crates/ui-egui/src/pencil_reset_defaults_tests.rs diff --git a/crates/ui-egui/src/canvas/paint_mouse.rs b/crates/ui-egui/src/canvas/paint_mouse.rs index fbf4e1ab0d..b757f3cc9b 100644 --- a/crates/ui-egui/src/canvas/paint_mouse.rs +++ b/crates/ui-egui/src/canvas/paint_mouse.rs @@ -43,7 +43,10 @@ pub fn sync_tool_brush(app: &mut PhotocraftApp) { // The Art History Brush also starts at full opacity (#10263): its Opacity is its own. // The Background Eraser and the Healing Brush start with their own measured tips instead, // as the whole brush Reset Tool gives them (#11911, #12099). + // The Pencil resets its tip to its own 1 px hard round (#12200) regardless of the Brush, + // while preserving `current.opacity`. None if matches!(tool, Tool::BackgroundEraser | Tool::Healing) => fresh_brush(tool, ¤t), + None if tool == Tool::Pencil => BrushSettings { opacity: current.opacity, ..fresh_brush(tool, ¤t) }, None => { let opacity = if tool == Tool::ArtHistoryBrush { BrushSettings::default().opacity } else { current.opacity }; BrushSettings { smoothing: first_smoothing(), mode: photocraft_color::BlendMode::Normal, opacity, ..current } @@ -77,17 +80,22 @@ const BRUSH_TOOL_TIP: (f32, f32, f32) = (13.0, 0.0, 0.25); const BACKGROUND_ERASER_TIP: (f32, f32, f32) = (13.0, 1.0, 0.25); /// The Healing Brush's tip after Reset Tool (#12099): a 19 px hard round at 25 % spacing. const HEALING_BRUSH_TIP: (f32, f32, f32) = (19.0, 1.0, 0.25); +/// The Pencil tool's starting and Reset Tool tip, as the reference measures it (#12200): size, +/// hardness and spacing of a 1 px hard round at 25 % spacing. +const PENCIL_TOOL_TIP: (f32, f32, f32) = (1.0, 1.0, 0.25); /// `tool`'s brush as it starts out (Reset Tool, #2825): the default brush at Photoshop's /// smoothing, with the session's own fields of `current`. The Brush tool's tip is /// [`BRUSH_TOOL_TIP`], the Background Eraser's [`BACKGROUND_ERASER_TIP`], the Healing Brush's -/// [`HEALING_BRUSH_TIP`]; the other tools keep the default tip. +/// [`HEALING_BRUSH_TIP`], and the Pencil's [`PENCIL_TOOL_TIP`]; the other tools keep the +/// default tip. pub(crate) fn fresh_brush(tool: Tool, current: &BrushSettings) -> BrushSettings { let mut brush = BrushSettings { smoothing: first_smoothing(), ..BrushSettings::default() }; match tool { Tool::Brush => (brush.size, brush.hardness, brush.spacing) = BRUSH_TOOL_TIP, Tool::BackgroundEraser => (brush.size, brush.hardness, brush.spacing) = BACKGROUND_ERASER_TIP, Tool::Healing => (brush.size, brush.hardness, brush.spacing) = HEALING_BRUSH_TIP, + Tool::Pencil => (brush.size, brush.hardness, brush.spacing) = PENCIL_TOOL_TIP, _ => {} } session_fields(current, &brush) @@ -541,3 +549,7 @@ pub fn show_picker(app: &mut PhotocraftApp, ctx: &egui::Context) { #[cfg(test)] mod tests; + +#[cfg(test)] +#[path = "../pencil_reset_defaults_tests.rs"] +mod pencil_reset_defaults_tests; diff --git a/crates/ui-egui/src/control/dispatch.rs b/crates/ui-egui/src/control/dispatch.rs index 6e7e14c87e..11e3bbdffb 100644 --- a/crates/ui-egui/src/control/dispatch.rs +++ b/crates/ui-egui/src/control/dispatch.rs @@ -1256,6 +1256,9 @@ fn pointer(app: &mut PhotocraftApp, ctx: &egui::Context, p: &Value) -> Outcome { }; if let Some(t) = parsed.tool { crate::tool_memory::select(app, t); + if t == crate::state::Tool::Pencil { + crate::paint_mouse::sync_tool_brush(app); + } } // Space held: the Crop tool moves the frame being drawn, a marquee, lasso or shape // being drawn moves instead of growing (hold_keys.rs). Like a modifier flag, it may be diff --git a/crates/ui-egui/src/input/hold_keys/tests.rs b/crates/ui-egui/src/input/hold_keys/tests.rs index 61d78d9ed3..5bc2164be2 100644 --- a/crates/ui-egui/src/input/hold_keys/tests.rs +++ b/crates/ui-egui/src/input/hold_keys/tests.rs @@ -782,7 +782,10 @@ fn tilde_held_with_the_brush_or_pencil_erases_with_its_brush() { drag_with(&mut h, Modifiers::NONE, 110.0, 130.0, 150.0, 130.0); key(&mut h, Key::Backtick, false, Modifiers::NONE); assert_eq!(last_stroke_erases(&h), Some(true), "{tool:?}"); - assert_eq!(rgba(&h, 130, 130)[3], 0.0, "{tool:?}: erased to transparency"); + // `drag_with` bends through `(118, 136)` on the way from `(110, 130)` to `(150, 130)`, + // so the Pencil's 1 px tip (#12200) no longer reaches `(130, 130)`; check `(110, 130)` + // at the stroke start instead. + assert_eq!(rgba(&h, 110, 130)[3], 0.0, "{tool:?}: erased to transparency"); assert_eq!(last_stroke(h.state())["mode"], json!("clear"), "{tool:?}"); assert_eq!(h.state().session.active().unwrap().history.undo_label(), Some(label)); assert_eq!(h.state().ui.tool, tool, "the tool stays"); diff --git a/crates/ui-egui/src/menus/invoke.rs b/crates/ui-egui/src/menus/invoke.rs index cbe858eba6..2bd1d868c8 100644 --- a/crates/ui-egui/src/menus/invoke.rs +++ b/crates/ui-egui/src/menus/invoke.rs @@ -78,6 +78,12 @@ fn frame_convert_dialog(app: &mut PhotocraftApp, id: &str) -> Result Option> { if let Some(tool) = crate::tool_shortcuts::tool(id) { crate::tool_memory::select(app, tool); + // A first pick of the Pencil via shortcut must start from `fresh_brush(Tool::Pencil, ...)` + // (#12200) rather than the outgoing Brush tip, whereas other tools inherit the current + // brush tip on first pick; sync here so an immediate `paint.pencil` uses the 1 px tip. + if tool == crate::state::Tool::Pencil { + crate::paint_mouse::sync_tool_brush(app); + } return Some(Ok(json!({"tool": tool}))); } if id == "layer.frame.convert" && params.as_object().is_none_or(|o| o.is_empty()) { diff --git a/crates/ui-egui/src/pencil_reset_defaults_tests.rs b/crates/ui-egui/src/pencil_reset_defaults_tests.rs new file mode 100644 index 0000000000..59847b42fa --- /dev/null +++ b/crates/ui-egui/src/pencil_reset_defaults_tests.rs @@ -0,0 +1,140 @@ +//! #12200: Reset Tool, Reset All Tools and a fresh first pick give the Pencil a 1 px hard round +//! tip (size 1, hardness 100 %, angle 0, roundness 100 %, spacing 25 %, both pressure overrides +//! off, options-bar chip "1"), and a default click at 100.2,100.2 paints only pixel 100,100. + +use egui::{Context, Modifiers, Pos2, RawInput, Rect, Shape, vec2}; +use serde_json::{Value, json}; + +use crate::PhotocraftApp; +use crate::canvas::{ToolEvent, tool_event}; +use crate::control::{ControlRequest, handle}; +use crate::state::Tool; + +/// Creates a test app with a 200x200 document. +fn app() -> PhotocraftApp { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); + app.run("file.new", json!({"width": 200, "height": 200})).unwrap(); + app.sync_views(); + app +} + +/// Dispatches a control request and syncs document views. +fn control(app: &mut PhotocraftApp, method: &str, params: Value) { + let ctx = Context::default(); + let (req, _rx) = ControlRequest::new(method, params); + let _ = handle(app, &ctx, &req); + app.sync_views(); +} + +/// Switches to `tool` and synchronizes its remembered brush. +fn pick(app: &mut PhotocraftApp, tool: Tool) { + app.ui.tool = tool; + crate::paint_mouse::sync_tool_brush(app); + app.sync_views(); +} + +/// Scrambles the active brush tip and pressure overrides away from defaults. +fn scramble(app: &mut PhotocraftApp) { + let b = &mut app.session.tools.brush; + (b.size, b.hardness, b.spacing, b.angle, b.roundness) = (42.0, 0.3, 0.6, 25.0, 0.5); + (b.pressure_size, b.pressure_opacity) = (true, true); +} + +/// Asserts that `brush.get` reports the Pencil's 1 px hard round default tip. +fn assert_pencil_tip(app: &mut PhotocraftApp) { + let b = app.run("brush.get", json!({})).unwrap(); + let tip = ["size", "hardness", "angle", "roundness", "spacing"].map(|k| (b[k].as_f64().unwrap() * 1e4).round() / 1e4); + assert_eq!(tip, [1.0, 1.0, 0.0, 1.0, 0.25], "{b}"); + assert_eq!(b["pressureSize"], json!(false), "{b}"); + assert_eq!(b["pressureOpacity"], json!(false), "{b}"); +} + +/// Renders the options bar and returns whether the brush preset chip displays `"1"`. +fn chip_shows_one(app: &mut PhotocraftApp) -> bool { + fn has_one(shape: &Shape, rect: Rect) -> bool { + match shape { + Shape::Text(t) => rect.contains(t.pos) && t.galley.text() == "1", + Shape::Vec(v) => v.iter().any(|s| has_one(s, rect)), + _ => false, + } + } + let ctx = Context::default(); + PhotocraftApp::setup_context(&ctx, Default::default()); + let screen_rect = Some(Rect::from_min_size(Pos2::ZERO, vec2(1400.0, 300.0))); + let mut out = ctx.run_ui(RawInput { screen_rect, ..Default::default() }, |ui| crate::panels::options_bar(app, ui)); + out.textures_delta.clear(); + let chip = ctx.read_response(crate::brush_picker::chip_id()).unwrap().rect; + out.shapes.iter().any(|s| has_one(&s.shape, chip)) +} + +/// Verifies that `tool.reset` and `tool.resetAll` give the Pencil its 1 px hard tip and `"1"` chip. +#[test] +fn reset_tool_and_reset_all_give_the_pencil_a_one_pixel_hard_tip() { + let mut a = app(); + pick(&mut a, Tool::Pencil); + scramble(&mut a); + a.session.tools.brush.opacity = 0.4; + control(&mut a, "ui.menu.invoke", json!({"id": "tool.reset"})); + assert_pencil_tip(&mut a); + assert_eq!(a.session.tools.brush.opacity, 1.0); + assert!(chip_shows_one(&mut a)); + + scramble(&mut a); + control(&mut a, "ui.menu.invoke", json!({"id": "tool.resetAll", "params": {"confirmed": true}})); + assert_pencil_tip(&mut a); + assert!(chip_shows_one(&mut a)); +} + +/// Verifies that first selecting the Pencil (including via `tools.select.pencil` before a UI pass) +/// uses its 1 px hard tip while preserving the outgoing brush opacity. +#[test] +fn pencil_starts_with_its_own_tip_whatever_the_brush_had() { + let mut a = app(); + pick(&mut a, Tool::Brush); + scramble(&mut a); + a.session.tools.brush.opacity = 0.4; + control(&mut a, "ui.menu.invoke", json!({"id": "tools.select.pencil"})); + assert_pencil_tip(&mut a); + assert!((a.session.tools.brush.opacity - 0.4).abs() < 1e-5); + assert!(chip_shows_one(&mut a)); +} + +/// Verifies that a default Pencil click at `(100.2, 100.2)` paints only pixel `(100, 100)`. +#[test] +fn a_default_click_at_100_2_paints_only_pixel_100_100() { + let mut a = app(); + a.run("layer.new.layer", json!({})).unwrap(); + pick(&mut a, Tool::Pencil); + tool_event(&mut a, ToolEvent::Down { x: 100.2, y: 100.2, pressure: 1.0 }, Modifiers::NONE); + tool_event(&mut a, ToolEvent::Up { x: 100.2, y: 100.2 }, Modifiers::NONE); + let st = a.session.active().unwrap(); + let surf = st.doc.layer(st.active_layer.unwrap()).unwrap().surface().unwrap(); + assert_eq!(surf.content_bounds(), photocraft_geom::Rect::new(100, 100, 101, 101)); + assert_eq!(surf.rgba(100, 100)[3], 1.0); +} + +/// Verifies that `tool.resetAll` resets a saved Pencil brush even when invoked from another tool, +/// while preserving the Brush and Eraser reset tips. +#[test] +fn brush_and_other_painting_tools_keep_their_reset_tips() { + let mut a = app(); + pick(&mut a, Tool::Eraser); + scramble(&mut a); + pick(&mut a, Tool::Pencil); + scramble(&mut a); + pick(&mut a, Tool::Brush); + scramble(&mut a); + control(&mut a, "ui.menu.invoke", json!({"id": "tool.resetAll", "params": {"confirmed": true}})); + let b = a.run("brush.get", json!({})).unwrap(); + let brush_tip = ["size", "hardness", "spacing"].map(|k| (b[k].as_f64().unwrap() * 1e4).round() / 1e4); + assert_eq!(brush_tip, [13.0, 0.0, 0.25]); + + pick(&mut a, Tool::Pencil); + assert_pencil_tip(&mut a); + assert!(chip_shows_one(&mut a)); + + pick(&mut a, Tool::Eraser); + let e = a.run("brush.get", json!({})).unwrap(); + let eraser_tip = ["size", "hardness", "spacing"].map(|k| (e[k].as_f64().unwrap() * 1e4).round() / 1e4); + assert_eq!(eraser_tip, [20.0, 1.0, 0.1]); +} diff --git a/crates/ui-egui/src/pencil_tests.rs b/crates/ui-egui/src/pencil_tests.rs index 6cc618e8fa..cd5deb8bdb 100644 --- a/crates/ui-egui/src/pencil_tests.rs +++ b/crates/ui-egui/src/pencil_tests.rs @@ -13,12 +13,11 @@ fn app() -> PhotocraftApp { let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); app.run("file.new", json!({"width": 120, "height": 80, "background": "transparent"})).unwrap(); app.run("tools.setColors", json!({"foreground": "#000000", "background": "#ffffff"})).unwrap(); - app.run("tools.setBrush", json!({"brush": {"size": 3, "hardness": 0.0}})).unwrap(); // Each tool keeps its own brush (#218): switch first, then set the Pencil's options, as the - // options bar does (its first frame takes the Brush's tip at Photoshop's 10 % smoothing). + // options bar does. app.ui.tool = Tool::Pencil; crate::paint_mouse::sync_tool_brush(&mut app); - app.run("tools.setBrush", json!({"brush": {"smoothing": {"amount": 0.0}}})).unwrap(); + app.run("tools.setBrush", json!({"brush": {"size": 3, "hardness": 0.0, "smoothing": {"amount": 0.0}}})).unwrap(); app } diff --git a/crates/ui-egui/tests/it/background_eraser_reset_tip.rs b/crates/ui-egui/tests/it/background_eraser_reset_tip.rs index f971412bc4..8d06ca4447 100644 --- a/crates/ui-egui/tests/it/background_eraser_reset_tip.rs +++ b/crates/ui-egui/tests/it/background_eraser_reset_tip.rs @@ -96,7 +96,7 @@ fn a_first_use_starts_with_the_tip() { #[test] fn other_tools_and_session_strokes_keep_their_tips() { - for tool in [Tool::Pencil, Tool::Eraser] { + for tool in [Tool::Eraser, Tool::CloneStamp] { let mut a = app(); pick(&mut a, tool); scramble(&mut a); diff --git a/crates/ui-egui/tests/it/brush_reset_defaults.rs b/crates/ui-egui/tests/it/brush_reset_defaults.rs index 0c596a2102..75d3d6a356 100644 --- a/crates/ui-egui/tests/it/brush_reset_defaults.rs +++ b/crates/ui-egui/tests/it/brush_reset_defaults.rs @@ -85,7 +85,7 @@ fn reset_all_tools_from_the_brush_gives_the_other_tools_the_default_tip() { let mut app = app(); pick(&mut app, Tool::Brush); control(&mut app, "ui.menu.invoke", json!({"id": "tool.resetAll", "params": {"confirmed": true}})); - for tool in [Tool::Pencil, Tool::Eraser] { + for tool in [Tool::Eraser, Tool::CloneStamp] { pick(&mut app, tool); assert_eq!(tip(&mut app), DEFAULT_TIP, "{tool:?}"); } @@ -93,7 +93,7 @@ fn reset_all_tools_from_the_brush_gives_the_other_tools_the_default_tip() { #[test] fn other_painting_tools_keep_the_default_reset_tip() { - for tool in [Tool::Pencil, Tool::Eraser] { + for tool in [Tool::Eraser, Tool::CloneStamp] { let mut a = app(); pick(&mut a, tool); scramble(&mut a); From 9ddef6cf7cbba5ac385e1ebe5799cbf70d7c212f Mon Sep 17 00:00:00 2001 From: David Mann Date: Wed, 11 Nov 2026 14:56:40 +0100 Subject: [PATCH 2/3] #12243: sync every selected tool's brush at once; tests follow main's Clone Stamp tip ui.pointer and tools.select.* now load the selected tool's own brush right away for any tool, not only the Pencil, so a brush command before the next frame never uses the outgoing tool's tip. The tilde-erase test checks the whole drag erases, the reset-tip tests use the Sponge as the default-tip tool (main gave the Clone Stamp its own tip), and the Shift-click test expects the Pencil's pixel-centre points. Co-Authored-By: ElNeMeR70 Co-Authored-By: Claude Opus 5.5 --- .../src/canvas/art_history_shift_click_tests.rs | 4 +++- crates/ui-egui/src/control/dispatch.rs | 6 +++--- crates/ui-egui/src/input/hold_keys/tests.rs | 4 ++++ crates/ui-egui/src/menus/invoke.rs | 9 +++------ crates/ui-egui/src/pencil_reset_defaults_tests.rs | 14 ++++++++++++++ .../tests/it/background_eraser_reset_tip.rs | 2 +- crates/ui-egui/tests/it/brush_reset_defaults.rs | 4 ++-- 7 files changed, 30 insertions(+), 13 deletions(-) diff --git a/crates/ui-egui/src/canvas/art_history_shift_click_tests.rs b/crates/ui-egui/src/canvas/art_history_shift_click_tests.rs index 011e4a4cd2..22caf24343 100644 --- a/crates/ui-egui/src/canvas/art_history_shift_click_tests.rs +++ b/crates/ui-egui/src/canvas/art_history_shift_click_tests.rs @@ -105,7 +105,9 @@ fn shift_click_still_connects_brush_pencil_history_brush_and_other_painting_tool tool_event(&mut app, ToolEvent::Up { x: 20.0, y: 40.0 }, none); tool_event(&mut app, ToolEvent::Down { x: 120.0, y: 40.0, pressure: 1.0 }, shift); tool_event(&mut app, ToolEvent::Up { x: 120.0, y: 40.0 }, shift); - assert_eq!(last_points(&app, cmd), vec![[20.0, 40.0], [120.0, 40.0]], "{tool:?}"); + // The Pencil's 1 px tip paints whole pixels, so its points sit on pixel centres (#12200). + let want = if tool == Tool::Pencil { vec![[20.5, 40.5], [120.5, 40.5]] } else { vec![[20.0, 40.0], [120.0, 40.0]] }; + assert_eq!(last_points(&app, cmd), want, "{tool:?}"); assert!(red(&app, 70, 40) > 0.9, "{tool:?} painted the connecting line midpoint"); } } diff --git a/crates/ui-egui/src/control/dispatch.rs b/crates/ui-egui/src/control/dispatch.rs index ee28eaa50c..2aa71a6915 100644 --- a/crates/ui-egui/src/control/dispatch.rs +++ b/crates/ui-egui/src/control/dispatch.rs @@ -1273,9 +1273,9 @@ fn pointer(app: &mut PhotocraftApp, ctx: &egui::Context, p: &Value) -> Outcome { }; if let Some(t) = parsed.tool { crate::tool_memory::select(app, t); - if t == crate::state::Tool::Pencil { - crate::paint_mouse::sync_tool_brush(app); - } + // The tool's own brush now, not at the next frame, so a paint command right after uses + // it (the Pencil's 1 px tip, #12200; any tool's remembered brush). + crate::paint_mouse::sync_tool_brush(app); } // Space held: the Crop tool moves the frame being drawn, a marquee, lasso or shape // being drawn moves instead of growing (hold_keys.rs). Like a modifier flag, it may be diff --git a/crates/ui-egui/src/input/hold_keys/tests.rs b/crates/ui-egui/src/input/hold_keys/tests.rs index 70000aaabb..109405eb72 100644 --- a/crates/ui-egui/src/input/hold_keys/tests.rs +++ b/crates/ui-egui/src/input/hold_keys/tests.rs @@ -786,6 +786,10 @@ fn tilde_held_with_the_brush_or_pencil_erases_with_its_brush() { // so the Pencil's 1 px tip (#12200) no longer reaches `(130, 130)`; check `(110, 130)` // at the stroke start instead. assert_eq!(rgba(&h, 110, 130)[3], 0.0, "{tool:?}: erased to transparency"); + // The whole drag erases, not only its first dab: a 1 px Pencil line along the 40 px drag + // clears far more pixels than one dab. + let cleared = (100..160).flat_map(|x| (120..146).map(move |y| (x, y))).filter(|&(x, y)| rgba(&h, x, y)[3] == 0.0).count(); + assert!(cleared >= 20, "{tool:?}: erased along the drag, {cleared} pixels"); assert_eq!(last_stroke(h.state())["mode"], json!("clear"), "{tool:?}"); assert_eq!(h.state().session.active().unwrap().history.undo_label(), Some(label)); assert_eq!(h.state().ui.tool, tool, "the tool stays"); diff --git a/crates/ui-egui/src/menus/invoke.rs b/crates/ui-egui/src/menus/invoke.rs index 102ee34ceb..5987a221c9 100644 --- a/crates/ui-egui/src/menus/invoke.rs +++ b/crates/ui-egui/src/menus/invoke.rs @@ -106,12 +106,9 @@ fn frame_convert_dialog(app: &mut PhotocraftApp, id: &str) -> Result Option> { if let Some(tool) = crate::tool_shortcuts::tool(id) { crate::tool_memory::select(app, tool); - // A first pick of the Pencil via shortcut must start from `fresh_brush(Tool::Pencil, ...)` - // (#12200) rather than the outgoing Brush tip, whereas other tools inherit the current - // brush tip on first pick; sync here so an immediate `paint.pencil` uses the 1 px tip. - if tool == crate::state::Tool::Pencil { - crate::paint_mouse::sync_tool_brush(app); - } + // The tool's own brush now, not at the next frame, so a paint command right after uses + // it: a first Pencil pick its 1 px tip (#12200), any other tool its remembered brush. + crate::paint_mouse::sync_tool_brush(app); return Some(Ok(json!({"tool": tool}))); } if id == "layer.frame.convert" && params.as_object().is_none_or(|o| o.is_empty()) { diff --git a/crates/ui-egui/src/pencil_reset_defaults_tests.rs b/crates/ui-egui/src/pencil_reset_defaults_tests.rs index 59847b42fa..37ebd78b4e 100644 --- a/crates/ui-egui/src/pencil_reset_defaults_tests.rs +++ b/crates/ui-egui/src/pencil_reset_defaults_tests.rs @@ -99,6 +99,20 @@ fn pencil_starts_with_its_own_tip_whatever_the_brush_had() { assert!(chip_shows_one(&mut a)); } +/// Selecting the Brush again by command, before a UI pass, gives back the Brush's own tip: the +/// Pencil's 1 px tip is not left for the next brush command, and the Brush's edit is not saved to +/// the Pencil. +#[test] +fn selecting_back_to_the_brush_by_command_restores_its_tip_at_once() { + let mut a = app(); + pick(&mut a, Tool::Brush); + a.session.tools.brush.size = 42.0; + control(&mut a, "ui.menu.invoke", json!({"id": "tools.select.pencil"})); + assert_pencil_tip(&mut a); + control(&mut a, "ui.menu.invoke", json!({"id": "tools.select.brush"})); + assert_eq!(a.session.tools.brush.size, 42.0, "the Brush's own size, before any frame"); +} + /// Verifies that a default Pencil click at `(100.2, 100.2)` paints only pixel `(100, 100)`. #[test] fn a_default_click_at_100_2_paints_only_pixel_100_100() { diff --git a/crates/ui-egui/tests/it/background_eraser_reset_tip.rs b/crates/ui-egui/tests/it/background_eraser_reset_tip.rs index 8d06ca4447..877dc1dd4f 100644 --- a/crates/ui-egui/tests/it/background_eraser_reset_tip.rs +++ b/crates/ui-egui/tests/it/background_eraser_reset_tip.rs @@ -96,7 +96,7 @@ fn a_first_use_starts_with_the_tip() { #[test] fn other_tools_and_session_strokes_keep_their_tips() { - for tool in [Tool::Eraser, Tool::CloneStamp] { + for tool in [Tool::Eraser, Tool::Sponge] { let mut a = app(); pick(&mut a, tool); scramble(&mut a); diff --git a/crates/ui-egui/tests/it/brush_reset_defaults.rs b/crates/ui-egui/tests/it/brush_reset_defaults.rs index 75d3d6a356..ab641cd6d1 100644 --- a/crates/ui-egui/tests/it/brush_reset_defaults.rs +++ b/crates/ui-egui/tests/it/brush_reset_defaults.rs @@ -85,7 +85,7 @@ fn reset_all_tools_from_the_brush_gives_the_other_tools_the_default_tip() { let mut app = app(); pick(&mut app, Tool::Brush); control(&mut app, "ui.menu.invoke", json!({"id": "tool.resetAll", "params": {"confirmed": true}})); - for tool in [Tool::Eraser, Tool::CloneStamp] { + for tool in [Tool::Eraser, Tool::Sponge] { pick(&mut app, tool); assert_eq!(tip(&mut app), DEFAULT_TIP, "{tool:?}"); } @@ -93,7 +93,7 @@ fn reset_all_tools_from_the_brush_gives_the_other_tools_the_default_tip() { #[test] fn other_painting_tools_keep_the_default_reset_tip() { - for tool in [Tool::Eraser, Tool::CloneStamp] { + for tool in [Tool::Eraser, Tool::Sponge] { let mut a = app(); pick(&mut a, tool); scramble(&mut a); From ae51bd1a5dc6219e450c9e9252e11ab402ccccc6 Mon Sep 17 00:00:00 2001 From: David Mann Date: Fri, 13 Nov 2026 03:09:25 +0100 Subject: [PATCH 3/3] #12243: main's Remove-tool reset test expects the Pencil's 1 px tip Main's other_tools_keep_their_reset_sizes (#12548) still listed the Pencil at the old 20 px reset size; with #12200 the Pencil resets to its 1 px hard round. Co-Authored-By: ElNeMeR70 Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/tools/remove_default_size_tests.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/tools/remove_default_size_tests.rs b/crates/ui-egui/src/tools/remove_default_size_tests.rs index ddc5af2bc0..5bcd0b5dc0 100644 --- a/crates/ui-egui/src/tools/remove_default_size_tests.rs +++ b/crates/ui-egui/src/tools/remove_default_size_tests.rs @@ -66,10 +66,11 @@ fn reset_all_tools_gives_it_19_px_active_or_picked_later() { assert_eq!(tip(&mut app), REMOVE_TIP, "picked after the reset"); } +/// The Pencil resets to its 1 px hard round (#12200). #[test] fn other_tools_keep_their_reset_sizes() { for (tool, want) in - [(Tool::Brush, 13.0), (Tool::Pencil, 20.0), (Tool::Eraser, 20.0), (Tool::SpotHealing, 20.0), (Tool::Healing, 19.0), (Tool::CloneStamp, 21.0)] + [(Tool::Brush, 13.0), (Tool::Pencil, 1.0), (Tool::Eraser, 20.0), (Tool::SpotHealing, 20.0), (Tool::Healing, 19.0), (Tool::CloneStamp, 21.0)] { let mut a = app(); pick(&mut a, tool);