M5: a chain of After delay variant changes plays to the end (#2352)

Change to swapped the instance's variant in place, so the next variant's After delay
kept the instance's node id and was already recorded as fired: the chain stopped
after one step. The swap now clears the fired keys inside the instance and records
when it happened; next_delay counts a timer from the later of the screen's arrival
and that swap.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Model-Effort: Opus 5.5 drove; Opus 5.5 briefed; Sonnet 5.5 wrote at medium
This commit is contained in:
Trevor BrownandClaude Sonnet 5.5 committed 2026-11-13 23:42:18 -05:00
1 parent 24613d3fa6
commit f451e60ceb
5 files changed
+113 -2

No files matched your search

+6
View File
@@ -290,6 +290,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 +372,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 +463,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,98 @@
//! 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");
}
#[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");
}
+4 -1
View File
@@ -170,6 +170,7 @@ impl Presenter {
}
self.arrived = now;
self.delays_fired.clear();
self.swapped.clear();
self.waiting.clear();
self.hovered.clear();
self.rev += 1;
@@ -245,7 +246,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`. |