From f2fe5d94c3fab92b3f81457bf257063c49d16801 Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sat, 31 Oct 2026 13:42:51 -0600 Subject: [PATCH 1/7] Select and Mask: resize the brush with Alt+right-drag Alt+right-drag, or Control+Alt-drag, on the image now changes the current brush tool's size (and the Brush tool's hardness) with the circle anchored where the drag began and a Diameter/Hardness readout, as on the main canvas and in Liquify. It no longer starts a selection stroke; Alt+left-drag still subtracts. Fixes #10497 Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/dialogs/select_mask_ui.rs | 58 ++++++++++++++--- .../src/dialogs/select_mask_ui/tests.rs | 63 +++++++++++++++++++ 2 files changed, 114 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/dialogs/select_mask_ui.rs b/crates/ui-egui/src/dialogs/select_mask_ui.rs index ebef97f740c..c54af2e9afa 100644 --- a/crates/ui-egui/src/dialogs/select_mask_ui.rs +++ b/crates/ui-egui/src/dialogs/select_mask_ui.rs @@ -426,6 +426,9 @@ pub struct SelectMaskWorkspace { /// Document px per reduced-copy px (High Quality Preview uses 1). k: u32, pressed: bool, + /// An on-canvas brush resize in progress (#10497): where it began on screen, and the size and + /// hardness then. + resize: Option<(Pos2, f64, f32)>, /// The device's texture side limit, as the context reports it each frame. texture_limit: usize, image_tex: Option, @@ -761,6 +764,7 @@ pub fn open(app: &mut PhotocraftApp) -> Result<(), String> { hide_view: false, k, pressed: false, + resize: None, texture_limit: 2048, image_tex: None, zoom: 0.0, @@ -1747,13 +1751,27 @@ fn paint_cursor(ctx: &egui::Context, w: &mut SelectMaskWorkspace, clip: &egui::P ctx.set_cursor_icon(egui::CursorIcon::Grab); } else if w.tool.brushes() { let r = (w.size() as f32 * 0.5 * v.zoom).max(2.0); - clip.circle_stroke(hp, r, Stroke::new(1.5, Color32::BLACK)); - clip.circle_stroke(hp, r, Stroke::new(0.75, Color32::WHITE)); - let add = w.add != alt; - for s in [Stroke::new(2.5, Color32::from_black_alpha(140)), Stroke::new(1.0, Color32::from_white_alpha(220))] { - clip.line_segment([hp - vec2(3.0, 0.0), hp + vec2(3.0, 0.0)], s); - if add { - clip.line_segment([hp - vec2(0.0, 3.0), hp + vec2(0.0, 3.0)], s); + // While its size is dragged the circle stays where the drag began, with the + // Diameter/Hardness readout beside the pointer, as on the main canvas (#10497). + let center = w.resize.map_or(hp, |(anchor, ..)| anchor); + clip.circle_stroke(center, r, Stroke::new(1.5, Color32::BLACK)); + clip.circle_stroke(center, r, Stroke::new(0.75, Color32::WHITE)); + if w.resize.is_some() { + let hardness = if w.tool == SmTool::Brush { format!("{}%", w.hardness.round() as i64) } else { "—".into() }; + crate::canvas::draw_readout( + ctx, + "select-mask-brush-resize-readout", + hp, + ["Diameter:", "Hardness:"], + [format!("{} px", w.size().round() as i64), hardness], + ); + } else { + let add = w.add != alt; + for s in [Stroke::new(2.5, Color32::from_black_alpha(140)), Stroke::new(1.0, Color32::from_white_alpha(220))] { + clip.line_segment([hp - vec2(3.0, 0.0), hp + vec2(3.0, 0.0)], s); + if add { + clip.line_segment([hp - vec2(0.0, 3.0), hp + vec2(0.0, 3.0)], s); + } } } ctx.set_cursor_icon(egui::CursorIcon::None); @@ -1780,6 +1798,32 @@ fn canvas_input( events: &mut Vec, mods: &mut egui::Modifiers, ) { + // Alt+right-drag, or Control+Alt-drag, resizes the brush instead of selecting (#10497), from + // the press on, so its first frame never starts a stroke. Alt+left-drag still subtracts. + let (secondary, now) = ui.input(|i| (i.pointer.button_down(egui::PointerButton::Secondary), i.modifiers)); + let gesture = if secondary { crate::brush_resize::is_right_gesture(now) } else { crate::brush_resize::is_gesture(now) }; + if !pan && w.tool.brushes() && !w.pressed && (w.resize.is_some() || (resp.is_pointer_button_down_on() && gesture)) { + if w.resize.is_none() + && let Some(p) = ui.input(|i| i.pointer.press_origin()).or_else(|| resp.interact_pointer_pos()) + { + w.resize = Some((p, w.size(), w.hardness)); + } + if let (Some((anchor, size0, hardness0)), Some(p)) = (w.resize, resp.interact_pointer_pos()) { + let d = p - anchor; + let zoom = if w.zoom.is_finite() && w.zoom > 0.0 { w.zoom } else { 1.0 }; + let (size, hardness) = crate::brush_resize::resized((size0 as f32, hardness0 / 100.0), f64::from(d.x / zoom), f64::from(d.y / zoom), zoom); + w.set_size(f64::from(size)); + // Only the Brush tool has a hardness; Quick Selection and Refine Edge change size only. + if w.tool == SmTool::Brush { + w.hardness = (hardness * 100.0).round(); + } + } + if resp.drag_stopped() || !ui.input(|i| i.pointer.any_down()) { + w.resize = None; + } + ctx.request_repaint(); + return; + } if pan && resp.dragged() { let dl = resp.drag_delta(); w.center = [w.center[0] - f64::from(dl.x / w.zoom), w.center[1] - f64::from(dl.y / w.zoom)]; diff --git a/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs b/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs index 95a3a2ace98..b2212dcaec1 100644 --- a/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs +++ b/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs @@ -808,3 +808,66 @@ fn sparse_large_preview_counts_coverage_without_a_dense_canvas_mask() { assert_eq!(selected_pixels(Some(&inverted), smaller), 999_999); assert_eq!(selected_pixels(None, area), 0); } + +/// Alt+right-drag (and Control+Alt-drag) on the image resizes the current brush tool instead of +/// selecting, as on the main canvas (#10497): only that tool's size changes, the Brush's hardness +/// follows vertical motion, nothing is painted, and the next Alt-drag still subtracts. +#[test] +fn alt_right_drag_resizes_the_workspace_brush() { + use egui::{PointerButton, Pos2}; + let mut app = app_with_selection(); + open(&mut app).unwrap(); + ui(&mut app, json!({"tool": "brush"})); + let mut h = egui_kittest::Harness::builder().with_size(vec2(1400.0, 900.0)).build_ui_state( + |ui, app: &mut PhotocraftApp| { + let ctx = ui.ctx().clone(); + if !ctx.fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) { + return; + } + crate::distort_ui::keys(app, &ctx); + keys(app, &ctx); + show(app, &ctx); + }, + app, + ); + PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ALL[0]); + h.run_steps(4); + let over = Pos2::new(LEFT_W + 300.0, BAR_H + TAB_H + 300.0); + let drag = |h: &mut egui_kittest::Harness<'_, PhotocraftApp>, button: PointerButton, modifiers: Modifiers, by: egui::Vec2| { + h.event(egui::Event::ModifiersChanged(modifiers)); + h.event(egui::Event::PointerMoved(over)); + h.run_steps(1); + h.event(egui::Event::PointerButton { pos: over, button, pressed: true, modifiers }); + h.run_steps(1); + for k in 1..=4 { + h.event(egui::Event::PointerMoved(over + by * (k as f32 / 4.0))); + h.run_steps(1); + } + h.event(egui::Event::PointerButton { pos: over + by, button, pressed: false, modifiers }); + h.event(egui::Event::ModifiersChanged(Modifiers::NONE)); + h.run_steps(2); + }; + let zoom = h.state().distort.select_mask.as_ref().unwrap().zoom; + drag(&mut h, PointerButton::Secondary, Modifiers::ALT, vec2(40.0, -60.0)); + let w = h.state().distort.select_mask.as_ref().unwrap(); + let want = (30.0 + 2.0 * f64::from(40.0 / zoom)).round(); + assert_eq!(w.brush_size, want, "horizontal motion sets the diameter (zoom {zoom})"); + assert_eq!(w.hardness, 70.0, "upward motion softens the brush, 200 points for 100 %"); + assert_eq!((w.quick_size, w.refine_size), (30.0, 30.0), "the other tools keep their sizes"); + assert!(w.strokes.is_empty() && w.edits.is_empty() && w.undo.is_empty(), "resizing selected nothing"); + assert!(w.resize.is_none(), "the gesture ends with the button"); + // Alt with the left button is still the subtracting stroke. + drag(&mut h, PointerButton::Primary, Modifiers::ALT, vec2(30.0, 0.0)); + let w = h.state().distort.select_mask.as_ref().unwrap(); + // A Brush stroke is an edit (Quick Selection's are strokes). + assert_eq!(w.edits.len(), 1, "Alt+left-drag selects"); + assert_eq!(w.edits[0]["mode"], json!("subtract")); + assert_eq!(w.brush_size, want, "and doesn't resize"); + // Control+Alt-drag (the macOS gesture) resizes Quick Selection on its own. + h.state_mut().distort.select_mask.as_mut().unwrap().pick(SmTool::Quick); + drag(&mut h, PointerButton::Primary, Modifiers::CTRL | Modifiers::ALT, vec2(-10.0, 0.0)); + let w = h.state().distort.select_mask.as_ref().unwrap(); + assert_eq!(w.quick_size, (30.0 - 2.0 * f64::from(10.0 / zoom)).round().max(1.0)); + assert_eq!((w.brush_size, w.hardness), (want, 70.0), "the Brush keeps its size and hardness"); + assert!(w.strokes.is_empty() && w.edits.len() == 1, "resizing Quick Selection selected nothing"); +} From 84f7ebe8c2c4122b961cedb14d5fee04ab664c69 Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sat, 31 Oct 2026 14:31:36 -0600 Subject: [PATCH 2/7] Select and Mask: end a brush resize released while Space pans (CodeRabbit review on crates/ui-egui/src/dialogs/select_mask_ui.rs:1805) Releasing the button of an Alt+right-drag resize while Space (or the middle button) was down left the resize pending, so a later Space-drag that went on after Space came up resized the brush from the old anchor instead of painting. Letting go of the button now ends the resize whether or not a pan is under way. The resize test's harness and drag steps move into helpers shared by the new test. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/dialogs/select_mask_ui.rs | 4 + .../src/dialogs/select_mask_ui/tests.rs | 100 +++++++++++++----- 2 files changed, 80 insertions(+), 24 deletions(-) diff --git a/crates/ui-egui/src/dialogs/select_mask_ui.rs b/crates/ui-egui/src/dialogs/select_mask_ui.rs index c54af2e9afa..4cb3e64edc4 100644 --- a/crates/ui-egui/src/dialogs/select_mask_ui.rs +++ b/crates/ui-egui/src/dialogs/select_mask_ui.rs @@ -1802,6 +1802,10 @@ fn canvas_input( // the press on, so its first frame never starts a stroke. Alt+left-drag still subtracts. let (secondary, now) = ui.input(|i| (i.pointer.button_down(egui::PointerButton::Secondary), i.modifiers)); let gesture = if secondary { crate::brush_resize::is_right_gesture(now) } else { crate::brush_resize::is_gesture(now) }; + // Space or the middle button may pan mid-resize; letting go of the button still ends it. + if pan && !ui.input(|i| i.pointer.any_down()) { + w.resize = None; + } if !pan && w.tool.brushes() && !w.pressed && (w.resize.is_some() || (resp.is_pointer_button_down_on() && gesture)) { if w.resize.is_none() && let Some(p) = ui.input(|i| i.pointer.press_origin()).or_else(|| resp.interact_pointer_pos()) diff --git a/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs b/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs index b2212dcaec1..8beb63e1583 100644 --- a/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs +++ b/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs @@ -809,15 +809,11 @@ fn sparse_large_preview_counts_coverage_without_a_dense_canvas_mask() { assert_eq!(selected_pixels(None, area), 0); } -/// Alt+right-drag (and Control+Alt-drag) on the image resizes the current brush tool instead of -/// selecting, as on the main canvas (#10497): only that tool's size changes, the Brush's hardness -/// follows vertical motion, nothing is painted, and the next Alt-drag still subtracts. -#[test] -fn alt_right_drag_resizes_the_workspace_brush() { - use egui::{PointerButton, Pos2}; +/// The workspace in a harness on `tool`, and a point over the image. +fn resize_harness(tool: &str) -> (egui_kittest::Harness<'static, PhotocraftApp>, egui::Pos2) { let mut app = app_with_selection(); open(&mut app).unwrap(); - ui(&mut app, json!({"tool": "brush"})); + ui(&mut app, json!({"tool": tool})); let mut h = egui_kittest::Harness::builder().with_size(vec2(1400.0, 900.0)).build_ui_state( |ui, app: &mut PhotocraftApp| { let ctx = ui.ctx().clone(); @@ -832,23 +828,49 @@ fn alt_right_drag_resizes_the_workspace_brush() { ); PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ALL[0]); h.run_steps(4); - let over = Pos2::new(LEFT_W + 300.0, BAR_H + TAB_H + 300.0); - let drag = |h: &mut egui_kittest::Harness<'_, PhotocraftApp>, button: PointerButton, modifiers: Modifiers, by: egui::Vec2| { - h.event(egui::Event::ModifiersChanged(modifiers)); - h.event(egui::Event::PointerMoved(over)); + (h, egui::Pos2::new(LEFT_W + 300.0, BAR_H + TAB_H + 300.0)) +} + +/// Presses `button` at `at` with `modifiers` held. +fn pointer_down(h: &mut egui_kittest::Harness<'_, PhotocraftApp>, at: egui::Pos2, button: egui::PointerButton, modifiers: Modifiers) { + h.event(egui::Event::ModifiersChanged(modifiers)); + h.event(egui::Event::PointerMoved(at)); + h.run_steps(1); + h.event(egui::Event::PointerButton { pos: at, button, pressed: true, modifiers }); + h.run_steps(1); +} + +/// Moves the held pointer from `from` by `by`, in four steps. +fn pointer_move(h: &mut egui_kittest::Harness<'_, PhotocraftApp>, from: egui::Pos2, by: egui::Vec2) { + for k in 1..=4 { + h.event(egui::Event::PointerMoved(from + by * (k as f32 / 4.0))); h.run_steps(1); - h.event(egui::Event::PointerButton { pos: over, button, pressed: true, modifiers }); - h.run_steps(1); - for k in 1..=4 { - h.event(egui::Event::PointerMoved(over + by * (k as f32 / 4.0))); - h.run_steps(1); - } - h.event(egui::Event::PointerButton { pos: over + by, button, pressed: false, modifiers }); - h.event(egui::Event::ModifiersChanged(Modifiers::NONE)); - h.run_steps(2); - }; + } +} + +fn tap_key(h: &mut egui_kittest::Harness<'_, PhotocraftApp>, key: Key, pressed: bool) { + h.event(egui::Event::Key { key, physical_key: None, pressed, repeat: false, modifiers: Modifiers::NONE }); + h.run_steps(1); +} + +/// A whole drag of `button` from `at` by `by` with `modifiers` held. +fn pointer_drag(h: &mut egui_kittest::Harness<'_, PhotocraftApp>, at: egui::Pos2, button: egui::PointerButton, modifiers: Modifiers, by: egui::Vec2) { + pointer_down(h, at, button, modifiers); + pointer_move(h, at, by); + h.event(egui::Event::PointerButton { pos: at + by, button, pressed: false, modifiers }); + h.event(egui::Event::ModifiersChanged(Modifiers::NONE)); + h.run_steps(2); +} + +/// Alt+right-drag (and Control+Alt-drag) on the image resizes the current brush tool instead of +/// selecting, as on the main canvas (#10497): only that tool's size changes, the Brush's hardness +/// follows vertical motion, nothing is painted, and the next Alt-drag still subtracts. +#[test] +fn alt_right_drag_resizes_the_workspace_brush() { + use egui::PointerButton; + let (mut h, over) = resize_harness("brush"); let zoom = h.state().distort.select_mask.as_ref().unwrap().zoom; - drag(&mut h, PointerButton::Secondary, Modifiers::ALT, vec2(40.0, -60.0)); + pointer_drag(&mut h, over, PointerButton::Secondary, Modifiers::ALT, vec2(40.0, -60.0)); let w = h.state().distort.select_mask.as_ref().unwrap(); let want = (30.0 + 2.0 * f64::from(40.0 / zoom)).round(); assert_eq!(w.brush_size, want, "horizontal motion sets the diameter (zoom {zoom})"); @@ -857,7 +879,7 @@ fn alt_right_drag_resizes_the_workspace_brush() { assert!(w.strokes.is_empty() && w.edits.is_empty() && w.undo.is_empty(), "resizing selected nothing"); assert!(w.resize.is_none(), "the gesture ends with the button"); // Alt with the left button is still the subtracting stroke. - drag(&mut h, PointerButton::Primary, Modifiers::ALT, vec2(30.0, 0.0)); + pointer_drag(&mut h, over, PointerButton::Primary, Modifiers::ALT, vec2(30.0, 0.0)); let w = h.state().distort.select_mask.as_ref().unwrap(); // A Brush stroke is an edit (Quick Selection's are strokes). assert_eq!(w.edits.len(), 1, "Alt+left-drag selects"); @@ -865,9 +887,39 @@ fn alt_right_drag_resizes_the_workspace_brush() { assert_eq!(w.brush_size, want, "and doesn't resize"); // Control+Alt-drag (the macOS gesture) resizes Quick Selection on its own. h.state_mut().distort.select_mask.as_mut().unwrap().pick(SmTool::Quick); - drag(&mut h, PointerButton::Primary, Modifiers::CTRL | Modifiers::ALT, vec2(-10.0, 0.0)); + pointer_drag(&mut h, over, PointerButton::Primary, Modifiers::CTRL | Modifiers::ALT, vec2(-10.0, 0.0)); let w = h.state().distort.select_mask.as_ref().unwrap(); assert_eq!(w.quick_size, (30.0 - 2.0 * f64::from(10.0 / zoom)).round().max(1.0)); assert_eq!((w.brush_size, w.hardness), (want, 70.0), "the Brush keeps its size and hardness"); assert!(w.strokes.is_empty() && w.edits.len() == 1, "resizing Quick Selection selected nothing"); } + +/// Space pressed mid-resize pans, and the button released before Space still ends the resize +/// (CodeRabbit on #10559): a Space-drag that goes on after Space comes up paints, as any +/// Space-drag does, instead of resizing the brush from the old anchor. +#[test] +fn a_resize_released_while_space_pans_lets_the_next_drag_paint() { + use egui::PointerButton; + let (mut h, over) = resize_harness("brush"); + let zoom = h.state().distort.select_mask.as_ref().unwrap().zoom; + pointer_down(&mut h, over, PointerButton::Secondary, Modifiers::ALT); + pointer_move(&mut h, over, vec2(40.0, 0.0)); + tap_key(&mut h, Key::Space, true); + h.event(egui::Event::PointerButton { pos: over + vec2(40.0, 0.0), button: PointerButton::Secondary, pressed: false, modifiers: Modifiers::ALT }); + h.event(egui::Event::ModifiersChanged(Modifiers::NONE)); + h.run_steps(2); + let want = (30.0 + 2.0 * f64::from(40.0 / zoom)).round(); + assert_eq!(h.state().distort.select_mask.as_ref().unwrap().brush_size, want); + // Space+drag pans; Space comes up mid-drag and the drag goes on. + pointer_down(&mut h, over, PointerButton::Primary, Modifiers::NONE); + pointer_move(&mut h, over, vec2(0.0, 20.0)); + tap_key(&mut h, Key::Space, false); + pointer_move(&mut h, over + vec2(0.0, 20.0), vec2(30.0, 0.0)); + h.event(egui::Event::PointerButton { pos: over + vec2(30.0, 20.0), button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE }); + h.run_steps(2); + let w = h.state().distort.select_mask.as_ref().unwrap(); + assert_eq!(w.brush_size, want, "the drag doesn't resize the brush"); + assert_eq!(w.edits.len(), 1, "the drag's rest paints"); + assert_eq!(w.edits[0]["mode"], json!("add")); + assert!(w.resize.is_none()); +} From 1c07f00188b600e22698c949b77e371e6bdb2f14 Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sat, 31 Oct 2026 14:33:44 -0600 Subject: [PATCH 3/7] Select and Mask: keep a brush resize on the tool it began on (CodeRabbit review on crates/ui-egui/src/dialogs/select_mask_ui.rs:1809) Picking another tool by key mid-resize (let go of Alt, press W) applied the Brush's starting size to Quick Selection, and picking a non-brush tool (L) let the rest of the held drag draw a lasso selection. The resize now records its tool; when the tool changes, the rest of the drag is consumed until the button is let go, and the anchored circle and readout show only for that tool. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/dialogs/select_mask_ui.rs | 31 ++++++++++----- .../src/dialogs/select_mask_ui/tests.rs | 39 +++++++++++++++++++ 2 files changed, 60 insertions(+), 10 deletions(-) diff --git a/crates/ui-egui/src/dialogs/select_mask_ui.rs b/crates/ui-egui/src/dialogs/select_mask_ui.rs index 4cb3e64edc4..95dd00cc91c 100644 --- a/crates/ui-egui/src/dialogs/select_mask_ui.rs +++ b/crates/ui-egui/src/dialogs/select_mask_ui.rs @@ -426,9 +426,9 @@ pub struct SelectMaskWorkspace { /// Document px per reduced-copy px (High Quality Preview uses 1). k: u32, pressed: bool, - /// An on-canvas brush resize in progress (#10497): where it began on screen, and the size and - /// hardness then. - resize: Option<(Pos2, f64, f32)>, + /// An on-canvas brush resize in progress (#10497): the tool it resizes, where it began on + /// screen, and the size and hardness then. + resize: Option<(SmTool, Pos2, f64, f32)>, /// The device's texture side limit, as the context reports it each frame. texture_limit: usize, image_tex: Option, @@ -1753,10 +1753,11 @@ fn paint_cursor(ctx: &egui::Context, w: &mut SelectMaskWorkspace, clip: &egui::P let r = (w.size() as f32 * 0.5 * v.zoom).max(2.0); // While its size is dragged the circle stays where the drag began, with the // Diameter/Hardness readout beside the pointer, as on the main canvas (#10497). - let center = w.resize.map_or(hp, |(anchor, ..)| anchor); + let resize = w.resize.filter(|&(tool, ..)| tool == w.tool); + let center = resize.map_or(hp, |(_, anchor, ..)| anchor); clip.circle_stroke(center, r, Stroke::new(1.5, Color32::BLACK)); clip.circle_stroke(center, r, Stroke::new(0.75, Color32::WHITE)); - if w.resize.is_some() { + if resize.is_some() { let hardness = if w.tool == SmTool::Brush { format!("{}%", w.hardness.round() as i64) } else { "—".into() }; crate::canvas::draw_readout( ctx, @@ -1802,17 +1803,27 @@ fn canvas_input( // the press on, so its first frame never starts a stroke. Alt+left-drag still subtracts. let (secondary, now) = ui.input(|i| (i.pointer.button_down(egui::PointerButton::Secondary), i.modifiers)); let gesture = if secondary { crate::brush_resize::is_right_gesture(now) } else { crate::brush_resize::is_gesture(now) }; - // Space or the middle button may pan mid-resize; letting go of the button still ends it. - if pan && !ui.input(|i| i.pointer.any_down()) { - w.resize = None; + // A resize keeps its drag until the button is let go: Space or the middle button may pan + // meanwhile, and if another tool is picked mid-drag the rest of it neither resizes nor + // selects with that tool. + if let Some((tool, ..)) = w.resize + && (pan || tool != w.tool) + { + if !ui.input(|i| i.pointer.any_down()) { + w.resize = None; + } + if !pan { + ctx.request_repaint(); + return; + } } if !pan && w.tool.brushes() && !w.pressed && (w.resize.is_some() || (resp.is_pointer_button_down_on() && gesture)) { if w.resize.is_none() && let Some(p) = ui.input(|i| i.pointer.press_origin()).or_else(|| resp.interact_pointer_pos()) { - w.resize = Some((p, w.size(), w.hardness)); + w.resize = Some((w.tool, p, w.size(), w.hardness)); } - if let (Some((anchor, size0, hardness0)), Some(p)) = (w.resize, resp.interact_pointer_pos()) { + if let (Some((_, anchor, size0, hardness0)), Some(p)) = (w.resize, resp.interact_pointer_pos()) { let d = p - anchor; let zoom = if w.zoom.is_finite() && w.zoom > 0.0 { w.zoom } else { 1.0 }; let (size, hardness) = crate::brush_resize::resized((size0 as f32, hardness0 / 100.0), f64::from(d.x / zoom), f64::from(d.y / zoom), zoom); diff --git a/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs b/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs index 8beb63e1583..a698cb8babe 100644 --- a/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs +++ b/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs @@ -923,3 +923,42 @@ fn a_resize_released_while_space_pans_lets_the_next_drag_paint() { assert_eq!(w.edits[0]["mode"], json!("add")); assert!(w.resize.is_none()); } + +/// A resize belongs to the tool it began on (CodeRabbit on #10559): if another tool is picked +/// mid-drag, the rest of the drag neither resizes that tool nor selects with it. +#[test] +fn picking_another_tool_mid_resize_neither_resizes_nor_selects() { + use egui::PointerButton; + let (mut h, over) = resize_harness("brush"); + let zoom = h.state().distort.select_mask.as_ref().unwrap().zoom; + let want = (30.0 + 2.0 * f64::from(40.0 / zoom)).round(); + // Alt+right-drag the Brush larger, let go of Alt, press W (Quick Selection) and drag on. + pointer_down(&mut h, over, PointerButton::Secondary, Modifiers::ALT); + pointer_move(&mut h, over, vec2(40.0, 0.0)); + h.event(egui::Event::ModifiersChanged(Modifiers::NONE)); + tap_key(&mut h, Key::W, true); + tap_key(&mut h, Key::W, false); + assert_eq!(h.state().distort.select_mask.as_ref().unwrap().tool, SmTool::Quick); + pointer_move(&mut h, over + vec2(40.0, 0.0), vec2(40.0, 0.0)); + h.event(egui::Event::PointerButton { pos: over + vec2(80.0, 0.0), button: PointerButton::Secondary, pressed: false, modifiers: Modifiers::NONE }); + h.run_steps(2); + let w = h.state().distort.select_mask.as_ref().unwrap(); + assert_eq!((w.brush_size, w.quick_size), (want, 30.0), "Quick Selection keeps its size"); + assert!(w.strokes.is_empty() && w.edits.is_empty() && w.undo.is_empty(), "nothing was selected"); + // The same with the Lasso (not a brush) picked mid-drag: the rest of the drag draws no lasso. + tap_key(&mut h, Key::B, true); + tap_key(&mut h, Key::B, false); + pointer_down(&mut h, over, PointerButton::Secondary, Modifiers::ALT); + pointer_move(&mut h, over, vec2(20.0, 0.0)); + h.event(egui::Event::ModifiersChanged(Modifiers::NONE)); + tap_key(&mut h, Key::L, true); + tap_key(&mut h, Key::L, false); + assert_eq!(h.state().distort.select_mask.as_ref().unwrap().tool, SmTool::Lasso); + pointer_move(&mut h, over + vec2(20.0, 0.0), vec2(0.0, 60.0)); + pointer_move(&mut h, over + vec2(20.0, 60.0), vec2(-60.0, 0.0)); + h.event(egui::Event::PointerButton { pos: over + vec2(-40.0, 60.0), button: PointerButton::Secondary, pressed: false, modifiers: Modifiers::NONE }); + h.run_steps(2); + let w = h.state().distort.select_mask.as_ref().unwrap(); + assert!(w.strokes.is_empty() && w.edits.is_empty() && w.undo.is_empty(), "the Lasso selected nothing"); + assert!(w.resize.is_none(), "the gesture ends with the button"); +} From c171557ff8da6415724d1ba3379dd36148948b8f Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sat, 31 Oct 2026 14:59:36 -0600 Subject: [PATCH 4/7] Select and Mask: end a brush resize when its own button comes up (CodeRabbit review on crates/ui-egui/src/dialogs/select_mask_ui.rs:1829) A resize ended only once no button at all was down. Releasing the right button while the middle button panned kept it pending, so a left-drag begun during that pan resized the brush from the old anchor on the frame the middle button came up. The resize now records the button that drags it and ends as soon as that button is let go. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/dialogs/select_mask_ui.rs | 18 +++++----- .../src/dialogs/select_mask_ui/tests.rs | 36 +++++++++++++++++++ 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/dialogs/select_mask_ui.rs b/crates/ui-egui/src/dialogs/select_mask_ui.rs index 95dd00cc91c..2ccb39e143e 100644 --- a/crates/ui-egui/src/dialogs/select_mask_ui.rs +++ b/crates/ui-egui/src/dialogs/select_mask_ui.rs @@ -427,8 +427,8 @@ pub struct SelectMaskWorkspace { k: u32, pressed: bool, /// An on-canvas brush resize in progress (#10497): the tool it resizes, where it began on - /// screen, and the size and hardness then. - resize: Option<(SmTool, Pos2, f64, f32)>, + /// screen, the size and hardness then, and the button that drags it. + resize: Option<(SmTool, Pos2, f64, f32, egui::PointerButton)>, /// The device's texture side limit, as the context reports it each frame. texture_limit: usize, image_tex: Option, @@ -1803,13 +1803,14 @@ fn canvas_input( // the press on, so its first frame never starts a stroke. Alt+left-drag still subtracts. let (secondary, now) = ui.input(|i| (i.pointer.button_down(egui::PointerButton::Secondary), i.modifiers)); let gesture = if secondary { crate::brush_resize::is_right_gesture(now) } else { crate::brush_resize::is_gesture(now) }; - // A resize keeps its drag until the button is let go: Space or the middle button may pan + // A resize keeps its drag until its button is let go: Space or the middle button may pan // meanwhile, and if another tool is picked mid-drag the rest of it neither resizes nor // selects with that tool. - if let Some((tool, ..)) = w.resize + let held = |button| ui.input(|i| i.pointer.button_down(button)); + if let Some((tool, .., button)) = w.resize && (pan || tool != w.tool) { - if !ui.input(|i| i.pointer.any_down()) { + if !held(button) { w.resize = None; } if !pan { @@ -1821,9 +1822,10 @@ fn canvas_input( if w.resize.is_none() && let Some(p) = ui.input(|i| i.pointer.press_origin()).or_else(|| resp.interact_pointer_pos()) { - w.resize = Some((w.tool, p, w.size(), w.hardness)); + let button = if secondary { egui::PointerButton::Secondary } else { egui::PointerButton::Primary }; + w.resize = Some((w.tool, p, w.size(), w.hardness, button)); } - if let (Some((_, anchor, size0, hardness0)), Some(p)) = (w.resize, resp.interact_pointer_pos()) { + if let (Some((_, anchor, size0, hardness0, _)), Some(p)) = (w.resize, resp.interact_pointer_pos()) { let d = p - anchor; let zoom = if w.zoom.is_finite() && w.zoom > 0.0 { w.zoom } else { 1.0 }; let (size, hardness) = crate::brush_resize::resized((size0 as f32, hardness0 / 100.0), f64::from(d.x / zoom), f64::from(d.y / zoom), zoom); @@ -1833,7 +1835,7 @@ fn canvas_input( w.hardness = (hardness * 100.0).round(); } } - if resp.drag_stopped() || !ui.input(|i| i.pointer.any_down()) { + if resp.drag_stopped() || w.resize.is_some_and(|(.., button)| !held(button)) { w.resize = None; } ctx.request_repaint(); diff --git a/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs b/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs index a698cb8babe..10183a99c19 100644 --- a/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs +++ b/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs @@ -962,3 +962,39 @@ fn picking_another_tool_mid_resize_neither_resizes_nor_selects() { assert!(w.strokes.is_empty() && w.edits.is_empty() && w.undo.is_empty(), "the Lasso selected nothing"); assert!(w.resize.is_none(), "the gesture ends with the button"); } + +/// A resize ends when its own button comes up, even while the middle button pans (CodeRabbit on +/// #10559): a left-drag begun before the middle button is let go doesn't resize the brush from +/// the old anchor when the pan ends. +#[test] +fn a_resize_released_while_the_middle_button_pans_ends_with_its_button() { + use egui::PointerButton; + let (mut h, over) = resize_harness("brush"); + let zoom = h.state().distort.select_mask.as_ref().unwrap().zoom; + let want = (30.0 + 2.0 * f64::from(40.0 / zoom)).round(); + pointer_down(&mut h, over, PointerButton::Secondary, Modifiers::ALT); + pointer_move(&mut h, over, vec2(40.0, 0.0)); + let at = over + vec2(40.0, 0.0); + h.event(egui::Event::PointerButton { pos: at, button: PointerButton::Middle, pressed: true, modifiers: Modifiers::ALT }); + h.run_steps(1); + h.event(egui::Event::PointerButton { pos: at, button: PointerButton::Secondary, pressed: false, modifiers: Modifiers::ALT }); + h.event(egui::Event::ModifiersChanged(Modifiers::NONE)); + h.run_steps(2); + assert_eq!(h.state().distort.select_mask.as_ref().unwrap().brush_size, want); + // The left button goes down while the middle one still pans, then the middle one comes up + // and the left drag goes on. + pointer_move(&mut h, at, vec2(0.0, 20.0)); + let at = at + vec2(0.0, 20.0); + h.event(egui::Event::PointerButton { pos: at, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE }); + h.run_steps(1); + pointer_move(&mut h, at, vec2(30.0, -20.0)); + let at = at + vec2(30.0, -20.0); + h.event(egui::Event::PointerButton { pos: at, button: PointerButton::Middle, pressed: false, modifiers: Modifiers::NONE }); + h.run_steps(1); + pointer_move(&mut h, at, vec2(60.0, -40.0)); + h.event(egui::Event::PointerButton { pos: at + vec2(60.0, -40.0), button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE }); + h.run_steps(2); + let w = h.state().distort.select_mask.as_ref().unwrap(); + assert_eq!((w.brush_size, w.hardness), (want, 100.0), "the later drag doesn't resize the brush"); + assert!(w.resize.is_none(), "the gesture ended with its button"); +} From 0d235ddcf61d80303a2cb5dc81b6ada6e8e4acc1 Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sat, 31 Oct 2026 15:47:16 -0600 Subject: [PATCH 5/7] Re-run CI The gate failed in photocraft-compose's proptest the_split_route_agrees_with_the_exact_path (flaky on main, #10386), which this PR doesn't touch. Co-Authored-By: Claude Opus 5.5 From d17d8950a8cd5ebe15bff60998627b383a91a1e1 Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sun, 1 Nov 2026 00:04:29 -0600 Subject: [PATCH 6/7] Select and Mask: Esc mid brush resize restores the brush and keeps the workspace (FredApps review) Esc during an Alt+right-drag or Control+Alt-drag resize closed the whole workspace. As in Photoshop it now puts the size and hardness back to where the drag began and ends only the resize; egui drops the drag on Esc, so the rest of it does nothing. Esc with Control+Alt still held (the macOS gesture) reaches it too. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/dialogs/distort_ui.rs | 6 ++- crates/ui-egui/src/dialogs/select_mask_ui.rs | 21 +++++++- .../src/dialogs/select_mask_ui/tests.rs | 54 +++++++++++++++++++ 3 files changed, 78 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/dialogs/distort_ui.rs b/crates/ui-egui/src/dialogs/distort_ui.rs index aa5c8fe4d9d..1f8e05d2140 100644 --- a/crates/ui-egui/src/dialogs/distort_ui.rs +++ b/crates/ui-egui/src/dialogs/distort_ui.rs @@ -361,10 +361,12 @@ pub fn keys(app: &mut PhotocraftApp, ctx: &egui::Context) -> bool { return true; } if app.distort.select_mask.is_some() { - // Enter closes a Polygonal Lasso polygon, else OK; Esc drops one, else Cancel. + // Enter closes a Polygonal Lasso polygon, else OK; Esc ends a brush resize (with + // Control+Alt, its macOS gesture, still held too), else drops a polygon, else Cancel. + let resize_esc = |ctx: &egui::Context| ctx.input_mut(|i| i.consume_key(Modifiers::CTRL | Modifiers::ALT, Key::Escape)); if enter(ctx) { crate::select_mask_ui::enter(app); - } else if esc(ctx) { + } else if esc(ctx) || (crate::select_mask_ui::resizing(app) && resize_esc(ctx)) { crate::select_mask_ui::escape(app); } return true; diff --git a/crates/ui-egui/src/dialogs/select_mask_ui.rs b/crates/ui-egui/src/dialogs/select_mask_ui.rs index 2ccb39e143e..d16acd4b7b8 100644 --- a/crates/ui-egui/src/dialogs/select_mask_ui.rs +++ b/crates/ui-egui/src/dialogs/select_mask_ui.rs @@ -485,6 +485,18 @@ impl SelectMaskWorkspace { } } + /// Esc mid-resize: the brush goes back to its size and hardness when the drag began, as in + /// Photoshop. egui drops the drag on Esc, so the rest of it does nothing. + fn escape_resize(&mut self) { + let Some((tool, _, size, hardness, _)) = self.resize.take() else { return }; + match tool { + SmTool::Quick => self.quick_size = size, + SmTool::RefineEdge => self.refine_size = size, + _ => self.brush_size = size, + } + self.hardness = hardness; + } + fn pick(&mut self, t: SmTool) { self.tool = t; match t { @@ -881,9 +893,16 @@ pub fn enter(app: &mut PhotocraftApp) -> bool { false } -/// Esc: drops a Polygonal Lasso polygon being drawn, else Cancel. +/// A brush resize is in progress (Esc then ends it, with Control+Alt still held too). +pub fn resizing(app: &PhotocraftApp) -> bool { + app.distort.select_mask.as_ref().is_some_and(|w| w.resize.is_some()) +} + +/// Esc: ends a brush resize as it began, else drops a Polygonal Lasso polygon being drawn, else +/// Cancel. pub fn escape(app: &mut PhotocraftApp) { match app.distort.select_mask.as_mut() { + Some(w) if w.resize.is_some() => w.escape_resize(), Some(w) if w.poly.is_some() => w.poly = None, _ => cancel(app), } diff --git a/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs b/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs index 10183a99c19..eb3d4a0f3a8 100644 --- a/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs +++ b/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs @@ -998,3 +998,57 @@ fn a_resize_released_while_the_middle_button_pans_ends_with_its_button() { assert_eq!((w.brush_size, w.hardness), (want, 100.0), "the later drag doesn't resize the brush"); assert!(w.resize.is_none(), "the gesture ended with its button"); } + +/// Esc mid-resize puts the brush back and ends only the resize, as in Photoshop (FredApps on +/// #10559): the workspace stays open, the rest of that drag neither resizes nor selects, and the +/// next drag selects as usual. +#[test] +fn escape_mid_resize_restores_the_brush_and_keeps_the_workspace() { + use egui::PointerButton; + let (mut h, over) = resize_harness("brush"); + pointer_down(&mut h, over, PointerButton::Secondary, Modifiers::ALT); + pointer_move(&mut h, over, vec2(40.0, -60.0)); + let w = h.state().distort.select_mask.as_ref().unwrap(); + assert!(w.resize.is_some() && w.brush_size > 30.0 && w.hardness < 100.0, "the drag resizes"); + // Esc with Alt and the right button still held. + h.event(egui::Event::Key { key: Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::ALT }); + h.run_steps(1); + h.event(egui::Event::Key { key: Key::Escape, physical_key: None, pressed: false, repeat: false, modifiers: Modifiers::ALT }); + h.run_steps(1); + let w = h.state().distort.select_mask.as_ref().expect("Esc ends the resize, not the workspace"); + assert_eq!((w.brush_size, w.hardness), (30.0, 100.0), "the brush is as it was"); + assert!(w.resize.is_none()); + // The drag goes on with Alt and the right button held: it does nothing. + pointer_move(&mut h, over + vec2(40.0, -60.0), vec2(40.0, 40.0)); + h.event(egui::Event::PointerButton { pos: over + vec2(80.0, -20.0), button: PointerButton::Secondary, pressed: false, modifiers: Modifiers::ALT }); + h.event(egui::Event::ModifiersChanged(Modifiers::NONE)); + h.run_steps(2); + let w = h.state().distort.select_mask.as_ref().unwrap(); + assert_eq!((w.brush_size, w.hardness), (30.0, 100.0), "the rest of the drag doesn't resize"); + assert!(w.strokes.is_empty() && w.edits.is_empty() && w.undo.is_empty(), "nor select"); + assert!(w.resize.is_none()); + // The next drag selects with the brush as it was. + pointer_drag(&mut h, over, PointerButton::Primary, Modifiers::NONE, vec2(30.0, 0.0)); + let w = h.state().distort.select_mask.as_ref().unwrap(); + assert_eq!((w.brush_size, w.hardness), (30.0, 100.0), "the next drag doesn't resize"); + assert_eq!(w.edits.len(), 1, "it selects"); + assert_eq!(w.edits[0]["mode"], json!("add")); + // Control+Alt-drag (the macOS gesture) on Quick Selection, Esc with both still held. + let ctrl_alt = Modifiers::CTRL | Modifiers::ALT; + h.state_mut().distort.select_mask.as_mut().unwrap().pick(SmTool::Quick); + pointer_down(&mut h, over, PointerButton::Primary, ctrl_alt); + pointer_move(&mut h, over, vec2(30.0, 0.0)); + assert!(h.state().distort.select_mask.as_ref().unwrap().quick_size > 30.0, "the drag resizes"); + h.event(egui::Event::Key { key: Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: ctrl_alt }); + h.run_steps(1); + let w = h.state().distort.select_mask.as_ref().expect("the workspace stays open"); + assert_eq!(w.quick_size, 30.0, "Quick Selection's size is as it was"); + assert!(w.resize.is_none()); + pointer_move(&mut h, over + vec2(30.0, 0.0), vec2(30.0, 0.0)); + h.event(egui::Event::PointerButton { pos: over + vec2(60.0, 0.0), button: PointerButton::Primary, pressed: false, modifiers: ctrl_alt }); + h.event(egui::Event::ModifiersChanged(Modifiers::NONE)); + h.run_steps(2); + let w = h.state().distort.select_mask.as_ref().unwrap(); + assert_eq!(w.quick_size, 30.0, "the rest of the drag doesn't resize"); + assert!(w.strokes.is_empty() && w.edits.len() == 1, "nor select"); +} From a78c313fb0d517f2ef6083d0d25a705e74da4c01 Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sun, 1 Nov 2026 00:07:02 -0600 Subject: [PATCH 7/7] Select and Mask: test the brush resize circle and readout (FredApps review) While the brush is resized its circle stays at the drag's start at the new size and the Diameter/Hardness readout follows the pointer; after the drag the circle follows the pointer again and the readout is gone. Co-Authored-By: Claude Opus 5.5 --- .../src/dialogs/select_mask_ui/tests.rs | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs b/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs index eb3d4a0f3a8..e9938305075 100644 --- a/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs +++ b/crates/ui-egui/src/dialogs/select_mask_ui/tests.rs @@ -1052,3 +1052,48 @@ fn escape_mid_resize_restores_the_brush_and_keeps_the_workspace() { assert_eq!(w.quick_size, 30.0, "the rest of the drag doesn't resize"); assert!(w.strokes.is_empty() && w.edits.len() == 1, "nor select"); } + +/// The brush circles drawn last frame (the black outline's centre and radius). +fn brush_circles(h: &egui_kittest::Harness<'_, PhotocraftApp>) -> Vec<(egui::Pos2, f32)> { + h.output() + .shapes + .iter() + .filter_map(|c| match &c.shape { + egui::Shape::Circle(s) if s.stroke == Stroke::new(1.5, Color32::BLACK) => Some((s.center, s.radius)), + _ => None, + }) + .collect() +} + +/// While the brush is resized its circle stays where the drag began, at the new size, and the +/// Diameter/Hardness readout follows the pointer, as on the main canvas (FredApps on #10559). +#[test] +fn the_resize_circle_stays_put_while_the_readout_follows_the_pointer() { + use egui::PointerButton; + let (mut h, over) = resize_harness("brush"); + let zoom = h.state().distort.select_mask.as_ref().unwrap().zoom; + let readout = || egui::Id::unique("select-mask-brush-resize-readout"); + h.event(egui::Event::PointerMoved(over)); + h.run_steps(2); + assert_eq!(brush_circles(&h), [(over, 15.0 * zoom)], "hovering, the circle is at the pointer"); + pointer_down(&mut h, over, PointerButton::Secondary, Modifiers::ALT); + for by in [vec2(40.0, -60.0), vec2(60.0, -60.0)] { + pointer_move(&mut h, over, by); + // The cursor is drawn before the frame's input, so it shows the new size a frame later. + h.run_steps(1); + let at = over + by; + let w = h.state().distort.select_mask.as_ref().unwrap(); + let (size, hardness) = (w.brush_size, w.hardness); + assert_eq!(brush_circles(&h), [(over, size as f32 * 0.5 * zoom)], "the circle stays at the anchor at the new size ({by:?})"); + let rect = h.ctx.memory(|m| m.area_rect(readout())).expect("the readout shows"); + assert_eq!(rect.min, at + vec2(16.0, 18.0), "the readout is beside the pointer"); + assert!(h.query_by_label(&format!("{} px", size.round() as i64)).is_some(), "it shows the diameter"); + assert!(h.query_by_label(&format!("{}%", hardness.round() as i64)).is_some(), "and the hardness"); + } + h.event(egui::Event::PointerButton { pos: over + vec2(60.0, -60.0), button: PointerButton::Secondary, pressed: false, modifiers: Modifiers::ALT }); + h.event(egui::Event::ModifiersChanged(Modifiers::NONE)); + h.run_steps(2); + let size = h.state().distort.select_mask.as_ref().unwrap().brush_size; + assert_eq!(brush_circles(&h), [(over + vec2(60.0, -60.0), size as f32 * 0.5 * zoom)], "after the drag the circle follows the pointer again"); + assert!(h.query_by_label("Diameter:").is_none(), "and the readout is gone"); +}