diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index d0cdf9a0af..8a70686d9c 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -5,21 +5,22 @@ //! Page pictures come from the page view's texture stores over [`pictures::DocPages`]; the app holds no raster. use std::collections::{HashMap, HashSet}; +use std::ops::Range; use std::sync::Arc; use craft::behavior::{CanvasView, PointerButton, PressPhase, Selection}; -use craft::pages::ui::{PageBody, PageView, PageViewOutput, PageViewState, PlacedPage, TextMark, TextMarks, TextSelectState, TextSelection}; use craft::host::queue::{JobQueue, QueueOptions}; +use craft::pages::ui::{PageBody, PageView, PageViewOutput, PageViewState, PlacedPage, TextMark, TextMarks, TextSelectState, TextSelection}; use craft::ui::canvas::{ContextRequest, Momentary, NavigationOptions, PageBorder, ToolHost}; use craft::ui::contract::Show as _; use craft::ui::display::Text; use craft::ui::list::OpenSet; use craft::ui::primitives::TextureStatistics; use craft::ui::style::DataColor; -use egui::{Color32, Rect}; +use egui::{Color32, Pos2, Rect, Vec2, pos2, vec2}; use pdfcraft_engine::text_links::TextLink; use pdfcraft_engine::{DocId, Edit}; -use pdfcraft_render::{DocInfo, LinkTarget, PageText}; +use pdfcraft_render::{DestView, DocInfo, LayerOp, LinkTarget, PageText, RenderRequest, RequestKind}; use crate::{PdfCraftApp, QuickTool, RightPanel, comments}; @@ -331,8 +332,6 @@ pub struct PageSession { pub(crate) pending_text_open: Option<(usize, pdfcraft_engine::BlockKey)>, pub(crate) text_background: crate::edit_text_ui::TextBackground, pub(crate) move_background: crate::content_ui::MoveBackground, - /// Edit text & images: the images per page (by document generation), and the selected one. - pub(crate) edit_images: HashMap)>, pub(crate) objects: crate::object_ui::ObjectSelection, pub image_selection: Option, /// Select tool: the picture clicked, to copy in its original format. @@ -402,7 +401,6 @@ impl PageSession { pending_text_open: None, text_background: Default::default(), move_background: Default::default(), - edit_images: HashMap::new(), objects: Default::default(), image_selection: None, picked_image: None, @@ -866,7 +864,12 @@ struct BodyOut { /// Select and Link), comments (only under Select), fields, sign tabs (painted over their fields), then prepare fields, /// selected objects and the frame band. A later part outranks an earlier one of the same layer, so this order is the /// stacking order hit testing ranks on. -fn page_parts_of(ui: &mut egui::Ui, body: &PageBody<'_>, session: &PageSession, cx: &PageBodyCx<'_>) -> (Vec, Vec<(usize, PageXform, Vec)>) { +fn page_parts_of( + ui: &mut egui::Ui, + body: &PageBody<'_>, + session: &PageSession, + cx: &PageBodyCx<'_>, +) -> (Vec, Vec<(usize, PageXform, Vec)>) { let mut parts = Vec::new(); // PLAN: assumed `edit_text_ui::picture_parts(out, session, doc, pages, rotation)`, `edit_text_ui::page_parts` and // `content_ui::page_parts` with the same shape (pdf-edit-w7, w8, w9 give no argument list). @@ -879,8 +882,7 @@ fn page_parts_of(ui: &mut egui::Ui, body: &PageBody<'_>, session: &PageSession, links_of(session, cx, body).parts(&mut parts); } if cx.tool == QuickTool::Select && !cx.comments_hidden { - // PLAN: assumed `comments::bridge::parts(out, session, info, pages, rotation, unobstructed)` (pdf-comments-w8). - crate::comments::bridge::parts(&mut parts, session, cx.info, body.pages, cx.rotation, cx.unobstructed); + crate::comments::parts(&mut parts, session, cx.info, body.pages, cx.rotation, cx.unobstructed); } if !cx.preparing { // PLAN: assumed `forms_ui::field_parts(out, session, doc, form, pages, rotation, tool)` (pdf-forms-w7 AP-5). @@ -939,13 +941,12 @@ fn route_press(session: &mut PageSession, press: &PagePress, cx: &PageBodyCx<'_> session.pending_pick = None; match event { LinkEvent::Follow { target, javascript } => out.link = Some((target, javascript)), - LinkEvent::Select { page, index, clicks } => crate::link_ui::select(session, page, index, clicks), - LinkEvent::Context { page, index } => session.links.context = Some((page, index)), + LinkEvent::Select { .. } | LinkEvent::Context { .. } => crate::link_ui::link_edit_press(&mut session.links, &event), } } } // PLAN: assumed `comments::tool::part_pressed(session, info, press)` (pdf-comments-w8). - Owner::Comment { .. } => crate::comments::tool::part_pressed(session, cx.info, press), + Owner::Comment { .. } => crate::comments::part_pressed(session, cx.info, press), // PLAN: assumed `forms_ui::field_press(session, doc, form, press)` (pdf-forms-w5). Owner::Field { .. } => crate::forms_ui::field_press(session, cx.doc, cx.form, press), Owner::SignTab { field } => { @@ -1043,7 +1044,7 @@ fn page_body(ui: &mut egui::Ui, body: &PageBody<'_>, session: &mut PageSession, if !cx.comments_hidden { // PLAN: assumed `comments::overlay::show(ui, body, session, info, prefs, tool, redact_hover)` (pdf-comments-w7, // L-90: the redaction hover is the user's setting, passed as a data colour). - crate::comments::overlay::show(ui, body, session, cx.info, cx.prefs, cx.tool, cx.redact_hover); + crate::comments::show(ui, body, session, cx.info, cx.prefs, cx.tool, cx.redact_hover); } if cx.calc_order { let hovered = match &parts_out.hovered { @@ -1053,8 +1054,16 @@ fn page_body(ui: &mut egui::Ui, body: &PageBody<'_>, session: &mut PageSession, let selected = session.prepare.selected.as_ref().map(|(name, _)| name.as_str()); // PLAN: assumed `CalcOrderOverlay::new(&CalcOrderView, pages, rotation, generation, selected, hovered, // viewport)` (pdf-forms-w12 gives `new(.., viewport: body.rect)`). - crate::calc_order_ui::CalcOrderOverlay::new(&session.calc_order, body.pages, cx.rotation, cx.doc.edit_generation(), selected, hovered, body.rect) - .show_at(ui, body.rect); + crate::calc_order_ui::CalcOrderOverlay::new( + &session.calc_order, + body.pages, + cx.rotation, + cx.doc.edit_generation(), + selected, + hovered, + body.rect, + ) + .show_at(ui, body.rect); } if let Some(preview) = cx.table_preview { // PLAN: assumed `field_table_ui::TablePreview::new(&Preview, pages, rotation)` (pdf-forms-w11). @@ -1069,8 +1078,7 @@ fn page_body(ui: &mut egui::Ui, body: &PageBody<'_>, session: &mut PageSession, None => marks, }; marks.show_at(ui, body.rect); - // PLAN: assumed `selection::show_picked(ui, body, session, info)` (pdf-canvas-w12). - selection::show_picked(ui, body, session, cx.info); + image_pick::show_picked(ui, body, session, cx.rotation, cx.info); if let Some(at) = cx.present_at { // PLAN: `PresentFrame::hide_pointer` asks for `CursorPriority::Hidden`; the page body has no `BodyCx` to claim // it through, so the pointer is not hidden yet (pdf-canvas-w18). @@ -1148,8 +1156,10 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu let show_secured_notice = app.show_secured_notice; // Offer to lock a just-placed signature (#2149) on the same terms the save-time question // asks: one is still there, saving doesn't lock it anyway, and the document isn't signed. - let lock_offer = - !app.flatten_fill_sign_on_save && app.placed_signatures.contains(&doc_id) && doc.info.annotations.iter().any(|a| a.fill_sign) && !doc.is_signed(); + let lock_offer = !app.flatten_fill_sign_on_save + && app.placed_signatures.contains(&doc_id) + && doc.info.annotations.iter().any(|a| a.fill_sign) + && !doc.is_signed(); let view = &mut app.views[index]; // Opened without the owner password and something is restricted. The notice says so unless // the user turned it off (#4035): the restrictions themselves, and Document Properties ▸ @@ -1170,7 +1180,7 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu let unobstructed = !app.modal_open() && !app.palette_open; if app.views[index].organize { let invert_middle = app.navigation_options().invert_middle; - organize_grid(&mut app.views[index], doc, &mut organize::GridCx { ui, zoom: &mut app.organize_zoom, invert_middle }); + organize_grid(&mut app.views[index], doc, &mut organize::GridCx { ui, session: &app.session, zoom: &mut app.organize_zoom, invert_middle }); return None; } // The room under the notice bars, inside the rect the caller gave. @@ -1182,8 +1192,8 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu // Prepare a form ▸ Calculation order: the order's steps and links on the page. let calc_order = preparing && crate::side_panels::panel_visible(app, crate::LeftPanel::CalculationOrder); // Edit a PDF: added text and images can be selected, moved and edited. - let editing_content = crate::side_panels::panel_visible(app, crate::LeftPanel::Tool("edit")) - || matches!(app.quick_tool, QuickTool::AddText | QuickTool::EditText); + let editing_content = + crate::side_panels::panel_visible(app, crate::LeftPanel::Tool("edit")) || matches!(app.quick_tool, QuickTool::AddText | QuickTool::EditText); let chosen = app.quick_tool; let navigation = app.navigation_options(); let presenting = app.views[index].presenting(); @@ -1217,7 +1227,8 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu view.session.move_background.prepare(ui.ctx(), doc, &view.session.content, scale); 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 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 }; let keep = view.session.presenter.keep_pages(); if view.momentary_options != navigation { @@ -1286,11 +1297,11 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu }; let source = DocPages::new(&app.session, doc_id).rotated(state.rotation).revisions(revisions).reports(reports); // A modal over the pages blocks the canvas's keys and presses in the framework, so the view needs no gate here. - let out = PageView::new(tl!("Pages"), &source, state, DataColor::new(paper)) - .navigation(navigation) - .border(border) - .keep(&keep) - .show_at(ui, rect, |ui, body| page_body(ui, body, session, momentary, &cx, &mut body_out)); + let out = PageView::new(tl!("Pages"), &source, state, DataColor::new(paper)).navigation(navigation).border(border).keep(&keep).show_at( + ui, + rect, + |ui, body| page_body(ui, body, session, momentary, &cx, &mut body_out), + ); if let Some(canvas) = &body_out.view { out.adopt(&mut view.view, canvas); } @@ -1301,10 +1312,8 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu // double-click time has passed with no object clicked and no selection made (#2070). let now = ui.input(|i| i.time); let has_selection = view.session.text.selection.is_some(); - let click = (presenting && matches!(out.canvas.press.phase, PressPhase::Release { click: true, .. })).then(|| presenter::PresentClick { - forward: !out.canvas.press.mods.shift, - clicks: if out.canvas.press.double_pressed() { 2 } else { 1 }, - }); + let click = (presenting && matches!(out.canvas.press.phase, PressPhase::Release { click: true, .. })) + .then(|| presenter::PresentClick { forward: !out.canvas.press.mods.shift, clicks: if out.canvas.press.double_pressed() { 2 } else { 1 } }); let delay = ui.ctx().options(|o| o.input_options.max_double_click_delay); let cancels = body_out.link.is_some() || has_selection; let click_turn = if presenting { view.session.presenter.click_turn(ui.ctx(), click, cancels, now, delay) } else { None }; @@ -1328,7 +1337,8 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu if view.session.text_queue.is_none() { let ctx = ui.ctx().clone(); let wake = craft::host::Wake::new(move || ctx.request_repaint()); - view.session.text_queue = Some(JobQueue::new(app.host.jobs_shared().clone(), wake, QueueOptions { name: "text-layers", ..QueueOptions::default() })); + view.session.text_queue = + Some(JobQueue::new(app.host.jobs_shared().clone(), wake, QueueOptions { name: "text-layers", ..QueueOptions::default() })); } let (visible_pages, rest_pages) = text_demand(view, out.visible.clone(), chosen == QuickTool::Hand); view.want_text(&app.session, &visible_pages, &rest_pages); @@ -1508,10 +1518,10 @@ fn apply_frame_requests(app: &mut PdfCraftApp, index: usize, requests: FrameRequ app.comment_attachment_action(doc, p, i, open); } if let Some((name, w)) = field_props { - crate::prepare::dialog::open(app, &name, w, crate::prepare::dialog::FieldTab::General); + crate::prepare::dialog::open(app, &name, w, crate::prepare::FieldTab::General); } if let Some(FieldMenu::Duplicate(name)) = field_menu { - crate::duplicate_field::open(app, name); + crate::dialogs::duplicate_field::open(app, name); } if let Some((page, rect)) = app.views[index].session.links.open_new.take() { app.open_link_props(page, Some(rect), None); @@ -1710,11 +1720,11 @@ fn apply_frame_requests(app: &mut PdfCraftApp, index: usize, requests: FrameRequ } } +pub(crate) mod page_box_drag; #[cfg(test)] mod sign_tab_tests; #[cfg(test)] mod tests; -pub(crate) mod page_box_drag; pub(crate) use page_box_drag::PageBoxDrag; pub(crate) mod page_menu; pub(crate) mod page_select; diff --git a/crates/ui-egui/src/canvas/bars.rs b/crates/ui-egui/src/canvas/bars.rs index 47b37c8356..a685bdd4b4 100644 --- a/crates/ui-egui/src/canvas/bars.rs +++ b/crates/ui-egui/src/canvas/bars.rs @@ -127,7 +127,8 @@ pub(super) fn notices( } } if let Some((icon, tone, template, arg)) = signed { - let out = bar(tone, icon, crate::i18n::fmt(tl!(template), &[("by", &arg)])).action(NoticeAction::new(tl!("Signature panel").to_string())).show(ui); + let out = + bar(tone, icon, crate::i18n::fmt(tl!(template), &[("by", &arg)])).action(NoticeAction::new(tl!("Signature panel").to_string())).show(ui); return (out.action == Some(0)).then_some(Notice::Signatures); } if view.notice_dismissed { diff --git a/crates/ui-egui/src/canvas/cache.rs b/crates/ui-egui/src/canvas/cache.rs index 82dc57397e..92110f3cc3 100644 --- a/crates/ui-egui/src/canvas/cache.rs +++ b/crates/ui-egui/src/canvas/cache.rs @@ -175,11 +175,7 @@ impl DocView { } let mut renderer = pdfcraft_render::PageRenderer::new(bytes, config); let out = renderer.render(RenderRequest { page, kind: RequestKind::Text, scale: 1.0, ..Default::default() }); - TextOutcome { - cut: out.warnings.contains(&pdfcraft_render::RenderWarning::ContentTruncated), - text: out.text, - error: out.error, - } + TextOutcome { cut: out.warnings.contains(&pdfcraft_render::RenderWarning::ContentTruncated), text: out.text, error: out.error } }); } } @@ -210,7 +206,6 @@ impl DocView { self.texts.retain(|p, _| keep.contains(p)); } - /// Device scale of a page raster: exactly the device scale, as a raster at any other scale is /// resampled on screen, which blurs every line and glyph (#260). pub(super) fn render_scale(&self, ppp: f32) -> f32 { diff --git a/crates/ui-egui/src/canvas/crop.rs b/crates/ui-egui/src/canvas/crop.rs index 29ffdac84c..9a1229ac55 100644 --- a/crates/ui-egui/src/canvas/crop.rs +++ b/crates/ui-egui/src/canvas/crop.rs @@ -2,11 +2,10 @@ //! rectangle; double-click a page to open Set Page Boxes for it. use craft::behavior::{CancelReason, Cursor, CursorIcon}; -use craft::ui::canvas::crop::{CropShield, paint_outside}; -use craft::ui::canvas::{CanvasTool, ToolAction, ToolContext, ToolPath, ToolPointer}; +use craft::pages::ui::PlacedPage; +use craft::ui::canvas::{CanvasTool, CropShield, ToolAction, ToolContext, ToolPath, ToolPointer, paint_outside}; use craft::ui::primitives::Draw; use craft::ui::style::DataColor; -use craft::pages::ui::PlacedPage; use pdfcraft_engine::{BoxSpec, Edit, PageBox}; use pdfcraft_render::DocInfo; diff --git a/crates/ui-egui/src/canvas/image_pick.rs b/crates/ui-egui/src/canvas/image_pick.rs index 1077b95b0f..cdde3a17b4 100644 --- a/crates/ui-egui/src/canvas/image_pick.rs +++ b/crates/ui-egui/src/canvas/image_pick.rs @@ -8,9 +8,9 @@ use std::sync::Arc; use craft::behavior::kurbo::BezPath; use craft::host::queue::{JobQueue, Priority, QueueOptions}; use craft::host::{Jobs, Wake}; +use craft::pages::ui::PageBody; #[cfg(not(target_arch = "wasm32"))] use craft::platform::clipboard::Flavor; -use craft::pages::ui::PageBody; use craft::ui::canvas_controls::SelectionOutline; use craft::ui::contract::Show as _; @@ -80,7 +80,13 @@ impl PagePictures { /// The pictures on `page`, or `None` while they are being found (the queue's `wake` repaints on the answer). // PLAN: the decisions give `get(ctx, host, wake, doc, page)`; the queue needs the host's jobs and the wake only. - pub(crate) fn get(&mut self, jobs: &Arc, wake: &Wake, doc: &pdfcraft_engine::Document, page: usize) -> Option<&[pdfcraft_engine::PagePicture]> { + pub(crate) fn get( + &mut self, + jobs: &Arc, + wake: &Wake, + doc: &pdfcraft_engine::Document, + page: usize, + ) -> Option<&[pdfcraft_engine::PagePicture]> { let key = (page, doc.edit_generation()); self.poll(); let known = self.ready.as_ref().is_some_and(|(k, _)| *k == key); @@ -96,7 +102,13 @@ impl PagePictures { self.ready.as_ref().filter(|(k, _)| *k == key).map(|(_, pictures)| pictures.as_slice()) } - fn start(&mut self, jobs: &Arc, wake: &Wake, key: PictureKey, work: impl FnOnce() -> Vec + Send + 'static) { + fn start( + &mut self, + jobs: &Arc, + wake: &Wake, + key: PictureKey, + work: impl FnOnce() -> Vec + Send + 'static, + ) { let queue = self.queue.get_or_insert_with(|| { let mut options = QueueOptions::default(); // One search at a time: each is a full read of a page. The web has no lanes; `poll` runs the job. diff --git a/crates/ui-egui/src/canvas/navigation.rs b/crates/ui-egui/src/canvas/navigation.rs index bc5c671769..c57f707904 100644 --- a/crates/ui-egui/src/canvas/navigation.rs +++ b/crates/ui-egui/src/canvas/navigation.rs @@ -1,6 +1,6 @@ +use craft::behavior::kurbo::{Point, Rect}; use craft::pages::Fit; use craft::pages::ui::view::GoTo; -use craft::behavior::kurbo::{Point, Rect}; use super::{DestView, DocInfo, DocView, pos2}; @@ -175,12 +175,8 @@ impl DocView { let (dw, dh) = size; let (w, h) = ((ax - bx).abs() * dw, (ay - by).abs() * dh); if w >= 1.0 && h >= 1.0 { - let rect = Rect::new( - f64::from(ax.min(bx) * dw), - f64::from(ay.min(by) * dh), - f64::from(ax.max(bx) * dw), - f64::from(ay.max(by) * dh), - ); + let rect = + Rect::new(f64::from(ax.min(bx) * dw), f64::from(ay.min(by) * dh), f64::from(ax.max(bx) * dw), f64::from(ay.max(by) * dh)); self.view.go_to = Some(GoTo::Rect { page, rect, margin: 0.0 }); } return; diff --git a/crates/ui-egui/src/canvas/organize.rs b/crates/ui-egui/src/canvas/organize.rs index 493e3dd792..f406bf5841 100644 --- a/crates/ui-egui/src/canvas/organize.rs +++ b/crates/ui-egui/src/canvas/organize.rs @@ -16,6 +16,7 @@ use craft::ui::tile_grid::ThumbnailSlider; // `app.invert_middle_drag` because `view` is borrowed out of `app.views`. pub(super) struct GridCx<'a> { pub ui: &'a mut egui::Ui, + pub session: &'a pdfcraft_engine::Session, pub zoom: &'a mut f64, pub invert_middle: bool, } @@ -179,8 +180,7 @@ pub(super) fn organize_grid(view: &mut DocView, doc: &pdfcraft_engine::Document, view.organize = false; } - // PLAN: assumed `DocPages::new(&Document)`, the `PageSource` over the document (pdf-canvas-w6). - let pages = crate::page_source::DocPages::new(doc); + let pages = super::pictures::DocPages::new(cx.session, view.id); let actions = [ (IconId::new("rotate_ccw"), CommandRef::new("page.rotate_ccw")), (IconId::new("rotate_cw"), CommandRef::new("page.rotate")), @@ -225,8 +225,7 @@ pub(super) fn organize_grid(view: &mut DocView, doc: &pdfcraft_engine::Document, } ThumbnailEvent::ContextMenu(request) => opened = Some(request.at), ThumbnailEvent::Insert(at) => view.pending_action = Some(ViewAction::InsertFromFileAt(at)), - // PLAN: assumed `crate::insert_dropped(files: Vec, at: usize)` (pdf-shell-w13). - ThumbnailEvent::FilesDropped { insert, files, .. } => crate::insert_dropped(files, insert), + ThumbnailEvent::FilesDropped { insert, .. } => view.grid_gap = Some(insert), ThumbnailEvent::Action { page, action, .. } => { view.pending_edit = match action { ROTATE_CCW => Some(Edit::RotatePages { pages: vec![page], degrees: -90 }), diff --git a/crates/ui-egui/src/canvas/page_menu.rs b/crates/ui-egui/src/canvas/page_menu.rs index b962f39791..2cfeb3d1b0 100644 --- a/crates/ui-egui/src/canvas/page_menu.rs +++ b/crates/ui-egui/src/canvas/page_menu.rs @@ -2,14 +2,14 @@ use craft::behavior::IconId; use craft::ui::canvas::ContextRequest; -use craft::ui::contract::overlay::Anchor; use craft::ui::contract::Show as _; +use craft::ui::contract::overlay::Anchor; use craft::ui::display::Divider; use craft::ui::menu::{Menu, MenuIcon, MenuIconRow, MenuItem}; use pdfcraft_engine::Edit; -use super::page_router::Owner; -use super::{DocInfo, DocView, cached_edit_images}; +use super::page_parts::Owner; +use super::{DocInfo, DocView}; use crate::{QuickTool, comments}; /// Default page right-click menu actions. @@ -96,7 +96,6 @@ pub(crate) struct PageMenuCx<'a> { pub info: &'a DocInfo, pub prefs: &'a comments::CommentPrefs, pub rights: comments::MenuRights, - // PLAN: assumed `comments::RecentColours` (pdf-comments-w10) pub recent: &'a comments::RecentColours, pub tool: QuickTool, pub preparing: bool, @@ -315,7 +314,7 @@ fn rows(ui: &mut egui::Ui, view: &mut DocView, cx: &PageMenuCx<'_>, menu_for: Op && let Some((page, Owner::Picture { index, .. })) = view.menu_for && let Some(sel) = view.image_selection.clone().filter(|s| (s.page, s.index) == (page, index)) { - let images = cached_edit_images(view, cx.doc, sel.page).to_vec(); + let images = cx.doc.page_images(sel.page); // Paste lands where the menu opened, on the picture's page: another page's point means nothing there. let at = view.comments.context_at.filter(|(page, _)| *page == sel.page).map(|(_, at)| at); let rotation = (view.rotation % 360 + cx.info.pages.get(sel.page).map_or(0, |p| p.rotation % 360)) % 360; @@ -324,7 +323,7 @@ fn rows(ui: &mut egui::Ui, view: &mut DocView, cx: &PageMenuCx<'_>, menu_for: Op } // The comment the press went to, when it is the one selected, or connected lines being drawn. let on_selected_comment = matches!(view.menu_for, Some((page, Owner::Comment { index, .. })) if view.comments.selected == Some((page, index))); - let drawing_points = matches!(&view.comments.gesture, Some(comments::Gesture::Draw { tool, .. }) if tool.clicks_points()); + let drawing_points = matches!(cx.tool, QuickTool::Comment(t) if t.clicks_points()) && !view.comments.tool.drawing().is_empty(); if on_selected_comment || drawing_points { let tool = if let QuickTool::Comment(t) = cx.tool { Some(t) } else { None }; pick.canvas = comments::context_rows( @@ -343,10 +342,9 @@ fn rows(ui: &mut egui::Ui, view: &mut DocView, cx: &PageMenuCx<'_>, menu_for: Op } let (page, at) = view.comments.context_at.unwrap_or((view.current, [0.0, 0.0])); // On a page still being read, the picture rows appear when the answer comes. - let picture_under = view - .comments - .context_at - .and_then(|(page, at)| view.pictures.get(ui.ctx(), cx.doc, page).and_then(|pictures| pdfcraft_engine::picture_at(pictures, at)).map(|(index, _)| *index)); + let picture_under = view.comments.context_at.and_then(|(page, at)| { + view.pictures.get(ui.ctx(), cx.doc, page).and_then(|pictures| pdfcraft_engine::picture_at(pictures, at)).map(|(index, _)| *index) + }); // A text selection whose pages are still being read copies once they are. let has_text = view.selected_text().is_some() || view.selection_waits_for_text().is_some(); let can_copy_items = cx.can_copy && (view.image_selection.is_some() || has_text || picture_under.is_some()); diff --git a/crates/ui-egui/src/canvas/page_overlays.rs b/crates/ui-egui/src/canvas/page_overlays.rs index 19df4816fa..901ac795dd 100644 --- a/crates/ui-egui/src/canvas/page_overlays.rs +++ b/crates/ui-egui/src/canvas/page_overlays.rs @@ -10,7 +10,7 @@ // its own component and their signatures are their owners'. use craft::behavior::{HitShape, IconId, Input, PointerButton, PressPhase, Sense}; -use craft::theme::Tone; +use craft::theme::variant::Tone; use craft::ui::contract::{Access, Animate as _, Common, Component, Cx, MeasureCx, NoValue, Outcome, PaintUi, Props, Role, Show as _}; use craft::ui::primitives::{Draw, IconSpec, PaintShape, StrokeWidth, TextRun}; use craft::ui::style::{ComponentStyle, DataColor, Metrics, StyleColor, StyleCx, TypeRole}; @@ -127,7 +127,10 @@ impl PageLinks<'_> { } let tip = self.unobstructed.then(|| link.uri.clone()); for r in &link.rects { - let rect = Rect::from_two_pos(self.xf.norm_to_screen(r[0] / self.xf.pw, r[1] / self.xf.ph), self.xf.norm_to_screen(r[2] / self.xf.pw, r[3] / self.xf.ph)); + let rect = Rect::from_two_pos( + self.xf.norm_to_screen(r[0] / self.xf.pw, r[1] / self.xf.ph), + self.xf.norm_to_screen(r[2] / self.xf.pw, r[3] / self.xf.ph), + ); if rect.is_finite() { out.push(link_part(Owner::TextLink { index }, self.page, HitShape::Rect(rect), tip.clone())); } @@ -260,13 +263,14 @@ pub(crate) fn overlay_parts(ui: &mut egui::Ui, xf: &PageXform, doc: &Document, p if empty.is_empty() { return out; } - let label = tl!("Sign").to_string(); - let width = SignTabMetrics::new(label).show_at(ui, Rect::from_min_size(xf.rect.min, Vec2::ZERO)).width; + let width = SignTabMetrics::new(tl!("Sign")).show_at(ui, Rect::from_min_size(xf.rect.min, Vec2::ZERO)).width; for (name, [x0, y0, x1, y1]) in empty { let Some(field) = form.iter().position(|f| f.name == name) else { continue }; let on_screen = xf.user_rect(info, page, [x0 as f32, y0 as f32, x1 as f32, y1 as f32]); let Some(tab) = sign_tab_on_page(on_screen, xf.rect, width) else { continue }; - out.parts.push(PagePart::new(Owner::SignTab { field }, page, HitShape::Rect(tab.rect), PageLayer::Field).cursor(CursorIcon::PointingHand).passes_drag()); + out.parts.push( + PagePart::new(Owner::SignTab { field }, page, HitShape::Rect(tab.rect), PageLayer::Field).cursor(CursorIcon::PointingHand).passes_drag(), + ); out.tabs.push(tab); } out @@ -307,18 +311,18 @@ pub(crate) struct SignTabMetrics { common: Common, /// The label, whose language the style follows. #[style_key] - label: String, + label: &'static str, } impl SignTabMetrics { /// A leaf measuring `label`. - pub(crate) fn new(label: String) -> Self { + pub(crate) fn new(label: &'static str) -> Self { SignTabMetrics { common: Common::new(), label } } /// A leaf for the suite. fn sample() -> Self { - SignTabMetrics::new("Sign".to_owned()) + SignTabMetrics::new("Sign") } } @@ -434,7 +438,8 @@ impl Component for PageOverlays<'_> { fn style(cx: &StyleCx<'_>, _: PageOverlaysStyleKey) -> PageOverlaysStyle { let tokens = cx.tokens; let colors = &tokens.color; - let tones = [Tone::Neutral, Tone::Accent, Tone::Info, Tone::Good, Tone::Warn, Tone::Bad].into_iter().map(|tone| (tone, cx.tone(tone))).collect(); + let tones = + [Tone::Neutral, Tone::Accent, Tone::Info, Tone::Good, Tone::Warn, Tone::Bad].into_iter().map(|tone| (tone, cx.tone(tone))).collect(); PageOverlaysStyle { metrics: Metrics::new(), field_fill: cx.color(colors.status.info.bg), diff --git a/crates/ui-egui/src/canvas/page_parts.rs b/crates/ui-egui/src/canvas/page_parts.rs index 1d35112c40..410d507b3e 100644 --- a/crates/ui-egui/src/canvas/page_parts.rs +++ b/crates/ui-egui/src/canvas/page_parts.rs @@ -367,9 +367,11 @@ impl Component for PageParts<'_> { /// Reads the press, the hover, the focused part's key and the focus that arrived. The press machine reports a /// press's phases one per pass, so a second pass of a frame reads only its own phase. fn update(&mut self, cx: &mut Cx<'_, Self>) { - let pressed = self.parts.iter().filter_map(|part| part.owner.part_ref(part.page)).any(|at| { - cx.part_if_declared(at).is_some_and(|result| result.press.phase.is_press()) - }); + let pressed = self + .parts + .iter() + .filter_map(|part| part.owner.part_ref(part.page)) + .any(|at| cx.part_if_declared(at).is_some_and(|result| result.press.phase.is_press())); if let Some(owner) = self.focus && (cx.is_focused() || pressed) && let Some(at) = self.parts.iter().filter(|part| part.focusable && part.owner == owner).find_map(|part| part.owner.part_ref(part.page)) @@ -403,5 +405,3 @@ impl Component for PageParts<'_> { PagePartsOutput { response: cx.response.clone(), press, key, hovered, focused } } } - - diff --git a/crates/ui-egui/src/canvas/page_tools.rs b/crates/ui-egui/src/canvas/page_tools.rs index 59f467dbe6..17d95c23a0 100644 --- a/crates/ui-egui/src/canvas/page_tools.rs +++ b/crates/ui-egui/src/canvas/page_tools.rs @@ -9,8 +9,7 @@ use craft::keymap::Mods; use craft::pages::ui::{PageTexts, PlacedPage, TextSelectState}; use craft::review::SavedSignature; use craft::ui::canvas::{ - CanvasTool, HandTool, NavigationOptions, ToolAccess, ToolAction, ToolClaims, ToolContext, ToolKey, ToolPath, ToolPointer, ToolRegion, - ZoomTool, + CanvasTool, HandTool, NavigationOptions, ToolAccess, ToolAction, ToolClaims, ToolContext, ToolKey, ToolPath, ToolPointer, ToolRegion, ZoomTool, }; use craft::ui::primitives::Draw; use pdfcraft_engine::{Document, Edit, FormField}; @@ -130,9 +129,9 @@ enum Arm<'a> { /// Redact: a text selection or a box, finished into marks. Redact(RedactTool<'a>), /// The signature rectangle of Digitally sign. - SignArea(SignAreaTool), + SignArea(SignAreaTool<'a>), /// Snapshot: the area to copy. - Snapshot(SnapshotTool<'a>), + Snapshot(SnapshotTool), /// Crop: the rectangle to crop the page to, or a double click for Set Page Boxes. Crop(CropTool), } @@ -262,7 +261,7 @@ pub(crate) fn page_tool<'a>( // and `.text(PageSelectTool)` (comments-w8 names the fields, not the constructor). _ => { let view = &mut session.comments; - let map = comments::bridge::PageMap::new(cx.info, cx.pages, cx.rotation); + let map = comments::PageMap::new(cx.info, cx.pages, cx.rotation); let annotate = CommentsTool::new(&mut view.tool, view.paste.as_mut(), map, &mut view.tool_done); let annotate = if selects_text { annotate.text(select) } else { annotate }; Arm::Area(Box::new(annotate)) @@ -295,9 +294,7 @@ pub(crate) fn page_tool<'a>( }; Arm::Area(Box::new(FillSignTool::new(&cx, input, fill))) } - QuickTool::Field(field_tool) => { - Arm::Area(Box::new(PrepareTool::new(Some(field_tool), cx.can_modify, cx.form, session))) - } + QuickTool::Field(field_tool) => Arm::Area(Box::new(PrepareTool::new(Some(field_tool), cx.can_modify, cx.form, session))), // PLAN: assumed `AddTextTool::new(session, doc, info)` in `content_ui` (pdf-edit-w7 gives no argument list). QuickTool::AddText => Arm::Area(Box::new(crate::tools::content_ui::AddTextTool::new(session, cx.doc, cx.info))), // PLAN: pdf-edit-w10's `EditTextTool::new(view, doc, info)` takes no placed pages, which the review asked to hand over. @@ -319,7 +316,7 @@ pub(crate) fn page_tool<'a>( }, // PLAN: assumed `LinkTool::new(session, doc, info, can_modify)` (pdf-edit-w11 gives `new(view, ..)`). QuickTool::Link => Arm::Area(Box::new(LinkTool::new(session, cx.doc, cx.info, cx.can_modify))), - QuickTool::SignArea { certify } => Arm::SignArea(SignAreaTool::new(certify)), + QuickTool::SignArea { certify } => Arm::SignArea(SignAreaTool::new(certify, cx.pages, cx.info)), QuickTool::Snapshot => Arm::Snapshot(SnapshotTool::new(cx.pages, cx.rotation, size)), }; PageTool { arm, tool, selects_text, released: false, presenting: cx.presenting, presenter_keys: Vec::new() } diff --git a/crates/ui-egui/src/canvas/pictures.rs b/crates/ui-egui/src/canvas/pictures.rs index a83e99e2e1..dce6f92dd0 100644 --- a/crates/ui-egui/src/canvas/pictures.rs +++ b/crates/ui-egui/src/canvas/pictures.rs @@ -8,7 +8,8 @@ use craft::behavior::kurbo::Size; use craft::pages::ui::PageSource; use craft::ui::primitives::textures::{LoadFailure, LoadedPicture, Revision, ThumbRender, ThumbRequest, ThumbSource}; use egui::{Color32, ColorImage, Rect}; -use pdfcraft_engine::{DocId, DocInfo, Session}; +use pdfcraft_engine::{DocId, Session}; +use pdfcraft_render::DocInfo; use pdfcraft_render::{PRINT_TAG, PageRenderer, RenderConfig, RenderRequest, RenderWarning, RequestKind, Tile}; use super::cache::{grayscale, texture_image}; diff --git a/crates/ui-egui/src/canvas/signature_drag.rs b/crates/ui-egui/src/canvas/signature_drag.rs index 3992008cf5..2626518ccf 100644 --- a/crates/ui-egui/src/canvas/signature_drag.rs +++ b/crates/ui-egui/src/canvas/signature_drag.rs @@ -344,7 +344,8 @@ impl SignatureDrag { // The box it is drawn in: a comment kept upright on a turned page (NoRotate) // isn't drawn in its /Rect, and the frame it follows is that box too. let rotation = doc.info.pages.get(page).map_or(0, |p| p.rotation); - let layer = StampLayer { renderer: alone.renderer(), from: a.shown_rect(rotation), tag: None, pixels: None, failed: None, stored: None }; + let layer = + StampLayer { renderer: alone.renderer(), from: a.shown_rect(rotation), tag: None, pixels: None, failed: None, stored: None }; self.moving = Some((key, Moving { layer, settling: false })); } _ => self.no_layer = Some(key), diff --git a/crates/ui-egui/src/canvas/tests.rs b/crates/ui-egui/src/canvas/tests.rs index e4f1382b97..2fdda0b3bc 100644 --- a/crates/ui-egui/src/canvas/tests.rs +++ b/crates/ui-egui/src/canvas/tests.rs @@ -1,3 +1,5 @@ +use super::area::{MARK_SIDE_SHARE, mark_anchor, verdict_mark_rect}; +use super::cache::grayscale; use super::*; use craft::pages::ui::{PageBody, PlacedPage}; use craft::ui::primitives::textures::{LoadFailure, Revision, TextureState, TextureStore, TextureStoreOptions}; diff --git a/crates/ui-egui/src/canvas/zoom_snap.rs b/crates/ui-egui/src/canvas/zoom_snap.rs index 4358a20d6c..63f33f81f9 100644 --- a/crates/ui-egui/src/canvas/zoom_snap.rs +++ b/crates/ui-egui/src/canvas/zoom_snap.rs @@ -1,8 +1,10 @@ //! Edit ▸ Take a Snapshot (drag a rectangle to copy that area as an image) and Fit Visible. use craft::behavior::{CancelReason, Cursor, CursorIcon}; +use craft::host::PickRequest; use craft::pages::Fit; use craft::pages::ui::{GoTo, PlacedPage}; +use craft::platform::clipboard::ClipboardImage; use craft::print::ui::HostedPrint; use craft::ui::canvas::{CanvasTool, ToolAction, ToolContext, ToolPath, ToolPointer}; use craft::ui::canvas_controls::TaskBar; @@ -222,40 +224,19 @@ impl PdfCraftApp { .and_then(|(_, id)| self.session.get(id)) .map_or_else(String::new, |d| d.name.trim_end_matches(".pdf").trim_end_matches(".PDF").to_string()); let name = format!("{stem} area.png"); - // PLAN: the save pick, the atomic write and the wasm download take the names pdf-shell-w15/w16 publish; `save_override` - // and `rfd` go with them. - #[cfg(not(target_arch = "wasm32"))] - { - let write = move |app: &mut Self, path: std::path::PathBuf| match crate::editing::write_atomically(&path.to_string_lossy(), &png) { + self.pick_first(PickRequest::save("snapshot").file_name(name).filter("PNG", &["png"]), None, move |app, path| { + match craft::atomic::atomic_write(&path, &png) { Ok(()) => app.notify_fmt("Exported to {path}", &[("path", &path.display().to_string())]), Err(e) => app.notify_fmt("Couldn't write {name}: {e}", &[("name", &path.display().to_string()), ("e", &e.to_string())]), - }; - match self.save_override.clone() { - Some(p) => write(self, p.into()), - None => { - let dialog = - rfd::AsyncFileDialog::new().set_title(tl!("Save as image").to_string()).add_filter("PNG", &["png"]).set_file_name(name); - self.ask_one(crate::pickers::Ask::Save(dialog), None, write); - } } - } - #[cfg(target_arch = "wasm32")] - if let Err(e) = crate::editing::download(&name, &png) { - self.notify_error(e); - } + }); } /// Render `view_rect` (page view points) of `page` and copy it to the clipboard (and keep it /// in `last_snapshot`), at the current zoom or [`SNAPSHOT_MIN_SCALE`] if that is finer. pub fn snapshot(&mut self, index: usize, page: usize, view_rect: [f32; 4]) -> Result<(u32, u32), String> { let (w, h, rgba) = self.render_area(index, page, view_rect)?; - // PLAN: the clipboard write goes through `clipboard.write_image` of the injected clipboard (pdf-shell-w17); - // `system_clipboard` and `os_clipboard::with` go. - #[cfg(not(target_arch = "wasm32"))] - if self.system_clipboard { - let img = arboard::ImageData { width: w as usize, height: h as usize, bytes: std::borrow::Cow::Borrowed(&rgba) }; - crate::os_clipboard::with(|c| c.set_image(img)).map_err(|e| e.to_string())?; - } + self.clipboard.write_image(&ClipboardImage { width: w, height: h, rgba: rgba.to_vec() }).map_err(|e| e.to_string())?; self.last_snapshot = Some((w, h, rgba)); self.last_snapshot_of = Some((self.views[index].id, page, view_rect)); Ok((w, h)) diff --git a/crates/ui-egui/src/commands.rs b/crates/ui-egui/src/commands.rs index 34eb202cd7..8e34ab0929 100644 --- a/crates/ui-egui/src/commands.rs +++ b/crates/ui-egui/src/commands.rs @@ -42,6 +42,14 @@ pub(crate) fn mac_shortcuts(ctx: &egui::Context) -> bool { ctx.os() == egui::os::OperatingSystem::Mac } +/// How a command's chord is written in a menu row (`⌘C` or `Ctrl+C`): the registry's shortcut, and the +/// clipboard chord for Copy, which the framework's clipboard commands own. +pub(crate) fn chord_label(ctx: &egui::Context, id: &str) -> Option { + let mac = mac_shortcuts(ctx); + let shortcut = commands::command(id)?.shortcut_for(mac).or((id == "edit.copy").then_some(COPY))?; + Some(shortcut.label(mac)) +} + impl PdfCraftApp { /// Runs a command the runtime fired from a key, a menu row, the palette, a component or /// automation. The catalog's app-side handlers come first; every other id is a registered @@ -923,7 +931,6 @@ impl PdfCraftApp { None => self.open_combine_tab(), } } - } /// The tab after `current` of `count` (before it when `forward` is false), wrapping around. From diff --git a/crates/ui-egui/src/commands/catalog.rs b/crates/ui-egui/src/commands/catalog.rs index 255657fd69..cea23627bd 100644 --- a/crates/ui-egui/src/commands/catalog.rs +++ b/crates/ui-egui/src/commands/catalog.rs @@ -4,13 +4,15 @@ use std::sync::OnceLock; -use craft::ui::runtime::commands::{AppCatalog, Binding, CommandDef, CommandDefError, CommandGate, CommandInput, CommandKind, CommandRef, CommandState, Scope}; +use craft::ui::runtime::commands::{ + AppCatalog, Binding, CommandDef, CommandDefError, CommandGate, CommandInput, CommandKind, CommandRef, CommandState, Scope, +}; use pdfcraft_engine::commands::{self as engine, CommandSpec}; use crate::menus::{self, CUT, DELETE, DOCUMENT, EXTRA, NO_RECENT, PANEL, PANELS, PASTE, SELECT_ALL}; -use craft::pages::PageDisplay; use crate::theme::ModeChoice; use crate::{Mode, PdfCraftApp, QuickTool}; +use craft::pages::PageDisplay; /// Commands only the catalog knows: id, English label and icon. Their handlers are the board's. const CATALOG_ONLY: &[(&str, &str, &str)] = &[ @@ -44,8 +46,8 @@ fn kind_of(id: &str) -> CommandKind { "view.layout.single" | "view.layout.two_up" => CommandKind::Radio { group: Some("layout".into()) }, "view.theme.system" | "view.theme.light" | "view.theme.dark" => CommandKind::Radio { group: Some("theme".into()) }, PANEL => CommandKind::Radio { group: Some("panel".into()) }, - "view.continuous" | "view.page_gaps" | "view.layout.cover" | "view.full_screen" | "view.read_mode" | "view.side_panel" | "view.tools_pane" - | "view.split" => CommandKind::Toggle, + "view.continuous" | "view.page_gaps" | "view.layout.cover" | "view.full_screen" | "view.read_mode" | "view.side_panel" + | "view.tools_pane" | "view.split" => CommandKind::Toggle, _ => CommandKind::Command, } } diff --git a/crates/ui-egui/src/panels/side_panels.rs b/crates/ui-egui/src/panels/side_panels.rs index f58ef2dcb4..adfc3c5fbd 100644 --- a/crates/ui-egui/src/panels/side_panels.rs +++ b/crates/ui-egui/src/panels/side_panels.rs @@ -5,8 +5,8 @@ //! by earlier versions (`side_panels`, `docking`) are read once by [`migrate`]. use craft::automation::dock as dock_rpc; -use craft::behavior::{Axis, DockSide}; use craft::behavior::dock::{Action, Column, DockEdge, DockPlacement, Group, Layout, Location, Node, Permissions, SplitSize, Target, Workspace}; +use craft::behavior::{Axis, DockSide}; use craft::keymap::CommandRef; use craft::ui::contract::{Bind, BodyCx}; use craft::ui::docking::{DockConfig, DockPanels, GroupAt, HidePanels, PanelSpec}; @@ -113,7 +113,6 @@ impl PanelId { Self::Tools | Self::Toolbar | Self::Document => return None, }) } - } impl From for PanelId { @@ -413,6 +412,11 @@ pub(crate) fn set_panel_visible(app: &mut PdfCraftApp, panel: PanelId, visible: } } +/// Whether the left panel `panel` is the one the tool panels show and the dock has them open. +pub(crate) fn panel_visible(app: &PdfCraftApp, panel: LeftPanel) -> bool { + app.left == panel && app.dock.layout.contains(&PanelId::Tools) +} + /// Moves the column holding `panel` to the `edge` dock. fn move_to_edge(app: &mut PdfCraftApp, panel: PanelId, edge: DockEdge) -> Result<(), String> { if !app.dock.layout.contains(&panel) { @@ -458,7 +462,9 @@ pub fn command(app: &mut PdfCraftApp, reset: bool, params: &Value) -> Result None, - Some(Value::String(side)) if side == "toggle" => Some(if rail_edge(app.rail_side) == DockEdge::Start { DockSide::End } else { DockSide::Start }), + Some(Value::String(side)) if side == "toggle" => { + Some(if rail_edge(app.rail_side) == DockEdge::Start { DockSide::End } else { DockSide::Start }) + } Some(value) => { let edge = edge_param(value.as_str().unwrap_or_default(), "rail_side")?; Some(if edge == DockEdge::Start { DockSide::Start } else { DockSide::End }) @@ -717,7 +723,11 @@ mod tests { "docked default", with_side( workspace( - split(json!({"FixedFirst": 300.0}), tabs(&["tools"]), split(json!({"FixedSecond": 400.0}), tabs(&["canvas"]), tabs(&["inspector"]))), + split( + json!({"FixedFirst": 300.0}), + tabs(&["tools"]), + split(json!({"FixedSecond": 400.0}), tabs(&["canvas"]), tabs(&["inspector"])), + ), json!([]), json!([]), ), @@ -730,7 +740,11 @@ mod tests { ( "tools on the right", workspace( - split(json!({"FixedSecond": 330.0}), tabs(&["canvas"]), split(json!({"FixedSecond": 290.0}), tabs(&["inspector"]), tabs(&["tools"]))), + split( + json!({"FixedSecond": 330.0}), + tabs(&["canvas"]), + split(json!({"FixedSecond": 290.0}), tabs(&["inspector"]), tabs(&["tools"])), + ), json!([]), json!([]), ), @@ -751,7 +765,10 @@ mod tests { ), ( "tools tabbed with the inspector", - with_side(workspace(split(json!({"FixedSecond": 350.0}), tabs(&["canvas"]), tabs(&["inspector", "tools"])), json!([]), json!([])), "Pages"), + with_side( + workspace(split(json!({"FixedSecond": 350.0}), tabs(&["canvas"]), tabs(&["inspector", "tools"])), json!([]), json!([])), + "Pages", + ), true, DockEdge::Start, true, @@ -759,7 +776,11 @@ mod tests { ( "hidden inspector and tools", with_side( - workspace(tabs(&["canvas"]), json!([]), json!([["inspector", hidden_place("Right", 380.0)], ["tools", hidden_place("Right", 300.0)]])), + workspace( + tabs(&["canvas"]), + json!([]), + json!([["inspector", hidden_place("Right", 380.0)], ["tools", hidden_place("Right", 300.0)]]), + ), "Bookmarks", ), false, @@ -768,7 +789,10 @@ mod tests { ), ( "version 1 value", - with_side(json!({"side_panels": {"version": 1, "tools_side": "right", "tools_open": true, "tools_width": 300.0, "side_width": 400.0}}), "Pages"), + with_side( + json!({"side_panels": {"version": 1, "tools_side": "right", "tools_open": true, "tools_width": 300.0, "side_width": 400.0}}), + "Pages", + ), true, DockEdge::End, true, diff --git a/crates/ui-egui/src/tools/camera_ui.rs b/crates/ui-egui/src/tools/camera_ui.rs index 5335c7bfd1..7e967bbdbb 100644 --- a/crates/ui-egui/src/tools/camera_ui.rs +++ b/crates/ui-egui/src/tools/camera_ui.rs @@ -62,7 +62,7 @@ pub struct CameraDone { } /// The page's size in view points. -fn page_points(placed: &PlacedPage) -> (f32, f32) { +pub(crate) fn page_points(placed: &PlacedPage) -> (f32, f32) { let scale = placed.scale.max(1e-6) as f32; (placed.rect.width() / scale, placed.rect.height() / scale) } diff --git a/crates/ui-egui/src/tools/comments.rs b/crates/ui-egui/src/tools/comments.rs index 154c8fc66b..060104f510 100644 --- a/crates/ui-egui/src/tools/comments.rs +++ b/crates/ui-egui/src/tools/comments.rs @@ -41,7 +41,7 @@ pub(crate) use bridge::{ use bridge::hover_tip; // PLAN: assumed colours exports (pdf-comments-w10): the colour pickers and buttons that `menu` exported before. pub use colours::{fill_picker, recent_custom_colours, remember_custom_colour, status_badge, swatch_grid}; -pub(crate) use colours::{border_colour_button, quick_bar_colour}; +pub(crate) use colours::{RecentColours, border_colour_button, quick_bar_colour}; pub(crate) use composer::composer; #[cfg(test)] use composer::edited_in_view; diff --git a/crates/ui-egui/src/tools/redact_ui/tool.rs b/crates/ui-egui/src/tools/redact_ui/tool.rs index 4f0f804866..06c25dba12 100644 --- a/crates/ui-egui/src/tools/redact_ui/tool.rs +++ b/crates/ui-egui/src/tools/redact_ui/tool.rs @@ -9,8 +9,8 @@ use pdfcraft_engine::rect_quad; use pdfcraft_render::DocInfo; use crate::QuickTool; -use crate::canvas::{DocView, PageBoxDrag, PageSelectTool, PlacedPage, ToolMarks}; use crate::canvas::PageXform; +use crate::canvas::{DocView, PageBoxDrag, PageSelectTool, PlacedPage, ToolMarks}; /// The smallest box, in screen points on each side, that counts as a mark. const LEAST_BOX: f32 = 3.0; @@ -25,7 +25,7 @@ enum Gesture { } /// What a finished gesture asks the document for. -enum RedactResult { +pub(crate) enum RedactResult { /// A box on `page`, as a user-space quad. Area { page: usize, quad: [f64; 8] }, /// A text selection that ended; the selection holds what to mark. @@ -48,7 +48,16 @@ impl<'a> RedactTool<'a> { /// The tool over the placed pages, with the select tool that runs text selections and the /// test of whether a screen point is over text (the same one the I-beam uses). pub(crate) fn new(select: PageSelectTool<'a>, placed: &'a [PlacedPage], info: &'a DocInfo, over_text: impl Fn(Pos2) -> bool + 'a) -> Self { - Self { select, drag: PageBoxDrag::default(), placed, info, over_text: Box::new(over_text), gesture: Gesture::Idle, text_page: None, finished: None } + Self { + select, + drag: PageBoxDrag::default(), + placed, + info, + over_text: Box::new(over_text), + gesture: Gesture::Idle, + text_page: None, + finished: None, + } } /// After the host ran: hands a finished gesture to the view as a pending redaction, or as a