mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 04:27:49 +00:00
Framework fwb9-c: port follow-ups (see runs/fwb9-c.md)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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")]
|
||||
|
||||
@@ -121,8 +121,13 @@ pub struct CommentMessage {
|
||||
pub reactions: Vec<Reaction>,
|
||||
/// 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 {
|
||||
|
||||
@@ -739,7 +739,7 @@ impl<H: Value> 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) {
|
||||
|
||||
@@ -229,13 +229,13 @@ pub(super) fn card_menu<H>(
|
||||
) -> Option<CardMenu> {
|
||||
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<H>(
|
||||
}
|
||||
});
|
||||
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() {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -403,10 +403,16 @@ fn pop_stroke(strokes: &mut Vec<Vec<[f32; 2]>>) -> 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<dyn FnMut(&mut egui::Ui, &mut SignatureDraft, Option<OsFile>) + 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<OsFile>),
|
||||
/// 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<dyn FnMut(&mut egui::Ui, &mut SignatureDraft, ScanEvent) + Send>;
|
||||
|
||||
/// 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<OsFile>) + 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);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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<OsFile>) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -19,6 +19,7 @@ fn thread() -> CommentThread {
|
||||
text: text.into(),
|
||||
reactions: Vec::new(),
|
||||
read: true,
|
||||
deletable: true,
|
||||
};
|
||||
CommentThread {
|
||||
id: ThreadId(7),
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<RefCell<Pad>> {
|
||||
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<Pad>, ui: &mut Ui) {
|
||||
let mut pad = pad.borrow_mut();
|
||||
|
||||
Reference in New Issue
Block a user