mirror of
https://github.com/storytold/figcraft.git
synced 2026-10-30 05:16:56 -06:00
test: 同帧按下/松开绘制从按下点开始的回归用例
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user