Merge pull request #2362 from TrevorBrown-dev/fix/afterdelay-variant-chain-2352

M5: a chain of After delay variant changes plays to the end (#2352)
This commit is contained in:
BFlat authored and GitHub committed 2026-11-17 18:08:59 +07:00
commit 7c0f1e5a87
5 files changed
+387 -2

No files matched your search

+12
View File
@@ -248,6 +248,12 @@ struct Snapshot {
overlays: Vec<OverlayState>,
history: Vec<Visit>,
scroll: HashMap<NodeId, (f64, f64)>,
/// When each instance last changed variant: a temporary change that reverts restores it, so
/// the variant shown again keeps its After delay deadline.
swapped: HashMap<NodeId, f64>,
/// The After delays that had fired: a temporary variant change clears the swapped instance's,
/// and the revert puts them back so a delay that already ran doesn't run again.
delays_fired: HashSet<(NodeId, usize)>,
}
/// A "while hovering / while pressing" state that reverts when the pointer leaves / lifts.
@@ -290,6 +296,8 @@ pub struct Presenter {
bar_thumb: Option<(NodeId, usize, egui::TextureHandle)>,
arrived: f64,
delays_fired: HashSet<(NodeId, usize)>,
/// When each instance last changed variant (Change to): its After delay timers count from then.
swapped: HashMap<NodeId, f64>,
/// Mouse triggers waiting out their delay.
waiting: Vec<Waiting>,
hovered: Vec<NodeId>,
@@ -370,6 +378,7 @@ impl Presenter {
bar_thumb: None,
arrived: -1.0,
delays_fired: HashSet::new(),
swapped: HashMap::new(),
waiting: Vec::new(),
hovered: Vec::new(),
press: None,
@@ -460,6 +469,9 @@ mod tail_tests;
#[cfg(test)]
mod delay_tests;
#[cfg(test)]
mod afterdelay_chain_tests;
#[cfg(test)]
mod overlay_anchor_tests;
+3
View File
@@ -218,6 +218,9 @@ impl Presenter {
}
figcraft_engine::components::sync_instance(d, inst);
self.settle(&before);
// The new variant's After delay interactions are fresh: they count from now.
self.delays_fired.retain(|(id, _)| !doc.is_ancestor(inst, *id));
self.swapped.insert(inst, now);
true
}
Action::SetVariable { variable, value, expr } => {
@@ -0,0 +1,350 @@
//! A chain of variant After delay steps (Change to) plays to the end, each step's delay counted
//! from when its variant appeared (#2352). Driven through egui headless on the harness's clock.
use figcraft_doc::{NodeId, NodeKind};
use figcraft_engine::Session;
use serde_json::{Value, json};
use crate::present_tests::{Ui as Harness, id};
fn ex(s: &mut Session, cmd: &str, p: Value) -> Value {
s.execute(cmd, &p).unwrap_or_else(|e| panic!("{cmd} {p}: {e}"))
}
/// Variants A to D of one set, an instance on A in a screen, each step an After delay of `ms`
/// changing to the next variant. (harness presenting the screen, the instance, the variants)
fn chain(ms: u32) -> (Harness, NodeId, Vec<NodeId>) {
let mut s = Session::new();
let variants: Vec<NodeId> = ["A", "B", "C", "D"]
.iter()
.enumerate()
.map(|(k, state)| {
let f = id(&ex(
&mut s,
"frame.create",
json!({"x": k as f64 * 150.0, "y": 600, "width": 100, "height": 60, "name": format!("State={state}")}),
));
id(&ex(&mut s, "component.create", json!({"ids": [f]})))
})
.collect();
ex(&mut s, "component.combineVariants", json!({"ids": variants.clone()}));
for pair in variants.windows(2) {
let it = json!({"id": pair[0], "trigger": {"type": "afterDelay", "ms": ms}, "action": {"type": "changeTo", "dest": pair[1]}, "transition": {"type": "instant"}, "durationMs": 0});
ex(&mut s, "proto.interaction.add", it);
}
let set = s.doc().unwrap().node(variants[0]).unwrap().parent.unwrap();
let screen = id(&ex(&mut s, "frame.create", json!({"x": 0, "y": 0, "width": 400, "height": 300, "name": "Screen"})));
let inst = id(&ex(&mut s, "instance.create", json!({"component": set, "x": 20, "y": 20, "parent": screen})));
ex(&mut s, "instance.swap", json!({"ids": [inst], "component": variants[0]}));
let mut u = Harness::new(s);
u.run("proto.present", json!({"start": screen}));
(u, inst, variants)
}
/// The variant (index) the instance shows in the presenter.
fn shown(u: &Harness, inst: NodeId, variants: &[NodeId]) -> Option<usize> {
let p = crate::tabs::shown_or_paused(&u.app)?;
let d = p.doc.as_ref()?;
match d.node(inst)?.kind {
NodeKind::Instance { component, .. } => variants.iter().position(|v| *v == component),
_ => None,
}
}
#[test]
fn a_chain_of_variant_after_delays_plays_to_the_end() {
let (mut u, inst, variants) = chain(0);
u.frames(30, Vec::new);
assert_eq!(shown(&u, inst, &variants), Some(3), "A -> B -> C -> D");
}
#[test]
fn each_step_waits_its_own_delay_from_when_its_variant_appeared() {
let (mut u, inst, variants) = chain(500);
// Step until the instance shows B, then note the time.
let mut guard = 0;
while shown(&u, inst, &variants) != Some(1) {
u.frame(Vec::new());
guard += 1;
assert!(guard < 120, "A never changed to B");
}
let appeared = u.time;
while u.time < appeared + 0.4 {
u.frame(Vec::new());
}
assert_eq!(shown(&u, inst, &variants), Some(1), "400 ms after B appeared: still B");
while u.time < appeared + 0.6 {
u.frame(Vec::new());
}
assert_eq!(shown(&u, inst, &variants), Some(2), "600 ms after B appeared: C");
}
/// A hover that changes the variant and reverts leaves the variant shown again on its own After
/// delay deadline (counted from the screen's arrival), not from the hover.
#[test]
fn a_hover_variant_that_reverts_keeps_the_after_delay_deadline() {
let mut s = Session::new();
let variants: Vec<NodeId> = ["A", "Hover", "Next"]
.iter()
.enumerate()
.map(|(k, state)| {
let f = id(&ex(
&mut s,
"frame.create",
json!({"x": k as f64 * 150.0, "y": 600, "width": 100, "height": 60, "name": format!("State={state}")}),
));
id(&ex(&mut s, "component.create", json!({"ids": [f]})))
})
.collect();
ex(&mut s, "component.combineVariants", json!({"ids": variants.clone()}));
let instant = json!({"type": "instant"});
let delay = json!({"id": variants[0], "trigger": {"type": "afterDelay", "ms": 1000}, "action": {"type": "changeTo", "dest": variants[2]}, "transition": instant, "durationMs": 0});
ex(&mut s, "proto.interaction.add", delay);
let hover = json!({"id": variants[0], "trigger": {"type": "onHover"}, "action": {"type": "changeTo", "dest": variants[1]}, "transition": instant, "durationMs": 0});
ex(&mut s, "proto.interaction.add", hover);
let set = s.doc().unwrap().node(variants[0]).unwrap().parent.unwrap();
let screen = id(&ex(&mut s, "frame.create", json!({"x": 0, "y": 0, "width": 400, "height": 300, "name": "Screen"})));
let inst = id(&ex(&mut s, "instance.create", json!({"component": set, "x": 20, "y": 20, "parent": screen})));
ex(&mut s, "instance.swap", json!({"ids": [inst], "component": variants[0]}));
let mut u = Harness::new(s);
u.run("proto.present", json!({"start": screen}));
u.frame(Vec::new());
let start = u.time;
let hot = u.app.inspect()["presenter"]["hotspots"].as_array().cloned().unwrap_or_default();
let h = hot.iter().find(|h| h["id"] == json!(inst)).unwrap_or_else(|| panic!("no hotspot on the instance: {hot:?}"));
let r: Vec<f32> = h["rect"].as_array().unwrap().iter().map(|v| v.as_f64().unwrap() as f32).collect();
let (on, away) = (egui::pos2((r[0] + r[2]) / 2.0, (r[1] + r[3]) / 2.0), egui::pos2(r[0] - 40.0, r[1] - 40.0));
while u.time < start + 0.8 {
u.frame(vec![egui::Event::PointerMoved(away)]);
}
u.frame(vec![egui::Event::PointerMoved(on)]);
u.frame(Vec::new());
assert_eq!(shown(&u, inst, &variants), Some(1), "while hovering: the hover variant");
while u.time < start + 0.9 {
u.frame(vec![egui::Event::PointerMoved(on)]);
}
u.frame(vec![egui::Event::PointerMoved(away)]);
u.frame(Vec::new());
assert_eq!(shown(&u, inst, &variants), Some(0), "the hover left: A again");
while u.time < start + 1.3 {
u.frame(vec![egui::Event::PointerMoved(away)]);
}
assert_eq!(shown(&u, inst, &variants), Some(2), "A's 1,000 ms delay from the arrival fired, not 1,000 ms after the hover");
}
/// A delay that already ran on a variant stays run after a hover changes the variant and reverts:
/// the keys the temporary change cleared come back with the revert.
#[test]
fn a_hover_variant_that_reverts_does_not_rerun_a_fired_delay() {
let mut s = Session::new();
ex(&mut s, "variable.createCollection", json!({"name": "Run", "modes": ["Default"]}));
ex(&mut s, "variable.create", json!({"collection": "Run", "name": "count", "type": "number", "value": 0}));
let count = s.doc().unwrap().variables.get("count").map(|v| v.id.clone()).unwrap();
let variants: Vec<NodeId> = ["A", "Hover"]
.iter()
.enumerate()
.map(|(k, state)| {
let f = id(&ex(
&mut s,
"frame.create",
json!({"x": k as f64 * 150.0, "y": 600, "width": 100, "height": 60, "name": format!("State={state}")}),
));
id(&ex(&mut s, "component.create", json!({"ids": [f]})))
})
.collect();
ex(&mut s, "component.combineVariants", json!({"ids": variants.clone()}));
let instant = json!({"type": "instant"});
// A's delay leaves A on screen: it counts its runs (count = count + 1).
let inc = json!({"op": {"op": "add", "args": [{"value": {"type": "alias", "value": count}}, {"value": {"type": "number", "value": 1}}]}});
let delay = json!({"id": variants[0], "trigger": {"type": "afterDelay", "ms": 100}, "action": {"type": "setVariable", "variable": count, "value": null, "expr": inc}, "transition": instant, "durationMs": 0});
ex(&mut s, "proto.interaction.add", delay);
let hover = json!({"id": variants[0], "trigger": {"type": "onHover"}, "action": {"type": "changeTo", "dest": variants[1]}, "transition": instant, "durationMs": 0});
ex(&mut s, "proto.interaction.add", hover);
let set = s.doc().unwrap().node(variants[0]).unwrap().parent.unwrap();
let screen = id(&ex(&mut s, "frame.create", json!({"x": 0, "y": 0, "width": 400, "height": 300, "name": "Screen"})));
let inst = id(&ex(&mut s, "instance.create", json!({"component": set, "x": 20, "y": 20, "parent": screen})));
ex(&mut s, "instance.swap", json!({"ids": [inst], "component": variants[0]}));
let mut u = Harness::new(s);
u.run("proto.present", json!({"start": screen}));
u.frame(Vec::new());
let start = u.time;
let hot = u.app.inspect()["presenter"]["hotspots"].as_array().cloned().unwrap_or_default();
let h = hot.iter().find(|h| h["id"] == json!(inst)).unwrap_or_else(|| panic!("no hotspot on the instance: {hot:?}"));
let r: Vec<f32> = h["rect"].as_array().unwrap().iter().map(|v| v.as_f64().unwrap() as f32).collect();
let (on, away) = (egui::pos2((r[0] + r[2]) / 2.0, (r[1] + r[3]) / 2.0), egui::pos2(r[0] - 40.0, r[1] - 40.0));
while u.time < start + 0.3 {
u.frame(vec![egui::Event::PointerMoved(away)]);
}
let fired: Vec<(NodeId, usize)> = crate::tabs::shown_or_paused(&u.app).map(|p| p.delays_fired.iter().copied().collect()).unwrap_or_default();
assert!(!fired.is_empty(), "A's delay ran before the hover");
u.frame(vec![egui::Event::PointerMoved(on)]);
u.frame(Vec::new());
assert_eq!(shown(&u, inst, &variants), Some(1), "while hovering: the hover variant");
u.frame(vec![egui::Event::PointerMoved(away)]);
u.frame(Vec::new());
assert_eq!(shown(&u, inst, &variants), Some(0), "the hover left: A again");
u.frames(5, Vec::new);
let p = crate::tabs::shown_or_paused(&u.app).expect("presenting");
assert!(fired.iter().all(|k| p.delays_fired.contains(k)), "the delay that ran before the hover is still marked as run: {:?}", p.delays_fired);
let runs = p.design.as_ref().and_then(|d| d.variables.resolve(&count, &Default::default()));
assert_eq!(runs, Some(figcraft_doc::VariableValue::Number(1.0)), "A's delay ran once, not again after the hover");
}
/// A delay that fires on the hover variant names that variant's interaction: after the revert it
/// doesn't count as A's delay at the same index, which still runs on its own deadline.
#[test]
fn a_delay_fired_on_a_hover_variant_does_not_block_the_restored_variants_delay() {
let mut s = Session::new();
ex(&mut s, "variable.createCollection", json!({"name": "Run", "modes": ["Default"]}));
ex(&mut s, "variable.create", json!({"collection": "Run", "name": "a_runs", "type": "number", "value": 0}));
ex(&mut s, "variable.create", json!({"collection": "Run", "name": "hover_runs", "type": "number", "value": 0}));
let var = |s: &Session, name: &str| s.doc().unwrap().variables.get(name).map(|v| v.id.clone()).unwrap();
let (a_runs, hover_runs) = (var(&s, "a_runs"), var(&s, "hover_runs"));
let inc = |v: &str| json!({"op": {"op": "add", "args": [{"value": {"type": "alias", "value": v}}, {"value": {"type": "number", "value": 1}}]}});
let variants: Vec<NodeId> = ["A", "Hover"]
.iter()
.enumerate()
.map(|(k, state)| {
let f = id(&ex(
&mut s,
"frame.create",
json!({"x": k as f64 * 150.0, "y": 600, "width": 100, "height": 60, "name": format!("State={state}")}),
));
id(&ex(&mut s, "component.create", json!({"ids": [f]})))
})
.collect();
ex(&mut s, "component.combineVariants", json!({"ids": variants.clone()}));
let instant = json!({"type": "instant"});
// A: index 0 a 1,000 ms delay counting its runs, index 1 the hover. Hover: index 0 a delay due at once.
let a_delay = json!({"id": variants[0], "trigger": {"type": "afterDelay", "ms": 1000}, "action": {"type": "setVariable", "variable": a_runs, "value": null, "expr": inc(&a_runs)}, "transition": instant, "durationMs": 0});
ex(&mut s, "proto.interaction.add", a_delay);
let hover = json!({"id": variants[0], "trigger": {"type": "onHover"}, "action": {"type": "changeTo", "dest": variants[1]}, "transition": instant, "durationMs": 0});
ex(&mut s, "proto.interaction.add", hover);
let h_delay = json!({"id": variants[1], "trigger": {"type": "afterDelay", "ms": 0}, "action": {"type": "setVariable", "variable": hover_runs, "value": null, "expr": inc(&hover_runs)}, "transition": instant, "durationMs": 0});
ex(&mut s, "proto.interaction.add", h_delay);
let set = s.doc().unwrap().node(variants[0]).unwrap().parent.unwrap();
let screen = id(&ex(&mut s, "frame.create", json!({"x": 0, "y": 0, "width": 400, "height": 300, "name": "Screen"})));
let inst = id(&ex(&mut s, "instance.create", json!({"component": set, "x": 20, "y": 20, "parent": screen})));
ex(&mut s, "instance.swap", json!({"ids": [inst], "component": variants[0]}));
let mut u = Harness::new(s);
u.run("proto.present", json!({"start": screen}));
u.frame(Vec::new());
let start = u.time;
let hot = u.app.inspect()["presenter"]["hotspots"].as_array().cloned().unwrap_or_default();
let h = hot.iter().find(|h| h["id"] == json!(inst)).unwrap_or_else(|| panic!("no hotspot on the instance: {hot:?}"));
let r: Vec<f32> = h["rect"].as_array().unwrap().iter().map(|v| v.as_f64().unwrap() as f32).collect();
let (on, away) = (egui::pos2((r[0] + r[2]) / 2.0, (r[1] + r[3]) / 2.0), egui::pos2(r[0] - 40.0, r[1] - 40.0));
let value = |u: &Harness, v: &str| {
crate::tabs::shown_or_paused(&u.app).and_then(|p| p.design.as_ref().and_then(|d| d.variables.resolve(v, &Default::default())))
};
while u.time < start + 0.2 {
u.frame(vec![egui::Event::PointerMoved(away)]);
}
while u.time < start + 0.4 {
u.frame(vec![egui::Event::PointerMoved(on)]);
}
assert_eq!(shown(&u, inst, &variants), Some(1), "while hovering: the hover variant");
assert_eq!(value(&u, &hover_runs), Some(figcraft_doc::VariableValue::Number(1.0)), "the hover variant's delay ran");
u.frame(vec![egui::Event::PointerMoved(away)]);
u.frame(Vec::new());
assert_eq!(shown(&u, inst, &variants), Some(0), "the hover left: A again");
while u.time < start + 1.3 {
u.frame(vec![egui::Event::PointerMoved(away)]);
}
assert_eq!(value(&u, &a_runs), Some(figcraft_doc::VariableValue::Number(1.0)), "A's own delay at index 0 ran on its deadline");
}
/// A layer that only the hover variant has, with its own After delay that ran during the hover,
/// leaves no fired key behind after the revert (its id may be issued again by the next hover).
#[test]
fn a_hover_variants_own_layer_leaves_no_fired_key_after_the_revert() {
let mut s = Session::new();
ex(&mut s, "variable.createCollection", json!({"name": "Run", "modes": ["Default"]}));
ex(&mut s, "variable.create", json!({"collection": "Run", "name": "runs", "type": "number", "value": 0}));
let runs = s.doc().unwrap().variables.get("runs").map(|v| v.id.clone()).unwrap();
let inc = json!({"op": {"op": "add", "args": [{"value": {"type": "alias", "value": runs}}, {"value": {"type": "number", "value": 1}}]}});
let frames: Vec<NodeId> = ["A", "Hover"]
.iter()
.enumerate()
.map(|(k, state)| {
id(&ex(&mut s, "frame.create", json!({"x": k as f64 * 150.0, "y": 600, "width": 100, "height": 60, "name": format!("State={state}")})))
})
.collect();
// Only the hover state has this layer, with a delay due at once.
let dot = id(&ex(&mut s, "shape.rectangle", json!({"x": 160, "y": 610, "width": 10, "height": 10, "parent": frames[1]})));
let instant = json!({"type": "instant"});
let dot_delay = json!({"id": dot, "trigger": {"type": "afterDelay", "ms": 0}, "action": {"type": "setVariable", "variable": runs, "value": null, "expr": inc}, "transition": instant, "durationMs": 0});
ex(&mut s, "proto.interaction.add", dot_delay);
let variants: Vec<NodeId> = frames.iter().map(|f| id(&ex(&mut s, "component.create", json!({"ids": [f]})))).collect();
ex(&mut s, "component.combineVariants", json!({"ids": variants.clone()}));
let hover = json!({"id": variants[0], "trigger": {"type": "onHover"}, "action": {"type": "changeTo", "dest": variants[1]}, "transition": instant, "durationMs": 0});
ex(&mut s, "proto.interaction.add", hover);
let set = s.doc().unwrap().node(variants[0]).unwrap().parent.unwrap();
let screen = id(&ex(&mut s, "frame.create", json!({"x": 0, "y": 0, "width": 400, "height": 300, "name": "Screen"})));
let inst = id(&ex(&mut s, "instance.create", json!({"component": set, "x": 20, "y": 20, "parent": screen})));
ex(&mut s, "instance.swap", json!({"ids": [inst], "component": variants[0]}));
let mut u = Harness::new(s);
u.run("proto.present", json!({"start": screen}));
u.frame(Vec::new());
let hot = u.app.inspect()["presenter"]["hotspots"].as_array().cloned().unwrap_or_default();
let h = hot.iter().find(|h| h["id"] == json!(inst)).unwrap_or_else(|| panic!("no hotspot on the instance: {hot:?}"));
let r: Vec<f32> = h["rect"].as_array().unwrap().iter().map(|v| v.as_f64().unwrap() as f32).collect();
let (on, away) = (egui::pos2((r[0] + r[2]) / 2.0, (r[1] + r[3]) / 2.0), egui::pos2(r[0] - 40.0, r[1] - 40.0));
for _ in 0..6 {
u.frame(vec![egui::Event::PointerMoved(on)]);
}
assert_eq!(shown(&u, inst, &variants), Some(1), "while hovering: the hover variant");
let p = crate::tabs::shown_or_paused(&u.app).expect("presenting");
let ran = p.design.as_ref().and_then(|d| d.variables.resolve(&runs, &Default::default()));
assert_eq!(ran, Some(figcraft_doc::VariableValue::Number(1.0)), "the hover variant's own layer ran its delay");
u.frame(vec![egui::Event::PointerMoved(away)]);
u.frame(Vec::new());
assert_eq!(shown(&u, inst, &variants), Some(0), "the hover left: A again");
let p = crate::tabs::shown_or_paused(&u.app).expect("presenting");
let d = p.design.as_ref().expect("a document");
let stale: Vec<_> = p.delays_fired.iter().filter(|(id, _)| !d.contains(*id)).collect();
assert!(stale.is_empty(), "no fired key names a layer the restored document lacks: {stale:?}");
}
/// An edit in the editor while presenting brings back the editor's variants, so the swap times of
/// the variants changed at run time no longer delay them.
#[test]
fn an_edit_while_presenting_drops_the_swap_times() {
let (mut u, inst, variants) = chain(500);
let start = u.time;
let mut guard = 0;
while shown(&u, inst, &variants) != Some(1) {
u.frame(Vec::new());
guard += 1;
assert!(guard < 120, "A never changed to B");
}
// An edit: the presenter shows the editor's document again, the instance on A.
u.run("page.rename", json!({"name": "Renamed"}));
u.frame(Vec::new());
let edited = u.time;
// A's 500 ms delay counts from the screen's arrival, long past: it fires at once, not 500 ms
// after the run-time change to B.
while u.time < edited + 0.2 {
u.frame(Vec::new());
}
assert!(edited < start + 0.9, "the edit came before B's own delay was due");
assert_eq!(shown(&u, inst, &variants), Some(1), "A changed to B again right after the edit");
}
#[test]
fn a_single_after_delay_still_fires_once() {
let mut s = Session::new();
let a = id(&ex(&mut s, "frame.create", json!({"x": 0, "y": 0, "width": 300, "height": 400, "name": "A"})));
let b = id(&ex(&mut s, "frame.create", json!({"x": 400, "y": 0, "width": 300, "height": 400, "name": "B"})));
let it = json!({"id": a, "trigger": {"type": "afterDelay", "ms": 100}, "action": {"type": "navigate", "dest": b}, "transition": {"type": "instant"}, "durationMs": 0});
ex(&mut s, "proto.interaction.add", it);
let mut u = Harness::new(s);
u.run("proto.present", json!({"start": a}));
u.frames(3, Vec::new);
let name = |u: &Harness| u.app.inspect()["presenter"]["name"].as_str().unwrap_or_default().to_string();
assert_eq!(name(&u), "A", "not before the delay");
u.frames(30, Vec::new);
assert_eq!(name(&u), "B", "once the delay is over");
u.frames(60, Vec::new);
assert_eq!(name(&u), "B", "and not again");
}
+20 -1
View File
@@ -42,6 +42,8 @@ impl Presenter {
self.closing.retain(|(_, o)| doc.contains(o.id));
// These hold states of the document before the edit.
self.temp = None;
// The edit's variants replace the runtime ones: their swap times no longer apply.
self.swapped.clear();
self.anim = None;
self.scroll_anim = None;
self.stop_scrolling();
@@ -150,6 +152,8 @@ impl Presenter {
overlays: self.overlays.clone(),
history: self.history.clone(),
scroll: self.scroll.clone(),
swapped: self.swapped.clone(),
delays_fired: self.delays_fired.clone(),
})
}
@@ -170,6 +174,7 @@ impl Presenter {
}
self.arrived = now;
self.delays_fired.clear();
self.swapped.clear();
self.waiting.clear();
self.hovered.clear();
self.rev += 1;
@@ -220,6 +225,16 @@ impl Presenter {
pub(super) fn revert(&mut self, now: f64) {
let Some(t) = self.temp.take() else { return };
// The delays fired during the temporary change: inside an instance it changed the variant
// of, a key names the temporary variant's interaction, not the restored one's, so drop it;
// keep the others, and put back the ones the change cleared.
let changed: Vec<NodeId> = self.swapped.iter().filter(|(i, at)| t.snap.swapped.get(*i) != Some(*at)).map(|(i, _)| *i).collect();
let restored = &t.snap.doc;
let during: Vec<(NodeId, usize)> = self.delays_fired.difference(&t.snap.delays_fired).copied().collect();
let mut fired = t.snap.delays_fired.clone();
fired.extend(during.into_iter().filter(|(id, _)| !changed.iter().any(|i| i == id || restored.is_ancestor(*i, *id))));
// A layer the temporary change added is gone again (and its id may be issued anew).
fired.retain(|(id, _)| restored.contains(*id));
self.begin(t.transition.reversed(), t.dur, t.easing, now);
self.current = t.snap.current;
self.design = Some(t.snap.doc);
@@ -227,6 +242,8 @@ impl Presenter {
self.overlays = t.snap.overlays;
self.history = t.snap.history;
self.scroll = t.snap.scroll;
self.swapped = t.snap.swapped;
self.delays_fired = fired;
self.stop_scrolling();
self.hovered.clear();
self.rev += 1;
@@ -245,7 +262,9 @@ pub(crate) fn next_delay(p: &Presenter, doc: &Document, root: NodeId, now: f64)
if let Trigger::AfterDelay { ms } = it.trigger
&& !p.delays_fired.contains(&(id, k))
{
let due = since + f64::from(ms) / 1000.0 - now;
// Inside an instance that changed variant, the timer starts when it did.
let from = p.swapped.iter().filter(|(inst, _)| doc.is_ancestor(**inst, id)).fold(since, |a, (_, t)| a.max(*t));
let due = from + f64::from(ms) / 1000.0 - now;
if next.is_none_or(|(_, d)| due < d) {
next = Some(((id, k), due));
}
+2 -1
View File
@@ -39,7 +39,7 @@ tool; opt-in), **silent** (the documentation doesn't say; the case pins the curr
| Key/gamepad on a controller: the trigger takes a controller button in place of a key, pressed anywhere on the screen | **added** | `Gamepad A` … `Gamepad Home` (the standard layout's 17 buttons, face buttons by position) as the trigger's key, picked from the Controller menu beside the key field; the player polls controllers only while the prototype has such a trigger and the window has the focus, and plays each press once (held buttons don't repeat); Windows reads Xbox-compatible controllers, the browser its Gamepad API's standard-mapped ones; `controller_buttons_fire_key_gamepad_triggers`, `controller_buttons_play_key_gamepad_triggers` |
| A controller button is not the keyboard key of the same name; the d-pad is not the arrow keys; a keyboard modifier held makes a button press another input | silent | pinned as stated |
| REST files: controller triggers (`device` other than `KEYBOARD`) | **added** | they were skipped; their code reads as the standard layout's button index (silent: the schema doesn't say what the codes count); two buttons at once or an unknown code is skipped with a warning; `controller_triggers_import_as_their_button` |
| After delay: timed from when the screen shows | pass | `triggers_fire_on_their_gesture` |
| After delay: timed from when the screen shows; a chain of variant changes on After delay plays to the end, each step's delay counted from when its variant appears (#2352) | pass | `triggers_fire_on_their_gesture`, `a_chain_of_variant_after_delays_plays_to_the_end` |
| After delay on an overlay: timed from when the overlay opens, again each time it opens | **fixed** | timed from when the screen under it arrived (a toast opened late closed at once) and fired only the first time; `an_overlays_after_delay_counts_from_when_it_opens` |
| Nested layers with the same trigger: the top-most layer's interaction wins; a layer without that trigger lets it through to the one under it | pass | `nested_hotspots_and_click_through`, `hotspots_priority_and_click_through` |
| A layer without interactions over a hotspot | silent | it doesn't block it: clicks reach the hotspot under it |
@@ -108,6 +108,7 @@ tool; opt-in), **silent** (the documentation doesn't say; the case pins the curr
| Date | Change | Summary |
|---|---|---|
| 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-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`. |