pdf-comments-w3: net change of 3 commits

- pdf-comments-w3: finished by an agent
- pdf-comments-w3: review fixes (review-1)
- pdf-comments-w3: review fixes (review-1b)
This commit is contained in:
Dylan M. Taylor
2026-11-18 06:54:15 -05:00
parent 8faf284b95
commit bac347860e
6 changed files with 872 additions and 93 deletions
+1 -1
View File
@@ -38,6 +38,6 @@ craft_ui::words! {
pin: template "thread.pin" = "Comment by {author}";
pin_text: template "thread.pinText" = "Comment by {author}: {words}";
cluster: template "thread.cluster" = "{n} comments";
note_title: "thread.noteTitle" = "Note";
note_title: template "thread.noteTitle" = "{kind} – {author}";
}
}
+528 -48
View File
@@ -2,10 +2,29 @@
use std::collections::HashMap;
use craft_ui::contract::SizeLimits;
use craft_ui::contract::overlay::PlacementKind;
use craft_ui::runtime::env::Label;
use egui::{Response, Ui, vec2};
use craft_behavior::{GesturePhase, IconId, Metrics, Sense};
use craft_theme::Opacity;
use craft_theme::variant::Variant;
use craft_ui::buttons::{Button, IconButton};
use craft_ui::contract::overlay::{PlacementChange, PlacementKind, ResizeEdges};
use craft_ui::contract::{
Bind, BindMut, BodyCx, Common, Component, Container, ContainerProps, Cx, DragBand, HeaderRegion, MeasureCx, Mount, NoValue, Outcome, Overlay,
PaintUi, Pattern, Props as _, Role, Show as _, ShowContainer as _, SizeLimits, clicked,
};
use craft_ui::display::{Shade, Text};
use craft_ui::layout_components::{Row, Stack};
use craft_ui::primitives::{IconSpec, PaintShape, TextRun, Wrap};
use craft_ui::runtime::env::{Env, EnvView, Label};
use craft_ui::runtime::overlay::CloseReason;
use craft_ui::style::{ComponentStyle, DataColor, StyleCx, SurfaceKind, TypeRole};
use craft_ui::text::TextField;
use egui::{Color32, CornerRadius, Pos2, Rect, Response, Ui, Vec2, pos2, vec2};
use crate::ui::annotate::DEFAULT_COLOR;
use crate::ui::avatar::Avatar;
use crate::ui::comments::age_text;
use super::ThreadWords;
/// One message of a note pop-up.
#[derive(Clone, Debug, PartialEq)]
@@ -26,16 +45,162 @@ pub struct NotePopupMessage<'a> {
pub editable: bool,
}
/// The pop-ups' reply drafts, one per note.
#[derive(Clone, Debug, Default)]
/// The pop-ups' drafts, by note: the typed text not yet committed, the open reply box and its text, and the window's
/// rect while a move or resize runs. The host keeps it, so a pop-up remembers nothing of its own across passes.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct NoteDrafts {
#[allow(dead_code)] // P3(pdf-comments-w3): CM-C17
drafts: HashMap<u64, String>,
texts: HashMap<u64, String>,
replies: HashMap<u64, (u64, String)>,
placing: HashMap<u64, Rect>,
}
/// The smallest size of a note pop-up, in points; it has no largest size.
impl NoteDrafts {
/// These drafts with the reply box of the note `note` open under its message `message`, on `text`, for a story that
/// shows the box.
#[cfg(feature = "screen-testing")]
pub(super) fn with_reply(mut self, note: u64, message: u64, text: &str) -> Self {
self.replies.insert(note, (message, text.to_owned()));
self
}
/// Forgets everything of the note `note`: the pop-up closed.
fn forget(&mut self, note: u64) {
self.texts.remove(&note);
self.replies.remove(&note);
self.placing.remove(&note);
}
/// Takes this pass's placement `changes` of the note `note`, whose window the host put at `window`: a running
/// gesture holds the window where it is, and a commit that changed the window by at least [`LEAST_CHANGE`] is the
/// report. Each pass applies only the changes its own input made, so a second pass in a frame changes nothing.
fn settle(&mut self, note: u64, window: Rect, changes: &[PlacementChange]) -> Option<(Rect, PlacementKind)> {
let mut placed = None;
for change in changes {
match change.phase {
GesturePhase::Begin | GesturePhase::Update => {
self.placing.insert(note, change.rect);
}
GesturePhase::Commit => {
self.placing.remove(&note);
if changed(window, change.rect) {
placed = Some((change.rect, change.kind));
}
}
_ => {
self.placing.remove(&note);
}
}
}
placed
}
}
/// The pop-up's body: the messages, each indented by its depth, then the reply box. It reads and writes the host's
/// drafts and gathers what the pass committed.
struct NoteBody<'a, 'm> {
id: u64,
messages: &'a [NotePopupMessage<'m>],
drafts: &'a mut NoteDrafts,
allowed: bool,
now: i64,
body: Option<String>,
reply: Option<(u64, String)>,
}
impl NoteBody<'_, '_> {
fn show(&mut self, ui: &mut Ui, words: &ThreadWords, view: &EnvView<'_>) {
let messages = self.messages;
Stack::new().fill_width().show(ui, |ui, _| {
for (index, message) in messages.iter().enumerate() {
let depth = u8::try_from(message.depth.min(MAX_NESTING)).unwrap_or(u8::MAX);
// The indent steps are the theme's, from the start edge.
Stack::new().fill_width().indent(depth).show(ui, |ui, _| {
if index > 0 {
byline(ui, message, view, self.now);
}
if index == 0 && self.allowed && message.editable {
self.note_text(ui, message, words);
} else {
Text::new(message.text.to_owned()).show(ui);
}
if self.allowed {
self.reply_box(ui, words, message.id);
}
});
}
});
}
/// The note's text, typed in place: it commits on focus loss, Escape drops what was typed.
fn note_text(&mut self, ui: &mut Ui, note: &NotePopupMessage<'_>, words: &ThreadWords) {
let id = self.id;
let mut text = self.drafts.texts.get(&id).cloned().unwrap_or_else(|| note.text.to_owned());
let field = TextField::new(words.add_comment.clone(), Bind::bound(&mut text)).lines(NOTE_ROWS).show(ui);
if let Some(committed) = field.events.committed().filter(|_| !field.escaped) {
self.body = edited(note.text, committed).or(self.body.take());
self.drafts.texts.remove(&id);
} else if field.escaped || text == note.text {
self.drafts.texts.remove(&id);
} else {
self.drafts.texts.insert(id, text);
}
}
/// The Reply button under the message `to`, or once it is pressed the box to answer that message in: Post or
/// Cmd/Ctrl+Enter posts the trimmed text, Cancel or Escape drops it. One box is open per note.
fn reply_box(&mut self, ui: &mut Ui, words: &ThreadWords, to: u64) {
let id = self.id;
let open = self.drafts.replies.get(&id).filter(|(target, _)| *target == to).map(|(_, text)| text.clone());
let Some(mut typed) = open else {
if clicked(&Button::new(words.reply.clone()).show(ui)) {
self.drafts.replies.insert(id, (to, String::new()));
}
return;
};
let field = TextField::new(words.reply.clone(), Bind::bound(&mut typed)).lines(NOTE_ROWS).placeholder(words.reply.clone()).submits().show(ui);
let text = typed.trim().to_owned();
// The multi-line field submits on Cmd/Ctrl+Enter; plain Enter adds a line.
let mut post = field.submitted && field.submit_mods.cmd;
let mut cancel = field.escaped;
Row::new().show(ui, |ui, _| {
post |= clicked(&Button::new(words.post.clone()).variant(Variant::PRIMARY).enabled(!text.is_empty()).show(ui));
cancel |= clicked(&Button::new(words.cancel.clone()).show(ui));
});
let posted = post && !text.is_empty();
if posted {
self.reply = Some((to, text));
}
if posted || cancel {
self.drafts.replies.remove(&id);
} else {
self.drafts.replies.insert(id, (to, typed));
}
}
}
/// A reply's author line: avatar, name and age.
fn byline(ui: &mut Ui, message: &NotePopupMessage<'_>, view: &EnvView<'_>, now: i64) {
Row::new().fill_width().show(ui, |ui, _| {
let _ = Avatar::new(message.author).show(ui);
Text::new(message.author.to_owned()).role(TypeRole::BodyStrong).show(ui);
let age = message.modified.map_or_else(String::new, |then| age_text(view, then, now));
Text::new(age).role(TypeRole::Caption).shade(Shade::Muted).show(ui);
});
}
/// The size a note pop-up keeps to, in points: 200 to 800 wide and 120 to 800 high, whatever size the file gives it.
pub const NOTE_POPUP_LIMITS: SizeLimits = SizeLimits::new(vec2(200.0, 120.0), vec2(800.0, 800.0));
/// The rows the note's text and a reply show.
const NOTE_ROWS: usize = 2;
/// Past this depth a reply indents no further.
const MAX_NESTING: usize = 8;
/// The least a move or resize changes the window by to be reported, in points: a press that ends where it began
/// changes nothing.
const LEAST_CHANGE: f32 = 2.0;
/// How opaque the connector wedge is: production's 90 of 255.
const CONNECTOR_SHARE: f32 = 90.0 / 255.0;
/// What a note pop-up did this pass.
#[derive(Debug)]
#[non_exhaustive]
@@ -46,84 +211,399 @@ pub struct NotePopupOutput {
pub closed: bool,
/// The note's edited text, once it is committed.
pub body: Option<String>,
/// A reply posted this pass.
pub reply: Option<String>,
/// A reply posted this pass: the id of the message it answers and the text.
pub reply: Option<(u64, String)>,
/// The window's new rectangle and the gesture that made it, reported when a move or resize commits.
pub placed: Option<(egui::Rect, PlacementKind)>,
}
/// A modeless note pop-up window over a note's messages. It keeps its size on screen at every zoom, so it takes no
/// zoom scale; a move or resize is reported as [`NotePopupOutput::placed`].
/// A modeless note pop-up window over a note's messages: a title band in the note's colour with its kind, author and
/// age, and Close; the note's text, typed in place while the note may be edited; its replies, each indented by its
/// depth; and a Reply button under each message that opens a box to answer it (Post or Cmd/Ctrl+Enter posts, Cancel
/// or Escape drops it).
///
/// - Place: at the host's `rect`, its size kept within [`NOTE_POPUP_LIMITS`] on screen at every zoom, so it takes no
/// zoom scale. The title band moves it and the lower end corner resizes it while commenting is allowed; a move or
/// resize is reported once as [`NotePopupOutput::placed`] when it commits, and one under 2 points is not.
/// - Text: the note's text commits when its field loses focus or the pop-up closes, with trailing whitespace trimmed.
/// - Connector: with [`anchor`](Self::anchor), a faint wedge joins the mark to the window while either is hovered or
/// the note is selected, and only while the two do not overlap.
#[must_use = "show the pop-up with `show`"]
#[allow(dead_code)] // P3(pdf-comments-w3): CM-C18
#[derive(Pattern)]
pub struct NotePopup<'a> {
id: u64,
label: Label,
rect: egui::Rect,
messages: &'a [NotePopupMessage<'a>],
drafts: &'a mut NoteDrafts,
color: Option<[u8; 3]>,
anchor: Option<(egui::Rect, bool)>,
selected: bool,
now: i64,
allowed: bool,
}
impl<'a> NotePopup<'a> {
/// The pop-up `id` named `label` at `rect` over `messages`, keeping its reply drafts in `drafts`.
pub fn new(id: u64, label: impl Into<Label>, rect: egui::Rect, messages: &'a [NotePopupMessage<'a>], drafts: &'a mut NoteDrafts) -> Self {
NotePopup { id, label: label.into(), rect, messages, drafts }
NotePopup { id, label: label.into(), rect, messages, drafts, color: None, anchor: None, selected: false, now: 0, allowed: true }
}
/// The note's colour, straight RGB.
/// The note's colour, straight RGB; `None` takes the default note colour.
#[must_use]
#[allow(dead_code)] // P3(pdf-comments-w3): CM-C18
pub fn color(self, color: Option<[u8; 3]>) -> Self {
let _ = color;
todo!("CM-C18")
}
/// Whether the note shows its checkmark.
#[must_use]
#[allow(dead_code)] // P3(pdf-comments-w3): CM-C18
pub fn mark(self, mark: bool) -> Self {
let _ = mark;
todo!("CM-C18")
pub fn color(mut self, color: Option<[u8; 3]>) -> Self {
self.color = color;
self
}
/// The annotation's screen rect (the first quad or the icon) and whether the host's page part is hovered: the
/// pop-up paints the faint connector from the mark to its window while `mark_hovered`, the window is hovered or the
/// note is selected, and only when the two do not overlap. It replaces `mark`.
/// note is selected, and only when the two do not overlap.
#[must_use]
#[allow(dead_code)] // P3(pdf-comments-w3): CM-C18
pub fn anchor(self, mark: egui::Rect, mark_hovered: bool) -> Self {
let _ = (mark, mark_hovered);
todo!("CM-C18")
pub fn anchor(mut self, mark: egui::Rect, mark_hovered: bool) -> Self {
self.anchor = Some((mark, mark_hovered));
self
}
/// Whether the note is the selected one.
#[must_use]
#[allow(dead_code)] // P3(pdf-comments-w3): CM-C18
pub fn selected(self, selected: bool) -> Self {
let _ = selected;
todo!("CM-C18")
pub fn selected(mut self, selected: bool) -> Self {
self.selected = selected;
self
}
/// The current time in Unix seconds, which the ages count from.
#[must_use]
#[allow(dead_code)] // P3(pdf-comments-w3): CM-C18
pub fn now(self, unix_seconds: i64) -> Self {
let _ = unix_seconds;
todo!("CM-C18")
pub fn now(mut self, unix_seconds: i64) -> Self {
self.now = unix_seconds;
self
}
/// Whether the document allows commenting: replying and editing.
#[must_use]
#[allow(dead_code)] // P3(pdf-comments-w3): CM-C18
pub fn allowed(self, allowed: bool) -> Self {
let _ = allowed;
todo!("CM-C18")
pub fn allowed(mut self, allowed: bool) -> Self {
self.allowed = allowed;
self
}
/// Shows the pop-up.
#[allow(dead_code)] // P3(pdf-comments-w3): CM-C18
pub fn show(self, ui: &mut Ui) -> NotePopupOutput {
let _ = ui;
todo!("CM-C18")
let NotePopup { id, label, rect, messages, drafts, color, anchor, selected, now, allowed } = self;
let env = Env::of(ui);
let words = env.words::<ThreadWords>();
let view = env.view();
let window = window_rect(rect);
let [r, g, b] = color.unwrap_or(DEFAULT_COLOR);
let fill = DataColor::new(Color32::from_rgb(r, g, b));
let note = messages.first();
let title = note.map_or_else(String::new, |note| {
if note.author.is_empty() { note.title.to_owned() } else { words.note_title.fill(&[("kind", note.title), ("author", note.author)]) }
});
let age = note.and_then(|note| note.modified).map_or_else(String::new, |then| age_text(&view, then, now));
// The grip sits at the lower end corner: the edges are physical, so it moves to the left under right to left.
let end = if env.direction.is_rtl() { ResizeEdges::LEFT } else { ResizeEdges::RIGHT };
let grip = if allowed { ResizeEdges::BOTTOM.union(end) } else { ResizeEdges::NONE };
// A running move or resize shows where the gesture holds the window; the host's rect changes once it commits.
let shown_at = drafts.placing.get(&id).copied().unwrap_or(window);
let overlay = Overlay::floating()
.modeless()
.movable(allowed)
.resize_edges(grip)
.body_scroll(true)
.size_limits(NOTE_POPUP_LIMITS)
.placed(shown_at);
let layer = NoteWindow::new(label, overlay, NoteLook { title, age, fill }, words.close.clone(), allowed, anchor, selected).id_salt(("note-popup", id));
let mut content = NoteBody { id, messages, drafts, allowed, now, body: None, reply: None };
let shown = layer.show(ui, |ui, _| content.show(ui, &words, &view));
let NoteBody { drafts, mut body, reply, .. } = content;
let out = shown.output;
let placed = drafts.settle(id, window, &out.changes);
if out.close {
// Close commits the typed text as a focus loss would.
if let (Some(note), Some(text)) = (note, drafts.texts.get(&id)) {
body = edited(note.text, text).or(body);
}
drafts.forget(id);
}
NotePopupOutput { response: out.response, closed: out.close, body, reply, placed }
}
}
/// The text a commit of `typed` reports for a note that reads `text`: trailing whitespace trimmed, `None` when that
/// leaves the text as it was.
fn edited(text: &str, typed: &str) -> Option<String> {
let typed = typed.trim_end();
(typed != text).then(|| typed.to_owned())
}
/// The window's rect on screen for the host's `rect`: its size kept within [`NOTE_POPUP_LIMITS`] (a side that is not
/// finite takes the least size) and its top left where the host put it (the screen's origin when that is not finite).
fn window_rect(rect: Rect) -> Rect {
let limits = NOTE_POPUP_LIMITS;
let most = limits.max.unwrap_or(Vec2::splat(SizeLimits::BOUND));
let side = |value: f32, least: f32, most: f32| if value.is_finite() { value.clamp(least, most) } else { least };
let size = vec2(side(rect.width(), limits.min.x, most.x), side(rect.height(), limits.min.y, most.y));
let min = if rect.min.is_finite() { rect.min } else { Pos2::ZERO };
Rect::from_min_size(min, size)
}
/// Whether a gesture that left the window at `to` from `from` is worth reporting: it moved a corner or changed a side
/// by at least [`LEAST_CHANGE`].
fn changed(from: Rect, to: Rect) -> bool {
(to.min - from.min).length() >= LEAST_CHANGE || (to.size() - from.size()).length() >= LEAST_CHANGE
}
/// The connector wedge from the mark to the window: its point on the mark where it is nearest the window, and the two
/// ends of its base (`half` wide each side of the middle) on the window's side that faces the mark. `None` without an
/// anchor, while neither the mark (`anchor`'s flag) nor the window (`hovered`) is hovered and the note is not
/// `selected`, and while the mark and the window overlap.
fn connector(anchor: Option<(Rect, bool)>, selected: bool, window: Rect, hovered: bool, half: f32) -> Option<[Pos2; 3]> {
let (mark, mark_hovered) = anchor?;
if !(mark_hovered || hovered || selected) || !mark.is_finite() || !window.is_positive() || mark.intersects(window) {
return None;
}
let from = nearest_on(mark, window.center());
let to = nearest_on(window, from);
let [start, end] = wedge_base(window, from, to, half);
Some([from, start, end])
}
/// The two ends of a connector's base on `window`: centred on `to` (the point of the window nearest the mark) along
/// the side that faces `from`, `half` each way and kept on that side. At a corner, the side is the one the mark lies
/// further beyond.
fn wedge_base(window: Rect, from: Pos2, to: Pos2, half: f32) -> [Pos2; 2] {
// `half` along [low, high] around `centre`, moved in to stay on the side (a side shorter than the base gives all
// of it).
let spread = |centre: f32, low: f32, high: f32| {
let half = half.min((high - low).max(0.0) / 2.0);
let centre = centre.clamp(low + half, high - half);
(centre - half, centre + half)
};
let on_horizontal = (to.y - window.top()).abs() < 0.5 || (to.y - window.bottom()).abs() < 0.5;
let on_vertical = (to.x - window.left()).abs() < 0.5 || (to.x - window.right()).abs() < 0.5;
let beyond_x = (from.x - to.x).abs() / window.width().max(1.0);
let beyond_y = (from.y - to.y).abs() / window.height().max(1.0);
if on_horizontal && !(on_vertical && beyond_x > beyond_y) {
let (a, b) = spread(to.x, window.left(), window.right());
[pos2(a, to.y), pos2(b, to.y)]
} else {
let (a, b) = spread(to.y, window.top(), window.bottom());
[pos2(to.x, a), pos2(to.x, b)]
}
}
/// The point of `rect`'s boundary nearest `point` (a point inside is pushed to the nearer vertical edge).
fn nearest_on(rect: Rect, point: Pos2) -> Pos2 {
let x = point.x.clamp(rect.left(), rect.right());
let y = point.y.clamp(rect.top(), rect.bottom());
if rect.left() < x && x < rect.right() && rect.top() < y && y < rect.bottom() {
pos2(if (point.x - rect.left()).abs() <= (point.x - rect.right()).abs() { rect.left() } else { rect.right() }, y)
} else {
pos2(x, y)
}
}
/// What the title band shows: the note's kind and author, its age, on the note's colour.
#[derive(Clone, Debug)]
struct NoteLook {
title: String,
age: String,
fill: DataColor,
}
/// The style of the note window's layer: the surface comes from the container.
#[derive(Clone, Debug, Default, PartialEq, ComponentStyle)]
#[non_exhaustive]
struct NoteWindowStyle {
#[style(metrics)]
metrics: Metrics,
/// Half the width of the connector wedge's base.
wedge: f32,
}
/// What the note window reports: its response, Close and the placement changes of this pass.
#[derive(Debug)]
struct NoteWindowOutput {
response: Response,
close: bool,
changes: Vec<PlacementChange>,
}
impl Outcome for NoteWindowOutput {
type Value = NoValue;
fn response(&self) -> &Response {
&self.response
}
}
/// The note pop-up's layer: a floating surface tinted with the note's colour, whose header is the title band (it
/// moves the layer) with Close at its end, under which it paints the connector wedge.
#[derive(craft_ui::contract::Component)]
#[component(container, unregistered)]
struct NoteWindow {
#[common]
common: Common,
#[container]
props: ContainerProps,
/// Open while the host shows the pop-up; the host shows it again each pass it wants it.
open: Bind<'static, bool>,
look: NoteLook,
close_label: Label,
allowed: bool,
anchor: Option<(Rect, bool)>,
selected: bool,
close: bool,
changes: Vec<PlacementChange>,
}
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));
NoteWindow {
common: Common::new(),
props,
open: Bind::given(true),
look,
close_label,
allowed,
anchor,
selected,
close: false,
changes: Vec::new(),
}
.label(label)
}
/// The wedge this pass, for the window at `response`'s rect: the window counts as hovered while the pointer is
/// over it, its children included (egui's `contains_pointer` of the topmost layer under the pointer).
fn wedge(&self, response: &Response, half: f32) -> Option<[Pos2; 3]> {
connector(self.anchor, self.selected, response.rect, response.contains_pointer(), half)
}
}
impl Component for NoteWindow {
const ROLE: Role = Role::GROUP;
const PARTS: bool = false;
const STOPS: bool = false;
type Style = NoteWindowStyle;
type Output = NoteWindowOutput;
fn style(cx: &StyleCx<'_>, _: NoteWindowStyleKey) -> NoteWindowStyle {
NoteWindowStyle { metrics: Metrics::new(), wedge: cx.tokens.space.gap.inline }
}
fn sense(&self) -> Sense {
Sense::HOVER
}
/// The body's tint over the surface, and the connector wedge, under the body.
fn paint(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) {
let draw = ui.draw();
let fill = self.look.fill;
draw.faded(Opacity::TINT, |draw| draw.data_fill(&PaintShape::Rect(cx.response.rect, CornerRadius::ZERO), fill));
if let Some(wedge) = self.wedge(&cx.response, cx.style.wedge) {
draw.faded(CONNECTOR_SHARE, |draw| draw.data_fill(&PaintShape::Polygon(wedge.to_vec()), fill));
}
}
fn finish(self, cx: Cx<'_, Self>) -> NoteWindowOutput {
NoteWindowOutput { response: cx.response.clone(), close: self.close, changes: self.changes }
}
}
impl Container for NoteWindow {
fn open(&mut self) -> Option<BindMut<'_, bool>> {
Some(self.open.reborrow())
}
/// The title band: the note's kind and author and its age, on the note's colour.
fn header(&mut self, ui: &mut Ui, _: &mut BodyCx<'_>) {
let look = self.look.clone();
let _ = NoteTitle { common: Common::new(), look: look.clone() }.label(look.title).show(ui);
}
/// Close, which needs the document to allow commenting, as closing changes the note.
fn controls(&mut self, ui: &mut Ui, _: &mut BodyCx<'_>) {
let close = IconButton::new(IconSpec::svg(IconId::new("close"))).label(self.close_label.clone()).enabled(self.allowed).show(ui);
self.close |= clicked(&close);
}
fn closed(&mut self, _: CloseReason) {
self.close = true;
}
fn placement_changed(&mut self, change: &PlacementChange) {
self.changes.push(*change);
}
}
/// The style of the title band.
#[derive(Clone, Debug, PartialEq, ComponentStyle)]
#[non_exhaustive]
struct NoteTitleStyle {
#[style(metrics)]
metrics: Metrics,
/// The band's height.
height: f32,
/// The padding at the start and the end.
pad_x: f32,
/// Between the title and the age.
gap: f32,
}
/// The title band of a note pop-up: the title (cut short to fit) at the start and the age at the end, in the ink that
/// reads on the note's colour.
#[derive(craft_ui::contract::Component)]
#[component(unregistered)]
struct NoteTitle {
#[common]
common: Common,
look: NoteLook,
}
impl Component for NoteTitle {
const ROLE: Role = Role::HEADING;
const PARTS: bool = false;
const OVERLAYS: bool = false;
type Style = NoteTitleStyle;
type Output = Response;
fn style(cx: &StyleCx<'_>, _: NoteTitleStyleKey) -> NoteTitleStyle {
let control = cx.control();
NoteTitleStyle { metrics: Metrics::new(), height: control.height, pad_x: control.pad_x, gap: cx.tokens.space.gap.inline }
}
fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 {
Vec2::new(cx.room.unwrap_or(0.0), cx.style.height)
}
fn sense(&self) -> Sense {
Sense::empty()
}
fn paint(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) {
let style = cx.style;
let draw = ui.draw();
let rect = cx.response.rect;
draw.data_fill(&PaintShape::Rect(rect, CornerRadius::ZERO), self.look.fill);
let ink = ui.with_style(Variant::SECONDARY, |styles| styles.ink_on(self.look.fill));
let inner = rect.shrink2(vec2(style.pad_x, 0.0));
let age = TextRun::new(self.look.age.as_str()).role(TypeRole::Caption).color(ink);
let age_size = if self.look.age.is_empty() { Vec2::ZERO } else { draw.layout(&age, f32::INFINITY).size() };
let room = (inner.width() - age_size.x - if age_size.x > 0.0 { style.gap } else { 0.0 }).max(0.0);
let title = TextRun::new(self.look.title.as_str()).role(TypeRole::BodyStrong).wrap(Wrap::Elide).color(ink);
let rtl = cx.env.direction().is_rtl();
let (title_x, age_x) = if rtl { (inner.right() - room, inner.left()) } else { (inner.left(), inner.right() - age_size.x) };
let line = draw.layout(&title, f32::INFINITY).size().y;
draw.text(Rect::from_min_size(pos2(title_x, inner.center().y - line / 2.0), Vec2::new(room, line)), &title);
if age_size.x > 0.0 {
let top = inner.center().y - age_size.y / 2.0;
draw.text(Rect::from_min_size(pos2(age_x, top), age_size), &age);
}
}
fn finish(self, cx: Cx<'_, Self>) -> Response {
cx.response.clone()
}
}
+66 -40
View File
@@ -3,7 +3,7 @@
use craft_behavior::IconId;
use craft_theme::variant::{Tone, Variant};
use craft_ui::buttons::{Button, IconButton, ToggleButton};
use craft_ui::contract::overlay::Anchor;
use craft_ui::contract::overlay::{Anchor, Dismiss, Outside};
use craft_ui::contract::{Bind, Pattern, Props as _, Remember as _, RowAlign, Show as _, ShowContainer as _, Trigger, clicked};
use craft_ui::display::{Shade, Text};
use craft_ui::layout_components::{Row, Stack};
@@ -234,43 +234,44 @@ impl ThreadPopover<'_> {
}
}
/// The floating composer card for a new comment at a point: a multi-line field with the focus, Post and
/// Cancel (Escape).
/// The floating composer card for a comment at a point: an optional title and author row, a multi-line field
/// with the focus, Post and Cancel (Escape). What Post sends follows the [`ComposerDraft`]; when the card closes
/// follows the [`ComposerClose`].
#[must_use = "show the composer with `show`"]
#[derive(Pattern)]
pub struct CommentComposer<'a> {
anchor: Option<Pos2>,
draft: &'a mut String,
header: Option<(Label, &'a str)>,
kind: ComposerDraft,
close: ComposerClose,
}
impl<'a> CommentComposer<'a> {
/// A composer at `anchor` (screen points; `None` hides it) that edits `draft`.
pub fn new(anchor: Option<Pos2>, draft: &'a mut String) -> Self {
CommentComposer { anchor, draft }
CommentComposer { anchor, draft, header: None, kind: ComposerDraft::New, close: ComposerClose::OnOutsidePress }
}
/// A header of `title` and the `author` above the field.
/// A header of `title` and the `author` above the field; the card is named `title`.
#[must_use]
#[allow(dead_code)] // P3(pdf-comments-w3): CM-C16
pub fn header(self, title: impl Into<Label>, author: &'a str) -> Self {
let _ = (title.into(), author);
todo!("CM-C16")
pub fn header(mut self, title: impl Into<Label>, author: &'a str) -> Self {
self.header = Some((title.into(), author));
self
}
/// The rule the post applies to the draft.
#[must_use]
#[allow(dead_code)] // P3(pdf-comments-w3): CM-C16
pub fn draft_kind(self, kind: ComposerDraft) -> Self {
let _ = kind;
todo!("CM-C16")
pub fn draft_kind(mut self, kind: ComposerDraft) -> Self {
self.kind = kind;
self
}
/// When the composer closes.
#[must_use]
#[allow(dead_code)] // P3(pdf-comments-w3): CM-C16
pub fn close(self, close: ComposerClose) -> Self {
let _ = close;
todo!("CM-C16")
pub fn close(mut self, close: ComposerClose) -> Self {
self.close = close;
self
}
}
@@ -287,6 +288,18 @@ pub enum ComposerDraft {
EditVerbatim,
}
impl ComposerDraft {
/// The text a post of `draft` sends, or `None` while this kind cannot post it: the one rule of the composer's Post
/// button and its Cmd/Ctrl+Enter.
fn posted(self, draft: &str) -> Option<String> {
match self {
ComposerDraft::New => Some(draft.trim_end()).filter(|text| !text.is_empty()).map(str::to_owned),
ComposerDraft::Edit => Some(draft.trim_end().to_owned()),
ComposerDraft::EditVerbatim => Some(draft.to_owned()),
}
}
}
/// When a composer closes.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
@@ -312,38 +325,51 @@ pub struct CommentComposerOutput {
impl CommentComposer<'_> {
/// Shows the composer and reports whether the user posted or closed it.
pub fn show(self, ui: &mut Ui) -> CommentComposerOutput {
let CommentComposer { anchor, draft } = self;
let CommentComposer { anchor, draft, header, kind, close } = self;
let mut output = CommentComposerOutput::default();
let Some(anchor) = anchor else { return output };
let words = Env::of(ui).words::<ThreadWords>();
let mut open = true;
let mut posted = None;
let mut cancel = false;
let shown =
Popover::new(words.add_comment.clone(), Bind::bound(&mut open)).at_point(anchor).initial_focus(Initial::Default).show(ui, |ui, _| {
Stack::new().show(ui, |ui, _| {
let field = TextField::new(words.add_comment.clone(), Bind::bound(&mut *draft))
.lines(COMPOSER_ROWS)
.placeholder(words.add_comment.clone())
.submits()
.default_stop()
.show(ui);
cancel |= field.escaped;
let text = draft.trim().to_owned();
// The multi-line field submits on Cmd/Ctrl+Enter; plain Enter adds a line.
if field.submitted && field.submit_mods.cmd && !text.is_empty() {
posted = Some(text.clone());
}
Row::new().show(ui, |ui, _| {
let post = Button::new(words.post.clone()).enabled(!text.is_empty()).show(ui);
if clicked(&post) && !text.is_empty() {
posted = Some(text.clone());
}
let close = Button::new(words.cancel.clone()).show(ui);
cancel |= clicked(&close);
let name = header.as_ref().map_or_else(|| words.add_comment.clone(), |(title, _)| title.clone());
let mut popover = Popover::new(name, Bind::bound(&mut open)).at_point(anchor).initial_focus(Initial::Default);
if close == ComposerClose::OnPostOrCancel {
popover = popover.overlay(|overlay| overlay.dismiss(Dismiss::new().outside(Outside::Keep)));
}
let shown = popover.show(ui, |ui, _| {
Stack::new().show(ui, |ui, _| {
if let Some((title, author)) = &header {
Row::new().fill_width().show(ui, |ui, _| {
let _ = Avatar::new(*author).show(ui);
Stack::new().fill_width().show(ui, |ui, _| {
Text::new(title.clone()).role(TypeRole::BodyStrong).show(ui);
Text::new(author.to_string()).role(TypeRole::Caption).shade(Shade::Muted).show(ui);
});
});
}
let field = TextField::new(words.add_comment.clone(), Bind::bound(&mut *draft))
.lines(COMPOSER_ROWS)
.placeholder(words.add_comment.clone())
.submits()
.default_stop()
.show(ui);
cancel |= field.escaped;
let text = kind.posted(draft);
// The multi-line field submits on Cmd/Ctrl+Enter; plain Enter adds a line.
if field.submitted && field.submit_mods.cmd && text.is_some() {
posted.clone_from(&text);
}
Row::new().show(ui, |ui, _| {
let post = Button::new(words.post.clone()).enabled(text.is_some()).show(ui);
if clicked(&post) && text.is_some() {
posted.clone_from(&text);
}
let cancelled = Button::new(words.cancel.clone()).show(ui);
cancel |= clicked(&cancelled);
});
});
});
let closed = !open || shown.output.closed.is_some();
if posted.is_some() || cancel || closed {
draft.clear();
+98 -4
View File
@@ -1,12 +1,12 @@
//! Stories of the pins, the thread popover and the composer.
use craft_ui::buttons::Button;
use craft_ui::contract::Show as _;
use craft_ui::contract::{Show as _, clicked};
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
use egui::{Ui, pos2};
use egui::{Rect, Ui, pos2, vec2};
use super::pins::{Face, PinBubble};
use super::{CommentComposer, CommentPin, CommentPins, ThreadPopover};
use super::{CommentComposer, CommentPin, CommentPins, ComposerClose, ComposerDraft, NoteDrafts, NotePopup, NotePopupMessage, ThreadPopover};
use crate::comments::{CommentAnchor, CommentMessage, CommentThread, ReviewStatus, ThreadId};
const NOW: i64 = 90_000;
@@ -27,7 +27,7 @@ fn thread() -> CommentThread {
color: None,
messages: vec![message("Ana", "Check @Bo before we ship.", NOW - 7_200), message("Bo", "On it.", NOW - 600)],
status: ReviewStatus::None,
statuses: Vec::new(), // P3(pdf-comments-w3): CM-C19
statuses: Vec::new(),
marked: false,
locked: false,
resolved: false,
@@ -72,3 +72,97 @@ fn comment_composer_open(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let _ = CommentComposer::new(Some(pos2(40.0, 60.0)), draft).show(ui);
opener.into()
}
#[story(CommentComposer<'static>, covers = [], drive = Drive::Never)]
fn comment_composer_edit_draft(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let opener = Button::new("Edit").show(ui);
let draft = data.value("draft", "Move this heading up.\n\n".to_owned());
let _ = CommentComposer::new(Some(pos2(40.0, 60.0)), draft)
.header("Typewriter", "Ana")
.draft_kind(ComposerDraft::EditVerbatim)
.close(ComposerClose::OnPostOrCancel)
.show(ui);
opener.into()
}
#[story(CommentComposer<'static>, covers = [], drive = Drive::Never)]
fn comment_composer_long_text(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let opener = Button::new("Add").show(ui);
let text = "The caption under the second figure runs into the margin on the printed proof, and the figure number \
does not match the one the text cites. Check both against the list of figures before the next round.";
let draft = data.value("draft", text.to_owned());
let _ = CommentComposer::new(Some(pos2(40.0, 60.0)), draft).header("Sticky Note", "Bo").draft_kind(ComposerDraft::Edit).show(ui);
opener.into()
}
/// A note's message: the note itself at depth 0, a reply deeper.
fn note_message(id: u64, author: &'static str, text: &'static str, depth: usize) -> NotePopupMessage<'static> {
NotePopupMessage { id, title: "Sticky Note", author, text, modified: Some(NOW - 600 * id as i64), depth, editable: depth == 0 }
}
/// A note pop-up over `messages`, opened from a button: the button's rect stands for the note's mark.
/// The drafts and the window's rect live in the story's data, as a host keeps them, so a reply box, typed text, a move
/// and a resize last across frames.
fn note_popup(ui: &mut Ui, data: &mut StoryData, messages: &[NotePopupMessage<'_>], allowed: bool, drafts: NoteDrafts) -> StoryOutput {
let opener = Button::new("Open note").show(ui);
let open = data.value("open", false);
*open |= clicked(&opener);
if *open {
let mark = opener.rect;
let at = *data.value("rect", None::<Rect>);
let rect = at.unwrap_or_else(|| Rect::from_min_size(mark.right_bottom() + vec2(80.0, 40.0), vec2(260.0, 200.0)));
let drafts = data.value("drafts", drafts);
let shown = NotePopup::new(1, "Note", rect, messages, drafts)
.color(Some([224, 48, 48]))
.anchor(mark, opener.hovered())
.now(NOW)
.allowed(allowed)
.show(ui);
if let Some((placed, _)) = shown.placed {
*data.value("rect", None::<Rect>) = Some(placed);
}
*data.value("open", false) = !shown.closed;
}
opener.into()
}
#[story(NotePopup<'static>, covers = [Default], drive = Drive::Never)]
fn note_popup_open(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let messages = [note_message(1, "Ana", "Tighten the leading in this paragraph.", 0)];
note_popup(ui, data, &messages, true, NoteDrafts::default())
}
#[story(NotePopup<'static>, covers = [], drive = Drive::Never)]
fn note_popup_replies(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let messages = [
note_message(1, "Ana", "Tighten the leading in this paragraph.", 0),
note_message(2, "Bo", "How tight? 12 on 14?", 1),
note_message(3, "Ana", "12 on 13.5.", 2),
];
note_popup(ui, data, &messages, true, NoteDrafts::default())
}
#[story(NotePopup<'static>, covers = [], drive = Drive::Never)]
fn note_popup_reply_box(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let messages = [note_message(1, "Ana", "Tighten the leading in this paragraph.", 0)];
note_popup(ui, data, &messages, true, NoteDrafts::default().with_reply(1, 1, "Done in the next proof."))
}
#[story(NotePopup<'static>, covers = [], drive = Drive::Never)]
fn note_popup_locked(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let messages = [note_message(1, "Ana", "Signed off; no more changes.", 0), note_message(2, "Bo", "Agreed.", 1)];
note_popup(ui, data, &messages, false, NoteDrafts::default())
}
#[story(NotePopup<'static>, covers = [], drive = Drive::Never)]
fn note_popup_long_thread(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let text = "The running head on the left pages still shows the old chapter title, and the folio drops below the \
trim on pages 40 to 52. Both need fixing before the files go to the printer.";
let mut messages = vec![note_message(1, "Ana", text, 0)];
// Deeper than the indent goes, so the last replies stop nesting.
for depth in 1..=10 {
let author = if depth % 2 == 0 { "Ana" } else { "Bo" };
messages.push(note_message(depth as u64 + 1, author, "Checked; see the next reply.", depth));
}
note_popup(ui, data, &messages, true, NoteDrafts::default())
}
+1
View File
@@ -3,3 +3,4 @@
mod annotate;
mod collab;
mod comments;
mod note_popup;
+178
View File
@@ -0,0 +1,178 @@
//! The note pop-up's hover and selection, its corner grip, and when the comment composer closes.
use std::cell::{Cell, RefCell};
use std::rc::Rc;
use craft_review::ui::{CommentComposer, ComposerClose, NOTE_POPUP_LIMITS, NoteDrafts, NotePopup, NotePopupMessage};
use craft_ui::buttons::Button;
use craft_ui::contract::Show as _;
use craft_ui::contract::overlay::PlacementKind;
use craft_ui::testing::{Fixture, trial};
use egui::{Event, Rect, pos2, vec2};
/// How far a measured rect may sit from the expected one.
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 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 {
rect: Cell<Rect>,
selected: Cell<bool>,
mark: Cell<Rect>,
window: Cell<Rect>,
placed: RefCell<Vec<(Rect, PlacementKind)>>,
}
impl NoteHost {
fn new(rect: Rect) -> Rc<Self> {
Rc::new(NoteHost {
rect: Cell::new(rect),
selected: Cell::new(false),
mark: Cell::new(Rect::NOTHING),
window: Cell::new(Rect::NOTHING),
placed: RefCell::new(Vec::new()),
})
}
/// A settled fixture that shows the mark and the pop-up.
fn fixture(host: &Rc<Self>) -> Fixture {
let shown = Rc::clone(host);
let mut drafts = NoteDrafts::default();
let mut fixture = Fixture::new(move |ui| {
let mark = Button::new("Mark").show(ui);
let out = NotePopup::new(1, "Note", shown.rect.get(), &NOTE, &mut drafts)
.anchor(mark.rect, mark.hovered())
.selected(shown.selected.get())
.show(ui);
shown.mark.set(mark.rect);
shown.window.set(out.response.rect);
if let Some((rect, kind)) = out.placed {
shown.rect.set(rect);
shown.placed.borrow_mut().push((rect, kind));
}
});
fixture.room(vec2(1000.0, 800.0)).settle();
fixture
}
}
/// Hovering the mark or the window and selecting the note leave the window where it is and report no placement; the
/// connector is painted by the window itself and is covered by the stories.
#[trial]
fn hovering_the_mark_or_window_or_selecting_the_note_reports_no_placement() {
let host = NoteHost::new(Rect::from_min_size(pos2(400.0, 300.0), vec2(240.0, 160.0)));
let mut fixture = NoteHost::fixture(&host);
let (mark, window) = (host.mark.get(), host.window.get());
assert!(window.is_positive() && !mark.intersects(window), "the window shows apart from the mark: {mark:?}, {window:?}");
for at in [pos2(900.0, 40.0), mark.center(), window.center()] {
fixture.frame(vec![Event::PointerMoved(at)]).settle();
assert!((host.window.get().min - window.min).length() < SLACK, "the pointer at {at:?} leaves the window: {:?}", host.window.get());
}
host.selected.set(true);
fixture.settle();
assert!((host.window.get().min - window.min).length() < SLACK, "a selected note stays put: {:?}", host.window.get());
// The window over the mark shows too.
host.rect.set(Rect::from_min_size(mark.min, vec2(240.0, 160.0)));
fixture.settle();
assert!(host.window.get().intersects(mark), "the window lies over the mark: {:?}", host.window.get());
assert!(host.placed.borrow().is_empty(), "no hover or selection is a placement: {:?}", host.placed.borrow());
}
/// The lower end corner resizes the window within `NOTE_POPUP_LIMITS`; a press that moves under 2 points reports
/// nothing, and a resize reports `placed` once, when the drag is released.
#[trial]
fn a_corner_drag_resizes_within_the_limits_and_reports_on_release() {
let start = Rect::from_min_size(pos2(300.0, 200.0), vec2(240.0, 160.0));
let host = NoteHost::new(start);
let mut fixture = NoteHost::fixture(&host);
let window = host.window.get();
assert!((window.size() - start.size()).length() < SLACK, "the window shows at the host's size: {window:?}");
// A press on the grip that hardly moves changes nothing.
fixture.drag_at(window.max, vec2(1.0, 0.5)).settle();
assert!(host.placed.borrow().is_empty(), "a move under 2 pt reports nothing: {:?}", host.placed.borrow());
assert!((host.window.get().size() - start.size()).length() < SLACK, "the window keeps its size: {:?}", host.window.get());
// The window follows the drag while it runs, and the report waits for the release.
let grow = vec2(60.0, 40.0);
fixture.drag_at_pausing(window.max, grow, |fixture| {
fixture.idle(1);
assert!(host.placed.borrow().is_empty(), "nothing is reported while the drag runs: {:?}", host.placed.borrow());
assert!(host.window.get().width() > start.width() + grow.x / 2.0, "the window follows the drag: {:?}", host.window.get());
});
fixture.settle();
let placed = host.placed.borrow().clone();
assert_eq!(placed.len(), 1, "one report when the drag commits: {placed:?}");
let (rect, kind) = placed[0];
assert!(matches!(kind, PlacementKind::Size(_)), "the grip reports a resize: {kind:?}");
assert!((rect.size() - (start.size() + grow)).length() < SLACK, "the window grew by the drag: {rect:?}");
assert!((rect.min - start.min).length() < SLACK, "the top left stays: {rect:?}");
assert!((host.window.get().size() - rect.size()).length() < SLACK, "the window takes the reported size: {:?}", host.window.get());
// Past the least size the window stops there.
host.placed.borrow_mut().clear();
fixture.drag_at(host.window.get().max, vec2(-400.0, -400.0)).settle();
let placed = host.placed.borrow().clone();
assert_eq!(placed.len(), 1, "one report for the second drag: {placed:?}");
let (rect, _) = placed[0];
assert!((rect.size() - NOTE_POPUP_LIMITS.min).length() < SLACK, "the window stops at its least size: {rect:?}");
}
/// The host of one composer: it shows the composer until it posts or cancels.
struct ComposerHost {
open: Cell<bool>,
posted: RefCell<Option<String>>,
cancelled: Cell<bool>,
draft: RefCell<String>,
}
/// Where a press lands outside the composer's card.
const OUTSIDE: egui::Pos2 = egui::Pos2::new(700.0, 550.0);
/// `ComposerClose::OnPostOrCancel` keeps the card open on a press outside and closes it on Post or Cancel; the default
/// closes it on the press outside.
#[trial]
fn a_composer_kept_open_on_outside_press_closes_only_on_post_or_cancel() {
for close in [ComposerClose::OnPostOrCancel, ComposerClose::OnOutsidePress] {
let host = Rc::new(ComposerHost { open: Cell::new(true), posted: RefCell::new(None), cancelled: Cell::new(false), draft: RefCell::new(String::new()) });
let shown = Rc::clone(&host);
let mut fixture = Fixture::new(move |ui| {
if !shown.open.get() {
return;
}
let mut draft = shown.draft.borrow_mut();
let out = CommentComposer::new(Some(pos2(200.0, 200.0)), &mut draft).close(close).show(ui);
if out.cancelled {
shown.cancelled.set(true);
shown.open.set(false);
}
if let Some(text) = out.posted {
*shown.posted.borrow_mut() = Some(text);
shown.open.set(false);
}
});
fixture.room(vec2(800.0, 600.0)).settle();
assert!(fixture.by_label("Post").is_some(), "{close:?}: the composer shows");
fixture.click_at(OUTSIDE).settle();
if close != ComposerClose::OnPostOrCancel {
assert!(host.cancelled.get() && !host.open.get(), "{close:?}: a press outside closes the composer");
continue;
}
assert!(host.open.get() && !host.cancelled.get(), "{close:?}: a press outside keeps the composer open");
assert!(fixture.by_label("Post").is_some(), "{close:?}: the card still shows");
// The field has the focus as the card opens.
fixture.type_text("Looks good ").settle();
let post = fixture.by_label("Post").expect("the Post button");
fixture.click(&post).settle();
assert_eq!(host.posted.borrow().as_deref(), Some("Looks good"), "{close:?}: Post sends the draft, trailing blanks trimmed");
assert!(!host.open.get(), "{close:?}: Post closes the composer");
host.open.set(true);
fixture.settle();
fixture.click_at(OUTSIDE).settle();
assert!(host.open.get() && !host.cancelled.get(), "{close:?}: the reopened card stays open on a press outside");
let cancel = fixture.by_label("Cancel").expect("the Cancel button");
fixture.click(&cancel).settle();
assert!(host.cancelled.get() && !host.open.get(), "{close:?}: Cancel closes the composer");
}
}