diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index d0f29c8262..db306ecde7 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -17,6 +17,7 @@ use craft::ui::contract::Show as _; use craft::ui::display::Text; use craft::ui::list::OpenSet; use craft::ui::primitives::TextureStatistics; +use craft::ui::primitives::textures::TextureState; use craft::ui::runtime::env::Env; use craft::ui::runtime::focus::{self, FocusTarget}; use craft::ui::style::DataColor; @@ -839,6 +840,8 @@ struct PageBodyCx<'a> { rotation: u16, /// The view's current page this pass. current: usize, + /// The scale the pages render at this pass, which the dragged comment's layers render at too. + render_scale: f32, /// Full screen: the page, display and rotation it shows, captured before the page view holds the view state; /// `None` outside full screen. present_at: Option, @@ -1315,6 +1318,31 @@ fn page_body(ui: &mut egui::Ui, body: &PageBody<'_>, session: &mut PageSession, let hover = comments::Hover { pointer, redact: cx.redact_hover, pick, allowed: cx.allowed }; comments::show(ui, body, session, cx.rotation, cx.info, cx.prefs, cx.tool, hover); } + // The comment being dragged, drawn from its own layers where it goes, over the page that still shows it where it + // was. A page whose picture is of this revision has the released move: its layer settles. + { + let ctx = ui.ctx().clone(); + let movable = matches!(cx.tool, QuickTool::Select | QuickTool::Fill(_)) && !cx.comments_hidden; + let target = movable.then(|| session.comments.primary()).flatten(); + let loading = |page: usize| body.pages.iter().any(|p| p.page == page && matches!(p.picture, TextureState::Loading { .. })); + let drag = &mut session.signature_drag; + drag.prepare(&ctx, cx.doc, target, cx.render_scale); + for placed in body.pages.iter().filter(|p| !loading(p.page)) { + drag.page_received(placed.page); + session.comments.page_rendered(placed.page); + } + let stale = drag.moving_page().is_some_and(loading); + drag.prepare_move(&ctx, cx.doc, &session.comments, session.pending_edit.as_ref(), stale, cx.render_scale); + let map = comments::PageMap::new(cx.info, body.pages, cx.rotation, body.view); + for placed in body.pages { + let size = cx.sizes.get(placed.page).copied().unwrap_or_default(); + let xf = PageXform::of(placed, cx.rotation, size); + let pcx = + comments::PageCx { page: placed.page, xf: &xf, info: cx.info, prefs: cx.prefs, allowed: cx.allowed, hidden: cx.comments_hidden }; + signature_drag::DragLayer::new(&session.signature_drag, &pcx, &map, cx.tool, &session.comments, session.pending_edit.as_ref()) + .show_at(ui, body.rect); + } + } if cx.calc_order { let hovered = match &parts_out.hovered { Some((Owner::Field { field, .. } | Owner::PrepareField { field, .. }, _)) => { @@ -1515,7 +1543,8 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu let find_marks: Vec = view.find.as_ref().map(Find::marks).unwrap_or_default(); let present_at = presenting.then_some(presenter::PresentAt { current: view.view.current, display: view.view.display, rotation: view.view.rotation }); - let border = if view.view.page_gaps { PageBorder::DropShadow } else { PageBorder::None }; + // Shadows only with the preference on, and only between gaps: they would darken the page before when pages touch. + let border = if view.view.page_gaps && app.show_page_edge_shadows { PageBorder::DropShadow } else { PageBorder::None }; let keep = view.session.presenter.keep_pages(); if view.momentary_options != navigation { view.momentary = Momentary::new(navigation); @@ -1584,6 +1613,7 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu chosen, rotation: state.rotation, current: state.current, + render_scale: scale, sizes: &page_sizes[..], view_key, tools, diff --git a/crates/ui-egui/src/canvas/signature_drag.rs b/crates/ui-egui/src/canvas/signature_drag.rs index 6c3b3120b5..d8689e3dbe 100644 --- a/crates/ui-egui/src/canvas/signature_drag.rs +++ b/crates/ui-egui/src/canvas/signature_drag.rs @@ -2,10 +2,13 @@ //! follows each pointer frame, moved or resized, without editing the PDF. Any other comment //! follows the pointer while it is moved: its own layer is drawn where it goes. +use craft::behavior::{Input, Sense}; use craft::review::AnnotationEdit; +use craft::ui::contract::{Access, Common, Component, Cx, MeasureCx, PaintUi, Role}; use craft::ui::primitives::textures::{CachedTexture, TextureStore, TextureStoreOptions}; use craft::ui::primitives::{Draw, backdrop}; -use egui::{ColorImage, Pos2, Rect, TextureId, pos2, vec2}; +use craft::ui::style::{ComponentStyle, Metrics, StyleCx}; +use egui::{ColorImage, Pos2, Rect, Response, TextureId, Vec2, pos2, vec2}; use pdfcraft_engine::{Document, Edit}; use pdfcraft_render::{PageInfo, RenderPool, RenderRequest, Tile}; @@ -383,6 +386,81 @@ impl SignatureDrag { } } +/// The style of the drag's layers: they paint the document's own pixels and nothing of the theme. +#[derive(Clone, Debug, PartialEq, ComponentStyle)] +#[non_exhaustive] +pub struct DragLayerStyle { + #[style(metrics)] + metrics: Metrics, +} + +/// The comment being dragged over one page, drawn from the drag's layers where it goes: the selected stamp's +/// ([`SignatureDrag::paint`]), then any other comment being moved ([`SignatureDrag::paint_move`]). Paint only. +// `unregistered`: it needs a live document and a drag under way, so the suite has no sample of it. +#[derive(craft::ui::contract::Component)] +#[component(canvas_control, unregistered)] +pub(crate) struct DragLayer<'a> { + #[common] + common: Common, + drag: &'a SignatureDrag, + cx: &'a PageCx<'a>, + map: &'a PageMap<'a>, + tool: QuickTool, + cv: &'a CommentView, + pending: Option<&'a Edit>, +} + +impl<'a> DragLayer<'a> { + pub(crate) fn new( + drag: &'a SignatureDrag, + cx: &'a PageCx<'a>, + map: &'a PageMap<'a>, + tool: QuickTool, + cv: &'a CommentView, + pending: Option<&'a Edit>, + ) -> Self { + DragLayer { common: Common::new(), drag, cx, map, tool, cv, pending } + } +} + +impl Component for DragLayer<'_> { + const ROLE: Role = Role::GROUP; + const ALT_ROLES: &'static [Role] = &[Role::None]; + const INPUT: Input = Input::Display; + const PARTS: bool = false; + const STOPS: bool = false; + const OVERLAYS: bool = false; + const SHOWS_LABEL: bool = false; + type Style = DragLayerStyle; + type Output = Response; + + fn style(_: &StyleCx<'_>, _: DragLayerStyleKey) -> DragLayerStyle { + DragLayerStyle { metrics: Metrics::new() } + } + + fn measure(&mut self, _: &MeasureCx<'_, Self>) -> Vec2 { + Vec2::ZERO + } + + fn sense(&self) -> Sense { + Sense::empty() + } + + fn paint(&mut self, ui: &mut PaintUi<'_>, _: &Cx<'_, Self>) { + let draw = ui.draw(); + self.drag.paint(&draw, self.cx, self.map, self.tool, self.cv, self.pending); + self.drag.paint_move(&draw, self.cx, self.map, self.cv, self.pending); + } + + fn access(&self, access: &mut Access, _: &Cx<'_, Self>) { + access.role(Role::None); + } + + fn finish(self, cx: Cx<'_, Self>) -> Response { + cx.response.clone() + } +} + impl Front { /// The key a stamp front's pixels were put in the store under. fn stored(&self) -> Option { diff --git a/crates/ui-egui/src/dialogs/standards_ui.rs b/crates/ui-egui/src/dialogs/standards_ui.rs index 2a5854c99e..fed2c22a22 100644 --- a/crates/ui-egui/src/dialogs/standards_ui.rs +++ b/crates/ui-egui/src/dialogs/standards_ui.rs @@ -186,8 +186,8 @@ impl StackDialog for PdfaDialog { Some(v) => { let findings: Vec = v.iter().enumerate().map(|(n, i)| finding(n as u64, i)).collect(); FindingsSummary::new(&findings).show(ui); - // The dialog's body scrolls, so the list scrolls its own rows past a few. - FindingsList::new(tl!("PDF/A problems").to_string()).max_rows(8).show_items( + // The dialog's body scrolls: the list takes its full height and owns no scroll of its own. + FindingsList::new(tl!("PDF/A problems").to_string()).natural_height(true).show_items( ui, &Findings::new(&findings), &mut |key, icx| findings[*key as usize].row(&icx.words::()), diff --git a/crates/ui-egui/src/tools/comments/state.rs b/crates/ui-egui/src/tools/comments/state.rs index 5d619f440d..e09c587c61 100644 --- a/crates/ui-egui/src/tools/comments/state.rs +++ b/crates/ui-egui/src/tools/comments/state.rs @@ -249,9 +249,10 @@ impl CommentView { self.slots = next; } - /// Every selected comment, the one the handles belong to first. + /// Every selected comment, the one the handles belong to first, then the others in the order they were selected. pub fn selection(&self) -> Vec<(usize, usize)> { - self.tool.selected.iter().rev().map(|id| bridge::key_of(*id)).collect() + let Some((lead, others)) = self.tool.selected.split_last() else { return Vec::new() }; + std::iter::once(lead).chain(others).map(|id| bridge::key_of(*id)).collect() } /// The selected comment the handles, the properties and the context menu act on: the last one selected. @@ -271,8 +272,8 @@ impl CommentView { } /// Select `keys`, the first being the lead (the one with the handles): repeated keys count once, at - /// their first place. The tool keeps its primary last, so the others are stored in reverse and the - /// lead last: [`Self::selection`] gives `keys` back in order. + /// their first place. The tool keeps its primary last, so the others are stored in order and the + /// lead after them: [`Self::selection`] gives `keys` back in order. pub fn select_keys(&mut self, keys: &[(usize, usize)]) { let mut unique: Vec<(usize, usize)> = Vec::with_capacity(keys.len()); for key in keys { @@ -280,7 +281,10 @@ impl CommentView { unique.push(*key); } } - self.tool.selected = unique.into_iter().rev().map(|(p, i)| bridge::id_of(p, i)).collect(); + if !unique.is_empty() { + unique.rotate_left(1); + } + self.tool.selected = unique.into_iter().map(|(p, i)| bridge::id_of(p, i)).collect(); self.member = None; } diff --git a/crates/ui-egui/tests/it/comments.rs b/crates/ui-egui/tests/it/comments.rs index 37280964cf..9759b53130 100644 --- a/crates/ui-egui/tests/it/comments.rs +++ b/crates/ui-egui/tests/it/comments.rs @@ -1299,7 +1299,7 @@ fn comment_properties_change_appearance_and_author() { drag_pt(&mut h, (40.0, 100.0), (140.0, 40.0)); open_comment_props(&mut h, 0, 0); h.run_steps(2); - h.get_by_label("Rectangle Properties"); + h.get_by_role_and_label(Role::Dialog, "Rectangle Properties"); { let s = h.state(); assert_eq!(s.session.get(s.views[0].id).unwrap().comment_props(0, 0).unwrap().width, Some(2.0)); @@ -1561,31 +1561,32 @@ fn the_panel_preserves_threads_source_order_and_unfiltered_page_counts() { app.views[0].session.comments.panel.filter.hidden_authors.push("Beta".into()); app.views[0].session.comments.select_only((0, 0)); }); - h.get_by_label("First root"); + // The panel names a card or reply row by its author, text and date. + h.get_by_label_contains("First root"); h.get_by_label("Page 1"); h.get_by_label("3"); // All three page roots count, including the two filtered out. - assert_eq!(h.query_all_by_label("Duplicate root").count(), 0); - assert_eq!(h.query_all_by_label("Unnamed root").count(), 0); + assert_eq!(h.query_all_by_label_contains("Duplicate root").count(), 0); + assert_eq!(h.query_all_by_label_contains("Unnamed root").count(), 0); assert!( - h.get_by_label("Needle first reply").rect().top() < h.get_by_label("Second reply").rect().top(), + h.get_by_label_contains("Needle first reply").rect().top() < h.get_by_label_contains("Second reply").rect().top(), "replies follow source order, not dates" ); h.get_by_label("Accepted"); h.get_by_label("Mark with checkmark"); // The later Unmarked reply wins independently. - assert_eq!(h.query_all_by_label("Status-only token").count(), 0, "status text is searchable but is not a displayed reply"); + assert_eq!(h.query_all_by_label_contains("Status-only token").count(), 0, "status text is searchable but is not a displayed reply"); h.state_mut().views[0].session.comments.panel.filter.hidden_authors.clear(); h.run_steps(2); // The replies point at the first root: sharing its /NM doesn't give the other its thread // (or a search match on that thread). - assert_eq!(h.query_all_by_label("Duplicate root").count(), 0); - assert_eq!(h.query_all_by_label("Needle first reply").count(), 1); + assert_eq!(h.query_all_by_label_contains("Duplicate root").count(), 0); + assert_eq!(h.query_all_by_label_contains("Needle first reply").count(), 1); h.state_mut().views[0].session.comments.panel.search = "status-only token".into(); h.state_mut().views[0].session.comments.panel.filter.hidden_statuses.push(ReviewStatus::Rejected); h.state_mut().views[0].session.comments.panel.filter.hidden_checks.push(true); h.run_steps(2); - h.get_by_label("First root"); - assert_eq!(h.query_all_by_label("Duplicate root").count(), 0); + h.get_by_label_contains("First root"); + assert_eq!(h.query_all_by_label_contains("Duplicate root").count(), 0); h.state_mut().views[0].session.comments.panel.filter.hidden_statuses.push(ReviewStatus::Accepted); h.run_steps(2); @@ -1598,8 +1599,8 @@ fn the_panel_preserves_threads_source_order_and_unfiltered_page_counts() { h.state_mut().views[0].session.comments.panel.search = "unnamed root".into(); h.state_mut().views[0].session.comments.panel.filter.hidden_checks.clear(); h.run_steps(2); - h.get_by_label("Unnamed root"); - assert_eq!(h.query_all_by_label("Needle first reply").count(), 0, "nothing replies to the unnamed root"); + h.get_by_label_contains("Unnamed root"); + assert_eq!(h.query_all_by_label_contains("Needle first reply").count(), 0, "nothing replies to the unnamed root"); } // Contributor-original PDF. A status is set on a reply (its /IRT names the reply, ISO 32000-2 @@ -1864,20 +1865,22 @@ fn replies_that_lead_nowhere_stay_comments_and_deeper_replies_join_their_thread( for orphan in ["Points at itself", "Points at an unlisted note", "Points at a pop-up", "Points at a link", "Points at a form field", "Loop one", "Loop two"] { - assert!(h.get_by_label(orphan).rect().top() > h.get_by_label("Page 2").rect().top(), "{orphan}"); + // The panel names a card or reply row by its author, text and date. + assert!(h.get_by_label_contains(orphan).rect().top() > h.get_by_label("Page 2").rect().top(), "{orphan}"); } // A reply to a reply joins the thread of the comment it starts from, also when that comment // has no /NM. - let (parent, direct, deeper) = (h.get_by_label("Unnamed parent"), h.get_by_label("Direct reply"), h.get_by_label("Reply to the reply")); + let (parent, direct, deeper) = + (h.get_by_label_contains("Unnamed parent"), h.get_by_label_contains("Direct reply"), h.get_by_label_contains("Reply to the reply")); assert!(parent.rect().top() < direct.rect().top() && direct.rect().top() < deeper.rect().top()); - assert!(deeper.rect().top() < h.get_by_label("Struck words").rect().top(), "under its own thread"); + assert!(deeper.rect().top() < h.get_by_label_contains("Struck words").rect().top(), "under its own thread"); // Comments: the unnamed parent, the strikeout and the seven on page 2. Replies: the two // replies, not the Replace Text caret grouped with its strikeout. h.get_by_label("9"); h.get_by_label("2 replies"); // A status whose comment no page lists is not a comment: no card, and nothing to pick on the // page where it sits. - assert_eq!(h.query_all_by_label("Stray status").count(), 0); + assert_eq!(h.query_all_by_label_contains("Stray status").count(), 0); click_pt(&mut h, (250.0, 30.0)); assert!(h.state().views[0].session.comments.selection().is_empty()); } @@ -2055,7 +2058,7 @@ fn comments_take_checkmarks_lock_hide_and_summarize() { h.get_by_label("Mark with checkmark").click(); h.run_steps(3); assert!(comments(&h).iter().any(|a| a.state.as_deref() == Some("Marked"))); - h.get_by_label("Remove checkmark"); + h.get_by_role_and_label(Role::Button, "Remove checkmark"); // "…" ▸ Copy text puts the comment's text on the clipboard. let ctx_h = h.ctx.clone(); @@ -2272,8 +2275,17 @@ fn the_panel_shows_each_reviewers_status_and_only_my_checkmark() { drag_pt(&mut h, (160.0, 100.0), (260.0, 40.0)); h.set_option("quick", "select").unwrap(); h.state_mut().views[0].session.comments.clear_selection(); + // The panel names a card by its author and text: each shape gets a text to tell its card by. + let oval = comments(&h).iter().find(|a| a.subtype == "Circle").map(|a| a.index).expect("the oval"); + for (index, text) in [(0, "The rectangle"), (oval, "The oval")] { + let ctx_h = h.ctx.clone(); + h.state_mut().apply_edit(&ctx_h, pdfcraft_engine::Edit::SetAnnotationContents { page: 0, index, text: text.into() }); + } h.run_steps(2); - let cards = |h: &Harness<'static, PdfCraftApp>| (h.query_all_by_label("Rectangle").count(), h.query_all_by_label("Oval").count()); + let cards = |h: &Harness<'static, PdfCraftApp>| { + (h.query_all_by_label_contains("The rectangle").count(), h.query_all_by_label_contains("The oval").count()) + }; + assert_eq!(cards(&h), (1, 1), "both cards show"); let shown = cards(&h); h.state_mut().views[0].session.comments.panel.filter.hidden_statuses = vec![ReviewStatus::Rejected]; h.run_steps(2); @@ -3969,9 +3981,9 @@ fn a_pop_up_threads_its_replies_and_takes_a_new_one() { assert!(h.query_all_by(|n| n.placeholder() == Some("Add a reply")).next().is_none(), "the box closes"); } -/// A pop-up window's box holding `text` (a comment's or a reply's). +/// A pop-up window's text `text` (a comment's or a reply's): the comment's box, or a reply's read-only text. fn shows_text(n: &egui_kittest::kittest::AccessKitNode<'_>, text: &str) -> bool { - n.role() == Role::MultilineTextInput && n.value().as_deref() == Some(text) + matches!(n.role(), Role::MultilineTextInput | Role::Label) && n.value().as_deref() == Some(text) } /// On a page turned a quarter (View ▸ Rotate View), a resized pop-up window stays where it is on @@ -4815,7 +4827,7 @@ fn edit_delete_from_a_native_menu_under_the_full_screen_prompt_leaves_the_commen let ctx_h = h.ctx.clone(); h.state_mut().open_bytes(&ctx_h, "deck.pdf", None, deck).expect("the deck opens"); h.run_steps(3); - let prompt = |h: &Harness<'static, PdfCraftApp>| h.query_by_label("Open in Full Screen mode?").is_some(); + let prompt = |h: &Harness<'static, PdfCraftApp>| h.query_by_role_and_label(Role::Dialog, "Open in Full Screen mode?").is_some(); assert!(prompt(&h), "the full-screen prompt is open"); support::fire_menu(&mut h, craft::menu::CommandRef::with_params("window.document", serde_json::json!({ "index": 0 }))); h.run_steps(3); diff --git a/crates/ui-egui/tests/it/pdf_links.rs b/crates/ui-egui/tests/it/pdf_links.rs index 361cc2ac20..8d918a3fde 100644 --- a/crates/ui-egui/tests/it/pdf_links.rs +++ b/crates/ui-egui/tests/it/pdf_links.rs @@ -113,8 +113,8 @@ fn link_properties_sets_the_page_view_zoom() { h.get_by_role_and_label(Role::Dialog, "Create Link"); h.get_by_label("Go to a page view").click(); h.run_steps(3); - // The field around the zoom choice carries its name too: the choice is the one that isn't the group. - h.get_by(|n| n.label().as_deref() == Some("Zoom") && n.role() != Role::Group).click(); + // The field's caption and the toolbar's zoom carry the name too: the choice is the drop-down. + h.get_by_role_and_label(Role::ComboBox, "Zoom").click(); h.run_steps(3); h.get_by_role_and_label(Role::Button, "200%").scroll_to_me(); h.run_steps(3); diff --git a/crates/ui-egui/tests/it/preferences.rs b/crates/ui-egui/tests/it/preferences.rs index 71369262b8..6642e1bb15 100644 --- a/crates/ui-egui/tests/it/preferences.rs +++ b/crates/ui-egui/tests/it/preferences.rs @@ -41,7 +41,7 @@ fn harness() -> H { /// Whether the Preferences window is on screen: its page list names the first page while it is open. fn preferences_shown(h: &H) -> bool { - h.query_by_label("General & Interface").is_some() + h.query_by_role_and_label(egui::accesskit::Role::ListItem, "General & Interface").is_some() } fn click(h: &mut H, label: &str) { @@ -75,6 +75,8 @@ fn cases() -> Vec { name: "layout and continuous on the active view", page: "Documents and view", edit: |h| { + // A choice row is a drop-down: its options show once it opens. + click(h, "Default page display"); click(h, "Two-page view"); click(h, "Continuous scrolling"); }, @@ -83,16 +85,24 @@ fn cases() -> Vec { v.display == craft::pages::PageDisplay::TwoUp && v.continuous != crate::control::new_app().views.first().map_or(true, |_| true) }, }, - Case { name: "units", page: "Documents and view", edit: |h| click(h, Unit::Millimetres.label()), applied: |a| a.units == Unit::Millimetres }, + Case { + name: "units", + page: "Documents and view", + edit: |h| { + click(h, "Units"); + click(h, Unit::Millimetres.label()); + }, + applied: |a| a.units == Unit::Millimetres, + }, Case { name: "tools side and rail side", page: "General & Interface", edit: |h| { - // The tools row comes first, then the rail row; each has a Left and a Right option. - h.get_all_by_label("Right").next().unwrap().click(); - h.run_steps(3); - h.get_all_by_label("Left").nth(1).unwrap().click(); - h.run_steps(3); + // Each side row is a drop-down of Left and Right. + click(h, "Tools panel side"); + click(h, "Right"); + click(h, "Navigation rail side"); + click(h, "Left"); }, applied: |a| { let dock = side_panels::state(a); @@ -102,7 +112,10 @@ fn cases() -> Vec { Case { name: "animation effects", page: "General & Interface", - edit: |h| click(h, "Off"), + edit: |h| { + click(h, "Animation effects"); + click(h, "Off"); + }, applied: |a| a.animation_effects == MotionChoice::Off, }, Case { @@ -131,7 +144,9 @@ fn edited(case: &Case) -> H { let mut h = harness(); h.state_mut().open_preferences(); h.run_steps(4); - click(&mut h, case.page); + // The page list's row, not the heading of the page it shows. + h.get_by_role_and_label(egui::accesskit::Role::ListItem, case.page).click(); + h.run_steps(3); (case.edit)(&mut h); h } diff --git a/crates/ui-egui/tests/it/stamps.rs b/crates/ui-egui/tests/it/stamps.rs index e8da7aee2c..7a810354fe 100644 --- a/crates/ui-egui/tests/it/stamps.rs +++ b/crates/ui-egui/tests/it/stamps.rs @@ -109,7 +109,7 @@ fn creating_placing_and_keeping_custom_stamps() { let ctx = h.ctx.clone(); h.state_mut().start_custom_stamp(&ctx, "logo.png".into(), png); h.run_steps(2); - h.get_by_label("Create Custom Stamp"); + h.get_by_role_and_label(egui::accesskit::Role::Dialog, "Create Custom Stamp"); h.get_by_label("Category").click(); h.run_steps(1); h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A);