diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 50dccb6e0f..e95619b6fb 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -1384,11 +1384,28 @@ fn page_body(ui: &mut egui::Ui, body: &PageBody<'_>, callbacks: &mut PageCallbac }) .collect(); // 5. The overlays. - page_overlays::PageBackdrop::new(body.pages, cx.sizes, cx.rotation, cx.info, session).show_at(ui, body.rect); + page_overlays::PageBackdrop::new( + body.pages, + cx.sizes, + cx.rotation, + cx.info, + session, + cx.form, + parts_out.hovered.as_ref().map(|(owner, _)| owner), + ) + .show_at(ui, body.rect); + let view_picked = session.picked_image; + let kept = session.area_pick.filter(|_| !session.box_drag.is_active()); for (page, xf, page_tabs) in &tabs { - PageOverlays::new(*page, *xf, cx.doc, page_tabs, &session.compare_marks, &mut session.flash) - .highlight_fields(session.highlight_fields) - .show_at(ui, body.rect); + let mut overlays = + PageOverlays::new(*page, *xf, cx.doc, page_tabs, &session.compare_marks, &mut session.flash).highlight_fields(session.highlight_fields); + if let Some(picked) = view_picked.filter(|p| p.page == *page) { + overlays = overlays.picked(picked.rect); + } + if let Some((_, area)) = kept.filter(|(p, _)| p == page) { + overlays = overlays.kept_area(area); + } + overlays.show_at(ui, body.rect); } if cx.preparing { crate::prepare::tool::show_overlays(ui, body.rect, body.view, session, cx.form, cx.info, body.pages, cx.rotation); @@ -1543,9 +1560,8 @@ fn page_body(ui: &mut egui::Ui, body: &PageBody<'_>, callbacks: &mut PageCallbac } if cx.chosen == QuickTool::Snapshot { let sizes = cx.sizes; - out.area_choice = crate::zoom_snap::area_bar(ui, body.rect, body.pages, session.area_pick, cx.rotation, |page| { - sizes.get(page).copied().unwrap_or_default() - }); + out.area_choice = + crate::zoom_snap::area_bar(ui, body, body.pages, session.area_pick, cx.rotation, |page| sizes.get(page).copied().unwrap_or_default()); } if cx.unobstructed && matches!(cx.tool, QuickTool::Select | QuickTool::ColumnSelect) { out.copy_selected = diff --git a/crates/ui-egui/src/canvas/bars.rs b/crates/ui-egui/src/canvas/bars.rs index 942e948e15..0a24854da6 100644 --- a/crates/ui-egui/src/canvas/bars.rs +++ b/crates/ui-egui/src/canvas/bars.rs @@ -50,8 +50,9 @@ pub(super) enum Notice { } /// One page notice bar with the icon named `icon`. -fn bar(tone: Tone, icon: &'static str, text: String) -> Bar<'static> { - Bar::new(tone, text).layout(NoticeLayout::Bar).icon(NoticeIcon::Custom(IconId::new(icon).into())) +fn bar(_tone: Tone, icon: &'static str, text: String) -> Bar<'static> { + // Production paints every notice bar on the soft accent surface, whatever it warns of; the icon says which kind. + Bar::new(Tone::Info, text).layout(NoticeLayout::Bar).icon(NoticeIcon::Custom(IconId::new(icon).into())) } /// The notices above the pages, one after another: a file changed on disk first, then what a historical @@ -202,7 +203,25 @@ pub(super) fn notices( // What each action returns, by the action's index; `None` is the field highlight toggle. let mut results: Vec> = Vec::new(); let mut notice = bar(tone, icon, text).dismiss(); - // The stopped-scripts notice leads with the Console, then the field highlights. + // Production lays the buttons out right to left, so the bar reads, left to right: Details, Don't show again, + // Unlock, Security settings, JavaScript Console, then the field highlights next to the dismiss control. + if repaired && !secured && info.fields.is_empty() { + notice = notice.action(NoticeAction::new(tl!("Details").to_string())); + results.push(Some(Notice::Repairs)); + } + // Only when the bar shows the security message: a form's stopped scripts come first. + if secured && !scripts_off { + notice = notice.action(NoticeAction::new(tl!("Don't show again").to_string())); + results.push(Some(Notice::HideSecured)); + } + if secured && doc.can_unlock() { + notice = notice.action(NoticeAction::new(tl!("Unlock…").to_string()).default_action()); + results.push(Some(Notice::Unlock)); + } + if secured { + notice = notice.action(NoticeAction::new(tl!("Security settings").to_string())); + results.push(Some(Notice::Security)); + } if scripts_off { notice = notice.action(NoticeAction::new(tl!("JavaScript Console").to_string())); results.push(Some(Notice::Console)); @@ -212,23 +231,6 @@ pub(super) fn notices( notice = notice.action(NoticeAction::new(label.to_string())); results.push(None); } - if secured { - notice = notice.action(NoticeAction::new(tl!("Security settings").to_string())); - results.push(Some(Notice::Security)); - } - if secured && doc.can_unlock() { - notice = notice.action(NoticeAction::new(tl!("Unlock…").to_string()).default_action()); - results.push(Some(Notice::Unlock)); - } - // Only when the bar shows the security message: a form's stopped scripts come first. - if secured && !scripts_off { - notice = notice.action(NoticeAction::new(tl!("Don't show again").to_string())); - results.push(Some(Notice::HideSecured)); - } - if repaired && !secured && info.fields.is_empty() { - notice = notice.action(NoticeAction::new(tl!("Details").to_string())); - results.push(Some(Notice::Repairs)); - } let out = notice.show(ui); if out.dismissed { view.notice_dismissed = true; diff --git a/crates/ui-egui/src/canvas/organize.rs b/crates/ui-egui/src/canvas/organize.rs index 93ca72c29c..a667be7149 100644 --- a/crates/ui-egui/src/canvas/organize.rs +++ b/crates/ui-egui/src/canvas/organize.rs @@ -167,7 +167,7 @@ pub(super) fn organize_grid(view: &mut DocView, doc: &pdfcraft_engine::Document, // What the grid shows is what is saved. // PLAN: assumed `Props::tooltip(impl Into)` and `TooltipSpec -> Tooltip`. let hint = craft::ui::contract::TooltipSpec::new(tl!("Save these pages as one PDF")).disabled_text(tl!("No changes to save")); - save |= Button::new(tl!("Save pages")).enabled(dirty).tooltip(hint).show(ui).clicked(); + save |= Button::new(tl!("Save pages")).variant(Variant::PRIMARY).enabled(dirty).tooltip(hint).show(ui).clicked(); close |= Button::new(tl!("Close")).variant(Variant::GHOST).icon(IconId::new("x")).show(ui).clicked(); }) .show(cx.ui, |ui, _| { @@ -219,7 +219,11 @@ pub(super) fn organize_grid(view: &mut DocView, doc: &pdfcraft_engine::Document, } let id = organize_grid_id(view); // PLAN: assumed `PageThumbnails::invert_middle(bool)` beside `middle_button` (pdf-canvas-w6). - let out = PageThumbnails::new(tl!("Pages"), &pages, &mut view.selected, current, DataColor::new(egui::Color32::WHITE)) + // With nothing picked, the current page shows as the picked one, as in production; that is a display, so the view's + // own selection stays empty until a click changes it. + let seeded = view.selected.items.is_empty() && current < n; + let mut shown = if seeded { Selection::new(vec![current], Some(current), Some(current)) } else { view.selected.clone() }; + let out = PageThumbnails::new(tl!("Pages"), &pages, &mut shown, current, DataColor::new(egui::Color32::WHITE)) .id(id) .arrangement(ThumbnailArrangement::Organize) .editable(editable) @@ -231,6 +235,9 @@ pub(super) fn organize_grid(view: &mut DocView, doc: &pdfcraft_engine::Document, .invert_middle(cx.invert_middle) .reveal(reveal) .show(cx.ui); + if !seeded || shown.items != [current] { + view.selected = shown; + } view.middle_scrolling = out.auto_scrolling; // The menu is open from the request until a row runs or it is dismissed. diff --git a/crates/ui-egui/src/canvas/page_overlays.rs b/crates/ui-egui/src/canvas/page_overlays.rs index df4dc8b6a6..e78696e4e8 100644 --- a/crates/ui-egui/src/canvas/page_overlays.rs +++ b/crates/ui-egui/src/canvas/page_overlays.rs @@ -488,6 +488,12 @@ pub(crate) struct PageOverlays<'a> { /// Acrobat's "Highlight existing fields". #[prop] highlight_fields: bool, + /// Snapshot's kept area on this page (view space): outlined until another tool or drag replaces it. + #[prop] + kept_area: Option<[f32; 4]>, + /// The selected picture on this page (user space): tinted like production's selection. + #[prop] + picked: Option<[f64; 4]>, } impl<'a> PageOverlays<'a> { @@ -502,7 +508,7 @@ impl<'a> PageOverlays<'a> { compare: &'a [(usize, [f32; 4], Color32)], flash: &'a mut Option<(usize, [f32; 4], f64)>, ) -> Self { - PageOverlays { common: Common::new(), page, xf, doc, tabs, compare, flash, highlight_fields: false } + PageOverlays { common: Common::new(), page, xf, doc, tabs, compare, flash, highlight_fields: false, kept_area: None, picked: None } } } @@ -554,6 +560,18 @@ impl Component for PageOverlays<'_> { } self.paint_compare_marks(&draw, style); self.paint_flash(&draw, cx); + if let Some(rect) = self.picked { + let rect = self.xf.user_rect_f64(&self.doc.info, self.page, rect); + if rect.is_finite() { + draw.faded(50.0 / 255.0, |draw| draw.fill(&PaintShape::Rect(rect, CornerRadius::ZERO), style.flash)); + } + } + if let Some(area) = self.kept_area { + let rect = self.xf.view_rect(area); + if rect.is_finite() { + draw.stroke(&PaintShape::Rect(rect, CornerRadius::ZERO), StrokeWidth::Thick, style.flash); + } + } for tab in self.tabs { paint_sign_tab(&draw, tab, style); } @@ -671,11 +689,22 @@ pub(crate) struct PageBackdrop<'a> { rotation: u16, info: &'a DocInfo, session: &'a PageSession, + /// The document's fields and the part under the pointer: the unbaked widgets, the hover frame and the drop-down arrows. + form: &'a [pdfcraft_engine::FormField], + hover: Option<&'a Owner>, } impl<'a> PageBackdrop<'a> { - pub(crate) fn new(pages: &'a [PlacedPage], sizes: &'a [(f32, f32)], rotation: u16, info: &'a DocInfo, session: &'a PageSession) -> Self { - Self { common: Common::new(), pages, sizes, rotation, info, session } + pub(crate) fn new( + pages: &'a [PlacedPage], + sizes: &'a [(f32, f32)], + rotation: u16, + info: &'a DocInfo, + session: &'a PageSession, + form: &'a [pdfcraft_engine::FormField], + hover: Option<&'a Owner>, + ) -> Self { + Self { common: Common::new(), pages, sizes, rotation, info, session, form, hover } } } @@ -724,6 +753,7 @@ impl Component for PageBackdrop<'_> { self.session.content.draft.as_ref(), ); self.session.move_background.paint(&draw, &content, placed, self.info, &self.session.content); + crate::forms_ui::paint_page(&draw, &content.painter, (&xf, placed.page), self.info, self.form, self.session, self.hover); } } diff --git a/crates/ui-egui/src/canvas/zoom_snap.rs b/crates/ui-egui/src/canvas/zoom_snap.rs index 026c77659a..9cb9409c88 100644 --- a/crates/ui-egui/src/canvas/zoom_snap.rs +++ b/crates/ui-egui/src/canvas/zoom_snap.rs @@ -107,7 +107,7 @@ impl CanvasTool for SnapshotTool<'_> { /// with it: the choice made this pass. The outline itself is the page body's (marching ants). pub(crate) fn area_bar( ui: &mut egui::Ui, - body_rect: egui::Rect, + body: &craft::pages::ui::PageBody<'_>, placed: &[PlacedPage], area_pick: Option<(usize, [f32; 4])>, rotation: u16, @@ -116,9 +116,9 @@ pub(crate) fn area_bar( let (page, area) = area_pick?; let placed = placed.iter().find(|p| p.page == page)?; let screen = PageXform::of(placed, rotation, page_size_of(page)).view_rect(area); - let anchor = [screen.left_top(), screen.right_top(), screen.right_bottom(), screen.left_bottom()].map(|p| placed.to_page(p)); + let anchor = [screen.left_top(), screen.right_top(), screen.right_bottom(), screen.left_bottom()].map(|p| body.view.to_doc(p)); let mut choice = None; - TaskBar::fixed(tl!("Snapshot area"), &anchor).show(ui, body_rect, |ui, _cx| { + TaskBar::fixed(tl!("Snapshot area"), &anchor).show(ui, body.rect, |ui, _cx| { if craft::ui::buttons::Button::new(tl!("Print area…")).show(ui).clicked() { choice = Some(AreaChoice::Print); } diff --git a/crates/ui-egui/src/home.rs b/crates/ui-egui/src/home.rs index 412555455f..3d6d79bb01 100644 --- a/crates/ui-egui/src/home.rs +++ b/crates/ui-egui/src/home.rs @@ -6,8 +6,8 @@ use std::cell::RefCell; use craft::behavior::IconId; use craft::behavior::{DisplayOrder, ItemSource, SizeHint}; use craft::keymap::CommandRef; -use craft::theme::variant::Tone; use craft::theme::TypeRole; +use craft::theme::variant::Tone; use craft::ui::buttons::{Button, IconButton}; use craft::ui::contract::{ActivateOn, CollectionEvent, Pad, Props as _, Show as _, ShowCollection as _, ShowContainer as _, clicked}; use craft::ui::display::{PictureSize, Text}; @@ -47,7 +47,8 @@ fn recommended_grid(ui: &mut egui::Ui, groups: &[&'static ToolGroup], asked: &Re .zoom(GridZoom::Fixed(1.05)) .show_items(ui, &Tools(groups.len() + 1), &mut |key, _| { if let Some(g) = groups.get(*key) { - let description = g.sections.first().map(|s| s.items.iter().take(3).map(|i| tl!(i.label)).collect::>().join(" · ")).unwrap_or_default(); + let description = + g.sections.first().map(|s| s.items.iter().take(3).map(|i| tl!(i.label)).collect::>().join(" · ")).unwrap_or_default(); tool_tile(g, false).accessible_name(tl!(g.label).to_string()).detail(description).summary_action(tl!("Use now").to_string()) } else { Tile::new(tl!("Open file").to_string()).icon(IconId::new("folder_open")).summary_action("") @@ -165,7 +166,8 @@ pub fn show(app: &mut PdfCraftApp, ui: &mut egui::Ui) { Row::new().wrap(true).show(ui, |ui, _| { for (i, link) in pdfcraft_engine::links::LINKS.iter().enumerate() { let label = if i == 0 { tl!("Join our Discord") } else { tl!(link.label) }; - if clicked(&Button::new(label.to_string()).icon(IconId::new(link.icon)).show(ui)) { + let variant = if i == 0 { craft::theme::Variant::PRIMARY } else { craft::theme::Variant::SECONDARY }; + if clicked(&Button::new(label.to_string()).variant(variant).icon(IconId::new(link.icon)).show(ui)) { asked.borrow_mut().push(Asked::Link(link.command)); } } diff --git a/crates/ui-egui/src/tools/prepare/tool.rs b/crates/ui-egui/src/tools/prepare/tool.rs index cf0f59107d..9b4cdf96bf 100644 --- a/crates/ui-egui/src/tools/prepare/tool.rs +++ b/crates/ui-egui/src/tools/prepare/tool.rs @@ -411,6 +411,9 @@ struct OverlayField { selected: bool, } +/// How much of the accent the prepare overlay's field fill keeps over the page. +const FIELD_FILL_SHARE: f32 = 89.0 / 255.0; + /// The fields of one page with their fill, outline, selection and name tags, and the tab-order /// badges while they are on. A field being moved is drawn at the moved place. #[derive(Component, Props)] @@ -504,7 +507,7 @@ impl Component for PrepareOverlay { let colors = &cx.tokens.color; PrepareOverlayStyle { metrics: Metrics::new(), - fill: cx.color(colors.accent.soft), + fill: cx.color(colors.accent.solid), outline: cx.color(colors.line.control_edge), selected: cx.color(colors.accent.solid), tag: cx.color(colors.text.normal), @@ -524,7 +527,8 @@ impl Component for PrepareOverlay { let draw = ui.draw(); for field in &self.fields { let r = field.rect; - draw.fill(&PaintShape::Rect(r, CornerRadius::ZERO), style.fill); + // A tint of the accent over the page, as production's (89/255), so the page shows through. + draw.faded(FIELD_FILL_SHARE, |draw| draw.fill(&PaintShape::Rect(r, CornerRadius::ZERO), style.fill)); if !field.selected { draw.stroke(&PaintShape::Rect(r, CornerRadius::ZERO), StrokeWidth::Thin, style.outline); }