From fb244d19504f1d68b6322b1e5352d3c675d1730e Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 20 Nov 2026 05:48:20 -0500 Subject: [PATCH] Framework fwb9-c: port follow-ups (see runs/fwb9-c.md) --- crates/review/src/annotate.rs | 4 +-- crates/review/src/annotate_tests.rs | 9 ++++++ crates/review/src/comments.rs | 5 ++++ crates/review/src/ui/comments.rs | 2 +- crates/review/src/ui/comments/menus.rs | 14 +++++----- crates/review/src/ui/comments/stories.rs | 2 +- crates/review/src/ui/mod.rs | 2 +- crates/review/src/ui/signature.rs | 23 ++++++++++----- crates/review/src/ui/signature/stories.rs | 14 ++++++---- crates/review/src/ui/thread/note_popup.rs | 2 +- crates/review/src/ui/thread/stories.rs | 1 + crates/review/tests/it/comments.rs | 34 ++++++++++++++++++++++- crates/review/tests/it/note_popup.rs | 16 +++++++++++ crates/review/tests/it/signature.rs | 23 ++++++++++++++- 14 files changed, 123 insertions(+), 28 deletions(-) diff --git a/crates/review/src/annotate.rs b/crates/review/src/annotate.rs index efb1e72e0..a5de1800e 100644 --- a/crates/review/src/annotate.rs +++ b/crates/review/src/annotate.rs @@ -180,8 +180,8 @@ pub enum HandleRule { NoResize, } -/// The knee of a callout stays at least this far from its box, in page units. -pub const CALLOUT_KNEE_GAP: f64 = 12.0; +/// The knee of a callout stays at least this far from its box, in canvas document units. +pub const CALLOUT_KNEE_GAP: f64 = 12.0 * 96.0 / 72.0; /// A move of at most this many page units is a slip, not a move. pub const SLIP_MOVE: f64 = 2.0; diff --git a/crates/review/src/annotate_tests.rs b/crates/review/src/annotate_tests.rs index 4de6a795e..f4486a365 100644 --- a/crates/review/src/annotate_tests.rs +++ b/crates/review/src/annotate_tests.rs @@ -158,6 +158,15 @@ fn a_callout_knee_stays_on_its_line_at_least_the_gap_from_the_box_and_only_the_t assert!(matches!(held.as_slice(), [t, k] if *k == knee && diagonal(*t)), "held to 45 degrees from the knee: {held:?}"); } +/// The document-space knee gap corresponds to twelve page points at the standard page scale. +#[trial] +fn a_callout_knee_keeps_the_page_point_gap_in_document_space() { + let rect = Rect::new(200.0, 100.0, 300.0, 150.0); + let points = [Point::new(20.0, 125.0), Point::new(160.0, 125.0)]; + let moved = callout_reshaped(rect, &points, 1, Point::new(210.0, 125.0), None); + assert!((rect.x0 - moved[1].x - 12.0 * 96.0 / 72.0).abs() < 0.001); +} + /// The overlay paints an annotation as the in-flight edit leaves it: moved with its points and strokes, resized, /// reshaped with its box around the new points, and a resized callout's box going while its tip and knee stay. #[cfg(feature = "ui")] diff --git a/crates/review/src/comments.rs b/crates/review/src/comments.rs index ed5536318..d66c726d5 100644 --- a/crates/review/src/comments.rs +++ b/crates/review/src/comments.rs @@ -121,8 +121,13 @@ pub struct CommentMessage { pub reactions: Vec, /// Read by the viewer (FigCraft's read state). pub read: bool, + /// Whether this message and its descendants may be deleted. + #[serde(default = "message_deletable")] + pub deletable: bool, } +fn message_deletable() -> bool { true } + /// A comment and its replies. #[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)] pub struct CommentThread { diff --git a/crates/review/src/ui/comments.rs b/crates/review/src/ui/comments.rs index 46db44b69..bd36bed94 100644 --- a/crates/review/src/ui/comments.rs +++ b/crates/review/src/ui/comments.rs @@ -739,7 +739,7 @@ impl CommentsPanel<'_, H> { } // The "..." buttons are the card drawn as the lead this pass. if let Some(thread) = lead.and_then(|selected| threads.iter().find(|thread| thread.id == selected)) { - let editable = !read_only && !thread.locked; + let editable = !read_only; for (index, button) in &buttons { let rows = host_rows.as_ref().map_or_else(Vec::new, |rows| rows(thread, *index)); if let Some(action) = card_menu(ui, &words, button, *index, thread, editable, &rows) { diff --git a/crates/review/src/ui/comments/menus.rs b/crates/review/src/ui/comments/menus.rs index 729357457..4f6104821 100644 --- a/crates/review/src/ui/comments/menus.rs +++ b/crates/review/src/ui/comments/menus.rs @@ -229,13 +229,13 @@ pub(super) fn card_menu( ) -> Option { let ran = std::cell::Cell::new(None); Menu::new(words.more.clone()).id_salt(index).opened_by(button, Trigger::Click).show(ui, |ui, _| { - let row = |ui: &mut Ui, label: &Label, action: CardMenu| { - if MenuItem::new(label.as_str().to_owned()).show(ui).ran { + let row = |ui: &mut Ui, label: &Label, action: CardMenu, enabled: bool| { + if MenuItem::new(label.as_str().to_owned()).enabled(enabled).show(ui).ran { ran.set(Some(action)); } }; if index == 0 { - row(ui, &words.edit, CardMenu::Edit); + row(ui, &words.edit, CardMenu::Edit, editable && !thread.locked); let _ = Menu::submenu_row(ui, words.set_status.clone(), |ui, _| { for status in ReviewStatus::MENU { if MenuItem::new(status_label(words, status).as_str().to_owned()).radio_mark(thread.status() == status).show(ui).ran { @@ -244,15 +244,15 @@ pub(super) fn card_menu( } }); Divider::horizontal().show(ui); - row(ui, &words.delete, CardMenu::Delete); + row(ui, &words.delete, CardMenu::Delete, editable && !thread.locked); } else { if editable { - row(ui, &words.edit, CardMenu::Edit); + row(ui, &words.edit, CardMenu::Edit, true); } - row(ui, &words.copy_text, CardMenu::Copy); + row(ui, &words.copy_text, CardMenu::Copy, true); if editable { Divider::horizontal().show(ui); - row(ui, &words.delete, CardMenu::Delete); + row(ui, &words.delete, CardMenu::Delete, thread.messages.get(index).is_some_and(|message| message.deletable)); } } if !host_rows.is_empty() { diff --git a/crates/review/src/ui/comments/stories.rs b/crates/review/src/ui/comments/stories.rs index b3aa775ff..2bfcacf12 100644 --- a/crates/review/src/ui/comments/stories.rs +++ b/crates/review/src/ui/comments/stories.rs @@ -14,7 +14,7 @@ use crate::comments::{CommentAnchor, CommentMessage, CommentThread, ReviewStatus const NOW: i64 = 90_000; fn message(author: &str, text: &str, created: i64) -> CommentMessage { - CommentMessage { author: author.into(), created, modified: None, text: text.into(), reactions: Vec::new(), read: true } + CommentMessage { author: author.into(), created, modified: None, text: text.into(), reactions: Vec::new(), read: true, deletable: true } } fn reviewer(name: &str, status: ReviewStatus) -> ReviewerStatus { diff --git a/crates/review/src/ui/mod.rs b/crates/review/src/ui/mod.rs index 800b4b7db..dae36be2c 100644 --- a/crates/review/src/ui/mod.rs +++ b/crates/review/src/ui/mod.rs @@ -37,7 +37,7 @@ pub use presence::{ FollowCommand, FollowFrame, FollowFrameOutput, PeopleBar, PeopleBarOutput, PresenceWords, RemoteCursor, RemoteCursors, paint_pointer, }; pub use revisions::{RevisionsPanel, RevisionsPanelOutput, RevisionsWords}; -pub use signature::{SignaturePadDialog, SignaturePadResult, SignatureSettings, SignatureWords, paint_signature}; +pub use signature::{ScanEvent, SignaturePadDialog, SignaturePadResult, SignatureSettings, SignatureWords, paint_signature}; pub use thread::{ CommentComposer, CommentComposerOutput, CommentPin, CommentPins, CommentPinsOutput, ComposerClose, ComposerDraft, NOTE_POPUP_LIMITS, NoteDrafts, NotePopup, NotePopupMessage, NotePopupOutput, PinCluster, PinMove, REACTIONS, ThreadPopover, ThreadPopoverOutput, ThreadWords, cluster, diff --git a/crates/review/src/ui/signature.rs b/crates/review/src/ui/signature.rs index 33b55bf44..ad8732559 100644 --- a/crates/review/src/ui/signature.rs +++ b/crates/review/src/ui/signature.rs @@ -403,10 +403,16 @@ fn pop_stroke(strokes: &mut Vec>) -> bool { false } -/// The Scan tab's content, the app's. -/// -/// It is handed the file dropped on the window in this pass, and `None` in every other call. -pub type ScanTab = Box) + Send>; +/// Input delivered to the host's scan tab. +pub enum ScanEvent { + /// Draw the scan tab, with any file dropped on it this pass. + Show(Option), + /// Clear the scan's own state and cancel any pending work. + Clear, +} + +/// The Scan tab's content and its clear handler, supplied by the host. +pub type ScanTab = Box; /// Acrobat's signature pad on the dialog host: "Create signature" or "Change initials" with the tabs Type (a field over /// the pad that shows the typed signature), Draw (a pad of strokes, Undo), Image (Browse… a PNG or JPEG up to @@ -444,9 +450,9 @@ impl SignaturePadDialog { Self { draft, scan: None, open: true, pick: None, decoding: None, error: None } } - /// The Scan tab's content: it fills `draft.image`. + /// The Scan tab's content: it fills `draft.image` and handles [`ScanEvent::Clear`]. #[must_use] - pub fn scan(mut self, tab: impl FnMut(&mut egui::Ui, &mut SignatureDraft, Option) + Send + 'static) -> Self { + pub fn scan(mut self, tab: impl FnMut(&mut egui::Ui, &mut SignatureDraft, ScanEvent) + Send + 'static) -> Self { self.scan = Some(Box::new(tab)); self } @@ -589,7 +595,7 @@ impl StackDialog for SignaturePadDialog { } SignatureTab::Scan => { if let Some(tab) = scan.as_mut() { - DropVeil::new(words.drop_photo.clone()).show(ui, |ui, files| tab(ui, draft, first_file(files))); + DropVeil::new(words.drop_photo.clone()).show(ui, |ui, files| tab(ui, draft, ScanEvent::Show(first_file(files)))); } } } @@ -600,6 +606,9 @@ impl StackDialog for SignaturePadDialog { if clicked(&Button::new(words.clear.clone()).show(ui)) { draft.clear(); *error = None; + if let Some(tab) = scan.as_mut() { + tab(ui, draft, ScanEvent::Clear); + } } }); }); diff --git a/crates/review/src/ui/signature/stories.rs b/crates/review/src/ui/signature/stories.rs index 9db022587..cad2e636f 100644 --- a/crates/review/src/ui/signature/stories.rs +++ b/crates/review/src/ui/signature/stories.rs @@ -1,9 +1,9 @@ //! Stories of the signature pad. -use super::{DrawPad, SignaturePadDialog}; +use super::{DrawPad, ScanEvent, SignaturePadDialog}; use crate::signature::{SignatureDraft, SignatureImage, SignatureTab}; use craft_ui::buttons::Button; -use craft_ui::contract::{Bind, OsFile, Show as _, Validity, clicked}; +use craft_ui::contract::{Bind, Show as _, Validity, clicked}; use craft_ui::dialog::StackDialog as _; use craft_ui::display::Text; use craft_ui::popover::DropVeil; @@ -80,10 +80,12 @@ fn dialog(ui: &mut Ui, data: &mut StoryData, start: &Start) -> StoryOutput { } /// The app's Scan tab as a stub: a line of text, and a dropped photo stands in for a cleaned scan. -fn scan_stub(ui: &mut Ui, draft: &mut SignatureDraft, dropped: Option) { - Text::new("The app's scan view: drop a photo of a signature on paper.").show(ui); - if dropped.is_some() { - draft.image = Some(ink_sample()); +fn scan_stub(ui: &mut Ui, draft: &mut SignatureDraft, event: ScanEvent) { + if let ScanEvent::Show(dropped) = event { + Text::new("The app's scan view: drop a photo of a signature on paper.").show(ui); + if dropped.is_some() { + draft.image = Some(ink_sample()); + } } } diff --git a/crates/review/src/ui/thread/note_popup.rs b/crates/review/src/ui/thread/note_popup.rs index 1e9bdaed4..4f4f665bd 100644 --- a/crates/review/src/ui/thread/note_popup.rs +++ b/crates/review/src/ui/thread/note_popup.rs @@ -498,7 +498,7 @@ struct NoteWindow { impl NoteWindow { fn new(label: Label, overlay: Overlay, look: NoteLook, close_label: Label, allowed: bool, anchor: Option<(Rect, bool)>, selected: bool) -> Self { let props = - ContainerProps::new().mount(Mount::Layer(overlay)).surface(SurfaceKind::Floating).header(HeaderRegion::new().band(DragBand::Move)); + ContainerProps::new().mount(Mount::Layer(overlay)).surface(SurfaceKind::Floating).header(HeaderRegion::new().band(DragBand::Move).trailing(true)); NoteWindow { common: Common::new(), props, diff --git a/crates/review/src/ui/thread/stories.rs b/crates/review/src/ui/thread/stories.rs index cae1203bf..ea939da1c 100644 --- a/crates/review/src/ui/thread/stories.rs +++ b/crates/review/src/ui/thread/stories.rs @@ -19,6 +19,7 @@ fn thread() -> CommentThread { text: text.into(), reactions: Vec::new(), read: true, + deletable: true, }; CommentThread { id: ThreadId(7), diff --git a/crates/review/tests/it/comments.rs b/crates/review/tests/it/comments.rs index 9ae665e7a..6e356db47 100644 --- a/crates/review/tests/it/comments.rs +++ b/crates/review/tests/it/comments.rs @@ -16,7 +16,39 @@ use craft_ui::testing::{Fixture, Room, trial}; use egui::{Key, Modifiers, Rect}; fn message(author: &str, text: &str) -> CommentMessage { - CommentMessage { author: author.into(), created: 0, modified: None, text: text.into(), reactions: Vec::new(), read: true } + CommentMessage { author: author.into(), created: 0, modified: None, text: text.into(), reactions: Vec::new(), read: true, deletable: true } +} + +/// A locked comment does not prevent editing or deleting its separate reply. +#[trial] +fn a_locked_comment_still_offers_reply_actions() { + let mut item = thread(1, 1, "Locked comment"); + item.locked = true; + item.messages.push(message("Bo", "Reply")); + let mut state = CommentsPanelState::default(); + state.selected = Selection::single(ThreadId(1)); + let mut fixture = Fixture::new(move |ui| { let _ = CommentsPanel::new("Comments", std::slice::from_ref(&item), &mut state).show(ui); }); + fixture.settle(); + let more = fixture.by_label("More").expect("the reply menu"); + fixture.click(&more).settle(); + assert!(fixture.by_label("Edit").is_some(), "the reply can be edited"); + assert!(fixture.by_label("Delete").is_some(), "the reply can be deleted"); + + let mut item = thread(2, 1, "Comment"); + let mut reply = message("Bo", "Locked reply"); + reply.deletable = false; + item.messages.push(reply); + let mut state = CommentsPanelState::default(); + state.selected = Selection::single(ThreadId(2)); + let mut fixture = Fixture::new(move |ui| { let _ = CommentsPanel::new("Comments", std::slice::from_ref(&item), &mut state).show(ui); }); + fixture.settle(); + let menus = fixture.by_role(Role::BUTTON); + let reply_menu = menus.into_iter().filter(|target| fixture.tree().name_of(target.node) == Some("More")).last().expect("the reply menu"); + fixture.click(&reply_menu).settle(); + let edit = fixture.by_label("Edit").expect("editing the reply is offered"); + let delete = fixture.by_label("Delete").expect("deletion is shown"); + assert!(!fixture.tree().is_disabled_key(edit.node), "locked reply text is editable"); + assert!(fixture.tree().is_disabled_key(delete.node), "a reply that cannot be deleted is disabled"); } fn thread(id: u64, page: usize, text: &str) -> CommentThread { diff --git a/crates/review/tests/it/note_popup.rs b/crates/review/tests/it/note_popup.rs index ae63b0393..c69d77a86 100644 --- a/crates/review/tests/it/note_popup.rs +++ b/crates/review/tests/it/note_popup.rs @@ -16,6 +16,22 @@ const SLACK: f32 = 1.5; const NOTE: [NotePopupMessage<'static>; 1] = [NotePopupMessage { id: 1, title: "Sticky Note", author: "Ana", text: "Check the margin.", modified: None, depth: 0, editable: true }]; +/// The title's close control reports the close to the host. +#[trial] +fn the_note_header_close_reports_to_the_host() { + let closed = Rc::new(Cell::new(false)); + let result = closed.clone(); + let mut drafts = NoteDrafts::default(); + let mut fixture = Fixture::new(move |ui| { + let out = NotePopup::new(1, "Note", Rect::from_min_size(pos2(100.0, 100.0), vec2(320.0, 200.0)), &NOTE, &mut drafts).show(ui); + result.set(result.get() || out.closed); + }); + fixture.room(vec2(1000.0, 800.0)).settle(); + let close = fixture.by_label("Close").expect("the header has a close control"); + fixture.click(&close).settle(); + assert!(closed.get(), "closing reaches the host"); +} + /// The host of one note pop-up: a button stands for the note's mark, and the pop-up sits at `rect`, which takes each /// reported placement. struct NoteHost { diff --git a/crates/review/tests/it/signature.rs b/crates/review/tests/it/signature.rs index 10b97eb78..ded6af396 100644 --- a/crates/review/tests/it/signature.rs +++ b/crates/review/tests/it/signature.rs @@ -7,7 +7,7 @@ use std::sync::Arc; use base64::{Engine as _, engine::general_purpose::STANDARD}; use craft_host::{AppInfo, Host, InlineJobs, Jobs, ManualJobs, MemorySections, Picked, ScriptedFiles, Section}; use craft_review::signature::{MAX_IMAGE_BYTES, SavedSignature, SignatureDraft, SignatureImage, SignatureTab}; -use craft_review::ui::{SignaturePadDialog, SignatureSettings}; +use craft_review::ui::{ScanEvent, SignaturePadDialog, SignatureSettings}; use craft_ui::contract::Role; use craft_ui::dialog::{DialogStack, StackDialog as _}; use craft_ui::popover::DropVeil; @@ -48,6 +48,27 @@ fn pad(draft: SignatureDraft) -> Rc> { Rc::new(RefCell::new(Pad { dialog, stack, ctx: None })) } +/// Clear must also reach scan-owned state so a later scan pass cannot restore the cleared image. +#[trial] +fn clearing_a_scan_does_not_let_the_scan_restore_the_image() { + let pad = pad(SignatureDraft { tab: SignatureTab::Scan, ..SignatureDraft::default() }); + let mut pending = true; + pad.borrow_mut().dialog = SignaturePadDialog::new(SignatureDraft { tab: SignatureTab::Scan, ..SignatureDraft::default() }) + .scan(move |_, draft, event| { + match event { + ScanEvent::Clear => pending = false, + ScanEvent::Show(_) if pending => draft.image = Some(SignatureImage::new(5, 1, PHOTO.to_vec())), + ScanEvent::Show(_) => {} + } + }); + let shown = pad.clone(); + let mut fx = Fixture::new(move |ui| show(&shown, ui)); + fx.room(vec2(900.0, 900.0)).settle(); + let clear = fx.by_label("Clear").expect("Clear is shown"); + fx.click(&clear).settle(); + assert!(saved(&pad).is_none(), "the cleared scan must not restore a pending result"); +} + /// Shows the dialog in `ui`. fn show(pad: &RefCell, ui: &mut Ui) { let mut pad = pad.borrow_mut();