mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-21 09:26:43 +00:00
Move tool: ΔX/ΔY readout beside the pointer while dragging (#5727)
Only Free Transform drew a readout of how far the layer moved (its Hit::Inside offset), so a Move-tool drag inside the transform controls, or without them, showed nothing. Photoshop shows ΔX/ΔY for a Move drag. The drag preview now draws the offset the release will commit (move_ui::drag_offset, whole pixels), for a layer drag and a drag of selected pixels, once the pointer has moved. It goes through draw_value_readout, so Preferences > Tools > Show Transformation Values hides it like the other readouts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8d840eab59
commit
097848ddb5
2 files changed
+41
No files matched your search
@@ -4695,6 +4695,11 @@ fn draw_drag_preview(app: &mut PhotocraftApp, painter: &egui::Painter, xf: &View
|
||||
app.trail = None;
|
||||
return;
|
||||
};
|
||||
// The Move tool's ΔX/ΔY beside the pointer, for layers and selected pixels alike (#5727).
|
||||
if let Some(values) = crate::move_ui::offset_readout(app) {
|
||||
let at = d.points.last().map_or(d.start, |p| [p[0], p[1]]);
|
||||
draw_value_readout(app, painter.ctx(), "move-readout", xf.to_screen(at[0] as f32, at[1] as f32), ["ΔX:", "ΔY:"], values);
|
||||
}
|
||||
// Dragging the selection: its own ants follow the pointer (`selection_shown_offset`).
|
||||
if d.sel_move.is_some() {
|
||||
return;
|
||||
|
||||
@@ -96,6 +96,15 @@ fn drag_offset(app: &PhotocraftApp) -> Option<(i32, i32)> {
|
||||
Some((dx, dy))
|
||||
}
|
||||
|
||||
/// The ΔX/ΔY values shown beside the pointer while the Move tool drags layers or selected pixels,
|
||||
/// as in Photoshop (#5727): the whole pixels the release will move them. Free Transform shows its
|
||||
/// own (`transform_tool::live_readout`). `None` until the pointer moves.
|
||||
pub(crate) fn offset_readout(app: &PhotocraftApp) -> Option<[String; 2]> {
|
||||
app.drag.as_ref().filter(|d| d.points.len() > 1)?;
|
||||
let (dx, dy) = drag_offset(app)?;
|
||||
Some([dx, dy].map(|v| format!("{v} px")))
|
||||
}
|
||||
|
||||
/// The document to show while a Move drag is under way on document `idx`: the moving layers at
|
||||
/// the pointer. `None` without a drag (or when the layers can't move: locked, say; the drag then
|
||||
/// shows its arrow and the release reports why).
|
||||
@@ -309,6 +318,33 @@ mod tests {
|
||||
assert_eq!(r, Rect::new(0, 0, 64, 64));
|
||||
}
|
||||
|
||||
/// The Move tool shows how far it has moved the layer, ΔX/ΔY in whole pixels, as Photoshop
|
||||
/// and Free Transform do (#5727): once the pointer moves, until the release.
|
||||
#[test]
|
||||
fn a_move_drag_reads_out_the_offset_it_will_commit() {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.session.execute("file.new", json!({"width": 64, "height": 64})).unwrap();
|
||||
app.sync_views();
|
||||
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(Rect::new(16, 16, 32, 32), &[1.0, 0.0, 0.0, 1.0]);
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
app.ui.tool = Tool::Move;
|
||||
app.ui.extras.snap = false;
|
||||
app.ui.view.show.smart_guides = false;
|
||||
let m = egui::Modifiers::NONE;
|
||||
assert_eq!(super::offset_readout(&app), None, "no drag");
|
||||
crate::canvas::tool_event(&mut app, ToolEvent::Down { x: 32.0, y: 32.0, pressure: 1.0 }, m);
|
||||
assert_eq!(super::offset_readout(&app), None, "pressed, not moved yet");
|
||||
crate::canvas::tool_event(&mut app, ToolEvent::Move { x: 42.4, y: 28.8, pressure: 1.0 }, m);
|
||||
assert_eq!(super::offset_readout(&app), Some(["10 px".to_string(), "-3 px".to_string()]));
|
||||
crate::canvas::tool_event(&mut app, ToolEvent::Up { x: 42.4, y: 28.8 }, m);
|
||||
assert_eq!(super::offset_readout(&app), None, "released");
|
||||
}
|
||||
|
||||
/// A shape reaching past the canvas edge renders cut at the canvas, but its path goes on: a
|
||||
/// drag frame must redraw where the rest of it was, or the cut edge stays behind (#3946).
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user