M5: a temporary variant change that reverts keeps the After delay deadline (#2352)

The swap times now travel with the while-hovering / while-pressing snapshot, so reverting a hover's variant change restores them and the variant shown again fires on its own deadline. Test a_hover_variant_that_reverts_keeps_the_after_delay_deadline (red before: left Some(0), right Some(2) at 1.3 s); present 102 passed, clippy clean (CodeRabbit on #2362).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Trevor BrownandClaude Opus 5.5 committed 2026-11-14 01:48:54 -05:00
1 parent f451e60ceb
commit d3f275fa70
3 files changed
+58

No files matched your search

+3
View File
@@ -248,6 +248,9 @@ 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>,
}
/// A "while hovering / while pressing" state that reverts when the pointer leaves / lifts.
@@ -79,6 +79,59 @@ fn each_step_waits_its_own_delay_from_when_its_variant_appeared() {
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");
}
#[test]
fn a_single_after_delay_still_fires_once() {
let mut s = Session::new();
+2
View File
@@ -150,6 +150,7 @@ impl Presenter {
overlays: self.overlays.clone(),
history: self.history.clone(),
scroll: self.scroll.clone(),
swapped: self.swapped.clone(),
})
}
@@ -228,6 +229,7 @@ impl Presenter {
self.overlays = t.snap.overlays;
self.history = t.snap.history;
self.scroll = t.snap.scroll;
self.swapped = t.snap.swapped;
self.stop_scrolling();
self.hovered.clear();
self.rev += 1;