diff --git a/crates/ui-egui/src/show.rs b/crates/ui-egui/src/show.rs index db7983c2b..64f0b4dc7 100644 --- a/crates/ui-egui/src/show.rs +++ b/crates/ui-egui/src/show.rs @@ -552,7 +552,8 @@ impl Show { true } - /// On entering a slide: auto-play its first step when it begins With/After Previous. + /// On entering a slide: auto-play its first step when it begins With/After Previous, once the + /// slide's transition is over. /// `ShowState` already starts such a step when it enters the slide (#631: asking it for the /// next step again finished the step at once, so the slide appeared fully built), so only /// its clock starts here. Autoplay previews start an On Click first step themselves. @@ -568,7 +569,9 @@ impl Show { None }; if let Some(k) = started { - self.step_start = now; + // The slide's transition plays first; its animations start when it has finished, as + // in PowerPoint (#2089). + self.step_start = self.trans.as_ref().map_or(now, |t| now.max(t.start + t.dur)); self.media_clock = Some((k, f64::NEG_INFINITY)); } } diff --git a/crates/ui-egui/src/show/tests.rs b/crates/ui-egui/src/show/tests.rs index a01989ac0..58fa5ffa3 100644 --- a/crates/ui-egui/src/show/tests.rs +++ b/crates/ui-egui/src/show/tests.rs @@ -516,6 +516,41 @@ fn a_transition_keeps_the_old_slide_in_its_own_texture() { assert!(show.tex.is_none(), "the new slide gets a texture of its own instead of overwriting the old one"); } +/// #2089: a slide's With Previous entrance waits for the slide's transition to finish, as in +/// PowerPoint, instead of playing under it. +#[test] +fn animations_start_after_the_slides_transition() { + let mut s = deckcraft_engine::Session::with_new(); + s.execute("slide.new", &json!({})).unwrap(); + s.execute("transition.set", &json!({"kind": "fade", "index": 1, "duration": 400})).unwrap(); + let id = s.active().unwrap().doc.slides[1].shapes[0].id; + s.execute("animation.add", &json!({"effect": "fade", "class": "entrance", "ids": [id.0], "start": "withPrevious", "duration": 500})).unwrap(); + let doc = s.active().unwrap().doc.clone(); + let mut show = Show::new(&doc, 0, false, false); + let a = show.state.next(&doc); + assert_eq!(a, ShowAction::Slide(1)); + assert!(show.apply(a, &doc, 10.0)); + assert!(show.trans.is_some(), "the fade plays"); + assert!(show.state.playing, "the With Previous step is under way"); + assert!((show.clock_snapshot().step_start - 10.4).abs() < 1e-9, "its clock starts when the 0.4 s fade ends"); + let tl = ShowState::timeline(&doc, 1); + let at = |now: f64| state_for(&tl, id, show.state.step, now - show.clock_snapshot().step_start, &[], &[]); + assert!(!at(10.3).visible, "hidden while the transition plays"); + assert!(at(10.6).visible && at(10.6).opacity < 1.0, "fading in after it"); + // The step is not cut short by the time the transition took. + let mut actions = Vec::new(); + assert!(show.queue_clock_actions(&doc, 10.8, &mut actions)); + assert!(actions.is_empty(), "0.4 s into a 0.5 s step: still playing"); + + // Without a transition the step starts at once, as before. + s.execute("transition.set", &json!({"kind": "none", "index": 1})).unwrap(); + let doc = s.active().unwrap().doc.clone(); + let mut show = Show::new(&doc, 0, false, false); + let a = show.state.next(&doc); + assert!(show.apply(a, &doc, 10.0)); + assert_eq!(show.clock_snapshot().step_start, 10.0); +} + #[test] fn going_back_plays_the_left_slides_transition_reversed() { // #1531: Back from B to A played A's own entrance transition. PowerPoint plays the one B came