Skip to content

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

fix(ui): preserve press origin on page pointer, support handle drag fallbacks, and add Flatten comments to page menu

Combiler01d4ae1adc3f04
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs
index 818819584..230872804 100644
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@ -1029,6 +1029,7 @@ pub(crate) enum PageMenuAction {
ExportPdf,
Find,
DocProperties,
+ FlattenComments,
}
pub(crate) struct PageMenuPerms {
@@ -1038,6 +1039,7 @@ pub(crate) struct PageMenuPerms {
pub can_print: bool,
pub can_copy: bool,
pub can_paste: bool,
+ pub has_annotations: bool,
}
pub(crate) fn default_page_context_menu(ui: &mut egui::Ui, page: usize, at: [f64; 2], perms: PageMenuPerms, action: &mut Option<PageMenuAction>) {
@@ -1087,6 +1089,10 @@ pub(crate) fn default_page_context_menu(ui: &mut egui::Ui, page: usize, at: [f64
*action = Some(PageMenuAction::AddComment(page, at));
ui.close();
}
+ if perms.has_annotations && ui.add_enabled(perms.can_modify, egui::Button::new(tl!("Flatten comments"))).clicked() {
+ *action = Some(PageMenuAction::FlattenComments);
+ ui.close();
+ }
if ui.add_enabled(perms.can_assemble, egui::Button::new(tl!("Add bookmark"))).clicked() {
*action = Some(PageMenuAction::AddBookmark(page));
ui.close();
@@ -4802,6 +4808,7 @@ pub fn document_area(app: &mut PdfCraftApp, index: usize, ui: &mut egui::Ui) {
can_print: doc.allows_printing(),
can_copy: can_copy_items,
can_paste,
+ has_annotations: !info.annotations.is_empty(),
};
default_page_context_menu(ui, page, at, perms, &mut page_action);
});
@@ -5235,6 +5242,10 @@ pub fn document_area(app: &mut PdfCraftApp, index: usize, ui: &mut egui::Ui) {
app.views[index].comments.composer =
Some(crate::comments::Composer { page, at, kind: crate::comments::ComposerKind::Note, text: String::new(), focus: true });
}
+ Some(PageMenuAction::FlattenComments) => {
+ app.views[index].comments.selected = None;
+ app.views[index].pending_edit = Some(pdfcraft_engine::Edit::Flatten { comments: true, fields: false });
+ }
Some(PageMenuAction::AddBookmark(_page)) => {
app.bookmark_action(crate::panels::BmAction::New);
}
diff --git a/crates/ui-egui/src/edit_text_ui.rs b/crates/ui-egui/src/edit_text_ui.rs
index 58e202964..a147f97c0 100644
--- a/crates/ui-egui/src/edit_text_ui.rs
+++ b/crates/ui-egui/src/edit_text_ui.rs
@@ -1368,7 +1368,7 @@ pub(crate) fn image_owns_pointer(_ui: &egui::Ui, xf: &PageXform, ptr: &PagePoint
}
let Some(image) = view.edit_images.get(&page).and_then(|(_, images)| images.get(selection.index)) else { return false };
let obb = ImageObb::from_image(image, xf, info, page);
- let p = if ptr.primary_down { ptr.origin } else { ptr.pos };
+ let p = if ptr.primary_down { ptr.origin.or(ptr.pos) } else { ptr.pos };
let Some(p) = p else { return false };
obb.handles().iter().any(|(_, h)| h.distance(p) < 8.0) || obb.s_rot.distance(p) < 8.0
diff --git a/crates/ui-egui/src/page_pointer.rs b/crates/ui-egui/src/page_pointer.rs
index ebb81ab5f..b069992d1 100644
--- a/crates/ui-egui/src/page_pointer.rs
+++ b/crates/ui-egui/src/page_pointer.rs
@@ -56,18 +56,17 @@ impl PagePointer {
// pointer is outside the window. With a dialog open only a drag counts, up to the frame
// it stops: on the frame one opens egui still gives the pages a press that lands under
// it, and its click.
- let held = resp.dragged() || resp.drag_stopped() || (!modal && resp.interact_pointer_pos().is_some());
- // `contains_pointer` alone also holds a few points under the edge of an Area over the
- // pages (egui's interact radius), so the top layer there must be the pages' own. A
- // dialog covers them from the frame it opens, before egui knows its layer.
let layer = ui.layer_id();
let on_top =
|p: &Pos2| !modal && !dragged_elsewhere(ui, resp) && resp.contains_pointer() && ui.ctx().layer_id_at(*p).is_none_or(|l| l == layer);
+ let press_origin = origin.or_else(|| first_press(&edges));
+ let held =
+ resp.dragged() || resp.drag_stopped() || (!modal && (resp.interact_pointer_pos().is_some() || press_origin.is_some_and(|p| on_top(&p))));
let pos = at.filter(|p| held || on_top(p));
if !held {
return Self { pos, origin: None, edges: Vec::new(), primary_down, any_down };
}
- Self { pos, origin: origin.or_else(|| first_press(&edges)), edges, primary_down, any_down }
+ Self { pos, origin: press_origin, edges, primary_down, any_down }
}
/// Where the pointer is, when it is inside `r`.