mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge branch 'bb-move-tool-mx4onk76' of github.com:storytold/photocraft into bb-move-tool-mx4onk76--18157-board-position-lock
This commit is contained in:
commit
046f4fe97c
18 files changed
+650
-53
No files matched your search
@@ -114,6 +114,56 @@ fn pick_target(doc: &Document, x: i32, y: i32, group: bool, move_auto_select: bo
|
||||
Some(if group { top_group(doc, hit) } else { hit })
|
||||
}
|
||||
|
||||
/// The layers the Move tool's Show Previous / Next Layer Boundary keys step through at (x, y),
|
||||
/// topmost first: the visible layers with pixels there that Auto-Select could pick (the same hit
|
||||
/// test, the same locks skipped), never the Background or an artboard.
|
||||
pub fn boundary_candidates(doc: &Document, x: i32, y: i32) -> Vec<LayerId> {
|
||||
layers_hit(doc, x, y, true)
|
||||
.into_iter()
|
||||
.filter(|id| {
|
||||
let locks = doc.effective_locks(*id);
|
||||
!locks.all && !locks.position && !doc.is_background(*id) && doc.layer(*id).is_some_and(|l| l.artboard().is_none())
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The layer the boundary box goes to from `from` among `candidates` (topmost first): `up` is one
|
||||
/// layer up the stack, wrapping from the top to the bottom, else one down, wrapping from the bottom
|
||||
/// to the top. A `from` that is not a candidate counts as the topmost. `None` when the next layer
|
||||
/// is `active`: the active layer ends the cycle, it is never skipped.
|
||||
pub fn next_boundary(candidates: &[LayerId], from: Option<LayerId>, up: bool, active: Option<LayerId>) -> Option<LayerId> {
|
||||
let n = candidates.len();
|
||||
if n == 0 {
|
||||
return None;
|
||||
}
|
||||
let at = from.and_then(|f| candidates.iter().position(|c| *c == f)).unwrap_or(0);
|
||||
let next = if up { (at + n - 1) % n } else { (at + 1) % n };
|
||||
let id = candidates[next];
|
||||
(Some(id) != active).then_some(id)
|
||||
}
|
||||
|
||||
/// `move.showPreviousLayerBoundary` / `move.showNextLayerBoundary`: where the boundary box goes
|
||||
/// from `from` at (x, y). Changes nothing; the shell shows the box and a click picks its layer.
|
||||
fn boundary(s: &mut Session, p: &Value, up: bool) -> Result<Value> {
|
||||
let cmd = if up { "move.showPreviousLayerBoundary" } else { "move.showNextLayerBoundary" };
|
||||
let coord = |k: &str| {
|
||||
p.get(k)
|
||||
.and_then(Value::as_f64)
|
||||
.filter(|v| v.is_finite())
|
||||
.ok_or_else(|| EngineError::BadParams { cmd: cmd.into(), msg: format!("missing or invalid `{k}`") })
|
||||
};
|
||||
let px = |v: f64| v.floor().clamp(f64::from(i32::MIN / 2), f64::from(i32::MAX / 2)) as i32;
|
||||
let (x, y) = (px(coord("x")?), px(coord("y")?));
|
||||
let from = match p.get("from") {
|
||||
None | Some(Value::Null) => None,
|
||||
Some(v) => Some(LayerId(v.as_u64().ok_or_else(|| EngineError::BadParams { cmd: cmd.into(), msg: "`from` must be a layer id".into() })?)),
|
||||
};
|
||||
let st = s.active().ok_or(EngineError::NoDocument)?;
|
||||
let candidates = boundary_candidates(&st.doc, x, y);
|
||||
let layer = next_boundary(&candidates, from, up, st.active_layer);
|
||||
Ok(json!({ "layer": layer.map(|l| l.0), "layers": candidates.iter().map(|l| l.0).collect::<Vec<_>>() }))
|
||||
}
|
||||
|
||||
/// List the hits for a context menu or pick one layer or group. A probe leaves the selection
|
||||
/// alone. A replace click on a selected member keeps the full multi-selection for dragging.
|
||||
fn pick(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
@@ -224,6 +274,26 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
journal: true,
|
||||
run: select_in_rect,
|
||||
},
|
||||
CommandSpec {
|
||||
id: "move.showPreviousLayerBoundary",
|
||||
label: "Show Previous Layer Boundary",
|
||||
menu: &[],
|
||||
shortcut: None,
|
||||
params: r##"{"x":px,"y":px,"from":layer id|null (the layer the box shows now; none = the topmost)} → {layer (one layer up the stack from `from`, wrapping to the bottom; null when that is the active layer), layers (the candidates, topmost first)}"##,
|
||||
enabled: has_doc,
|
||||
journal: false,
|
||||
run: |s, p| boundary(s, p, true),
|
||||
},
|
||||
CommandSpec {
|
||||
id: "move.showNextLayerBoundary",
|
||||
label: "Show Next Layer Boundary",
|
||||
menu: &[],
|
||||
shortcut: None,
|
||||
params: r##"{"x":px,"y":px,"from":layer id|null (the layer the box shows now; none = the topmost)} → {layer (one layer down the stack from `from`, wrapping to the top; null when that is the active layer), layers (the candidates, topmost first)}"##,
|
||||
enabled: has_doc,
|
||||
journal: false,
|
||||
run: |s, p| boundary(s, p, false),
|
||||
},
|
||||
CommandSpec {
|
||||
id: "layer.pickAt",
|
||||
label: "Auto-Select Layer",
|
||||
|
||||
@@ -945,6 +945,8 @@ file.package
|
||||
file.export.pathsToIllustrator
|
||||
edit.installedProfiles
|
||||
layer.selectInRect
|
||||
move.showPreviousLayerBoundary
|
||||
move.showNextLayerBoundary
|
||||
layer.pickAt
|
||||
layer.selectAbove
|
||||
layer.selectBelow
|
||||
|
||||
@@ -76,6 +76,7 @@ impl PhotocraftApp {
|
||||
preset_art: Default::default(),
|
||||
move_preview: None,
|
||||
move_hover: None,
|
||||
move_boundary: None,
|
||||
move_distance: None,
|
||||
object_finder: None,
|
||||
blend_preview: None,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//! The Artboard tool's options bar (#11385): the background for the boards it draws, the size the bar edits and
|
||||
//! the gear menu's Auto-nest Layers.
|
||||
//! The Artboard tool's options bar (#11385): the background for the boards it draws and the size the bar edits.
|
||||
|
||||
use craft::behavior::kurbo::Size;
|
||||
use craft::behavior::{EditEvent, EditEvents, GestureId};
|
||||
@@ -262,27 +261,3 @@ fn other_opens_the_color_picker_and_ok_sets_the_option() {
|
||||
crate::dialogs::testing::confirm(&mut app, id).unwrap();
|
||||
assert_eq!((app.ui.artboard_tool.background.as_str(), app.ui.artboard_tool.background_color.as_str()), ("custom", "#123456"));
|
||||
}
|
||||
|
||||
/// Auto-nest Layers off: a layer dragged with the Move tool onto another board stays where it was.
|
||||
#[test]
|
||||
fn auto_nest_layers_turns_the_move_tools_nesting_on_and_off() {
|
||||
for (nest, joins) in [(true, true), (false, false)] {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
|
||||
app.session.execute("file.new", json!({"width": 300, "height": 100, "background": "transparent"})).unwrap();
|
||||
app.sync_views();
|
||||
app.session.execute("layer.new.layer", json!({})).unwrap();
|
||||
app.session.execute("select.rect", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap();
|
||||
app.session.execute("edit.fill", json!({"color": "#ff0000"})).unwrap();
|
||||
app.session.execute("select.deselect", json!({})).unwrap();
|
||||
let red = app.session.active().unwrap().active_layer.unwrap();
|
||||
app.session.execute("layer.new.artboardFromLayers", json!({"name": "A"})).unwrap();
|
||||
app.session.execute("layer.artboard.set", json!({"width": 40, "height": 40})).unwrap();
|
||||
let b = LayerId(app.session.execute("layer.new.artboard", json!({"rect": [200, 20, 40, 40], "name": "B"})).unwrap()["layer"].as_u64().unwrap());
|
||||
app.session.execute("layer.select", json!({"layer": red.0})).unwrap();
|
||||
app.ui.tool = Tool::Move;
|
||||
app.ui.artboard_tool.auto_nest = nest;
|
||||
crate::canvas::move_ui::finish(&mut app, 190.0, 10.0);
|
||||
let board = app.session.active().unwrap().doc.artboard_of(red);
|
||||
assert_eq!(board == Some(b), joins, "auto_nest {nest}");
|
||||
}
|
||||
}
|
||||
@@ -269,6 +269,10 @@ mod layer_edges_tests;
|
||||
#[path = "canvas/move_readout_arrows_tests.rs"]
|
||||
mod move_readout_arrows_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "canvas/move_autonest_option_tests.rs"]
|
||||
mod move_autonest_option_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "canvas/move_reference_point_drag_tests.rs"]
|
||||
mod move_reference_point_drag_tests;
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
//! The Artboard tool's Auto-nest Layers does not change what a Move drag does (#18155): with it on
|
||||
//! or off, a layer dragged onto another board joins it and one dragged off every board leaves for
|
||||
//! the top level.
|
||||
|
||||
use photocraft_doc::LayerId;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::state::Tool;
|
||||
|
||||
fn id(v: serde_json::Value) -> LayerId {
|
||||
LayerId(v["layer"].as_u64().unwrap())
|
||||
}
|
||||
|
||||
/// A filled layer at the top of the stack, `rect` as `[x, y, width, height]`.
|
||||
fn square(app: &mut PhotocraftApp, rect: [u32; 4], color: &str) -> LayerId {
|
||||
let s = &mut app.session;
|
||||
s.execute("layer.new.layer", json!({})).unwrap();
|
||||
s.execute("select.rect", json!({"x": rect[0], "y": rect[1], "width": rect[2], "height": rect[3]})).unwrap();
|
||||
s.execute("edit.fill", json!({"color": color})).unwrap();
|
||||
s.execute("select.deselect", json!({})).unwrap();
|
||||
s.active().unwrap().active_layer.unwrap()
|
||||
}
|
||||
|
||||
/// The issue's document: Board1 (50,50 400x400) holds A, B and group G with G1; Board2 (550,50
|
||||
/// 400x400) is to its right. Returns A, G1 and Board2.
|
||||
fn boards() -> (Box<PhotocraftApp>, LayerId, LayerId, LayerId) {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
|
||||
app.session.execute("file.new", json!({"width": 1000, "height": 700, "background": "transparent"})).unwrap();
|
||||
app.sync_views();
|
||||
app.ui.extras.snap = false;
|
||||
app.ui.view.show.smart_guides = false;
|
||||
let a = square(&mut app, [100, 100, 100, 100], "#ff0000");
|
||||
let b = square(&mut app, [250, 250, 100, 100], "#0000ff");
|
||||
let g1 = square(&mut app, [300, 100, 100, 50], "#808080");
|
||||
let g = id(app.session.execute("layer.groupLayers", json!({})).unwrap());
|
||||
app.session.execute("layer.select", json!({"layer": a.0, "mode": "replace"})).unwrap();
|
||||
for l in [b, g] {
|
||||
app.session.execute("layer.select", json!({"layer": l.0, "mode": "add"})).unwrap();
|
||||
}
|
||||
let board1 = id(app.session.execute("layer.new.artboardFromLayers", json!({"name": "Board1"})).unwrap());
|
||||
app.session.execute("layer.artboard.set", json!({"rect": [50, 50, 400, 400], "moveContents": false})).unwrap();
|
||||
let board2 = id(app.session.execute("layer.new.artboard", json!({"rect": [550, 50, 400, 400], "name": "Board2"})).unwrap());
|
||||
let doc = &app.session.active().unwrap().doc;
|
||||
assert!([a, g1].iter().all(|l| doc.artboard_of(*l) == Some(board1)), "A and G1 start in Board1");
|
||||
app.ui.tool = Tool::Move;
|
||||
(app, a, g1, board2)
|
||||
}
|
||||
|
||||
fn drag(app: &mut PhotocraftApp, layer: LayerId, dx: f64, dy: f64) {
|
||||
app.session.execute("layer.select", json!({"layer": layer.0, "mode": "replace"})).unwrap();
|
||||
crate::canvas::move_ui::finish(app, dx, dy);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_layer_dragged_onto_another_board_joins_it_with_auto_nest_on_or_off() {
|
||||
for auto_nest in [true, false] {
|
||||
let (mut app, a, _, board2) = boards();
|
||||
app.ui.artboard_tool.auto_nest = auto_nest;
|
||||
drag(&mut app, a, 500.0, 150.0);
|
||||
assert_eq!(app.session.active().unwrap().doc.artboard_of(a), Some(board2), "auto_nest {auto_nest}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_layer_dragged_off_every_board_leaves_for_the_top_level_with_auto_nest_on_or_off() {
|
||||
for auto_nest in [true, false] {
|
||||
let (mut app, _, g1, _) = boards();
|
||||
app.ui.artboard_tool.auto_nest = auto_nest;
|
||||
drag(&mut app, g1, 0.0, 500.0);
|
||||
let doc = &app.session.active().unwrap().doc;
|
||||
assert_eq!(doc.artboard_of(g1), None, "auto_nest {auto_nest}");
|
||||
assert!(doc.layers.iter().any(|l| l.id == g1), "auto_nest {auto_nest}: G1 is a top-level layer");
|
||||
}
|
||||
}
|
||||
@@ -416,10 +416,10 @@ pub(crate) fn finish(app: &mut PhotocraftApp, dx: f64, dy: f64) {
|
||||
if dx == 0.0 && dy == 0.0 {
|
||||
return;
|
||||
}
|
||||
// `nest`: a layer dropped on another artboard joins it (Photoshop's auto-nesting).
|
||||
let Ok(result) =
|
||||
app.run("layer.translate", pattern_wrap(app, json!({"dx": dx, "dy": dy, "selection": carries_selection(app), "nest": app.ui.artboard_tool.auto_nest})))
|
||||
else {
|
||||
// `nest`: a layer dropped on another artboard joins it, one dropped off every board leaves for
|
||||
// the top level. Always, as in the reference application: the Artboard tool's Auto-nest Layers
|
||||
// does not change what a Move drag does (#18155).
|
||||
let Ok(result) = app.run("layer.translate", pattern_wrap(app, json!({"dx": dx, "dy": dy, "selection": carries_selection(app), "nest": true}))) else {
|
||||
return;
|
||||
};
|
||||
// A layer that changed board is clipped by its new board, not the old one the preview showed,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! 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
|
||||
//! tip, over the canvas, the pasteboard, the transform box (#18160) and locked pixels alike, and for ⌘ held with a
|
||||
//! painting tool. The plain arrow inside a selection. 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.
|
||||
|
||||
@@ -46,10 +46,10 @@ fn the_move_tool_shows_the_arrow_with_the_cross_over_the_canvas_and_the_pasteboa
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inside_the_transform_box_it_is_the_plain_arrow_only_with_auto_select_and_the_controls_on() {
|
||||
fn inside_the_transform_box_it_is_the_cross_too() {
|
||||
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, 175.0, 160.0, Modifiers::NONE), cross(), "inside the box (#18160)");
|
||||
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");
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
//! The Move tool's cursor while a drag runs (#18160): the small arrowhead with no four-way cross, hollow for the layer
|
||||
//! that was already active or for the selected pixels, solid for a layer Auto-Select picked at the press, ⇧ and ⌥
|
||||
//! alike. The layer marquee keeps the hover cursor, and so does a hover inside the transform box. Driven through the
|
||||
//! canvas host's real press and moves; the assertions read the cursor the tool asked the host for.
|
||||
|
||||
use craft::behavior::{Cursor, CursorIcon, PaintedCursor, PointerGlyph};
|
||||
use egui::Modifiers;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::canvas::{ToolEvent, tool_event_response};
|
||||
use crate::state::Tool;
|
||||
use crate::{PhotocraftApp, Services};
|
||||
|
||||
/// A 200 × 200 document with two opaque pixel layers, 20..60 square below and 100..140 square on top, the top one
|
||||
/// active; Move tool, Auto-Select on, Snap and Smart Guides off.
|
||||
fn app() -> Box<PhotocraftApp> {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Services::default());
|
||||
app.session.execute("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
app.sync_views();
|
||||
for (x0, x1) in [(20, 60), (100, 140)] {
|
||||
app.session.execute("layer.new.layer", json!({})).unwrap();
|
||||
app.session
|
||||
.edit("paint", |doc, a| {
|
||||
doc.layer_mut(a.unwrap()).unwrap().surface_mut().unwrap().fill_rect(photocraft_geom::Rect::new(x0, x0, x1, x1), &[1.0, 0.0, 0.0, 1.0]);
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
app.ui.tool = Tool::Move;
|
||||
app.ui.tool_options.move_auto_select = true;
|
||||
app.ui.extras.snap = false;
|
||||
app.ui.view.show.smart_guides = false;
|
||||
app
|
||||
}
|
||||
|
||||
fn active(app: &PhotocraftApp) -> Option<photocraft_doc::LayerId> {
|
||||
app.session.active().and_then(|st| st.active_layer)
|
||||
}
|
||||
|
||||
fn hover(app: &mut PhotocraftApp, x: f64, y: f64, mods: Modifiers) -> Option<Cursor> {
|
||||
tool_event_response(app, ToolEvent::Move { x, y, pressure: 1.0 }, mods).cursor
|
||||
}
|
||||
|
||||
/// Presses at (`x`, `y`) and drags 15 px right and 10 px down, the button still down; the cursor at the end.
|
||||
fn drag(app: &mut PhotocraftApp, x: f64, y: f64, mods: Modifiers) -> Option<Cursor> {
|
||||
let _ = tool_event_response(app, ToolEvent::Down { x, y, pressure: 1.0 }, mods);
|
||||
let _ = tool_event_response(app, ToolEvent::Move { x: x + 8.0, y: y + 5.0, pressure: 1.0 }, mods);
|
||||
tool_event_response(app, ToolEvent::Move { x: x + 15.0, y: y + 10.0, pressure: 1.0 }, mods).cursor
|
||||
}
|
||||
|
||||
fn arrowhead(hollow: bool) -> Option<Cursor> {
|
||||
Some(Cursor::Painted(PaintedCursor::arrow(hollow)))
|
||||
}
|
||||
|
||||
fn cross() -> Option<Cursor> {
|
||||
Some(Cursor::Painted(PaintedCursor::pointer_tool(PointerGlyph::Arrow, crate::icons::tool_icon(Tool::Move))))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_drag_of_the_active_layer_shows_the_hollow_arrowhead_plain_shift_and_alt_alike() {
|
||||
for mods in [Modifiers::NONE, Modifiers::SHIFT, Modifiers::ALT] {
|
||||
let mut app = app();
|
||||
let before = active(&app);
|
||||
let cursor = drag(&mut app, 120.0, 120.0, mods);
|
||||
// ⌥'s duplicate becomes the active layer once the drag leaves its press; without ⌥ the press keeps it.
|
||||
if !mods.alt {
|
||||
assert_eq!(active(&app), before, "{mods:?}: the press kept the active layer");
|
||||
}
|
||||
assert!(app.canvas_tools.mover.offset().is_some(), "{mods:?}: the press started a layer drag");
|
||||
assert_eq!(cursor, arrowhead(true), "{mods:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_drag_of_a_layer_auto_select_picked_shows_the_solid_arrowhead() {
|
||||
let mut app = app();
|
||||
let before = active(&app);
|
||||
let picked = drag(&mut app, 40.0, 40.0, Modifiers::NONE);
|
||||
assert_ne!(active(&app), before, "Auto-Select picked the lower layer at the press");
|
||||
assert!(app.canvas_tools.mover.offset().is_some(), "the press started a layer drag");
|
||||
assert_eq!(picked, arrowhead(false));
|
||||
let mut app = self::app();
|
||||
assert_ne!(picked, drag(&mut app, 120.0, 120.0, Modifiers::NONE), "a drag of the active layer looks different");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_drag_of_the_selected_pixels_shows_the_hollow_arrowhead() {
|
||||
let mut app = app();
|
||||
app.run("select.rect", json!({"x": 100, "y": 100, "width": 40, "height": 40})).unwrap();
|
||||
let cursor = drag(&mut app, 120.0, 120.0, Modifiers::NONE);
|
||||
assert!(app.canvas_tools.mover.layer_drag().is_some_and(|d| d.moves_selection), "the press floated the selected pixels");
|
||||
assert_eq!(cursor, arrowhead(true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_layer_marquee_keeps_the_hover_cursor() {
|
||||
let mut app = app();
|
||||
let hovered = hover(&mut app, 175.0, 25.0, Modifiers::NONE);
|
||||
assert_eq!(hovered, cross(), "the hover cursor over empty canvas");
|
||||
let cursor = drag(&mut app, 160.0, 15.0, Modifiers::NONE);
|
||||
assert!(app.canvas_tools.mover.dragging() && app.canvas_tools.mover.offset().is_none(), "the press started the layer marquee");
|
||||
assert_eq!(cursor, hovered);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inside_the_transform_box_the_hover_shows_the_arrow_with_the_cross() {
|
||||
let mut app = app();
|
||||
app.ui.tool_options.move_show_transform = true;
|
||||
assert!(crate::canvas::transform_controls::frame(&app).is_some(), "the active layer shows its transform box");
|
||||
// Off the centre: the reference point there has its own drag (#18161), and off the handles (#16820).
|
||||
assert_eq!(hover(&mut app, 110.0, 128.0, Modifiers::NONE), cross());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alt_before_a_drag_keeps_the_copy_arrow() {
|
||||
let mut app = app();
|
||||
assert_eq!(hover(&mut app, 120.0, 120.0, Modifiers::ALT), Some(Cursor::System(CursorIcon::Copy)));
|
||||
}
|
||||
@@ -53,11 +53,14 @@ struct Run {
|
||||
prompted: bool,
|
||||
/// The float at the press of a pixels drag (an ⌥-drag drops it and floats a copy).
|
||||
floating_before: Option<Floating>,
|
||||
/// Auto-Select (or a ⌘-click) made another layer active at the press: the drag shows the solid arrowhead, not
|
||||
/// the hollow one of a drag of the layer that was already active.
|
||||
picked: bool,
|
||||
}
|
||||
|
||||
impl Run {
|
||||
fn plain(kind: Kind, start: [f64; 2]) -> Self {
|
||||
Run { kind, gesture: None, start, box_rect: None, delta: [0.0; 2], offset: (0, 0), moved: false, prompted: false, floating_before: None }
|
||||
Run { kind, gesture: None, start, box_rect: None, delta: [0.0; 2], offset: (0, 0), moved: false, prompted: false, floating_before: None, picked: false }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,12 +140,6 @@ 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)]
|
||||
}
|
||||
@@ -182,6 +179,7 @@ fn press_at(app: &mut PhotocraftApp, p: [f64; 2], mods: Mods, style: ConstrainSt
|
||||
(ToolAction::Claimed, Some(Run::plain(Kind::Marquee, p)))
|
||||
};
|
||||
let pixels_now = crate::move_ui::moves_selected_pixels_with(app, Tool::Move);
|
||||
let mut picked = false;
|
||||
// A press that doesn't drag the floating piece drops it first.
|
||||
if !pixels_now && app.session.active().is_some_and(|st| photocraft_engine::float_cmds::floating(st).is_some()) {
|
||||
let _ = app.run("select.drop", json!({}));
|
||||
@@ -232,7 +230,13 @@ fn press_at(app: &mut PhotocraftApp, p: [f64; 2], mods: Mods, style: ConstrainSt
|
||||
});
|
||||
let active_before = app.session.active().and_then(|st| st.active_layer);
|
||||
let revealed = crate::layer_reveal::mark(app);
|
||||
let _ = app.run("layer.pickAt", json!({"x": p[0], "y": p[1], "target": target, "mode": mode, "moveAutoSelect": auto}));
|
||||
// After Show Previous / Next Layer Boundary a plain Auto-Select click picks the layer the outline shows (#18432).
|
||||
let plain_auto = app.ui.tool_options.move_auto_select && !mods.cmd && mode == "replace" && target == "layer";
|
||||
let _ = match plain_auto.then(|| crate::move_hover::cycled_layer(app, p)).flatten() {
|
||||
Some(layer) => app.run("layer.select", json!({"layer": layer.0, "mode": "replace"})),
|
||||
None => app.run("layer.pickAt", json!({"x": p[0], "y": p[1], "target": target, "mode": mode, "moveAutoSelect": auto})),
|
||||
};
|
||||
picked = app.session.active().and_then(|st| st.active_layer) != active_before;
|
||||
note_move_pick(app, active_before);
|
||||
crate::layer_reveal::file(app, revealed);
|
||||
if locked_hit {
|
||||
@@ -257,6 +261,7 @@ fn press_at(app: &mut PhotocraftApp, p: [f64; 2], mods: Mods, style: ConstrainSt
|
||||
run.gesture = Some(gesture);
|
||||
run.box_rect = moving_box(app, true);
|
||||
run.floating_before = before;
|
||||
run.picked = picked;
|
||||
return (ToolAction::Claimed, Some(run));
|
||||
}
|
||||
// PLAN: assumed `move_mods::begin(app, alt)` (tools-w65) latches ⌥ for the duplicate.
|
||||
@@ -264,6 +269,7 @@ fn press_at(app: &mut PhotocraftApp, p: [f64; 2], mods: Mods, style: ConstrainSt
|
||||
let mut run = Run::plain(Kind::Layers, p);
|
||||
run.gesture = Some(gesture);
|
||||
run.box_rect = moving_box(app, false);
|
||||
run.picked = picked;
|
||||
(ToolAction::Claimed, Some(run))
|
||||
}
|
||||
|
||||
@@ -459,18 +465,23 @@ 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.
|
||||
/// The arrow with the four-way cross below right of it, the hotspot on the arrow's tip (#16819), also inside the
|
||||
/// transform box; the plain arrow inside a selection, and ⌥'s copy arrow before a drag. A layer or pixels drag shows
|
||||
/// the small arrowhead, ⇧ and ⌥ alike: hollow for the layer that was already active or the selected pixels, solid
|
||||
/// for a layer Auto-Select picked at the press (#18160). The layer marquee keeps the hover cursor.
|
||||
fn cursor(&self, cx: &ToolContext<'_>) -> Cursor {
|
||||
let alt = cx.mods.alt;
|
||||
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();
|
||||
match self.state.run.as_ref().map(|r| (r.kind, r.picked)) {
|
||||
Some((Kind::Layers | Kind::Pixels, picked)) => return Cursor::Painted(PaintedCursor::arrow(!picked)),
|
||||
Some((Kind::Refused, _)) => return Cursor::System(CursorIcon::Default),
|
||||
Some((Kind::Marquee, _)) | None => {}
|
||||
}
|
||||
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)) {
|
||||
if at.is_some_and(|at| inside_selection(app, [at.x, at.y])) {
|
||||
return Cursor::System(CursorIcon::Default);
|
||||
}
|
||||
Cursor::Painted(PaintedCursor::pointer_tool(PointerGlyph::Arrow, crate::icons::tool_icon(Tool::Move)))
|
||||
@@ -492,5 +503,8 @@ impl CanvasTool for MoveRun<'_> {
|
||||
#[path = "move_cursor_cross_tests.rs"]
|
||||
mod move_cursor_cross_tests;
|
||||
#[cfg(test)]
|
||||
#[path = "move_drag_cursor_tests.rs"]
|
||||
mod move_drag_cursor_tests;
|
||||
#[cfg(test)]
|
||||
#[path = "../snap_off_lines_tests.rs"]
|
||||
mod snap_off_lines_tests;
|
||||
@@ -296,6 +296,10 @@ pub(crate) fn command_rows(app: &PhotocraftApp) -> Vec<CommandDef> {
|
||||
if def.paths.is_empty() {
|
||||
def.paths.extend(menu_path(&def.command.id));
|
||||
}
|
||||
// The Move tool's boundary keys are in no menu; they are filed under Tools, as in Photoshop's list.
|
||||
if def.paths.is_empty() && crate::move_hover::boundary_command(&def.command.id).is_some() {
|
||||
def.paths.push(vec!["Tools".into(), def.label.clone()]);
|
||||
}
|
||||
push_row(&mut rows, &mut index, def);
|
||||
}
|
||||
|
||||
@@ -712,6 +716,11 @@ fn run_pressed(app: &mut PhotocraftApp, ctx: &egui::Context, f: &Fired) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// With the Move tool the bracket keys step the rollover outline through the layers under the pointer (#18432).
|
||||
if let Some(boundary) = crate::move_hover::bracket_command(app, id) {
|
||||
dispatch(app, ctx, boundary);
|
||||
return;
|
||||
}
|
||||
if id == EditCommands::Delete.id() {
|
||||
// A finished work path shown by a Pen or Path Selection, or the path or segment Direct Selection targets:
|
||||
// ⌫/Delete edits the path, as in Photoshop (#5702, #12695, #13203), never Edit › Clear on the pixels under it.
|
||||
|
||||
@@ -634,7 +634,8 @@ fn move_alt_copy_cursor_follows_the_latched_duplication_drag() {
|
||||
h.run_steps(2);
|
||||
h.event(egui::Event::ModifiersChanged(Modifiers::NONE));
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.output().platform_output.cursor_icon, egui::CursorIcon::Copy, "releasing Alt does not undo an active copy");
|
||||
// The drag itself shows the hollow arrowhead of a drag of the active layer, ⌥ or not (#18160).
|
||||
assert_eq!(requested(&h), Some(craft::behavior::Cursor::Painted(craft::behavior::PaintedCursor::arrow(true))), "the drag's arrowhead");
|
||||
h.event(egui::Event::PointerButton { pos: end, button: egui::PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
|
||||
h.run_steps(2);
|
||||
assert_eq!(requested(&h), move_cursor, "back to the Move cursor");
|
||||
|
||||
@@ -375,6 +375,8 @@ pub struct PhotocraftApp {
|
||||
pub(crate) move_preview: Option<move_ui::MovePreview>,
|
||||
/// Move tool › Show Highlight on Rollover: the last hover answer (`move_hover`).
|
||||
pub(crate) move_hover: Option<move_hover::Hover>,
|
||||
/// Move tool › Show Previous / Next Layer Boundary: where the keys left the outline (`move_hover`).
|
||||
pub(crate) move_boundary: Option<move_hover::Cycle>,
|
||||
/// Smart Guides distances shown with ⌘ held over the canvas: the last answer (`move_distance`).
|
||||
pub(crate) move_distance: Option<move_distance::Cache>,
|
||||
/// Object Selection › Object Finder: the hover preview (`object_finder`).
|
||||
|
||||
@@ -412,6 +412,9 @@ pub(crate) fn invoke_unguarded(app: &mut PhotocraftApp, ctx: &egui::Context, id:
|
||||
if id == "layer.selectUnderCursor" {
|
||||
return select_layer_under_cursor(app, ctx);
|
||||
}
|
||||
if let Some(up) = crate::move_hover::boundary_command(id) {
|
||||
return boundary_step(app, ctx, ¶ms, up);
|
||||
}
|
||||
if let Some(result) = invoke_early_commands(app, ctx, id, ¶ms) {
|
||||
return result;
|
||||
}
|
||||
@@ -903,6 +906,17 @@ fn select_layer_under_cursor(app: &mut PhotocraftApp, ctx: &egui::Context) -> Re
|
||||
Ok(picked)
|
||||
}
|
||||
|
||||
/// Show Previous / Next Layer Boundary at the point the parameters name (`x`, `y`, document px),
|
||||
/// else at the pointer over the active canvas (#18432).
|
||||
fn boundary_step(app: &mut PhotocraftApp, ctx: &egui::Context, params: &Value, up: bool) -> Result<Value, String> {
|
||||
let given = params.get("x").and_then(Value::as_f64).zip(params.get("y").and_then(Value::as_f64));
|
||||
let at = given.map(|(x, y)| [x, y]).or_else(|| {
|
||||
let pointer = ctx.pointer_hover_pos()?;
|
||||
crate::canvas::document_display::doc_point_at(app, pointer).map(|p| [p.x, p.y])
|
||||
});
|
||||
crate::move_hover::step(app, at, up)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "view_show_grid_extras_off_tests.rs"]
|
||||
mod view_show_grid_extras_off_tests;
|
||||
@@ -0,0 +1,202 @@
|
||||
//! Move tool › Show Previous / Next Layer Boundary (#18432): `]` and `[` step the rollover outline
|
||||
//! through the visible layers under the pointer, the active layer ends the cycle, and a plain
|
||||
//! Auto-Select click or drag then takes the layer the outline shows.
|
||||
|
||||
use egui::{Key, Modifiers, PointerButton};
|
||||
use egui_kittest::Harness;
|
||||
use photocraft_doc::LayerId;
|
||||
use photocraft_geom::Rect;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::guide_cursor_tests::{harness, hover, screen};
|
||||
use crate::shortcut_dispatch::tests::tap;
|
||||
use crate::state::Tool;
|
||||
|
||||
type H = Harness<'static, Box<PhotocraftApp>>;
|
||||
|
||||
struct Stack {
|
||||
background: LayerId,
|
||||
red: LayerId,
|
||||
blue: LayerId,
|
||||
green: LayerId,
|
||||
}
|
||||
|
||||
fn paint(app: &mut PhotocraftApp, name: &str, bounds: Rect) -> LayerId {
|
||||
let layer = LayerId(app.run("layer.new.layer", json!({"name": name})).unwrap()["layer"].as_u64().unwrap());
|
||||
app.session
|
||||
.edit("Paint fixture", |doc, _| {
|
||||
doc.layer_mut(layer).unwrap().surface_mut().unwrap().fill_rect(bounds, &[1.0, 0.0, 0.0, 1.0]);
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
layer
|
||||
}
|
||||
|
||||
/// From the bottom up: Background, Red, Blue, Green (top). At (130, 130) all three have pixels, at
|
||||
/// (100, 100) Blue and Red, at (70, 70) only Red. The guide the harness adds is at x = 200, away
|
||||
/// from every point used. The Background is active.
|
||||
fn stack() -> (H, Stack) {
|
||||
let mut h = harness(Tool::Move);
|
||||
let app = h.state_mut();
|
||||
let background = app.session.active().unwrap().doc.layers[0].id;
|
||||
let red = paint(app, "Red", Rect::new(60, 60, 140, 140));
|
||||
let blue = paint(app, "Blue", Rect::new(90, 90, 170, 170));
|
||||
let green = paint(app, "Green", Rect::new(120, 120, 190, 190));
|
||||
app.ui.tool_options.move_auto_select = true;
|
||||
app.run("layer.select", json!({"layer": background.0})).unwrap();
|
||||
h.run_steps(2);
|
||||
(h, Stack { background, red, blue, green })
|
||||
}
|
||||
|
||||
fn shown(h: &H) -> Option<LayerId> {
|
||||
h.state().canvas_hover_layer
|
||||
}
|
||||
|
||||
/// `]` (Show Previous Layer Boundary) or `[` (Show Next Layer Boundary), then the outline.
|
||||
fn key(h: &mut H, previous: bool) -> Option<LayerId> {
|
||||
tap(h, if previous { Key::CloseBracket } else { Key::OpenBracket }, Modifiers::NONE);
|
||||
h.run_steps(1);
|
||||
shown(h)
|
||||
}
|
||||
|
||||
fn history(h: &H) -> usize {
|
||||
h.state().session.active().unwrap().history.past_len()
|
||||
}
|
||||
|
||||
fn active(h: &H) -> Option<LayerId> {
|
||||
h.state().session.active().unwrap().active_layer
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_two_commands_are_listed_under_tools_and_run_without_the_shell() {
|
||||
let (h, _) = stack();
|
||||
let rows = crate::shortcut_dispatch::command_rows(h.state());
|
||||
for (id, label) in [("move.showPreviousLayerBoundary", "Show Previous Layer Boundary"), ("move.showNextLayerBoundary", "Show Next Layer Boundary")] {
|
||||
let row = rows.iter().find(|r| r.command.id == id).unwrap_or_else(|| panic!("{id} has no Keyboard Shortcuts row"));
|
||||
assert_eq!(row.paths, [vec!["Tools".to_string(), label.to_string()]], "{id} is filed under Tools");
|
||||
}
|
||||
|
||||
// Headless: the engine answers for a pointer position and changes nothing.
|
||||
let mut session = photocraft_engine::Session::new();
|
||||
let none = session.execute("move.showNextLayerBoundary", json!({"x": 130, "y": 130}));
|
||||
assert!(none.is_err(), "no document: refused, not a crash");
|
||||
session.execute("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
let mut ids = Vec::new();
|
||||
for (name, at) in [("Red", 60), ("Blue", 90), ("Green", 120)] {
|
||||
ids.push(session.execute("layer.new.layer", json!({"name": name})).unwrap()["layer"].as_u64().unwrap());
|
||||
session.execute("select.rect", json!({"x": at, "y": at, "width": 80, "height": 80})).unwrap();
|
||||
session.execute("edit.fill", json!({"color": "#ff0000"})).unwrap();
|
||||
}
|
||||
session.execute("select.deselect", json!({})).unwrap();
|
||||
let (red, blue, green) = (ids[0], ids[1], ids[2]);
|
||||
let background = session.active().unwrap().doc.layers[0].id;
|
||||
session.execute("layer.select", json!({"layer": background.0})).unwrap();
|
||||
let before = (session.active().unwrap().revision, session.active().unwrap().active_layer);
|
||||
let r = session.execute("move.showPreviousLayerBoundary", json!({"x": 130, "y": 130})).unwrap();
|
||||
assert_eq!(r["layers"], json!([green, blue, red]), "the candidates, topmost first, without the Background");
|
||||
assert_eq!(r["layer"], json!(red), "one layer up from the topmost wraps to the bottom");
|
||||
let r = session.execute("move.showNextLayerBoundary", json!({"x": 130, "y": 130, "from": red})).unwrap();
|
||||
assert_eq!(r["layer"], json!(green), "one layer down from the bottom wraps to the top");
|
||||
assert_eq!((session.active().unwrap().revision, session.active().unwrap().active_layer), before, "nothing changed");
|
||||
session.execute("layer.select", json!({"layer": green})).unwrap();
|
||||
let r = session.execute("move.showPreviousLayerBoundary", json!({"x": 130, "y": 130, "from": blue})).unwrap();
|
||||
assert_eq!(r["layer"], json!(null), "Green is active: the cycle ends there");
|
||||
assert!(session.execute("move.showNextLayerBoundary", json!({"y": 130})).is_err(), "missing x");
|
||||
assert!(session.execute("move.showNextLayerBoundary", json!({"x": 1, "y": 1, "from": "Red"})).is_err(), "a bad from");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn brackets_cycle_the_outline_through_the_layers_under_the_pointer() {
|
||||
let (mut h, s) = stack();
|
||||
hover(&mut h, 130.0, 130.0, Modifiers::NONE);
|
||||
assert_eq!(shown(&h), Some(s.green), "the outline starts on the topmost layer");
|
||||
let h0 = history(&h);
|
||||
let brush = h.state().session.tools.brush.size;
|
||||
assert_eq!([key(&mut h, true), key(&mut h, true), key(&mut h, true), key(&mut h, true)], [Some(s.red), Some(s.blue), Some(s.green), Some(s.red)]);
|
||||
hover(&mut h, 136.0, 130.0, Modifiers::NONE);
|
||||
assert_eq!(shown(&h), Some(s.green), "a pointer move puts the outline back on the topmost layer");
|
||||
assert_eq!([key(&mut h, false), key(&mut h, false), key(&mut h, false)], [Some(s.blue), Some(s.red), Some(s.green)]);
|
||||
assert_eq!(history(&h), h0, "the keys add no history state");
|
||||
assert_eq!(active(&h), Some(s.background), "the keys change no layer");
|
||||
assert_eq!(h.state().session.tools.brush.size, brush, "with the Move tool the keys leave the brush size");
|
||||
|
||||
// Two layers alternate; with one the outline stays, and the Background is never added.
|
||||
hover(&mut h, 100.0, 100.0, Modifiers::NONE);
|
||||
assert_eq!([shown(&h), key(&mut h, true), key(&mut h, true), key(&mut h, false)], [Some(s.blue), Some(s.red), Some(s.blue), Some(s.red)]);
|
||||
hover(&mut h, 70.0, 70.0, Modifiers::NONE);
|
||||
assert_eq!([shown(&h), key(&mut h, true), key(&mut h, false)], [Some(s.red); 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hidden_layers_are_skipped() {
|
||||
let (mut h, s) = stack();
|
||||
h.state_mut().run("layer.setProps", json!({"layer": s.blue.0, "visible": false})).unwrap();
|
||||
hover(&mut h, 130.0, 130.0, Modifiers::NONE);
|
||||
assert_eq!([shown(&h), key(&mut h, true), key(&mut h, true)], [Some(s.green), Some(s.red), Some(s.green)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_active_layer_ends_the_cycle_until_the_pointer_moves() {
|
||||
let (mut h, s) = stack();
|
||||
h.state_mut().run("layer.select", json!({"layer": s.blue.0})).unwrap();
|
||||
hover(&mut h, 130.0, 130.0, Modifiers::NONE);
|
||||
assert_eq!([shown(&h), key(&mut h, true), key(&mut h, true), key(&mut h, true), key(&mut h, false)], [Some(s.green), Some(s.red), None, None, None]);
|
||||
hover(&mut h, 131.0, 130.0, Modifiers::NONE);
|
||||
assert_eq!(shown(&h), None, "a 1 px move keeps the ended cycle");
|
||||
hover(&mut h, 134.0, 130.0, Modifiers::NONE);
|
||||
assert_eq!(shown(&h), Some(s.green), "a 4 px move brings the outline back on the topmost layer");
|
||||
assert_eq!(key(&mut h, false), None, "from the topmost, the next layer down is the active one");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_click_or_drag_after_cycling_takes_the_layer_the_outline_shows() {
|
||||
let (mut h, s) = stack();
|
||||
hover(&mut h, 130.0, 130.0, Modifiers::NONE);
|
||||
assert_eq!(key(&mut h, true), Some(s.red));
|
||||
let h0 = history(&h);
|
||||
let p = screen(&h, 130.0, 130.0);
|
||||
h.event(egui::Event::PointerButton { pos: p, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
|
||||
h.run_steps(1);
|
||||
h.event(egui::Event::PointerButton { pos: p, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
|
||||
h.run_steps(3);
|
||||
assert_eq!(active(&h), Some(s.red), "the click picks the outlined layer, not the topmost Green");
|
||||
assert_eq!(history(&h), h0, "a click adds no history state");
|
||||
|
||||
// A drag after cycling moves the outlined layer.
|
||||
let (mut h, s) = stack();
|
||||
hover(&mut h, 130.0, 130.0, Modifiers::NONE);
|
||||
assert_eq!(key(&mut h, true), Some(s.red));
|
||||
let h0 = history(&h);
|
||||
let from = screen(&h, 130.0, 130.0);
|
||||
h.event(egui::Event::PointerButton { pos: from, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
|
||||
h.run_steps(1);
|
||||
for x in [140.0, 160.0, 170.0] {
|
||||
h.event(egui::Event::PointerMoved(screen(&h, x, 130.0)));
|
||||
h.run_steps(1);
|
||||
}
|
||||
let to = screen(&h, 170.0, 130.0);
|
||||
h.event(egui::Event::PointerButton { pos: to, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
|
||||
h.run_steps(3);
|
||||
let st = h.state().session.active().unwrap();
|
||||
let bounds = |id: LayerId| photocraft_compose::bounds::content_bounds(st.doc.layer(id).unwrap().surface().unwrap());
|
||||
assert!(bounds(s.red).x0 > 60, "Red moved right: {:?}", bounds(s.red));
|
||||
assert_eq!(bounds(s.green).x0, 120, "Green stayed");
|
||||
assert_eq!(st.active_layer, Some(s.red));
|
||||
assert_eq!(st.history.past_len(), h0 + 1);
|
||||
assert_eq!(st.history.entries().pop().as_deref(), Some("Move"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn other_tools_keep_the_brush_size_keys() {
|
||||
let (mut h, s) = stack();
|
||||
h.state_mut().ui.tool = Tool::Brush;
|
||||
hover(&mut h, 130.0, 130.0, Modifiers::NONE);
|
||||
let size = h.state().session.tools.brush.size;
|
||||
tap(&mut h, Key::CloseBracket, Modifiers::NONE);
|
||||
assert!(h.state().session.tools.brush.size > size, "] grows the brush");
|
||||
tap(&mut h, Key::OpenBracket, Modifiers::NONE);
|
||||
tap(&mut h, Key::OpenBracket, Modifiers::NONE);
|
||||
assert!(h.state().session.tools.brush.size < size, "[ shrinks it");
|
||||
assert_eq!(active(&h), Some(s.background));
|
||||
}
|
||||
@@ -52,8 +52,9 @@ impl Gear {
|
||||
}
|
||||
}
|
||||
|
||||
/// Only Auto-nest Layers does something yet (the Move tool's auto-nesting, #10512); the others
|
||||
/// are drawn checked and disabled until their behaviour is measured.
|
||||
/// Only Auto-nest Layers can be switched; the others are drawn checked and disabled until their
|
||||
/// behaviour is measured. The Move tool nests layers into and out of boards whatever Auto-nest
|
||||
/// Layers says, as the reference application does (#18155).
|
||||
pub fn enabled(self) -> bool {
|
||||
self == Gear::AutoNest
|
||||
}
|
||||
|
||||
@@ -4,12 +4,17 @@
|
||||
//! (`pick_cmds::move_auto_select_target`), so a type layer is outlined anywhere inside its text, as it
|
||||
//! is picked there (#2591). The answer is cached per document revision and pointer pixel: a
|
||||
//! pointer resting on the canvas costs nothing per frame. The active layer itself is never outlined.
|
||||
//!
|
||||
//! Show Previous / Next Layer Boundary (`]` / `[` with the Move tool, #18432) step the outline
|
||||
//! through the layers under the pointer ([`step`]); a plain Auto-Select click then picks the layer
|
||||
//! the outline shows ([`cycled_layer`]).
|
||||
|
||||
use craft::behavior::kurbo;
|
||||
use craft::ui::canvas_controls::{HoverOutline, HoverShape};
|
||||
use craft::ui::contract::Show as _;
|
||||
use photocraft_doc::{DocId, Document, Layer, LayerContent, LayerId};
|
||||
use photocraft_geom::Rect;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::state::Tool;
|
||||
@@ -24,6 +29,97 @@ pub(crate) struct Hover {
|
||||
bounds: Option<Rect>,
|
||||
}
|
||||
|
||||
/// Show Previous Layer Boundary: one layer up the stack (`]`).
|
||||
pub(crate) const PREVIOUS_BOUNDARY: &str = "move.showPreviousLayerBoundary";
|
||||
/// Show Next Layer Boundary: one layer down the stack (`[`).
|
||||
pub(crate) const NEXT_BOUNDARY: &str = "move.showNextLayerBoundary";
|
||||
|
||||
/// Where the boundary keys left the outline at a pointer pixel. `shown` is `None` once the cycle
|
||||
/// reached the active layer: no outline, and the keys do nothing, until the pointer moves.
|
||||
pub(crate) struct Cycle {
|
||||
doc: DocId,
|
||||
revision: u64,
|
||||
at: [i32; 2],
|
||||
shown: Option<LayerId>,
|
||||
}
|
||||
|
||||
/// A pointer move of this many document pixels (on either axis) ends a cycle: in the reference a
|
||||
/// 1 px move kept it and a 4 px move ended it.
|
||||
const CYCLE_SLACK: i32 = 2;
|
||||
|
||||
/// The cycle still in force with the pointer at `at` on revision `revision` of `doc`: `Some(shown)`.
|
||||
/// A cycle of another document or revision, or one the pointer moved away from, ends here.
|
||||
fn live_cycle(app: &mut PhotocraftApp, doc: DocId, revision: u64, at: [i32; 2]) -> Option<Option<LayerId>> {
|
||||
let c = app.move_boundary.as_ref()?;
|
||||
if c.doc == doc && c.revision == revision && (c.at[0] - at[0]).abs() < CYCLE_SLACK && (c.at[1] - at[1]).abs() < CYCLE_SLACK {
|
||||
return Some(c.shown);
|
||||
}
|
||||
app.move_boundary = None;
|
||||
None
|
||||
}
|
||||
|
||||
/// Whether `id` is one of the two boundary commands; `Some(true)` for Show Previous Layer Boundary.
|
||||
pub(crate) fn boundary_command(id: &str) -> Option<bool> {
|
||||
match id {
|
||||
PREVIOUS_BOUNDARY => Some(true),
|
||||
NEXT_BOUNDARY => Some(false),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The boundary command the fired brush-size key `id` runs instead: with the Move tool picking
|
||||
/// layers, `]` and `[` step the outline (Photoshop's Tools shortcuts share the keys). Auto-Select:
|
||||
/// Group keeps the brush-size keys, as do the other tools.
|
||||
pub(crate) fn bracket_command(app: &PhotocraftApp, id: &str) -> Option<&'static str> {
|
||||
if app.ui.tool != Tool::Move || app.ui.tool_options.move_target == "group" {
|
||||
return None;
|
||||
}
|
||||
match id {
|
||||
"tools.increaseBrushSize" => Some(PREVIOUS_BOUNDARY),
|
||||
"tools.decreaseBrushSize" => Some(NEXT_BOUNDARY),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Runs Show Previous (`up`) or Show Next Layer Boundary with the pointer at `at` (document px):
|
||||
/// the outline moves to the next layer with pixels there, or goes away when that is the active
|
||||
/// layer. Changes no layer and adds no history state. `{"layer": null}` with no pointer on the
|
||||
/// canvas, or after the cycle ended until the pointer moves.
|
||||
pub(crate) fn step(app: &mut PhotocraftApp, at: Option<[f64; 2]>, up: bool) -> Result<Value, String> {
|
||||
let id = if up { PREVIOUS_BOUNDARY } else { NEXT_BOUNDARY };
|
||||
let Some(at) = at.filter(|p| p[0].is_finite() && p[1].is_finite()) else { return Ok(json!({"layer": null})) };
|
||||
let Some(st) = app.session.active() else { return app.run(id, json!({"x": at[0], "y": at[1]})) };
|
||||
let (doc, revision) = (st.doc.id, st.revision);
|
||||
let px = [at[0].floor() as i32, at[1].floor() as i32];
|
||||
let from = match live_cycle(app, doc, revision, px) {
|
||||
Some(None) => return Ok(json!({"layer": null})),
|
||||
Some(shown) => shown,
|
||||
None => None,
|
||||
};
|
||||
let out = app.run(id, json!({"x": at[0], "y": at[1], "from": from.map(|l| l.0)}))?;
|
||||
if out["layers"].as_array().is_some_and(|l| !l.is_empty()) {
|
||||
let shown = out["layer"].as_u64().map(LayerId);
|
||||
// A cycle already in force keeps its pixel, so steps of a resting pointer never drift.
|
||||
let at = app.move_boundary.as_ref().map_or(px, |c| c.at);
|
||||
app.move_boundary = Some(Cycle { doc, revision, at, shown });
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// The layer the boundary keys show with the pointer at `p` (document px), when it has pixels
|
||||
/// there: a plain Auto-Select click picks it instead of the topmost layer.
|
||||
pub(crate) fn cycled_layer(app: &mut PhotocraftApp, p: [f64; 2]) -> Option<LayerId> {
|
||||
if !(p[0].is_finite() && p[1].is_finite()) {
|
||||
return None;
|
||||
}
|
||||
let st = app.session.active()?;
|
||||
let (doc, revision) = (st.doc.id, st.revision);
|
||||
let at = [p[0].floor() as i32, p[1].floor() as i32];
|
||||
let shown = live_cycle(app, doc, revision, at)??;
|
||||
let st = app.session.active()?;
|
||||
photocraft_engine::pick_cmds::boundary_candidates(&st.doc, at[0], at[1]).contains(&shown).then_some(shown)
|
||||
}
|
||||
|
||||
/// The document-space bounds to outline with the pointer at `at` (document px), or `None` when
|
||||
/// nothing is highlighted: the preference is off, another tool is current, the hover mode is
|
||||
/// inactive, the selected pixels move instead, a button is down, or a transform is under way.
|
||||
@@ -59,6 +155,15 @@ pub(crate) fn target(app: &mut PhotocraftApp, at: Option<[f64; 2]>, command: boo
|
||||
(target_layer, bounds)
|
||||
}
|
||||
};
|
||||
// The boundary keys' layer replaces the topmost one while the pointer stays (#18432).
|
||||
let (target_layer, bounds) = match if group { None } else { live_cycle(app, doc, revision, at) } {
|
||||
Some(shown) => {
|
||||
let st = app.session.active()?;
|
||||
let bounds = shown.and_then(|id| outline(&st.doc, id));
|
||||
(shown.filter(|_| bounds.is_some()), bounds)
|
||||
}
|
||||
None => (target_layer, bounds),
|
||||
};
|
||||
// The active layer is never outlined (#18433). Checked after the cache: picking another layer
|
||||
// doesn't change the document revision.
|
||||
if target_layer.is_some() && target_layer == active {
|
||||
@@ -139,6 +244,10 @@ mod move_hover_auto_select_off_tests;
|
||||
#[path = "../move_hover_active_layer_tests.rs"]
|
||||
mod move_hover_active_layer_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../move_layer_boundary_cycle_tests.rs"]
|
||||
mod move_layer_boundary_cycle_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json::json;
|
||||
|
||||
@@ -2,21 +2,21 @@
|
||||
|
||||
Generated by `cargo xtask parity` from `crates/ui-egui/src/menu_catalog.rs` (Photoshop's menu tree) and the live command registry. Do not edit by hand.
|
||||
|
||||
**663 of 663 menu items live (100.0%).**
|
||||
**664 of 664 menu items live (100.0%).**
|
||||
|
||||
| Menu | Live | Total | % |
|
||||
|---|---:|---:|---:|
|
||||
| File | 53 | 53 | 100% |
|
||||
| Edit | 74 | 74 | 100% |
|
||||
| Image | 61 | 61 | 100% |
|
||||
| Layer | 163 | 163 | 100% |
|
||||
| Layer | 164 | 164 | 100% |
|
||||
| Type | 74 | 74 | 100% |
|
||||
| Select | 25 | 25 | 100% |
|
||||
| Filter | 75 | 75 | 100% |
|
||||
| View | 76 | 76 | 100% |
|
||||
| Window | 62 | 62 | 100% |
|
||||
|
||||
**Headless ([RFC-0052](https://github.com/storytold/craft-contrib/blob/main/rfcs/0052-headless-reach.md)): 516 yes, 48 no (window 48, os 0, engine-gap 0), 0 partial, 99 unknown.**
|
||||
**Headless ([RFC-0052](https://github.com/storytold/craft-contrib/blob/main/rfcs/0052-headless-reach.md)): 517 yes, 48 no (window 48, os 0, engine-gap 0), 0 partial, 99 unknown.**
|
||||
|
||||
Live counts the desktop app's own panels, workspaces, tools and view handlers. Headless counts only the engine registry that `photocraft-cli` and the MCP server load: an item is `yes` when its id is an engine command. The rest are listed under [Not headless](#not-headless), with the hand mark from `HEADLESS` in `crates/ui-egui/src/menus/parity.rs`, `no` (`window`) for a desktop panel, workspace or tool, or `unknown`.
|
||||
|
||||
|
||||
Reference in new issue
Block a user