Move tool: the arrow with a four-way cross (#16819)

The Move tool, and its Ctrl stand-in for painting tools, now shows the
arrow with the framework's four-way cross below right of it, hotspot on
the arrow tip, over the canvas, the pasteboard and locked pixels. It stays
the plain arrow inside a selection, and inside the transform box while
Auto-Select and Show Transform Controls are both on. A drag keeps the
plain arrow and Alt's duplicate the copy arrow, as before.
This commit is contained in:
RickiNano committed 2026-11-25 22:31:40 +01:00
1 parent b5c762017a
commit 257cb13fb3
3 files changed
+114 -4

No files matched your search

@@ -0,0 +1,81 @@
//! The Move tool's cursor (#16819): the arrow with a small four-way cross below right of it, the hotspot on the arrow
//! tip, over the canvas, the pasteboard and locked pixels alike, and for ⌘ held with a painting tool. The plain arrow
//! inside a selection, and inside the transform box while Auto-Select and Show Transform Controls are both on. Driven
//! through real egui input on the real canvas; the assertions read the cursor the tool (or its stand-in) asked the
//! tool host for.
use craft::behavior::{Cursor, CursorIcon, PaintedCursor, PointerGlyph};
use egui::Modifiers;
use egui_kittest::Harness;
use serde_json::json;
use crate::PhotocraftApp;
use crate::guide_cursor_tests::{harness, hover};
use crate::state::Tool;
/// The cursor the tool host was asked for at document point (`x`, `y`) with `mods` held. The harness's guide is at
/// x = 200, so no point here is on it.
fn cursor_at(h: &mut Harness<'static, Box<PhotocraftApp>>, x: f32, y: f32, mods: Modifiers) -> Option<Cursor> {
hover(h, x, y, mods);
h.state().canvas_tools.last_response.as_ref().and_then(|r| r.cursor.clone())
}
fn cross() -> Option<Cursor> {
Some(Cursor::Painted(PaintedCursor::pointer_tool(PointerGlyph::Arrow, crate::icons::tool_icon(Tool::Move))))
}
fn arrow() -> Option<Cursor> {
Some(Cursor::System(CursorIcon::Default))
}
/// A shape layer over 150..250 × 100..200, selected, with `show_transform` for Show Transform Controls.
fn with_shape(show_transform: bool) -> Harness<'static, Box<PhotocraftApp>> {
let mut h = harness(Tool::Move);
let app = h.state_mut();
app.run("shape.create", json!({"kind": "rect", "rect": [150, 100, 100, 100], "fill": "#ff0000"})).unwrap();
app.ui.tool_options.move_show_transform = show_transform;
h.run_steps(2);
h
}
#[test]
fn the_move_tool_shows_the_arrow_with_the_cross_over_the_canvas_and_the_pasteboard() {
let mut h = harness(Tool::Move);
assert_eq!(cursor_at(&mut h, 100.0, 150.0, Modifiers::NONE), cross(), "over the canvas");
assert_eq!(cursor_at(&mut h, -40.0, 150.0, Modifiers::NONE), cross(), "over the pasteboard");
}
#[test]
fn inside_the_transform_box_it_is_the_plain_arrow_only_with_auto_select_and_the_controls_on() {
let mut h = with_shape(true);
assert!(h.state().ui.tool_options.move_auto_select, "Auto-Select is on by default");
assert_eq!(cursor_at(&mut h, 175.0, 160.0, Modifiers::NONE), arrow(), "inside the box");
assert_eq!(cursor_at(&mut h, 320.0, 160.0, Modifiers::NONE), cross(), "outside the box");
h.state_mut().ui.tool_options.move_auto_select = false;
assert_eq!(cursor_at(&mut h, 175.0, 160.0, Modifiers::NONE), cross(), "Auto-Select off: the cross inside the box too");
let mut h = with_shape(false);
assert_eq!(cursor_at(&mut h, 175.0, 160.0, Modifiers::NONE), cross(), "Show Transform Controls off: the cross on the layer");
}
#[test]
fn inside_a_selection_it_is_the_plain_arrow() {
let mut h = harness(Tool::Move);
h.state_mut().run("select.rect", json!({"x": 50, "y": 50, "width": 100, "height": 100})).unwrap();
assert_eq!(cursor_at(&mut h, 100.0, 100.0, Modifiers::NONE), arrow(), "inside the selection");
assert_eq!(cursor_at(&mut h, 300.0, 100.0, Modifiers::NONE), cross(), "outside it");
}
#[test]
fn command_with_a_painting_tool_shows_the_same_move_cursor() {
let mut h = harness(Tool::Brush);
let brush = cursor_at(&mut h, 100.0, 150.0, Modifiers::NONE);
assert_ne!(brush, cross(), "the Brush shows its own cursor");
assert_eq!(cursor_at(&mut h, 100.0, 150.0, Modifiers::COMMAND), cross(), "⌘: the Move cursor");
}
#[test]
fn a_locked_layers_pixels_show_the_cross_and_no_not_allowed() {
let mut h = with_shape(false);
h.state_mut().run("layer.lockLayers", json!({"all": true})).unwrap();
assert_eq!(cursor_at(&mut h, 175.0, 160.0, Modifiers::NONE), cross());
}
+25 -2
View File
@@ -13,7 +13,7 @@ use crate::canvas::document_display::CanvasHost;
use crate::state::Tool;
use craft::behavior::geometry::{ConstrainStyle, Directions, MoveGesture};
use craft::behavior::kurbo::{self, Point};
use craft::behavior::{CancelReason, Cursor, CursorIcon};
use craft::behavior::{CancelReason, Cursor, CursorIcon, PaintedCursor, PointerGlyph};
use craft::keymap::{Chord, Key, Mods};
use craft::ui::canvas::{CanvasTool, ToolAction, ToolClaims, ToolContext, ToolKey, ToolPath, ToolPointer};
use craft::ui::primitives::{Draw, PaintShape, StrokeColor, StrokeWidth};
@@ -137,6 +137,12 @@ fn inside_selection(app: &PhotocraftApp, p: [f64; 2]) -> bool {
app.session.active().and_then(|st| st.doc.selection.as_ref()).is_some_and(|sel| covers(sel, p))
}
/// Whether document point `p` lies inside the Move tool's transform box with Auto-Select on (the box shows only with
/// Show Transform Controls on, [`frame`](crate::canvas::transform_controls::frame)).
fn inside_transform_box(app: &PhotocraftApp, p: Point) -> bool {
app.ui.tool_options.move_auto_select && crate::canvas::transform_controls::frame(app).is_some_and(|b| b.contains(p))
}
fn rect4(r: photocraft_geom::Rect) -> [f64; 4] {
[f64::from(r.x0), f64::from(r.y0), f64::from(r.x1), f64::from(r.y1)]
}
@@ -428,9 +434,22 @@ impl CanvasTool for MoveRun<'_> {
draw.stroke(&PaintShape::Path(vec![to - dir * 10.0 + side * 5.0, to, to - dir * 10.0 - side * 5.0]), StrokeWidth::Medium, accent);
}
/// The arrow with the four-way cross below right of it, the hotspot on the arrow's tip (#16819); the plain arrow
/// inside a selection, and inside the transform box while Auto-Select and Show Transform Controls are both on. A
/// drag keeps the plain arrow, and ⌥'s duplicate the copy arrow.
fn cursor(&self, cx: &ToolContext<'_>) -> Cursor {
let alt = cx.mods.alt;
if self.scope.with_app(|app| crate::move_mods::copying(app, alt)) { Cursor::System(CursorIcon::Copy) } else { Cursor::System(CursorIcon::Default) }
let at = cx.pointer.as_ref().zip(cx.space()).map(|(pointer, space)| space.view.to_doc(pointer.pos));
let dragging = self.state.run.is_some();
self.scope.with_app(|app| {
if crate::move_mods::copying(app, alt) {
return Cursor::System(CursorIcon::Copy);
}
if dragging || at.is_some_and(|at| inside_selection(app, [at.x, at.y]) || inside_transform_box(app, at)) {
return Cursor::System(CursorIcon::Default);
}
Cursor::Painted(PaintedCursor::pointer_tool(PointerGlyph::Arrow, crate::icons::tool_icon(Tool::Move)))
})
}
/// A layer or pixel move takes every move from the press, so a move of a few pixels moves; its click is decided by
@@ -443,3 +462,7 @@ impl CanvasTool for MoveRun<'_> {
ToolPath::Command("the Move Layer command")
}
}
#[cfg(test)]
#[path = "move_cursor_cross_tests.rs"]
mod move_cursor_cross_tests;
+8 -2
View File
@@ -613,10 +613,16 @@ fn move_alt_copy_cursor_follows_the_latched_duplication_drag() {
h.state_mut().ui.tool = crate::state::Tool::Move;
h.state_mut().ui.tool_options.move_show_transform = false;
let before = h.state().session.active().unwrap().doc.layers.len();
// Without ⌥ the Move tool asks for its painted arrow with the cross (#16819), which the window shows as an image.
let move_cursor = Some(craft::behavior::Cursor::Painted(craft::behavior::PaintedCursor::pointer_tool(
craft::behavior::PointerGlyph::Arrow,
crate::icons::tool_icon(crate::state::Tool::Move),
)));
let requested = |h: &Harness<'static, Box<PhotocraftApp>>| h.state().canvas_tools.last_response.as_ref().and_then(|r| r.cursor.clone());
let p = h.state().last_canvas_rect.center();
h.hover_at(p);
h.run_steps(2);
assert_eq!(h.output().platform_output.cursor_icon, egui::CursorIcon::Default);
assert_eq!(requested(&h), move_cursor);
h.event(egui::Event::ModifiersChanged(Modifiers::ALT));
h.run_steps(2);
assert_eq!(h.output().platform_output.cursor_icon, egui::CursorIcon::Copy);
@@ -631,7 +637,7 @@ fn move_alt_copy_cursor_follows_the_latched_duplication_drag() {
assert_eq!(h.output().platform_output.cursor_icon, egui::CursorIcon::Copy, "releasing Alt does not undo an active copy");
h.event(egui::Event::PointerButton { pos: end, button: egui::PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
h.run_steps(2);
assert_eq!(h.output().platform_output.cursor_icon, egui::CursorIcon::Default);
assert_eq!(requested(&h), move_cursor, "back to the Move cursor");
assert_eq!(h.state().session.active().unwrap().doc.layers.len(), before + 1);
}