mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-18 08:07:26 +00:00
Merge pull request #2211 from TrevorBrown-dev/feat/present-add-comment-2209
M7: Present mode: a click in comment mode adds a comment on the frame (#2209)
This commit is contained in:
7 files changed
+307
-37
No files matched your search
@@ -312,9 +312,12 @@ fn own(cmd: &str, m: &Message, who: &str, what: &str) -> crate::Result<()> {
|
||||
}
|
||||
|
||||
/// A node to pin to: a node id on `page`, `true` for the innermost frame under the point, else none.
|
||||
fn anchor_at(doc: &Document, page: NodeId, x: f64, y: f64, v: Option<&Value>) -> Option<NodeId> {
|
||||
fn anchor_at(doc: &Document, page: NodeId, x: f64, y: f64, v: Option<&Value>, within: Option<NodeId>) -> Option<NodeId> {
|
||||
match v {
|
||||
Some(Value::Bool(true)) => frame_at(doc, page, x, y),
|
||||
Some(Value::Bool(true)) => match within.filter(|w| *w != page && doc.page_of(*w) == Some(page) && contains(doc, *w, x, y)) {
|
||||
Some(w) => frame_in(doc, w, x, y, Some(w)),
|
||||
None => frame_at(doc, page, x, y),
|
||||
},
|
||||
Some(v) => id_of(v).filter(|a| *a != page && doc.page_of(*a) == Some(page)),
|
||||
None => None,
|
||||
}
|
||||
@@ -670,7 +673,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
spec!(
|
||||
"comment.add",
|
||||
"Add comment",
|
||||
"{x, y, text, page?, author?, anchor? (node id to pin to; true = innermost frame under the point)}",
|
||||
"{x, y, text, page?, author?, anchor? (node id to pin to; true = innermost frame under the point), within? (with anchor true: search only inside this frame on the page, which is the anchor when no child holds the point)}",
|
||||
true,
|
||||
|s, p| {
|
||||
let x = req_num("comment.add", p, "x")?;
|
||||
@@ -682,7 +685,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
if !doc.pages.contains(&page) {
|
||||
return Err(bad("comment.add", format!("{page} is not a page")));
|
||||
}
|
||||
let anchor = anchor_at(doc, page, x, y, get(p, "anchor"));
|
||||
let anchor = anchor_at(doc, page, x, y, get(p, "anchor"), id(p, "within"));
|
||||
let (lx, ly) = local(doc, anchor, x, y);
|
||||
let mut c = Comment {
|
||||
id: s.doc_mut()?.new_comment_id(),
|
||||
@@ -772,7 +775,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
let (x, y) = (req_num("comment.move", p, "x")?, req_num("comment.move", p, "y")?);
|
||||
let doc = s.doc()?;
|
||||
let page = doc.comment(id).map(|c| c.page).ok_or_else(|| bad("comment.move", "no comment"))?;
|
||||
let anchor = anchor_at(doc, page, x, y, Some(get(p, "anchor").unwrap_or(&Value::Bool(true))));
|
||||
let anchor = anchor_at(doc, page, x, y, Some(get(p, "anchor").unwrap_or(&Value::Bool(true))), None);
|
||||
let (lx, ly) = local(doc, anchor, x, y);
|
||||
if let Some(c) = s.doc_mut()?.comment_mut(id) {
|
||||
(c.x, c.y, c.anchor) = (lx, ly, anchor);
|
||||
@@ -974,9 +977,20 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
|
||||
/// Innermost frame (or component/instance/section) under a page point, for anchoring.
|
||||
fn frame_at(doc: &Document, page: NodeId, x: f64, y: f64) -> Option<NodeId> {
|
||||
frame_in(doc, page, x, y, None)
|
||||
}
|
||||
|
||||
/// Whether the page point lies inside node `n`'s box.
|
||||
fn contains(doc: &Document, n: NodeId, x: f64, y: f64) -> bool {
|
||||
let Some(node) = doc.node(n) else { return false };
|
||||
let l = doc.world_transform(n).inverse() * geom::Point::new(x, y);
|
||||
l.x >= 0.0 && l.y >= 0.0 && l.x <= node.width && l.y <= node.height
|
||||
}
|
||||
|
||||
/// The innermost frame-like or section under the point, searching from `root` (with `found` as the fallback).
|
||||
fn frame_in(doc: &Document, root: NodeId, x: f64, y: f64, mut found: Option<NodeId>) -> Option<NodeId> {
|
||||
let pt = geom::Point::new(x, y);
|
||||
let mut found = None;
|
||||
let mut stack = vec![page];
|
||||
let mut stack = vec![root];
|
||||
while let Some(parent) = stack.pop() {
|
||||
let Some(n) = doc.node(parent) else { continue };
|
||||
for c in n.children.iter().rev() {
|
||||
@@ -1012,6 +1026,25 @@ mod tests {
|
||||
assert_eq!(super::parse_link("figcraft://comment/5/"), Some(5));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn comment_add_within_anchors_to_the_presented_frame() {
|
||||
let mut s = Session::new();
|
||||
let mk = |s: &mut Session, params: serde_json::Value| crate::params::id_of(&s.execute("node.create", ¶ms).unwrap()["id"]).unwrap();
|
||||
let a = mk(&mut s, json!({"type": "frame", "x": 0, "y": 0, "width": 200, "height": 200}));
|
||||
let b = mk(&mut s, json!({"type": "frame", "x": 100, "y": 0, "width": 200, "height": 200}));
|
||||
let anchor = |s: &mut Session, params: serde_json::Value| {
|
||||
let c = s.execute("comment.add", ¶ms).unwrap();
|
||||
let id = c["id"].as_u64().unwrap();
|
||||
s.doc().unwrap().comment(id).unwrap().anchor
|
||||
};
|
||||
assert_eq!(anchor(&mut s, json!({"x": 150, "y": 50, "text": "t", "anchor": true})), Some(b));
|
||||
assert_eq!(anchor(&mut s, json!({"x": 150, "y": 50, "text": "t", "anchor": true, "within": a})), Some(a));
|
||||
let c = mk(&mut s, json!({"type": "frame", "x": 120, "y": 20, "width": 50, "height": 50, "parent": a}));
|
||||
assert_eq!(anchor(&mut s, json!({"x": 130, "y": 30, "text": "t", "anchor": true, "within": a})), Some(c));
|
||||
// A point outside `within` ignores it.
|
||||
assert_eq!(anchor(&mut s, json!({"x": 250, "y": 50, "text": "t", "anchor": true, "within": a})), Some(b));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn comment_thread_lifecycle_and_anchoring() {
|
||||
let mut s = Session::new();
|
||||
|
||||
@@ -830,37 +830,53 @@ fn escape(app: &mut FigApp, ctx: &egui::Context) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// The draft's composer next to its pin at `at` (screen), kept inside `bounds`; posting adds the
|
||||
/// comment (on `page` when given, else the current one) and shows its thread. The editor and the
|
||||
/// presenter both draw it here.
|
||||
///
|
||||
/// `target` is the page and the presented frame when called from the presenter: the comment then
|
||||
/// anchors within that frame. A comment that fails to post leaves the draft and its text.
|
||||
fn draft_composer(app: &mut FigApp, ctx: &egui::Context, at: Pos2, bounds: Rect, target: Option<(NodeId, NodeId)>) {
|
||||
let Some((x, y, mut text)) = app.ui.comments.draft.clone() else { return };
|
||||
let t = Tokens::get(ctx);
|
||||
let people = app.session.doc().map(|d| d.comment_people()).unwrap_or_default();
|
||||
let me = me(app);
|
||||
let mut pick = std::mem::take(&mut app.ui.comments.mention);
|
||||
let mut post = false;
|
||||
egui::Area::new(Id::unique("comment_draft")).order(egui::Order::Foreground).fixed_pos(popover_pos(at, bounds)).show(ctx, |ui| {
|
||||
popover_frame(&t).show(ui, |ui| {
|
||||
ui.set_width(POPOVER_W - 24.0);
|
||||
post = composer(ui, Id::unique("comment_draft_text"), &mut text, tr("Add a comment"), &people, &me, &mut pick);
|
||||
});
|
||||
});
|
||||
app.ui.comments.mention = pick;
|
||||
if post {
|
||||
let mut params = json!({"x": x, "y": y, "text": text.trim(), "anchor": true});
|
||||
if let (Some((page, frame)), Some(o)) = (target, params.as_object_mut()) {
|
||||
o.insert("page".into(), json!(page));
|
||||
o.insert("within".into(), json!(frame));
|
||||
}
|
||||
if let Some(r) = app.run("comment.add", params) {
|
||||
app.ui.comments.draft = None;
|
||||
if let Some(id) = r.get("id").and_then(Value::as_u64) {
|
||||
app.ui.comments.show(id);
|
||||
}
|
||||
} else if let Some(d) = &mut app.ui.comments.draft {
|
||||
d.2 = text;
|
||||
}
|
||||
} else if let Some(d) = &mut app.ui.comments.draft {
|
||||
d.2 = text;
|
||||
}
|
||||
}
|
||||
|
||||
/// The thread popover and the draft composer, floating next to their pins on the canvas.
|
||||
pub fn popovers(app: &mut FigApp, ctx: &egui::Context) {
|
||||
if escape(app, ctx) {
|
||||
return;
|
||||
}
|
||||
let canvas = app.canvas.rect;
|
||||
if let Some((x, y, mut text)) = app.ui.comments.draft.clone() {
|
||||
let t = Tokens::get(ctx);
|
||||
let people = app.session.doc().map(|d| d.comment_people()).unwrap_or_default();
|
||||
let me = me(app);
|
||||
let mut pick = std::mem::take(&mut app.ui.comments.mention);
|
||||
let mut post = false;
|
||||
egui::Area::new(Id::unique("comment_draft")).order(egui::Order::Foreground).fixed_pos(popover_pos(app.to_screen(x, y), canvas)).show(
|
||||
ctx,
|
||||
|ui| {
|
||||
popover_frame(&t).show(ui, |ui| {
|
||||
ui.set_width(POPOVER_W - 24.0);
|
||||
post = composer(ui, Id::unique("comment_draft_text"), &mut text, tr("Add a comment"), &people, &me, &mut pick);
|
||||
});
|
||||
},
|
||||
);
|
||||
app.ui.comments.mention = pick;
|
||||
if post {
|
||||
let r = app.run("comment.add", json!({"x": x, "y": y, "text": text.trim(), "anchor": true}));
|
||||
app.ui.comments.draft = None;
|
||||
if let Some(id) = r.and_then(|v| v.get("id").and_then(Value::as_u64)) {
|
||||
app.ui.comments.show(id);
|
||||
}
|
||||
} else if let Some(d) = &mut app.ui.comments.draft {
|
||||
d.2 = text;
|
||||
}
|
||||
if let Some((x, y, _)) = app.ui.comments.draft {
|
||||
draft_composer(app, ctx, app.to_screen(x, y), canvas, None);
|
||||
return;
|
||||
}
|
||||
let Some(open) = app.ui.comments.open else { return };
|
||||
@@ -1228,6 +1244,34 @@ pub fn presenter(app: &mut FigApp, ctx: &egui::Context, frame: NodeId, place: cr
|
||||
if let Some(id) = clicked {
|
||||
toggle(app, id);
|
||||
}
|
||||
// A click on the presented frame (not on a pin or a popover) starts a comment there: the
|
||||
// presented point back to the frame as designed.
|
||||
let frame_rect = place.rect(fb).intersect(clip);
|
||||
let click = ctx.input(|i| if i.pointer.primary_clicked() { i.pointer.interact_pos() } else { None });
|
||||
// The draft's own pin isn't interactable, so a click on it would start a new draft and lose
|
||||
// the typed text: it is left alone.
|
||||
let draft_pin = app.ui.comments.draft.as_ref().map(|(x, y, _)| pin_rect(to_screen((*x, *y))));
|
||||
if clicked.is_none()
|
||||
&& let Some(q) = click.filter(|q| frame_rect.contains(*q) && !draft_pin.is_some_and(|r| r.contains(*q)))
|
||||
&& ctx.layer_id_at(q).is_none_or(|l| l.order == egui::Order::Background)
|
||||
{
|
||||
let pt = place.page(q);
|
||||
start_draft(app, fb.x0 + (pt.x - place.page_min.0), fb.y0 + (pt.y - place.page_min.1));
|
||||
}
|
||||
if let Some((x, y, _)) = app.ui.comments.draft {
|
||||
let at = to_screen((x, y));
|
||||
let r = pin_rect(at);
|
||||
egui::Area::new(Id::unique("present_comment_draft_pin")).order(egui::Order::Foreground).fixed_pos(r.min).interactable(false).show(
|
||||
ctx,
|
||||
|ui| {
|
||||
let (rr, _) = ui.allocate_exact_size(r.size(), Sense::hover());
|
||||
ui.painter().rect_filled(rr, BUBBLE, ACCENT);
|
||||
ui.painter().circle_filled(rr.center(), 3.0, crate::theme::ACCENT_ON);
|
||||
},
|
||||
);
|
||||
draft_composer(app, ctx, at, ctx.content_rect(), doc.page_of(frame).map(|page| (page, frame)));
|
||||
return;
|
||||
}
|
||||
match app.ui.comments.open.and_then(|o| pins.iter().find(|p| p.id == o)) {
|
||||
Some(p) => thread(app, ctx, p.id, p.at, ctx.content_rect()),
|
||||
// A thread on another frame (or none) closes.
|
||||
|
||||
@@ -272,6 +272,156 @@ fn the_presenter_shows_the_frames_comments() {
|
||||
let _ = other;
|
||||
}
|
||||
|
||||
/// A presenter on a 400 x 300 frame (at page 50, 40) with a second frame, the comment mode on.
|
||||
/// Returns the harness, the frame, the other frame and the presented frame's top-left on screen.
|
||||
fn present_comment_mode() -> (Ui, figcraft_doc::NodeId, figcraft_doc::NodeId, Pos2) {
|
||||
let mut s = Session::new();
|
||||
let f = id(&s.execute("node.create", &json!({"type": "frame", "x": 50, "y": 40, "width": 400, "height": 300})).unwrap());
|
||||
let other = id(&s.execute("node.create", &json!({"type": "frame", "x": 700, "y": 0, "width": 400, "height": 300})).unwrap());
|
||||
let mut u = Ui::new(s);
|
||||
u.run("proto.present", json!({"start": f}));
|
||||
key(&mut u, Key::C, Modifiers::NONE);
|
||||
assert_eq!(u.app.inspect()["presenter"]["comments"], true);
|
||||
let screen = egui::Rect::from_min_size(pos2(0.0, 80.0), vec2(1440.0, 820.0));
|
||||
(u, f, other, screen.center() - vec2(200.0, 150.0))
|
||||
}
|
||||
|
||||
fn comment_count(u: &Ui) -> usize {
|
||||
u.app.session.doc().unwrap().comments.len()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_click_in_the_presenters_comment_mode_adds_a_comment_on_the_frame() {
|
||||
let (mut u, f, _, frame_min) = present_comment_mode();
|
||||
click(&mut u, frame_min + vec2(120.0, 90.0));
|
||||
assert!(comments(&u)["draft"].is_array(), "the click opens a draft");
|
||||
u.frame(vec![Event::Text("hello".into())]);
|
||||
key(&mut u, Key::Enter, Modifiers::NONE);
|
||||
assert_eq!(comment_count(&u), 1);
|
||||
let doc = u.app.session.doc().unwrap();
|
||||
let c = &doc.comments[0];
|
||||
assert_eq!(c.first.text, "hello");
|
||||
assert_eq!(c.anchor, Some(f));
|
||||
assert!((c.x - 120.0).abs() <= 1.0 && (c.y - 90.0).abs() <= 1.0, "frame-relative spot {},{}", c.x, c.y);
|
||||
assert_eq!(u.app.inspect()["presenter"]["comments"], true, "the mode stays on");
|
||||
assert!(u.app.ui.present.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_click_on_the_presenters_draft_pin_keeps_the_typed_draft() {
|
||||
let (mut u, _, _, frame_min) = present_comment_mode();
|
||||
let at = frame_min + vec2(120.0, 90.0);
|
||||
click(&mut u, at);
|
||||
u.frame(vec![Event::Text("typed".into())]);
|
||||
// The pin's body sits above and right of the point it marks.
|
||||
click(&mut u, at + vec2(6.0, -6.0));
|
||||
let draft = u.app.ui.comments.draft.clone();
|
||||
assert_eq!(draft.as_ref().map(|d| d.2.as_str()), Some("typed"), "the draft stays open with its text: {draft:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_click_off_the_frame_in_the_presenters_comment_mode_adds_no_draft() {
|
||||
let (mut u, _, _, frame_min) = present_comment_mode();
|
||||
click(&mut u, frame_min + vec2(-60.0, 90.0));
|
||||
assert!(comments(&u)["draft"].is_null());
|
||||
assert_eq!(comment_count(&u), 0);
|
||||
assert_eq!(u.app.inspect()["presenter"]["comments"], true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn escape_closes_the_presenters_draft_then_the_mode() {
|
||||
let (mut u, _, _, frame_min) = present_comment_mode();
|
||||
click(&mut u, frame_min + vec2(120.0, 90.0));
|
||||
u.frame(vec![Event::Text("draft".into())]);
|
||||
key(&mut u, Key::Escape, Modifiers::NONE);
|
||||
assert!(comments(&u)["draft"].is_null(), "Escape closes the draft");
|
||||
assert_eq!(comment_count(&u), 0, "and adds no comment");
|
||||
assert_eq!(u.app.inspect()["presenter"]["comments"], true);
|
||||
assert!(u.app.ui.present.is_some());
|
||||
key(&mut u, Key::Escape, Modifiers::NONE);
|
||||
assert_eq!(u.app.inspect()["presenter"]["comments"], false, "Escape with no draft turns the mode off");
|
||||
assert!(u.app.ui.present.is_some(), "and keeps the presentation open");
|
||||
key(&mut u, Key::Escape, Modifiers::NONE);
|
||||
assert!(u.app.ui.present.is_none(), "with the mode off Escape still ends the presentation");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_click_in_the_presenters_comment_mode_does_not_navigate() {
|
||||
let (mut u, f, other, frame_min) = present_comment_mode();
|
||||
u.run("proto.interaction.add", json!({"id": f, "trigger": {"type": "onClick"}, "action": {"type": "navigate", "dest": other}}));
|
||||
u.frames(2, Vec::new);
|
||||
click(&mut u, frame_min + vec2(120.0, 90.0));
|
||||
u.frames(30, Vec::new);
|
||||
assert_eq!(u.app.inspect()["presenter"]["current"], json!(f), "the click placed a comment, it didn't follow the link");
|
||||
assert!(comments(&u)["draft"].is_array());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn typing_c_into_the_presenters_draft_keeps_the_mode_on() {
|
||||
let (mut u, _, _, frame_min) = present_comment_mode();
|
||||
click(&mut u, frame_min + vec2(120.0, 90.0));
|
||||
u.frame(vec![Event::Text("c".into())]);
|
||||
key(&mut u, Key::C, Modifiers::NONE);
|
||||
assert_eq!(u.app.inspect()["presenter"]["comments"], true);
|
||||
assert!(comments(&u)["draft"].is_array());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_comment_posted_in_the_overlap_anchors_to_the_presented_frame() {
|
||||
let mut s = Session::new();
|
||||
let a = id(&s.execute("node.create", &json!({"type": "frame", "x": 50, "y": 40, "width": 400, "height": 300})).unwrap());
|
||||
// Stacked after `a` and overlapping its right part.
|
||||
s.execute("node.create", &json!({"type": "frame", "x": 250, "y": 40, "width": 400, "height": 300})).unwrap();
|
||||
let mut u = Ui::new(s);
|
||||
u.run("proto.present", json!({"start": a}));
|
||||
key(&mut u, Key::C, Modifiers::NONE);
|
||||
let screen = egui::Rect::from_min_size(pos2(0.0, 80.0), vec2(1440.0, 820.0));
|
||||
let frame_min = screen.center() - vec2(200.0, 150.0);
|
||||
click(&mut u, frame_min + vec2(250.0, 90.0));
|
||||
u.frame(vec![Event::Text("overlap".into())]);
|
||||
key(&mut u, Key::Enter, Modifiers::NONE);
|
||||
assert_eq!(comment_count(&u), 1);
|
||||
let c = u.app.session.doc().unwrap().comments[0].clone();
|
||||
assert_eq!(c.anchor, Some(a), "the comment is on the presented frame, not the one stacked over it");
|
||||
assert_eq!(comments(&u)["open"], c.id, "its pin shows in the presenter");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_draft_that_fails_to_post_keeps_its_text() {
|
||||
let (mut h, _) = crate::live_tests::Harness::new();
|
||||
// A view-only link: the session refuses every edit, a comment too.
|
||||
crate::live_server_tests::joined(&mut h, figcraft_engine::live::Access::View);
|
||||
h.frames(2);
|
||||
start_draft(&mut h.app, 150.0, 150.0);
|
||||
h.frame(vec![]);
|
||||
h.frame(vec![Event::Text("hello".into())]);
|
||||
let k = |pressed| Event::Key { key: Key::Enter, physical_key: None, pressed, repeat: false, modifiers: Modifiers::NONE };
|
||||
h.frame(vec![k(true), k(false)]);
|
||||
h.frames(2);
|
||||
assert!(h.app.session.doc().unwrap().comments.is_empty(), "the session refused the comment");
|
||||
let draft = h.app.ui.comments.draft.clone();
|
||||
assert_eq!(draft.as_ref().map(|d| d.2.as_str()), Some("hello"), "the draft and its text stay: {draft:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_press_held_into_the_presenters_comment_mode_does_not_navigate_on_release() {
|
||||
let mut s = Session::new();
|
||||
let f = id(&s.execute("node.create", &json!({"type": "frame", "x": 50, "y": 40, "width": 400, "height": 300})).unwrap());
|
||||
let other = id(&s.execute("node.create", &json!({"type": "frame", "x": 700, "y": 0, "width": 400, "height": 300})).unwrap());
|
||||
let mut u = Ui::new(s);
|
||||
u.run("proto.interaction.add", json!({"id": f, "trigger": {"type": "onClick"}, "action": {"type": "navigate", "dest": other}}));
|
||||
u.run("proto.present", json!({"start": f}));
|
||||
u.frames(2, Vec::new);
|
||||
let screen = egui::Rect::from_min_size(pos2(0.0, 80.0), vec2(1440.0, 820.0));
|
||||
let at = screen.center() - vec2(200.0, 150.0) + vec2(120.0, 90.0);
|
||||
u.button(at, true);
|
||||
key(&mut u, Key::C, Modifiers::NONE);
|
||||
assert_eq!(u.app.inspect()["presenter"]["comments"], true);
|
||||
u.button(at, false);
|
||||
u.frames(30, Vec::new);
|
||||
assert_eq!(u.app.inspect()["presenter"]["current"], json!(f), "the press began before comment mode, so its release is no click");
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
struct Clip(Arc<Mutex<Option<String>>>);
|
||||
|
||||
|
||||
@@ -94,12 +94,24 @@ pub fn show(app: &mut FigApp, ui: &mut Ui) {
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
// Escape with no draft or thread open turns the comment mode off and keeps the presentation.
|
||||
let cu = &app.ui.comments;
|
||||
if live
|
||||
&& pres.view.comments
|
||||
&& pres.link_notice.is_none()
|
||||
&& cu.open.is_none()
|
||||
&& cu.draft.is_none()
|
||||
&& !cu.mention.active()
|
||||
&& ctx.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Escape))
|
||||
{
|
||||
pres.view.comments = false;
|
||||
}
|
||||
if live
|
||||
&& pres.view.comments
|
||||
&& let Some((frame, place, clip)) = pres.shown
|
||||
{
|
||||
crate::comments::presenter(app, &ctx, frame, place, clip);
|
||||
} else if app.ui.comments.open.is_some() {
|
||||
} else if app.ui.comments.open.is_some() || app.ui.comments.draft.is_some() {
|
||||
app.ui.comments.close();
|
||||
}
|
||||
finish(app, &mut pres);
|
||||
|
||||
@@ -34,6 +34,19 @@ fn release_drag_scroll(p: &mut Presenter, l: &Layout, down: bool, velocity: Vec2
|
||||
}
|
||||
}
|
||||
|
||||
/// Without clicks (the comment mode), forget a press in progress and what it began: a drag-scroll and a
|
||||
/// transition following the pointer.
|
||||
fn drop_press(p: &mut Presenter, clicks: bool) {
|
||||
if clicks {
|
||||
return;
|
||||
}
|
||||
p.press = None;
|
||||
p.drag_scroll = None;
|
||||
if let Some(a) = p.anim.as_mut() {
|
||||
a.follow = None;
|
||||
}
|
||||
}
|
||||
|
||||
/// Scrolls the first of `targets` the wheel can still move, and smooths the wheel's speed over
|
||||
/// ~50 ms whatever the frame rate.
|
||||
fn wheel_scroll(p: &mut Presenter, l: &Layout, base: &Document, targets: Vec<Scroller>, wheel: Vec2, dt: f64) {
|
||||
@@ -162,13 +175,16 @@ fn fire_pads(p: &mut Presenter, doc: &Document, root: NodeId, pads: &[String], n
|
||||
/// player takes the keyboard; `pane`: it plays in the preview pane (which always fits).
|
||||
pub(super) struct InputMode {
|
||||
pub over_area: bool,
|
||||
/// Presses reach the prototype: false in the presenter's comment mode, where a click places a
|
||||
/// comment (hover and the wheel still work).
|
||||
pub clicks: bool,
|
||||
pub keys_on: bool,
|
||||
pub pane: bool,
|
||||
pub now: f64,
|
||||
}
|
||||
|
||||
pub(super) fn input(p: &mut Presenter, ctx: &egui::Context, l: &Layout, mode: InputMode) {
|
||||
let InputMode { over_area, keys_on, pane, now } = mode;
|
||||
let InputMode { over_area, clicks, keys_on, pane, now } = mode;
|
||||
let (pos, pressed, released, down, wheel, velocity, dt, keys) = ctx.input(|i| {
|
||||
let keys: Vec<(egui::Key, egui::Modifiers)> = i
|
||||
.events
|
||||
@@ -190,6 +206,9 @@ pub(super) fn input(p: &mut Presenter, ctx: &egui::Context, l: &Layout, mode: In
|
||||
)
|
||||
});
|
||||
let keys = if keys_on { keys } else { Vec::new() };
|
||||
let pressed = pressed && clicks;
|
||||
// A press already in progress when the comment mode starts is dropped, so its release is no click.
|
||||
drop_press(p, clicks);
|
||||
// Controller buttons pressed while a link notice shows are dropped, as keys are.
|
||||
let pads = std::mem::take(&mut p.pads);
|
||||
let pads = if p.link_notice.is_none() { pads } else { Vec::new() };
|
||||
|
||||
@@ -60,7 +60,18 @@ pub(super) fn player(p: &mut Presenter, ui: &mut Ui, rect: Rect, now: f64, chrom
|
||||
// The pane only takes the keyboard while the pointer is over it. While a link notice shows
|
||||
// the prototype takes neither keys nor the pointer (Escape there cancels the notice).
|
||||
let keys = chrome.keys && p.link_notice.is_none() && (!chrome.pane || over);
|
||||
input(p, &ctx, &l, InputMode { over_area: over && p.link_notice.is_none(), keys_on: keys, pane: chrome.pane, now });
|
||||
input(
|
||||
p,
|
||||
&ctx,
|
||||
&l,
|
||||
InputMode {
|
||||
over_area: over && p.link_notice.is_none(),
|
||||
clicks: !(p.view.comments && !chrome.pane),
|
||||
keys_on: keys,
|
||||
pane: chrome.pane,
|
||||
now,
|
||||
},
|
||||
);
|
||||
} else {
|
||||
p.pads.clear();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Prototyping parity
|
||||
|
||||
> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-09 · **Change:** patch (a connection dragged from a variant, or a layer in it, onto a sibling variant makes Change to, On click, Instant, with the sibling outlined (#2158); `proto.settings` refuses an unknown device with the list of devices instead of saving it, takes a known one in any case, and answers the page's settings, so `proto.settings {}` reads them (#2027); Hide UI in the presenter's Options menu, and Cmd/Ctrl+\ as in the editor: the bar above the prototype and the navigation bar under it go away, a toast names the key that brings them back, `proto.presentOptions {hideUi}` (#1820); the Controller menu names each button as PlayStation and Switch controllers do; "Open in new tab" on Open link: off, the web build's own tab goes to the link; a manual overlay's position can be dragged on the canvas (#405); Open link notices now cover mail links, and skipping them covers only links the viewer fired (#1096); overlay positions relative to the layer that opens them; the Triggers row no longer lists delays on mouse triggers as missing; top-level frames bigger than the device's screen scroll in the player; Change to, set variable and set variable mode lay out what they change in the player, as the canvas does; presentation tabs, one per page of a file; a Present tab with device and scale controls (#537); core editor leftovers: delays on mouse triggers and manual overlay offsets; controller buttons on key/gamepad triggers, widgets that react in prototypes, `proto.evaluate` and the mode lookup rules pinned) · **Target:** Figma Design (desktop app 126.10.7)
|
||||
> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-09 · **Change:** patch (in the presenter's comment mode (C) a click on the presented frame starts a comment there and the mode stays on for the next one, Escape closes the draft and then the mode, measured in Figma's web app 2026-11-10 (#2209); a connection dragged from a variant, or a layer in it, onto a sibling variant makes Change to, On click, Instant, with the sibling outlined (#2158); `proto.settings` refuses an unknown device with the list of devices instead of saving it, takes a known one in any case, and answers the page's settings, so `proto.settings {}` reads them (#2027); Hide UI in the presenter's Options menu, and Cmd/Ctrl+\ as in the editor: the bar above the prototype and the navigation bar under it go away, a toast names the key that brings them back, `proto.presentOptions {hideUi}` (#1820); the Controller menu names each button as PlayStation and Switch controllers do; "Open in new tab" on Open link: off, the web build's own tab goes to the link; a manual overlay's position can be dragged on the canvas (#405); Open link notices now cover mail links, and skipping them covers only links the viewer fired (#1096); overlay positions relative to the layer that opens them; the Triggers row no longer lists delays on mouse triggers as missing; top-level frames bigger than the device's screen scroll in the player; Change to, set variable and set variable mode lay out what they change in the player, as the canvas does; presentation tabs, one per page of a file; a Present tab with device and scale controls (#537); core editor leftovers: delays on mouse triggers and manual overlay offsets; controller buttons on key/gamepad triggers, widgets that react in prototypes, `proto.evaluate` and the mode lookup rules pinned) · **Target:** Figma Design (desktop app 126.10.7)
|
||||
|
||||
**Breadth ~92%, ready ~74% (estimated).** Every Figma trigger except media, every action except
|
||||
media control, every transition and easing exist; key/gamepad triggers take controller buttons,
|
||||
@@ -93,7 +93,7 @@ tool; opt-in), **silent** (the documentation doesn't say; the case pins the curr
|
||||
| Interactive components: instances play their variant's interactions, overridden per trigger | done | |
|
||||
| Drag-driven animations that follow the pointer, in their direction | done | |
|
||||
| Presenter: device frames and colours, rotation, custom sizes, fit/fill/100%, responsive frames | done | device bodies drawn in code. Presenting opens a tab for the page, named "file - page", which keeps its screen and history while you go back to the design, with a thumbnail of the current frame, previous / next, device presets and scale choices; the frame is laid out again for the device's screen on the prototype's copy (constraints and auto layout; the file is untouched); on phones and tablets overflowing content drags while the device stays put: a top-level frame bigger than the screen always scrolls (as in Figma, with no overflow setting), content past the frame's own edges as its overflow setting allows ("No scrolling" clips it); closing the window asks about unsaved changes above the presentation (#537). Devices not compared with Figma's |
|
||||
| Hotspot hints, inspect panel in the presenter, comments in the presenter | done | |
|
||||
| Hotspot hints, inspect panel in the presenter, comments in the presenter | done | in comment mode (C) a click on the presented frame starts a comment there (a click off the frame does nothing, and the prototype's own click interactions don't fire) and the mode stays on for the next comment; Escape closes the draft, then the mode (the presentation stays open), as measured in Figma's web app 2026-11-10 (#2209). No comments sidebar in the presenter |
|
||||
| Hide UI in the presenter (Options menu, Cmd/Ctrl+\) | done | the bar above the prototype and the navigation bar under it go away and the prototype takes their room; a toast names the key that brings them back; `proto.presentOptions {hideUi}`, kept for later presentations (#1820) |
|
||||
| Preview pane following edits live | done | |
|
||||
| Edit interactions on several layers at once | done | |
|
||||
@@ -110,6 +110,7 @@ tool; opt-in), **silent** (the documentation doesn't say; the case pins the curr
|
||||
|---|---|---|
|
||||
| 2026-11-14 | patch | M5, #2352: a chain of variant changes on After delay plays to the end (A to B to C to D); before, the step a variant had fired stayed marked as fired when the instance changed variant, so the chain stopped after one step, and now each step's delay counts from when its variant appears (`crates/ui-egui/src/present/afterdelay_chain_tests.rs`). Numbers unchanged |
|
||||
| 2026-11-09 | patch | M7, #2158: a connection dragged from a variant (or a layer in it) onto a sibling variant of its set did nothing, because the drop looked only for top-level frames and a variant's top-level frame is its set. It now creates Change to the sibling (On click, Instant, as measured in Figma's web app) and outlines the sibling while dragging; the set's background and the variant itself still add nothing, and a frame outside the set still gets Navigate to |
|
||||
| 2026-11-10 | patch | M7, #2209: the presenter's comment mode showed the frame's pins but nothing started a comment. Measured in Figma's web app: with the mode on (C or the bar's comment button) a click on the presented frame drops a pin at the click and opens an "Add a comment" composer beside it; Enter posts, the pin stays at the same frame-relative spot and the mode stays on; a click on the background does nothing; Escape closes a composer, and with none open turns the mode off; the comment shows on the frame in the editor. Now the same: the click starts the draft at the point mapped back through the presenter's placement, the editor's composer is shared, the post carries the frame's page, the player ignores the pointer while the mode is on (no click interactions or hotspots fire), and Escape closes the draft, then the mode. Tests: `comments_tests::a_click_in_the_presenters_comment_mode_adds_a_comment_on_the_frame` and four more. |
|
||||
| 2026-11-06 | patch | M5, #2027: `proto.settings` took any string as the device (`"Pixel Nonexistent"`, `"iphone 16"`) and saved it in the file; the presenter then drew no device while its picker showed the name as if it were one, and the settings couldn't be read back over MCP (`proto.settings {}` answered `{ok: true}`). An unknown name (or a non-string) is now refused with every name the picker offers (`None`, `Custom size` and the devices), as an unknown colour is refused with the device's colours, and nothing changes; a known name is taken in any case and stored as the picker spells it. Every call answers the page's settings after it: device, background, rotation, the colour shown, the screen as presented, the custom size and responsive. Test: `proto_present_tests::unknown_devices_are_refused_and_settings_read_back` |
|
||||
| 2026-10-31 | minor | Gap 15: the Controller menu names buttons as PlayStation and Switch controllers do; that item leaves the missing list. Estimate unchanged. Test: `present::tail_tests`. |
|
||||
| 2026-10-30 | minor | Opening a link in place: Open link has "Open in new tab", on by default; off, the web build's own tab goes to the link after the notice (or at once with it skipped); the desktop app has no tab of its own and opens the browser either way. Saved in files only when off (`openInNewTab`) and read from REST files. |
|
||||
|
||||
Reference in new issue
Block a user