From b73f85b00562aa2e5b5dbb05eb977d10aefbd9d0 Mon Sep 17 00:00:00 2001 From: David Mann Date: Tue, 1 Dec 2026 01:39:25 +0100 Subject: [PATCH] Color Replacement: the popup's "Size:" is the brush's Shape Dynamics size control (#11931) The options bar's "Always use pressure for size" switch (#11929) is measured off after Reset Tool while the popup's "Size:" reads Pen Pressure, so the two cannot share `pressure_size`. "Size:" now sets the Shape Dynamics size control; the bar switch stays the override. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/canvas/paint_mouse.rs | 2 +- .../color_replacement_brush_popup_tests.rs | 10 ++++--- crates/ui-egui/src/tools/bg_eraser_popup.rs | 27 ++++++++++--------- .../tests/it/color_replacement_reset_tip.rs | 3 +-- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/crates/ui-egui/src/canvas/paint_mouse.rs b/crates/ui-egui/src/canvas/paint_mouse.rs index d0a9e34d80..56ed8e03bc 100644 --- a/crates/ui-egui/src/canvas/paint_mouse.rs +++ b/crates/ui-egui/src/canvas/paint_mouse.rs @@ -174,7 +174,7 @@ pub(crate) fn fresh_brush(tool: Tool, current: &BrushSettings) -> BrushSettings Tool::ColorReplacement => { (brush.size, brush.hardness, brush.spacing) = COLOR_REPLACEMENT_TIP; // Its popup's "Size:" starts at Pen Pressure (#11931). - brush.pressure_size = true; + crate::bg_eraser_popup::set_size_control(&mut brush, crate::bg_eraser_popup::PEN_PRESSURE); } Tool::CloneStamp => { (brush.size, brush.hardness, brush.spacing) = CLONE_STAMP_TIP; diff --git a/crates/ui-egui/src/color_replacement_brush_popup_tests.rs b/crates/ui-egui/src/color_replacement_brush_popup_tests.rs index 75d9c0aacb..a1b4384393 100644 --- a/crates/ui-egui/src/color_replacement_brush_popup_tests.rs +++ b/crates/ui-egui/src/color_replacement_brush_popup_tests.rs @@ -11,6 +11,7 @@ use egui_kittest::kittest::{NodeT, Queryable}; use serde_json::json; use crate::PhotocraftApp; +use crate::bg_eraser_popup::size_control; use crate::state::Tool; /// Where the picker opens: on the canvas by a right-click, or from the options bar's field. @@ -109,7 +110,8 @@ fn both_ways_open_the_compact_popup_in_the_measured_order_with_its_defaults() { assert_eq!(number(&h, label), want, "{how:?}: {label}"); } let app = h.state(); - assert!(app.session.tools.brush.pressure_size, "{how:?}: \"Size:\" is on Pen Pressure"); + assert_eq!(size_control(&app.session.tools.brush), crate::bg_eraser_popup::PEN_PRESSURE, "{how:?}: \"Size:\" is on Pen Pressure"); + assert!(!app.session.tools.brush.pressure_size, "{how:?}: the bar's pressure override stays off"); assert_eq!(app.ui.tool_options.cr_tolerance_control, crate::bg_eraser_popup::OFF, "{how:?}: \"Tolerance:\" is Off"); // One triangle: "Size:" is on Pen Pressure and "Tolerance:" is Off. let warnings: Vec<_> = h.query_all_by_label(crate::bg_eraser_popup::PRESSURE_WARNING).collect(); @@ -175,19 +177,19 @@ fn the_tolerance_control_is_stored_with_the_tool_and_size_with_its_brush() { h.run_steps(3); h.get_by_label("Off").click(); h.run_steps(3); - assert!(!h.state().session.tools.brush.pressure_size, "\"Size:\" Off is the brush's"); + assert_eq!(size_control(&h.state().session.tools.brush), crate::bg_eraser_popup::OFF, "\"Size:\" Off is the brush's"); // The tool's brush and options travel with it: another tool and back keeps them. h.state_mut().ui.tool = Tool::Brush; crate::paint_mouse::sync_tool_brush(h.state_mut()); h.state_mut().ui.tool = Tool::ColorReplacement; crate::paint_mouse::sync_tool_brush(h.state_mut()); - assert!(!h.state().session.tools.brush.pressure_size, "the Color Replacement brush keeps \"Size:\" Off"); + assert_eq!(size_control(&h.state().session.tools.brush), crate::bg_eraser_popup::OFF, "the Color Replacement brush keeps \"Size:\" Off"); assert_eq!(h.state().ui.tool_options.cr_tolerance_control, crate::bg_eraser_popup::STYLUS_WHEEL); // Reset Tool gives the measured defaults back. let ctx = h.ctx.clone(); crate::menus::invoke(h.state_mut(), &ctx, crate::tools::tool_reset::RESET, json!({})).unwrap(); assert_eq!(h.state().ui.tool_options.cr_tolerance_control, crate::bg_eraser_popup::OFF); - assert!(h.state().session.tools.brush.pressure_size); + assert_eq!(size_control(&h.state().session.tools.brush), crate::bg_eraser_popup::PEN_PRESSURE); } #[test] diff --git a/crates/ui-egui/src/tools/bg_eraser_popup.rs b/crates/ui-egui/src/tools/bg_eraser_popup.rs index f2c8bcfc29..2ff2ffea57 100644 --- a/crates/ui-egui/src/tools/bg_eraser_popup.rs +++ b/crates/ui-egui/src/tools/bg_eraser_popup.rs @@ -44,25 +44,28 @@ fn pen_entries() -> [Entry; 3] { ] } -/// What the brush's "Size:" control is: Pen Pressure is the brush's pressure-for-size switch, -/// Stylus Wheel its Shape Dynamics size control. +/// What the brush's "Size:" control is: its Shape Dynamics size control. The options bar's +/// "Always use pressure for size" switch (`pressure_size`) is a separate override, as in the +/// reference, where it stays off while "Size:" reads Pen Pressure (#11931). pub fn size_control(b: &BrushSettings) -> &'static str { - if b.pressure_size { - PEN_PRESSURE - } else if b.shape_dynamics.enabled && b.shape_dynamics.size.control == Control::StylusWheel { - STYLUS_WHEEL - } else { - OFF + match (b.shape_dynamics.enabled, b.shape_dynamics.size.control) { + (true, Control::PenPressure) => PEN_PRESSURE, + (true, Control::StylusWheel) => STYLUS_WHEEL, + _ => OFF, } } /// Set the brush's "Size:" control. pub fn set_size_control(b: &mut BrushSettings, control: &str) { - b.pressure_size = control == PEN_PRESSURE; - if control == STYLUS_WHEEL { + let to = match control { + PEN_PRESSURE => Control::PenPressure, + STYLUS_WHEEL => Control::StylusWheel, + _ => Control::Off, + }; + if to != Control::Off { b.shape_dynamics.enabled = true; - b.shape_dynamics.size.control = Control::StylusWheel; - } else if b.shape_dynamics.size.control == Control::StylusWheel { + b.shape_dynamics.size.control = to; + } else if matches!(b.shape_dynamics.size.control, Control::PenPressure | Control::StylusWheel) { b.shape_dynamics.size.control = Control::Off; } } diff --git a/crates/ui-egui/tests/it/color_replacement_reset_tip.rs b/crates/ui-egui/tests/it/color_replacement_reset_tip.rs index 6fdf62c553..064e8a18b8 100644 --- a/crates/ui-egui/tests/it/color_replacement_reset_tip.rs +++ b/crates/ui-egui/tests/it/color_replacement_reset_tip.rs @@ -55,8 +55,7 @@ fn reset_tool_gives_color_replacement_a_13_px_hard_tip() { scramble(&mut app); control(&mut app, "ui.menu.invoke", json!({"id": "tool.reset"})); assert_eq!(tip(&mut app), COLOR_REPLACEMENT_TIP); - // The compact popup's "Size:" reads Pen Pressure after a reset, as measured (#11931). - assert!(app.session.tools.brush.pressure_size, "Pressure for Size on, as Reset Tool leaves it"); + assert!(!app.session.tools.brush.pressure_size, "Pressure for Size off, as Reset Tool leaves it"); // The options-bar brush chip paints the live brush's `size.round()` as plain text (no // accessibility label carries it), so this is the number it reads. assert_eq!(app.session.tools.brush.size.round(), 13.0);