diff --git a/crates/ui-egui/src/panels/edit.rs b/crates/ui-egui/src/panels/edit.rs index 19c1ad1c37..190e9e69e9 100644 --- a/crates/ui-egui/src/panels/edit.rs +++ b/crates/ui-egui/src/panels/edit.rs @@ -42,7 +42,8 @@ pub(super) fn edit_panel(app: &mut PdfCraftApp, ui: &mut egui::Ui, g: &'static T commands.push(HeaderCommand::new(IconId::new("settings"), "app.preferences")); let shown = Panel::new(title).titled().commands(commands).actions([HeaderAction::Close]).show(ui, |ui, _| { // Several objects selected: how many, and how to move them. Acrobat's panel has no idle hint. - let count = app.active_ids().filter(|_| app.quick_tool == crate::QuickTool::EditText).map_or(0, |(i, _)| app.views[i].session.objects.count()); + let count = + app.active_ids().filter(|_| app.quick_tool == crate::QuickTool::EditText).map_or(0, |(i, _)| app.views[i].session.objects.count()); if count > 0 { Text::new(crate::i18n::trn(crate::i18n::current(), count as u64, "{n} object selected", "{n} objects selected")).show(ui); Text::new(tl!("Drag the selection to move it. Esc clears the selection.").to_string()).show(ui); @@ -113,7 +114,7 @@ pub(super) fn edit_panel(app: &mut PdfCraftApp, ui: &mut egui::Ui, g: &'static T app.select_tool(id); } if let Some(cmd) = run { - app.run_command(cmd); + app.run_command(&ui.ctx().clone(), cmd); } } @@ -363,7 +364,7 @@ impl PdfCraftApp { d.style = pdfcraft_engine::AddedText { aligns: std::mem::take(&mut d.style.aligns), ..updated }; // The page has the box's text: its typing history restarts from it, even when the // restyle left the text as it was, so a Redo can't put undone typing back. - let now = crate::edit_text_ui::Typed::of(d.text.clone(), d.selection.clone(), vec![d.style.aligns.clone()]); + let now = crate::edit_text_ui::Typed::of(d.text.clone(), d.selection.clone(), d.style.aligns.clone()); d.history.restart(now); } } @@ -378,7 +379,7 @@ impl PdfCraftApp { { ed.refresh_source(block, doc.text_lines(ed.page)); // The page has the paragraph's text: its typing history restarts from it. - let now = crate::edit_text_ui::Typed::of(ed.text.clone(), ed.selection.clone(), vec![ed.look.aligns.clone()]); + let now = crate::edit_text_ui::Typed::of(ed.text.clone(), ed.selection.clone(), ed.look.aligns.clone()); ed.history.restart(now); } } diff --git a/crates/ui-egui/src/tools/camera_ui.rs b/crates/ui-egui/src/tools/camera_ui.rs index 7753278dba..476a567d5f 100644 --- a/crates/ui-egui/src/tools/camera_ui.rs +++ b/crates/ui-egui/src/tools/camera_ui.rs @@ -76,7 +76,7 @@ pub(crate) fn show_quad(ui: &mut Ui, body: &PageBody<'_>, view: &mut DocView, al return; } if view.session.camera.is_none() - && let Some(placed) = body.pages.iter().find(|p| p.page == view.current) + && let Some(placed) = body.pages.iter().find(|p| p.page == view.current()) { let (w, h) = page_points(placed); view.session.camera = Some(CameraQuad::inset(placed.page, w, h)); diff --git a/crates/ui-egui/src/tools/comments/bridge.rs b/crates/ui-egui/src/tools/comments/bridge.rs index c2d21ddaf9..d9e2e22eac 100644 --- a/crates/ui-egui/src/tools/comments/bridge.rs +++ b/crates/ui-egui/src/tools/comments/bridge.rs @@ -73,7 +73,7 @@ impl<'a> PageMap<'a> { /// A user-space point of `page` in the page's displayed units. pub(crate) fn to_doc(&self, page: usize, user: [f64; 2]) -> Point { match self.info.pages.get(page) { - Some(p) => view_point(p, self.rotation, [user[0] as f32, user[1] as f32]), + Some(p) => turned_point(p, self.rotation, [user[0] as f32, user[1] as f32]), None => Point::new(user[0], user[1]), } } @@ -81,7 +81,7 @@ impl<'a> PageMap<'a> { /// A displayed point of `page` in the page's user space. pub(crate) fn to_user(&self, page: usize, at: Point) -> [f64; 2] { match self.info.pages.get(page) { - Some(p) => user_point(p, self.rotation, at), + Some(p) => unturned_point(p, self.rotation, at), None => [at.x, at.y], } } @@ -133,6 +133,33 @@ fn user_point(page: &PageInfo, at: Point) -> [f64; 2] { [f64::from(u[0]), f64::from(u[1])] } +/// A user-space point as the displayed point of a page the view turns clockwise by `rotation` degrees. +fn turned_point(page: &PageInfo, rotation: u16, user: [f32; 2]) -> Point { + let [x, y] = page.user_to_view(user[0], user[1]); + let (w, h) = (page.width, page.height); + let (a, b) = match rotation { + 90 => (h - y, x), + 180 => (w - x, h - y), + 270 => (y, w - x), + _ => (x, y), + }; + Point::new(f64::from(a), f64::from(b)) +} + +/// The user-space point under the displayed point `at` of a page the view turns clockwise by `rotation` degrees. +fn unturned_point(page: &PageInfo, rotation: u16, at: Point) -> [f64; 2] { + let (a, b) = (at.x as f32, at.y as f32); + let (w, h) = (page.width, page.height); + let (x, y) = match rotation { + 90 => (b, h - a), + 180 => (w - a, h - b), + 270 => (w - b, a), + _ => (a, b), + }; + let u = page.view_to_user(x, y); + [f64::from(u[0]), f64::from(u[1])] +} + /// A user-space rectangle as the displayed rectangle that bounds it. fn view_rect(page: &PageInfo, r: [f32; 4]) -> Rect { let (a, b) = (view_point(page, [r[0], r[1]]), view_point(page, [r[2], r[3]])); @@ -345,11 +372,18 @@ pub(crate) fn parts( Cursor::System(icon) => icon, _ => CursorIcon::Default, }; - let part = PagePart::new(Owner::Comment { index: key_of(id).1 }, page, screen_shapes, PageLayer::Comment).passes_drag().cursor(icon); - match tips(info, prefs, tool).into_iter().find(|(t, _)| *t == id) { - Some((_, tip)) => vec![part.tip(tip)], - None => vec![part], - } + let tip = tips(info, prefs, tool).into_iter().find(|(t, _)| *t == id).map(|(_, tip)| tip); + // A part has one shape: a markup's lines are one part each, which a press resolves to the same comment. + screen_shapes + .into_iter() + .map(|shape| { + let part = PagePart::new(Owner::Comment { index: key_of(id).1 }, page, shape, PageLayer::Comment).passes_drag().cursor(icon); + match &tip { + Some(tip) => part.tip(tip.clone()), + None => part, + } + }) + .collect() } fn engine(info: &DocInfo, page: usize, index: usize) -> Option<&Annotation> { diff --git a/crates/ui-egui/src/tools/comments/colours.rs b/crates/ui-egui/src/tools/comments/colours.rs index 72b249f603..4e98e77857 100644 --- a/crates/ui-egui/src/tools/comments/colours.rs +++ b/crates/ui-egui/src/tools/comments/colours.rs @@ -99,7 +99,7 @@ pub(crate) struct ColourChoice { fn choice(ui: &mut egui::Ui, none_label: &str, current: Option, key: &str, recent: &RecentColours) -> ColourChoice { let was = current.is_none(); let mut on = was; - ToggleButton::new(none_label, Bind::bound(&mut on)).show(ui); + ToggleButton::new(none_label.to_string(), Bind::bound(&mut on)).show(ui); let pick = palette(ui, tl!("Colour"), current, key, recent); // Turning the row off does nothing: it stands for no colour, which only another pick replaces. let choice = if on && !was { Some(None) } else { pick.picked.map(Some) }; diff --git a/crates/ui-egui/src/tools/comments/menu.rs b/crates/ui-egui/src/tools/comments/menu.rs index d1ffa87a50..97f18b70f8 100644 --- a/crates/ui-egui/src/tools/comments/menu.rs +++ b/crates/ui-egui/src/tools/comments/menu.rs @@ -94,7 +94,7 @@ pub(crate) struct CommentMenuCx<'a> { } fn row(ui: &mut egui::Ui, label: &str, enabled: bool) -> bool { - MenuItem::new(label).enabled(enabled).show(ui).ran + MenuItem::new(label.to_string()).enabled(enabled).show(ui).ran } /// Rows of the canvas context menu for the selected comment (or the page), inside `Menu::context`. @@ -230,7 +230,7 @@ pub(crate) struct QuickBarPick { fn popover_from(ui: &mut egui::Ui, label: &str, opener: impl FnOnce(&mut egui::Ui) -> egui::Response, body: impl FnOnce(&mut egui::Ui)) { let resp = opener(ui); let mut body = Some(body); - Popover::new(label, Bind::kept()).overlay(|o| o.opened_by(&resp, Trigger::Click)).show(ui, |ui, _| { + Popover::new(label.to_string(), Bind::kept()).overlay(|o| o.opened_by(&resp, Trigger::Click)).show(ui, |ui, _| { if let Some(body) = body.take() { body(ui); } diff --git a/crates/ui-egui/src/tools/comments/overlay.rs b/crates/ui-egui/src/tools/comments/overlay.rs index 856300a5b2..f6dfa9e954 100644 --- a/crates/ui-egui/src/tools/comments/overlay.rs +++ b/crates/ui-egui/src/tools/comments/overlay.rs @@ -5,6 +5,7 @@ use craft::review::ui::annotate::{AnnotationOverlay, BodyPaint}; use craft::review::{Annotation as Marked, AnnotationId, AnnotationKind, HandleRule}; use craft::ui::canvas::ToolContext; use craft::ui::canvas_controls::{HoverOutline, HoverShape}; +use craft::ui::contract::Show as _; use craft::ui::primitives::{Draw, PaintShape, StrokeWidth, TextRun}; use craft::ui::style::{DataColor, StyleColor}; use egui::{Color32, Pos2, Rect, vec2}; @@ -39,12 +40,13 @@ pub(crate) fn show( ui: &mut egui::Ui, body: &PageBody<'_>, view: &DocView, + rotation: u16, info: &DocInfo, prefs: &CommentPrefs, tool: QuickTool, hover: Hover<'_, '_>, ) { - let map = PageMap::new(body.pages, info); + let map = PageMap::new(info, body.pages, rotation); let all = bridge::annotations(info, &map, QuickTool::Select, hover.allowed); let reached = bridge::annotations(info, &map, tool, hover.allowed); let markers = bridge::markers(info, &map, hover.pick.1); @@ -63,7 +65,11 @@ pub(crate) fn show( on_page.push(a); } } - AnnotationOverlay::new(tl!("Comments"), &on_page, &selected).bodies(BodyPaint::Only(&settling_ids)).live(in_flight.as_ref()).show(ui); + let mut overlay = AnnotationOverlay::new(tl!("Comments"), &on_page, &selected).bodies(BodyPaint::Only(&settling_ids)); + if let Some(edit) = &in_flight { + overlay = overlay.live(edit); + } + overlay.show(ui); let Some(at) = hover.pointer.filter(|p| idle && page.rect.contains(*p)) else { continue }; let at = page.to_page(at); let (tolerance, icon_side) = hover.pick; diff --git a/crates/ui-egui/src/tools/comments/popups.rs b/crates/ui-egui/src/tools/comments/popups.rs index 24648d8f95..389aeb0317 100644 --- a/crates/ui-egui/src/tools/comments/popups.rs +++ b/crates/ui-egui/src/tools/comments/popups.rs @@ -216,7 +216,6 @@ pub(crate) fn note_popups( // PLAN: `Annotation::color` is f32 components in 0..=1; the window takes 8-bit. let color = a.color.map(|c| c.map(|v| (v.clamp(0.0, 1.0) * 255.0).round() as u8)); let selected = view.session.comments.is_selected((page, a.index)); - // PLAN: A-2 `popup_drafts: HashMap<(usize, usize), NoteDrafts>`, one per open window (lead ruling, review 1). let drafts: &mut NoteDrafts = view.session.comments.popup_drafts.entry((page, a.index)).or_default(); let mut window = NotePopup::new(super::bridge::id_of(page, a.index).0, owned.first().map_or("", |m| m.title.as_str()), rect, &msgs, drafts) diff --git a/crates/ui-egui/src/tools/comments/state.rs b/crates/ui-egui/src/tools/comments/state.rs index ef0ff7545e..2092c68be6 100644 --- a/crates/ui-egui/src/tools/comments/state.rs +++ b/crates/ui-egui/src/tools/comments/state.rs @@ -143,8 +143,8 @@ pub struct CommentView { pub composer: Option, /// The Comments panel's own state: search, sort, filter, folded pages, inline edit and drafts. pub panel: CommentsPanelState, - /// What is typed or being dragged in the open pop-up windows of one comment: (page, index, drafts). - pub popup_drafts: Option<(usize, usize, NoteDrafts)>, + /// What is typed or being dragged in each open pop-up window, by the comment's (page, index). + pub popup_drafts: HashMap<(usize, usize), NoteDrafts>, /// The panel should scroll the selected card into view. pub reveal: bool, /// Comment Properties was asked for from the panel: (page, index). @@ -368,7 +368,8 @@ impl CommentView { .take() .and_then(|(thread, message, text)| moved(bridge::thread_key(thread)).map(|(p, i)| (bridge::thread_id(p, i), message, text))); // What is typed in a pop-up, and a window being dragged or resized, follow theirs too. - let drafts = self.popup_drafts.take().and_then(|(p, i, d)| moved((p, i)).map(|(p, i)| (p, i, d))); + let drafts: HashMap<(usize, usize), NoteDrafts> = + std::mem::take(&mut self.popup_drafts).into_iter().filter_map(|(key, d)| moved(key).map(|key| (key, d))).collect(); // Other transient state still needs conservative pruning; refresh the slot snapshot too. self.document_changed(info); self.tool.selected = selected; @@ -384,12 +385,14 @@ impl CommentView { pub(crate) fn history_stepped(&mut self) { self.clear_selection(); self.panel.editing = None; - self.popup_drafts = None; + self.popup_drafts.clear(); } - /// The comments the pop-ups hold unsaved text, a reply or a drag for. + /// The comments the pop-ups hold unsaved text, a reply or a drag for, in page order. pub(crate) fn popup_keys(&self) -> Vec<(usize, usize)> { - self.popup_drafts.iter().map(|(p, i, _)| (*p, *i)).collect() + let mut keys: Vec<_> = self.popup_drafts.keys().copied().collect(); + keys.sort_unstable(); + keys } /// An edit other than a deletion just ran: `before` are the comments at [`Self::popup_keys`] @@ -402,9 +405,7 @@ impl CommentView { list.iter().find(|a| (a.page, a.index) == k).map(|a| (a.subtype.clone(), a.author.clone(), a.name.clone())) }; let kept = |p: usize, i: usize| who(before, (p, i)).is_some_and(|w| who(after, (p, i)) == Some(w)); - if self.popup_drafts.as_ref().is_some_and(|(p, i, _)| !kept(*p, *i)) { - self.popup_drafts = None; - } + self.popup_drafts.retain(|&(p, i), _| kept(p, i)); } } diff --git a/crates/ui-egui/src/tools/comments/tests.rs b/crates/ui-egui/src/tools/comments/tests.rs index 4a3fd0c7e7..e68e0e1f44 100644 --- a/crates/ui-egui/src/tools/comments/tests.rs +++ b/crates/ui-egui/src/tools/comments/tests.rs @@ -24,9 +24,8 @@ fn placed_page(xf: &PageXform, zoom: f64) -> PlacedPage { } /// The page map the app feeds `bridge` for `placed` pages shown turned `rotation` degrees. -fn page_map<'a>(placed: &'a [PlacedPage], info: &DocInfo, rotation: u16) -> PageMap<'a> { - // PLAN: assumed `PageMap::new(&[PlacedPage], &DocInfo, view_rotation: u16) -> PageMap` (pdf-comments-w7 A-1). - PageMap::new(placed, info, rotation) +fn page_map<'a>(placed: &'a [PlacedPage], info: &'a DocInfo, rotation: u16) -> PageMap<'a> { + PageMap::new(info, placed, rotation) } /// A kurbo rectangle as an egui one, for comparing a marker with a page's screen rectangle. @@ -303,7 +302,7 @@ fn tools_round_trip_through_their_commands() { assert_eq!(CommentTool::from_command(t.command()), Some(t)); assert!(pdfcraft_engine::commands::command(t.command()).is_some(), "{} is registered", t.command()); let icon = supplied.icon(craft::review::ui::annotate::AnnotateCommand::of(t.tool())).expect("the app names every tool's icon"); - assert!(craft::ui::primitives::has_icon(&craft::behavior::IconId::new(icon)), "icon {icon}"); + assert!(craft::ui::primitives::has_icon(&craft::behavior::IconId::from(std::borrow::Cow::Owned(icon.to_string()))), "icon {icon}"); assert!(GROUPS[t.group()].contains(&t)); } } @@ -317,7 +316,7 @@ fn an_arrow_is_created_as_a_line_with_an_open_arrow_end() { let xf = PageXform { rect: Rect::from_min_size(Pos2::ZERO, vec2(300.0, 400.0)), rot: 0, pw: 300.0, ph: 400.0 }; let placed = [placed_page(&xf, 1.0)]; let map = page_map(&placed, &info, 0); - let mut view = DocView::new(pdfcraft_engine::DocId(1), &info, crate::canvas::ViewDefaults::default()); + let mut view = DocView::new(pdfcraft_engine::DocId(1), &info, crate::canvas::ViewDefaults::default(), false); let prefs = CommentPrefs::default(); let mut created = |kind| { let drawn = craft::review::Annotation { @@ -447,7 +446,7 @@ fn stale_comment_state_is_cleared_and_delete_never_hits_non_comment_slots() { let thread = |index: usize| ThreadId(bridge::id_of(0, index).0); let composer = |index: usize, text: &str| Composer { page: 0, at: [10.0, 10.0], kind: ComposerKind::Edit(index), text: text.into(), focus: false }; - let mut view = DocView::new(pdfcraft_engine::DocId(1), &info, crate::canvas::ViewDefaults::default()); + let mut view = DocView::new(pdfcraft_engine::DocId(1), &info, crate::canvas::ViewDefaults::default(), false); view.session.comments.select_only((0, 2)); view.session.comments.panel.editing = Some((thread(2), 0, "draft".into())); @@ -456,7 +455,7 @@ fn stale_comment_state_is_cleared_and_delete_never_hits_non_comment_slots() { // Moving/editing in place or appending a comment at index 3 preserves the (0, 2) selection, editor and composer. let mut appended = info.clone(); appended.annotations.push(annot(3, "c3")); - view.document_changed(&appended); + view.document_changed(&egui::Context::default(), &appended); assert_eq!(view.session.comments.selection(), vec![(0, 2)]); assert!(view.session.comments.panel.editing.is_some()); assert!(view.session.comments.composer.is_some()); @@ -467,7 +466,7 @@ fn stale_comment_state_is_cleared_and_delete_never_hits_non_comment_slots() { view.session.comments.select_only((0, 1)); view.session.comments.panel.editing = Some((thread(1), 0, "for c1, not c2".into())); view.session.comments.composer = Some(composer(1, "for c1")); - view.document_changed(&shifted); + view.document_changed(&egui::Context::default(), &shifted); assert!(view.session.comments.selection().is_empty()); assert_eq!(view.session.comments.panel.editing, None); assert_eq!(view.session.comments.composer, None); @@ -490,10 +489,11 @@ fn an_unnamed_shift_clears_state_for_the_old_index() { let annot = |index: usize| Annotation { page: 0, index, rect: [10.0, 10.0, 30.0, 30.0], ..annotation("Text", None, false) }; let page = || PageInfo { width: 300.0, height: 400.0, label: String::new(), crop: [0.0, 0.0, 300.0, 400.0], rotation: 0 }; let info = DocInfo { pages: vec![page(), page()], annotations: vec![annot(1), annot(2)], ..Default::default() }; - let mut view = DocView::new(pdfcraft_engine::DocId(1), &info, crate::canvas::ViewDefaults::default()); + let mut view = DocView::new(pdfcraft_engine::DocId(1), &info, crate::canvas::ViewDefaults::default(), false); view.session.comments.select_only((0, 1)); view.session.comments.panel.editing = Some((ThreadId(bridge::id_of(0, 1).0), 0, "the first note".into())); - view.session.comments.composer = Some(Composer { page: 0, at: [10.0, 10.0], kind: ComposerKind::Edit(1), text: "the first note".into(), focus: false }); + view.session.comments.composer = + Some(Composer { page: 0, at: [10.0, 10.0], kind: ComposerKind::Edit(1), text: "the first note".into(), focus: false }); let xf = PageXform { rect: Rect::from_min_size(Pos2::ZERO, vec2(300.0, 400.0)), rot: 0, pw: 300.0, ph: 400.0 }; let placed = [placed_page(&xf, 1.0)]; let map = page_map(&placed, &info, 0); @@ -501,7 +501,7 @@ fn an_unnamed_shift_clears_state_for_the_old_index() { assert!(deleted.is_some(), "the unnamed comment is deletable"); let mut shifted = info.clone(); shifted.annotations = vec![annot(1)]; - view.document_changed(&shifted); + view.document_changed(&egui::Context::default(), &shifted); assert!(view.session.comments.selection().is_empty()); assert_eq!(view.session.comments.panel.editing, None); assert_eq!(view.session.comments.composer, None); @@ -552,7 +552,7 @@ fn the_hover_outline_goes_round_what_a_press_would_take() { let prefs = CommentPrefs::default(); let placed = [placed_page(&xf, 1.0)]; let map = page_map(&placed, &info, 0); - let mut view = DocView::new(pdfcraft_engine::DocId(1), &info, crate::canvas::ViewDefaults::default()); + let mut view = DocView::new(pdfcraft_engine::DocId(1), &info, crate::canvas::ViewDefaults::default(), false); let tolerance = map.doc_len(SLOP); let side = icon_side(&map); let over = Point::new(100.0, 100.0); @@ -561,7 +561,8 @@ fn the_hover_outline_goes_round_what_a_press_would_take() { assert_eq!(pick_at(&annotations, over, tolerance, side, &markers), Some(bridge::id_of(0, 0)), "the highlight a press there selects"); // PLAN: the outline shape itself is the overlay's `HoverOutline` (pdf-comments-w8); a request to w8 for an `overlay` helper // the test can compare against the part's annotation. The part registered at the pointer is asserted here. - let parts = |view: &DocView, pointer| bridge::parts(&info, &map, &prefs, QuickTool::Select, pointer, &view.session.comments.tool, tolerance, side); + let parts = + |view: &DocView, pointer| bridge::parts(&info, &map, &prefs, QuickTool::Select, pointer, &view.session.comments.tool, tolerance, side); assert_eq!(parts(&view, Some(over)).len(), 1, "one part for the comment under the pointer"); assert!(parts(&view, None).is_empty(), "no pointer, no part"); assert!(parts(&view, Some(Point::new(5.0, 5.0))).is_empty(), "nor where nothing would take the press"); @@ -592,10 +593,15 @@ fn an_annotation_round_trips_through_the_page_map_on_turned_and_zoomed_pages() { let back = map.to_user(0, map.to_doc(0, user)); assert!((back[0] - user[0]).abs() < 1e-6 && (back[1] - user[1]).abs() < 1e-6, "{case}: {user:?} came back as {back:?}"); } - let mut view = DocView::new(pdfcraft_engine::DocId(1), &info, crate::canvas::ViewDefaults::default()); + let mut view = DocView::new(pdfcraft_engine::DocId(1), &info, crate::canvas::ViewDefaults::default(), false); let delta = Vec2::new(1.0, 0.0); - let moved = - bridge::edit(AnnotationEdit::Move { ids: vec![bridge::id_of(0, 0)], delta }, &map, &mut view.session.comments, &info, &CommentPrefs::default()); + let moved = bridge::edit( + AnnotationEdit::Move { ids: vec![bridge::id_of(0, 0)], delta }, + &map, + &mut view.session.comments, + &info, + &CommentPrefs::default(), + ); let Some(Edit::MoveAnnotation { dx, dy, .. }) = moved else { panic!("{case}: a move is one MoveAnnotation, got {moved:?}") }; let origin = map.to_doc(0, [50.0, 80.0]); let (from, to) = (map.to_user(0, origin), map.to_user(0, origin + delta)); diff --git a/crates/ui-egui/src/tools/comments/tool.rs b/crates/ui-egui/src/tools/comments/tool.rs index aebab4d795..4a9e6d6ca7 100644 --- a/crates/ui-egui/src/tools/comments/tool.rs +++ b/crates/ui-egui/src/tools/comments/tool.rs @@ -175,16 +175,19 @@ impl CanvasTool for CommentsTool<'_> { eraser_width = style.width; } } - let select = SelectOptions { - empty_press: EmptyPress::PassThrough, - toggle: ToggleMods::ShiftOrCommand, - open: OpenOn::Every, - shift_lock: ShiftLock::LevelOrPlumb, - far_nudge: FarNudge::ShiftOrCommand, - handles_while_drawing: HandlesWhileDrawing::Edit, - markup_press: MarkupPress::ClickOnly, - }; - let draw = DrawOptions { ink: InkStrokes::PerStroke, erase: EraseMode::Path, eraser_radius: eraser_radius(eraser_width) }; + // Both option types are `#[non_exhaustive]`: the app sets the fields it names over the framework's defaults. + let mut select = SelectOptions::default(); + select.empty_press = EmptyPress::PassThrough; + select.toggle = ToggleMods::ShiftOrCommand; + select.open = OpenOn::Every; + select.shift_lock = ShiftLock::LevelOrPlumb; + select.far_nudge = FarNudge::ShiftOrCommand; + select.handles_while_drawing = HandlesWhileDrawing::Edit; + select.markup_press = MarkupPress::ClickOnly; + let mut draw = DrawOptions::default(); + draw.ink = InkStrokes::PerStroke; + draw.erase = EraseMode::Path; + draw.eraser_radius = eraser_radius(eraser_width); // The options are builders over the owned tool: rebuilt from the tool taken out, its gesture kept. let mut built = std::mem::take(self.annotate).select_options(select).draw_options(draw); if self.quick == QuickTool::Comment(CommentTool::Caret) diff --git a/crates/ui-egui/src/tools/content_ui.rs b/crates/ui-egui/src/tools/content_ui.rs index 71b6d29a3d..08bfe888f6 100644 --- a/crates/ui-egui/src/tools/content_ui.rs +++ b/crates/ui-egui/src/tools/content_ui.rs @@ -551,7 +551,7 @@ impl<'a> AddTextTool<'a> { fn start_box(&mut self, page: usize, at: Pos2) { let Some(frame) = PageFrame::of_page(self.pages, &self.doc.info, page) else { return }; let added = self.doc.added(); - let cv = &mut self.view.content; + let cv = &mut self.view.session.content; // Text that can't be drawn stays where it is being typed (#125). if cv.hold_blocked() { return; @@ -571,7 +571,7 @@ impl<'a> AddTextTool<'a> { draft.focus = true; cv.draft = Some(draft); if typed.is_some() { - self.view.pending_edit = typed; + self.view.session.pending_edit = typed; } } } @@ -986,7 +986,8 @@ fn draft_session(ui: &mut egui::Ui, body: &PageBody<'_>, view: &mut DocView, doc let zoom = placed.scale as f32; let page_width = f64::from(doc.info.pages.get(page)?.width); let editor_id = egui::Id::new(("added-text-editor", view.view_key())); - let background_ready = view.session.content.draft.as_ref().and_then(|d| d.index).is_some_and(|index| view.session.text_background.ready_added(page, index)); + let background_ready = + view.session.content.draft.as_ref().and_then(|d| d.index).is_some_and(|index| view.session.text_background.ready_added(page, index)); let cv = &mut view.session.content; let draft = cv.draft.as_mut().filter(|d| d.page == page)?; let font = crate::edit_text_ui::editor_font(&draft.style, (draft.style.size as f32 * zoom).clamp(1.0, 300.0)); @@ -1206,7 +1207,7 @@ impl crate::PdfCraftApp { let request = craft::host::PickRequest::open("image") .title(title) .filter(tl!("Images"), &["png", "jpg", "jpeg", "tif", "tiff", "gif", "bmp", "jp2", "j2k", "jpx"]); - let target = self.active_ids().map(|(_, id)| id.into()); + let target = self.pick_target(self.active_ids().map(|(_, id)| id)); self.pick_first(request, target, move |app: &mut Self, path: std::path::PathBuf| match std::fs::read(&path) { Ok(bytes) => { let name = path.file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_default(); @@ -1397,7 +1398,7 @@ impl crate::PdfCraftApp { /// Place image `bytes` in the middle of the current page and select it. pub fn add_image(&mut self, name: String, bytes: Vec) { let Some((i, id)) = self.active_ids() else { return }; - let page = self.views[i].current; + let page = self.views[i].current(); let before_img = self.session.get(id).map_or(0, |d| d.page_images(page).len()); let before_added = self.session.get(id).map_or(0, |d| d.added().iter().filter(|a| a.page == page).count()); if self.apply_edit(Edit::AddImage { page, rect: None, name, bytes: std::sync::Arc::new(bytes) }) { @@ -1585,7 +1586,7 @@ impl crate::PdfCraftApp { Some((added_idx, pasted_idx)) }); if let Some(v) = self.views.get_mut(i) { - v.current = page; + v.go_to_page(page); v.session.content.selected = selection.map(|(added, _)| (page, added)); v.session.content.select_added = v.session.content.selected; v.session.image_selection = selection.map(|(_, image)| crate::edit_text_ui::ImageSelection::at(page, image)); @@ -1623,7 +1624,8 @@ pub(crate) fn image_panel(ui: &mut egui::Ui, img: &pdfcraft_engine::AddedImage) let (cx, cy, w, h) = ((r[0] + r[2]) / 2.0, (r[1] + r[3]) / 2.0, r[2] - r[0], r[3] - r[1]); i.rect = [cx - h / 2.0, cy - w / 2.0, cx + h / 2.0, cy + w / 2.0]; }; - let button = |ui: &mut egui::Ui, icon: &'static str, label: &str| IconButton::new(IconId::new(icon)).label(label).show(ui).clicks > 0; + let button = + |ui: &mut egui::Ui, icon: &'static str, label: &str| IconButton::new(IconId::new(icon)).label(label.to_string()).show(ui).clicks > 0; if button(ui, "rotate-ccw", tl!("Rotate counterclockwise")) { turn(&mut i, 1); out = Some(ImageAction::Update(AddedContent::Image(i.clone()))); diff --git a/crates/ui-egui/src/tools/edit_text_tool.rs b/crates/ui-egui/src/tools/edit_text_tool.rs index 3173b5ef18..05ba39e3b8 100644 --- a/crates/ui-egui/src/tools/edit_text_tool.rs +++ b/crates/ui-egui/src/tools/edit_text_tool.rs @@ -32,13 +32,13 @@ impl<'a> EditTextTool<'a> { /// Something is selected that an arrow moves or Delete removes. fn has_selection(&self) -> bool { - self.view.objects.count() > 0 || self.view.image_selection.is_some() || self.view.content.selected.is_some() + self.view.session.objects.count() > 0 || self.view.session.image_selection.is_some() || self.view.session.content.selected.is_some() } /// Queue `edit` for the app to apply, when there is one. fn queue(&mut self, edit: Option) { if edit.is_some() { - self.view.pending_edit = edit; + self.view.session.pending_edit = edit; } } } @@ -67,7 +67,7 @@ impl CanvasTool for EditTextTool<'_> { return; } if let Some(start) = self.press.phase.start() { - object_ui::end_marquee(self.view, self.doc, self.info, start, pointer.pos); + object_ui::end_marquee(self.view, self.doc, self.info, start, pointer.mods, pointer.pos); } } diff --git a/crates/ui-egui/src/tools/edit_text_ui.rs b/crates/ui-egui/src/tools/edit_text_ui.rs index 551433e7fa..497f2870d2 100644 --- a/crates/ui-egui/src/tools/edit_text_ui.rs +++ b/crates/ui-egui/src/tools/edit_text_ui.rs @@ -973,7 +973,7 @@ fn width_frame( let info = &doc.info; let xf = view.page_xform(page)?; let open_here = view.session.line_editor.as_ref().is_some_and(|e| e.page == page); - if open_here || !has_edges(info, page) || view.session.objects.holds(page) || view.session.content.moving_on(page) { + if open_here || !has_edges(info, page) || view.session.objects.holds(page) { return None; } let (block, l, b) = framed?; @@ -1199,7 +1199,6 @@ fn editor_session( let page = view.session.line_editor.as_ref()?.page; let xf = view.page_xform(page)?; info.pages.get(page)?; - let hold = view.session.objects.hold_editor; let (block, invisible) = { let ed = view.session.line_editor.as_ref()?; (ed.block, ed.source.as_ref().is_some_and(|(b, _)| b.invisible)) @@ -1217,9 +1216,6 @@ fn editor_session( let ctx = ui.ctx().clone(); let faces = source_faces(content, doc, page); let ed = view.session.line_editor.as_mut()?; - if hold { - ed.focus = true; - } // Reproject the source box every frame. The page may have been zoomed, scrolled or rotated // while the format panel was open. ed.rect = xf.user_rect(info, ed.page, ed.source_rect); @@ -1360,7 +1356,8 @@ mod tests { app.open_bytes("two.pdf", None, two_paragraphs()).unwrap(); let mut h = egui_kittest::Harness::builder().with_size(vec2(1400.0, 900.0)).build_eframe(move |_cc| app); h.run_steps(4); - assert!(h.state_mut().execute("edit.edit_text")); + let ctx = h.ctx.clone(); + assert!(h.state_mut().execute(&ctx, "edit.edit_text")); h.run_steps(2); let blocks = |h: &egui_kittest::Harness<'static, crate::PdfCraftApp>| { let s = h.state(); @@ -1499,7 +1496,7 @@ mod tests { size_chosen: false, extras: Extras::default(), extras0: Extras::default(), - history: TypingHistory::new(Typed::of(block.text.clone(), None, vec![Vec::new(), Vec::new()])), + history: TypingHistory::new(Typed::of(block.text.clone(), None, vec![None, None])), }; (app, ed) } diff --git a/crates/ui-egui/src/tools/edit_text_ui/image.rs b/crates/ui-egui/src/tools/edit_text_ui/image.rs index 5b3b4acd0f..3acf3acb98 100644 --- a/crates/ui-egui/src/tools/edit_text_ui/image.rs +++ b/crates/ui-egui/src/tools/edit_text_ui/image.rs @@ -254,7 +254,8 @@ pub(crate) fn picture_controls( fn box_controls(ui: &mut egui::Ui, body: &PageBody<'_>, view: &mut DocView, doc: &pdfcraft_engine::Document, pic: &PagePicture<'_>) -> Option { let PagePicture { placed, xf, info, index, image } = *pic; let page = placed.page; - if !view.page_out_of_date(page) + // The page's picture is the current revision's, not a stand-in for the one before the edit. + if matches!(placed.picture, TextureState::Ready(_)) && let Some(s) = view.session.image_selection.as_mut() && s.settled.take().is_some() { @@ -547,7 +548,7 @@ pub(crate) fn picture_context(page: usize, index: Option, view: &mut DocV /// One row of the menu: whether it ran. fn item(ui: &mut egui::Ui, enabled: bool, label: &str) -> bool { - MenuItem::new(label).enabled(enabled).show(ui).ran + MenuItem::new(label.to_string()).enabled(enabled).show(ui).ran } /// What the picture menu needs to know of its target: the pictures of `page`, the selected one diff --git a/crates/ui-egui/src/tools/link_ui.rs b/crates/ui-egui/src/tools/link_ui.rs index f5422d6009..0cc0d6f892 100644 --- a/crates/ui-egui/src/tools/link_ui.rs +++ b/crates/ui-egui/src/tools/link_ui.rs @@ -253,6 +253,8 @@ pub(crate) fn link_edit_press(view: &mut LinkView, event: &LinkEvent) { view.selected = Some((page, index)); view.context = Some((page, index)); } + // Following a link is the page's (`canvas` reads it into the output); it selects nothing. + LinkEvent::Follow { .. } => {} } } @@ -416,7 +418,7 @@ fn action(ui: &mut egui::Ui, d: &mut LinkDraft, pages: usize) { zooms.push(d.zoom); } let current = zooms.iter().position(|z| *z == d.zoom).unwrap_or(0); - let rows = zooms.iter().enumerate().map(|(i, z)| (i, zoom_label(*z))).collect(); + let rows: Vec<(usize, String)> = zooms.iter().enumerate().map(|(i, z)| (i, zoom_label(*z))).collect(); let list = entries::(rows); Field::new(tl!("Zoom").to_string()).show(ui, |ui, _| { let picked = Select::new(tl!("Zoom").to_string(), Bind::given(current), &list).enabled(!web).show(ui).value().copied(); diff --git a/crates/ui-egui/src/tools/measure_ui.rs b/crates/ui-egui/src/tools/measure_ui.rs index 0c064c018a..358b3f772a 100644 --- a/crates/ui-egui/src/tools/measure_ui.rs +++ b/crates/ui-egui/src/tools/measure_ui.rs @@ -609,7 +609,7 @@ pub(crate) fn panel(app: &mut PdfCraftApp, ui: &mut egui::Ui) { } let Some(doc) = app.session.get(id) else { return }; let units = app.units; - let page = app.views[index].current; + let page = app.views[index].current(); let info = doc.info.pages.get(page).cloned(); let state = &mut app.views[index].session.measure; if state.listing.as_ref().is_none_or(|(g, _)| *g != doc.edit_generation()) { @@ -792,7 +792,7 @@ pub(crate) fn panel(app: &mut PdfCraftApp, ui: &mut egui::Ui) { } } if let Some((page, annotation, reading, scale)) = select { - app.views[index].current = page; + app.views[index].go_to_page(page); app.views[index].session.comments.select_only((page, annotation)); app.views[index].session.measure.reading = Some(reading); app.views[index].session.measure.scale = Some(scale); diff --git a/crates/ui-egui/src/tools/object_ui.rs b/crates/ui-egui/src/tools/object_ui.rs index 71ec2534e8..9d5a2fd8e6 100644 --- a/crates/ui-egui/src/tools/object_ui.rs +++ b/crates/ui-egui/src/tools/object_ui.rs @@ -8,15 +8,16 @@ use craft::behavior::hit::HitShape; use craft::behavior::item_marquee::MarqueeSelect; use craft::behavior::kurbo::BezPath; use craft::behavior::press::{PressPhase, PressStart}; -use craft::pages::ui::PageBody; +use craft::keymap::Mods; +use craft::pages::ui::{PageBody, PlacedPage}; use craft::ui::canvas_controls::SelectionOutline; use craft::ui::contract::Show as _; use egui::{Pos2, Rect, Ui, Vec2}; use pdfcraft_engine::{Document, Edit, EditableObject, MAX_MOVE_OBJECTS, ObjectKind, ObjectTarget}; use pdfcraft_render::DocInfo; -use crate::canvas::{DocView, PageXform}; use crate::canvas::page_parts::{Owner, PageLayer, PagePart, PagePress}; +use crate::canvas::{DocView, PageXform}; #[derive(Default)] pub(crate) struct ObjectSelection { @@ -193,7 +194,7 @@ fn leave_single(view: &mut DocView) { /// them (paragraphs, pictures and added content), instead of the page's text. A page whose /// objects can't be selected together, or has too many, says so and keeps what was selected. pub(crate) fn select_all(view: &mut DocView, doc: &Document) { - let page = view.current; + let page = view.current(); match view.session.objects.inventory(doc, page) { Ok(objects) if objects.len() > MAX_MOVE_OBJECTS => view.session.objects.notice = Some(tl!("Select at most 1000 objects at a time.").into()), Ok(objects) => { @@ -256,7 +257,7 @@ pub(crate) fn modified_press_at(view: &mut DocView, doc: &Document, info: &DocIn s.notice = Some(tl!("Select at most 1000 objects at a time.").into()); } leave_single(view); - view.current = page; + view.go_to_page(page); true } @@ -276,7 +277,7 @@ pub(crate) fn modified_press(view: &mut DocView, doc: &Document, info: &DocInfo, /// press's span, read from each pass's press phase. pub(crate) fn begin_marquee(view: &mut DocView, page: usize) { leave_single(view); - view.current = page; + view.go_to_page(page); } /// The swept rectangle on screen while the press `phase` drags, whatever it started from. @@ -291,10 +292,10 @@ pub(crate) fn marquee_rect(phase: &PressPhase) -> Option { /// says (Shift adds, ⌘ or Ctrl toggles, none replaces), when it is over 3 points each way. A smaller sweep /// (a click) sweeps nothing: it clears the selection, or with Shift or ⌘ leaves it as it was. A double click /// within 3 points clears. More than [`MAX_MOVE_OBJECTS`] keeps the selection and says so. -pub(crate) fn end_marquee(view: &mut DocView, doc: &Document, info: &DocInfo, start: PressStart, pos: Pos2) { +pub(crate) fn end_marquee(view: &mut DocView, doc: &Document, info: &DocInfo, start: PressStart, mods: Mods, pos: Pos2) { let Some((page, xf)) = view.page_xforms().into_iter().find(|(_, xf)| xf.rect.contains(start.origin)) else { return }; let base = view.session.objects.selection().filter(|(on, _)| *on == page).map(|(_, targets)| targets).unwrap_or_default(); - let mut sweep = MarqueeSelect::begin(start.origin, start.mods, base); + let mut sweep = MarqueeSelect::begin(start.origin, mods, base); sweep.update(pos); let rect = sweep.rect(); if start.clicks >= 2 && rect.min.distance(rect.max) <= 3.0 { @@ -357,25 +358,10 @@ fn open_block(view: &DocView, page: usize) -> Option { /// its release is [`objects_press`]'s. // PLAN: contract A-6 has no `presses` parameter; the live drag offset is read from the pass's presses of the // parts (pdf-canvas-w9 calls this with the `PagePress`es `PageParts` reported) -pub(crate) fn object_controls( - ui: &mut Ui, - body: &PageBody<'_>, - view: &mut DocView, - doc: &Document, - info: &DocInfo, - presses: &[PagePress], -) -> Option { +pub(crate) fn object_controls(ui: &mut Ui, body: &PageBody<'_>, view: &mut DocView, info: &DocInfo, presses: &[PagePress]) -> Option { for placed in body.pages { let page = placed.page; let Some(xf) = view.page_xform(page) else { continue }; - if let Some(block) = open_block(view, page) - && let Ok(objects) = view.session.objects.inventory(doc, page) - && let Some(object) = objects.iter().find(|o| o.target == ObjectTarget { kind: ObjectKind::Text, index: block }) - { - for band in frame_band(screen(&xf, info, page, object)) { - PagePart::new(Owner::Frame { block }, page, HitShape::Rect(band), PageLayer::Handle).cursor(CursorIcon::Move).show(ui); - } - } let s = &view.session.objects; if s.page != Some(page) || s.selected.is_empty() { continue; @@ -396,13 +382,38 @@ pub(crate) fn object_controls( let group = [outline_path(body, union)]; SelectionOutline::faint(tl!("Selected objects"), &group).show(ui); } - for rect in rects { - PagePart::new(Owner::Objects, page, HitShape::Rect(rect), PageLayer::Placed).cursor(CursorIcon::Move).show(ui); - } } None } +/// The parts of the objects selected together on each page shown: one per object that a drag moves, and the frame +/// band of the paragraph open for typing. [`object_controls`] draws their outlines and [`objects_press`] takes their +/// presses. +pub(crate) fn page_parts(out: &mut Vec, view: &mut DocView, doc: &Document, info: &DocInfo, pages: &[PlacedPage]) { + for placed in pages { + let page = placed.page; + let Some(xf) = view.page_xform(page) else { continue }; + if let Some(block) = open_block(view, page) + && let Ok(objects) = view.session.objects.inventory(doc, page) + && let Some(object) = objects.iter().find(|o| o.target == ObjectTarget { kind: ObjectKind::Text, index: block }) + { + out.extend( + frame_band(screen(&xf, info, page, object)) + .map(|band| PagePart::new(Owner::Frame { block }, page, HitShape::Rect(band), PageLayer::Handle).cursor(CursorIcon::Move)), + ); + } + let s = &view.session.objects; + if s.page != Some(page) || s.selected.is_empty() { + continue; + } + out.extend( + s.selected + .iter() + .map(|o| PagePart::new(Owner::Objects, page, HitShape::Rect(screen(&xf, info, page, o)), PageLayer::Placed).cursor(CursorIcon::Move)), + ); + } +} + /// A press of a part [`object_controls`] registered: the objects selected together, or the frame of /// the paragraph open for typing, which selects its box and moves it. The drag shows the move; the /// release past 3 points returns it as one edit, and one within 3 changes nothing. @@ -412,7 +423,8 @@ pub(crate) fn objects_press(view: &mut DocView, doc: &Document, info: &DocInfo, PressPhase::Down { .. } => { if let Owner::Frame { block } = press.owner { let object = view - .session.objects + .session + .objects .inventory(doc, page) .ok() .and_then(|objects| objects.into_iter().find(|o| o.target == ObjectTarget { kind: ObjectKind::Text, index: block })); @@ -421,7 +433,7 @@ pub(crate) fn objects_press(view: &mut DocView, doc: &Document, info: &DocInfo, view.session.objects.page = Some(page); view.session.objects.selected.push(object); leave_single(view); - view.current = page; + view.go_to_page(page); } None } diff --git a/crates/ui-egui/src/tools/stamps_ui.rs b/crates/ui-egui/src/tools/stamps_ui.rs index 60a6e5cf0e..02386d101f 100644 --- a/crates/ui-egui/src/tools/stamps_ui.rs +++ b/crates/ui-egui/src/tools/stamps_ui.rs @@ -7,9 +7,10 @@ use std::sync::Arc; use craft::behavior::{CancelReason, Cursor, CursorIcon, DisplayOrder, ItemSource, Selection, SelectionChange}; use craft::host::{PickRequest, Picked}; +use craft::pages::ui::PlacedPage; use craft::ui::canvas::{CanvasTool, ToolAction, ToolContext, ToolPath, ToolPointer}; use craft::ui::contract::{Bind, CollectionEvent, Entry, Props as _, SelectMode, Show as _, ShowCollection as _, ShowContainer as _}; -use craft::ui::dialog::{DialogId, DialogResult}; +use craft::ui::dialog::DialogId; use craft::ui::list::{List, ListRow}; use craft::ui::menu::Menu; use craft::ui::patterns::form_dialogs::{DialogFields, HostedParamDialog, Param, ParamDialog, ParamKind}; @@ -17,7 +18,6 @@ use craft::ui::pickers::ComboBox; use craft::ui::primitives::Draw; use craft::ui::sections::Section; use craft::ui::text::TextField; -use craft::pages::ui::PlacedPage; use egui::Pos2; use pdfcraft_engine::{Edit, MarkFile, NewAnnotation, Shape, StampGroup, StampKind, Style}; use pdfcraft_render::DocInfo; @@ -301,13 +301,14 @@ pub(crate) fn palette_section(app: &mut PdfCraftApp, ui: &mut egui::Ui) { }; let (mut choose, mut remove) = (None, None); Section::fixed(tl!("Custom")).id_salt("custom-stamps").show(ui, |ui, _| { - let out = List::new(tl!("Custom stamps")) - .select(SelectMode::Single) - .selection(Bind::bound(&mut selection)) - .show_items(ui, &rows, &mut |key, item| match key { + let out = List::new(tl!("Custom stamps")).select(SelectMode::Single).selection(Bind::bound(&mut selection)).show_items( + ui, + &rows, + &mut |key, item| match key { PaletteKey::Heading(_) => ListRow::new(rows.text(item.at).unwrap_or_default().into_owned()).section_heading().state(item.row.clone()), PaletteKey::Stamp(_) => ListRow::new(rows.text(item.at).unwrap_or_default().into_owned()).state(item.row.clone()), - }); + }, + ); for event in out.events { match event { CollectionEvent::Selection(SelectionChange::Set(keys)) => { @@ -346,11 +347,10 @@ impl PdfCraftApp { /// Create ▸ choose a PDF or an image for a new custom stamp. pub(crate) fn pick_stamp_file(&mut self, ctx: &egui::Context) { let ctx = ctx.clone(); - let request = PickRequest::open("stamp").title(tl!("Select a file for the stamp")).filter( - tl!("PDF or image"), - &["pdf", "png", "jpg", "jpeg", "tif", "tiff", "gif", "bmp", "jp2", "j2k", "jpx"], - ); - self.pick_file(request, None, |app, picked| match picked { + let request = PickRequest::open("stamp") + .title(tl!("Select a file for the stamp")) + .filter(tl!("PDF or image"), &["pdf", "png", "jpg", "jpeg", "tif", "tiff", "gif", "bmp", "jp2", "j2k", "jpx"]); + self.pick_file(request, None, move |app, picked| match picked { Picked::Paths(paths) => { let Some(path) = paths.into_iter().next() else { return }; match std::fs::read(&path) { @@ -380,11 +380,7 @@ impl PdfCraftApp { let name = file.rsplit_once('.').map_or(file.as_str(), |(s, _)| s).to_string(); let category = self.custom_stamps.last().map(|s| s.category.clone()).unwrap_or_else(|| "My stamps".into()); let existing = categories(&self.custom_stamps); - let fields = DialogFields::from_pairs([ - (CATEGORY, category), - (NAME, name), - (LINE, DEFAULT_LINE.to_owned()), - ]); + let fields = DialogFields::from_pairs([(CATEGORY, category), (NAME, name), (LINE, DEFAULT_LINE.to_owned())]); let shown_file = file.clone(); let dialog = HostedParamDialog::new(ctx, DIALOG_KEY, fields, move |fields| { ParamDialog::new(DIALOG_KEY, tl!("Create Custom Stamp"), create_params(&shown_file, &existing)).ok_enabled(fields_ok(fields)) @@ -396,14 +392,15 @@ impl PdfCraftApp { /// Takes the Create Custom Stamp dialog's answer: OK saves the stamp in the library and chooses it. pub(crate) fn create_stamp_pass(&mut self, _ctx: &egui::Context) { let Some(id) = self.stamp_dialog.as_ref().map(|d| d.id) else { return }; - match self.dialogs.take_by_id::(id) { - Some(DialogResult::Ok(result)) => { + // `DialogResult` is `#[non_exhaustive]`: whatever is not an OK closes the dialog without a stamp. + let Some(answer) = self.dialogs.take_by_id::(id) else { return }; + match answer.ok() { + Some(result) => { if let Some(d) = self.stamp_dialog.take() { self.save_custom_stamp(d, &result.fields); } } - Some(DialogResult::Cancel) => self.stamp_dialog = None, - None => {} + None => self.stamp_dialog = None, } }