mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-17 10:46:46 +00:00
Arrange: the canvas takes a drop where the button went up
The canvas took carried artwork only while the pointer was over it at the end of the frame. A release inside the canvas followed in the same frame by a move onto the tab strip kept the drag alive past cleanup, and the drop was lost when the frame ended. The canvas now checks the release position against its own rect and layer, as the tiled and floating panes do (canvas/panes.rs artwork_over).
This commit is contained in:
@@ -196,9 +196,14 @@ pub(crate) fn drop_on_canvas(app: &mut VectorcraftApp, resp: &Response, xf: &can
|
||||
if resp.contains_pointer() {
|
||||
resp.ctx.set_cursor_icon(if same && !copy { egui::CursorIcon::Move } else { egui::CursorIcon::Copy });
|
||||
}
|
||||
if let Some(art) = resp.dnd_release_payload::<Artwork>()
|
||||
&& let Some(at) = resp.ctx.input(released_at).map(|p| xf.to_doc(p))
|
||||
// The canvas takes a release where the button went up, as [`cleanup`] judges it, and not where
|
||||
// a later move in the same frame leaves the pointer.
|
||||
let ctx = &resp.ctx;
|
||||
let over = |p: egui::Pos2| resp.interact_rect.contains(p) && !ctx.layer_id_at(p).is_some_and(|l| l != resp.layer_id);
|
||||
if let Some(p) = ctx.input(|i| i.pointer.primary_released().then(|| released_at(i)).flatten()).filter(|p| over(*p))
|
||||
&& let Some(art) = egui::DragAndDrop::take_payload::<Artwork>(ctx)
|
||||
{
|
||||
let at = xf.to_doc(p);
|
||||
let result = if same {
|
||||
// Back in the source tab, resume the ordinary move (Alt copies).
|
||||
let copy = release_alt(&resp.ctx);
|
||||
|
||||
@@ -316,6 +316,26 @@ fn a_drop_back_in_the_source_uses_the_release_position_and_alt() {
|
||||
assert!((bounds.x0 - 150.0).abs() < 0.001 && (bounds.y0 - 150.0).abs() < 0.001, "{bounds:?}");
|
||||
}
|
||||
|
||||
/// Verify that a release inside the other document's canvas drops the artwork there, though the
|
||||
/// pointer moves onto the tab strip later in the frame of the release.
|
||||
#[test]
|
||||
fn a_release_in_the_canvas_drops_though_the_pointer_then_leaves_it() {
|
||||
let (mut app, ctx, _, tabs) = drag_fixture();
|
||||
frame(&mut app, &ctx, 0.2, vec![Event::PointerMoved(tabs[1].center())]);
|
||||
frame(&mut app, &ctx, 0.25, vec![]);
|
||||
frame(&mut app, &ctx, 0.8, vec![]);
|
||||
assert_eq!(app.session.active_index(), Some(1));
|
||||
let before = app.session.active().unwrap().doc.layers[0].children().map_or(0, Vec::len);
|
||||
let drop = canvas::Xf::new(app.canvas_rect.unwrap(), app.view().unwrap()).to_screen(Point::new(175.0, 180.0));
|
||||
assert!(!app.canvas_rect.unwrap().contains(tabs[0].center()));
|
||||
frame(&mut app, &ctx, 0.9, vec![Event::PointerMoved(drop)]);
|
||||
frame(&mut app, &ctx, 1.0, vec![button(drop, false), Event::PointerMoved(tabs[0].center())]);
|
||||
let st = app.session.active().unwrap();
|
||||
assert_eq!(st.doc.layers[0].children().map_or(0, Vec::len), before + 1);
|
||||
let bounds = st.doc.node(st.selection.objects[0]).unwrap().geometric_bounds().unwrap();
|
||||
assert!((bounds.x0 - 150.0).abs() < 0.001 && (bounds.y0 - 150.0).abs() < 0.001, "{bounds:?}");
|
||||
}
|
||||
|
||||
/// Back in the source tab, the move resumes even when coming to the front measured the source's
|
||||
/// type again in its own composite fonts, which replaces the document without editing it.
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user