mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-28 12:08:46 -06:00
test(comments): the eraser preview is as wide as it rubs while held (#3747)
From review of #3749: the hit test alone would pass with a fixed 12-pixel preview. Read the preview stroke from the frame drawn mid-drag: 12 pixels at the default 2 pt, 72 at 12 pt, and gone once released. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c6f58baa74
commit
7eb4e5d557
@@ -1416,6 +1416,48 @@ fn the_eraser_rubs_as_wide_as_its_thickness_setting() {
|
||||
assert_eq!(stroke_near(12.0), 0, "the largest rubs the drawing out");
|
||||
}
|
||||
|
||||
/// The widths of the eraser preview's strokes drawn in the last frame.
|
||||
fn eraser_preview_widths(h: &Harness<'static, PdfCraftApp>) -> Vec<f32> {
|
||||
fn walk(shape: &egui::Shape, out: &mut Vec<f32>) {
|
||||
let preview = egui::Color32::from_gray(128).gamma_multiply(0.35);
|
||||
match shape {
|
||||
egui::Shape::Vec(shapes) => shapes.iter().for_each(|s| walk(s, out)),
|
||||
egui::Shape::Path(p) if p.stroke.color == egui::epaint::ColorMode::Solid(preview) => out.push(p.stroke.width),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let mut out = Vec::new();
|
||||
for clipped in &h.output().shapes {
|
||||
walk(&clipped.shape, &mut out);
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_eraser_preview_is_as_wide_as_it_rubs() {
|
||||
// #3747: while the eraser is held, its preview stroke is as wide as what it rubs out
|
||||
// (twice its radius, three pixels per point of thickness): 12 pixels by default, 72 at 12 pt.
|
||||
for (width, across) in [(2.0, 12.0), (12.0, 72.0)] {
|
||||
let mut h = harness(move |app| {
|
||||
app.comment_prefs.set_width(pdfcraft_ui_egui::comments::CommentTool::Eraser, width);
|
||||
app.set_option("quick", "eraser").unwrap();
|
||||
});
|
||||
let (from, to) = (at(&h, 60.0, 100.0), at(&h, 240.0, 100.0));
|
||||
h.hover_at(from);
|
||||
h.run_steps(1);
|
||||
h.drag_at(from);
|
||||
h.run_steps(1);
|
||||
for k in 1..=3 {
|
||||
h.hover_at(from + (to - from) * (k as f32 / 4.0));
|
||||
h.run_steps(1);
|
||||
}
|
||||
assert_eq!(eraser_preview_widths(&h), [across], "{width} pt: the preview while held");
|
||||
h.drop_at(to);
|
||||
h.run_steps(3);
|
||||
assert!(eraser_preview_widths(&h).is_empty(), "{width} pt: gone once released");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hovering_a_comment_shows_its_author_and_text() {
|
||||
// A square comment by Ada over the first page's text.
|
||||
|
||||
Reference in New Issue
Block a user