From c6ba81b6e63a324d0657a11bbefd6522f10194fe Mon Sep 17 00:00:00 2001 From: Nicek Date: Wed, 28 Oct 2026 18:39:09 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E5=90=8C=E5=B8=A7=E6=8C=89=E4=B8=8B/?= =?UTF-8?q?=E6=9D=BE=E5=BC=80=E7=BB=98=E5=88=B6=E4=BB=8E=E6=8C=89=E4=B8=8B?= =?UTF-8?q?=E7=82=B9=E5=BC=80=E5=A7=8B=E7=9A=84=E5=9B=9E=E5=BD=92=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/ui-egui/src/canvas_fixes_tests.rs | 25 +++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/canvas_fixes_tests.rs b/crates/ui-egui/src/canvas_fixes_tests.rs index dc3f7e94..d3f0d8d7 100644 --- a/crates/ui-egui/src/canvas_fixes_tests.rs +++ b/crates/ui-egui/src/canvas_fixes_tests.rs @@ -6,7 +6,7 @@ use std::sync::Arc; use std::sync::atomic::{AtomicUsize, Ordering}; use std::time::{Duration, Instant}; -use egui::{Pos2, Shape}; +use egui::{Event, Modifiers, PointerButton, Pos2, Shape}; use figcraft_engine::Session; use serde_json::json; @@ -25,6 +25,29 @@ fn dashes_along(shapes: &[Shape], a: Pos2, b: Pos2) -> usize { shapes.iter().filter(|s| matches!(s, Shape::LineSegment { points: [p, q], .. } if on(*p) && on(*q))).count() } +#[test] +fn a_press_and_release_in_one_frame_draw_from_the_press() { + // A quick drag (or a slow frame) puts both in one frame, where the hover position is the end: + // the press must still use its own position, or the shape starts where the pointer let go. + let mut u = Ui::new(Session::new()); + u.app.run("tool.set", json!({"tool": "rectangle"})); + u.frame(vec![]); + let press = u.app.to_screen(100.0, 100.0); + let release = u.app.to_screen(260.0, 220.0); + u.frame(vec![ + Event::PointerMoved(release), + Event::PointerButton { pos: press, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE }, + Event::PointerButton { pos: release, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE }, + ]); + for _ in 0..3 { + u.frame(vec![]); + } + let doc = u.app.session.doc().unwrap(); + let drawn = u.app.session.selection().first().copied().expect("the press drew a shape"); + let b = doc.world_bounds(drawn).expect("the shape has bounds"); + assert!((b.x0 - 100.0).abs() < 1.0 && (b.y0 - 100.0).abs() < 1.0, "drawn from the press, not the release: {b:?}"); +} + #[test] fn frame_outlines_and_slices_draw_when_shown() { let mut s = Session::new();