Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

M7: a dragged page image leaves no outline where it was

komo1iddinbef4e28a4d71
diff --git a/crates/ui-egui/src/edit_text_ui.rs b/crates/ui-egui/src/edit_text_ui.rs
index adfbc675a..d6ddab2a9 100644
--- a/crates/ui-egui/src/edit_text_ui.rs
+++ b/crates/ui-egui/src/edit_text_ui.rs
@@ -677,14 +677,17 @@ pub(crate) fn image_input(
// hovered boxes, so a ~1000-image CAD page stays interactive in Edit text & images.
// Fully clipped placements (empty visible frames) get no outline.
let faint_all = boxes.len() <= MAX_OUTLINES;
+ // The picture being dragged has its frame at the pointer; its outline where it was would
+ // trail behind until the release.
+ let moving = selected.filter(|_| dragging);
if faint_all {
- for b in boxes.iter().filter(|b| b.is_positive()) {
+ for (_, b) in boxes.iter().enumerate().filter(|(i, b)| b.is_positive() && moving != Some(*i)) {
painter.rect_stroke(*b, CornerRadius::ZERO, Stroke::new(0.75, ACCENT.gamma_multiply(0.35)), egui::StrokeKind::Outside);
}
}
let hovered_box = hover_pos.and_then(|p| boxes.iter().enumerate().rposition(|(i, b)| b.is_positive() && b.contains(p) && image_contains(i, p)));
if !faint_all {
- for i in selected.into_iter().chain(hovered_box.filter(|h| Some(*h) != selected)) {
+ for i in selected.filter(|_| moving.is_none()).into_iter().chain(hovered_box.filter(|h| Some(*h) != selected)) {
if let Some(b) = boxes.get(i).filter(|b| b.is_positive()) {
painter.rect_stroke(*b, CornerRadius::ZERO, Stroke::new(0.75, ACCENT.gamma_multiply(0.35)), egui::StrokeKind::Outside);
}
diff --git a/crates/ui-egui/tests/editing.rs b/crates/ui-egui/tests/editing.rs
index 67d22f77a..e1f542bde 100644
--- a/crates/ui-egui/tests/editing.rs
+++ b/crates/ui-egui/tests/editing.rs
@@ -4518,6 +4518,12 @@ fn a_resized_image_keeps_its_new_size_until_the_page_is_redrawn() {
h.hover_at(grip + (to - grip) * (k as f32 / 4.0));
h.run_steps(1);
}
+ // While dragged, no outline stays where the picture was.
+ let old = egui::Rect::from_two_pos(at(60.0, 40.0), at(140.0, 120.0));
+ let trailing = h.output().shapes.iter().any(|shape| {
+ matches!(&shape.shape, egui::Shape::Rect(r) if r.stroke.width == 0.75 && (r.rect.min - old.min).length() < 2.0 && (r.rect.max - old.max).length() < 2.0)
+ });
+ assert!(!trailing, "the dragged picture's outline trails behind it");
h.state_mut().views[0].hold_rasters = true;
h.drop_at(to);
for frame in 0..4 {