Patch: an arrow badge over the selection shows that a drag moves the patch (#12130)

The Patch tool's cursor shows a new single right-pointing arrow badge over the selection (no Shift or Alt), also while a drag that started inside is in progress. Content-Aware Move keeps no badge and the Curvature Pen keeps its four-arrow badge.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Model-Effort: Opus 5.5 drove; Opus 5.5 briefed; Sonnet 5.5 wrote at medium
This commit is contained in:
Trevor BrownandClaude Sonnet 5.5 committed 2026-11-08 01:10:52 -05:00
1 parent aae9b7ea61
commit 11607cfaad
3 files changed
+69 -2

No files matched your search

+11 -1
View File
@@ -19,6 +19,8 @@ pub enum Badge {
Intersect,
/// Four arrows: a press drags the point under the pointer (the Curvature Pen over an anchor).
Move,
/// One right-pointing arrow: a press drags the patch (the Patch tool over the selection).
Arrow,
}
impl Badge {
@@ -124,7 +126,7 @@ pub fn badge(app: &PhotocraftApp, tool: Tool, m: egui::Modifiers) -> Option<Badg
if matches!(tool, Tool::Patch | Tool::ContentAwareMove) {
let at = app.drag.as_ref().filter(|d| d.tool == tool).map(|d| d.start).or(app.hover_doc);
if at.is_some_and(|p| crate::retouch_ui::patch_drags_selection(app, p, m)) {
return None;
return (tool == Tool::Patch).then_some(Badge::Arrow);
}
return Badge::from_mode(document_selection_mode(app, Tool::Lasso, m));
}
@@ -159,6 +161,10 @@ pub fn badge_glyph(b: Badge, c: Pos2, h: f32) -> Vec<[Pos2; 2]> {
}
v
}
Badge::Arrow => {
let a = h * 0.6;
vec![[c - vec2(h, 0.0), c + vec2(h, 0.0)], [c + vec2(h, 0.0), c + vec2(h - a, a)], [c + vec2(h, 0.0), c + vec2(h - a, -a)]]
}
Badge::Intersect => {
let d = h * 0.8;
vec![[c + vec2(-d, -d), c + vec2(d, d)], [c + vec2(-d, d), c + vec2(d, -d)]]
@@ -319,3 +325,7 @@ mod tests {
assert!(e.len() >= 16 && e.iter().all(|p| p.x >= -0.01 && p.x <= 100.01 && p.y >= -0.01 && p.y <= 50.01));
}
}
#[cfg(test)]
#[path = "../patch_cursor_badge_tests.rs"]
mod patch_cursor_badge_tests;
@@ -0,0 +1,56 @@
//! The Patch tool's cursor shows a right-pointing arrow over the selection (#12130).
use egui::Modifiers;
use serde_json::json;
use crate::PhotocraftApp;
use crate::canvas::Drag;
use crate::state::Tool;
use crate::tool_feedback::{Badge, badge, badge_glyph};
fn app() -> PhotocraftApp {
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({"width": 100, "height": 100})).unwrap();
app.run("select.rect", json!({"x": 20, "y": 20, "width": 30, "height": 30})).unwrap();
app
}
const INSIDE: [f64; 2] = [30.0, 30.0];
const OUTSIDE: [f64; 2] = [80.0, 80.0];
#[test]
fn arrow_over_the_selection_without_modifiers() {
let mut app = app();
app.hover_doc = Some(INSIDE);
assert_eq!(badge(&app, Tool::Patch, Modifiers::NONE), Some(Badge::Arrow));
assert_ne!(Badge::Arrow, Badge::Move, "a new single-arrow glyph");
let glyph = badge_glyph(Badge::Arrow, egui::pos2(0.0, 0.0), 4.0);
let tip = glyph.iter().flatten().map(|p| p.x).fold(f32::MIN, f32::max);
assert!(glyph.iter().flatten().all(|p| p.x <= tip) && glyph.len() == 3, "one shaft and two barbs pointing right");
}
#[test]
fn the_arrow_stays_during_a_drag_started_inside() {
let mut app = app();
app.drag = Some(Drag::new(Tool::Patch, INSIDE, vec![[INSIDE[0], INSIDE[1], 1.0]], Modifiers::NONE, false));
app.hover_doc = Some(OUTSIDE);
assert_eq!(badge(&app, Tool::Patch, Modifiers::NONE), Some(Badge::Arrow));
}
#[test]
fn outside_and_with_shift_or_alt_the_badges_are_as_before() {
let mut app = app();
app.hover_doc = Some(OUTSIDE);
assert_eq!(badge(&app, Tool::Patch, Modifiers::NONE), None);
app.hover_doc = Some(INSIDE);
assert_eq!(badge(&app, Tool::Patch, Modifiers::SHIFT), Some(Badge::Add));
assert_eq!(badge(&app, Tool::Patch, Modifiers::ALT), Some(Badge::Subtract));
}
#[test]
fn content_aware_move_and_the_curvature_pen_keep_their_cursors() {
let mut app = app();
app.hover_doc = Some(INSIDE);
assert_eq!(badge(&app, Tool::ContentAwareMove, Modifiers::NONE), None);
assert_eq!(badge_glyph(Badge::Move, egui::pos2(0.0, 0.0), 4.0).len(), 10, "four-arrow glyph unchanged");
}
+2 -1
View File
@@ -587,7 +587,8 @@ fn patch_cursor_shows_the_selection_mode_badge() {
app.ui.selection_mode = 1;
assert_eq!(badge(&app, tool, none), Some(Badge::Add), "{tool:?}: the options-bar mode outside the selection");
app.hover_doc = Some([20.0, 30.0]);
assert_eq!(badge(&app, tool, none), None, "{tool:?}: a press over the selection drags the patch");
let over = (tool == Tool::Patch).then_some(Badge::Arrow);
assert_eq!(badge(&app, tool, none), over, "{tool:?}: a press over the selection drags the patch (Patch shows an arrow, #12130)");
assert_eq!(badge(&app, tool, shift), Some(Badge::Add), "{tool:?}: ⇧ over the selection adds");
}
}