Skip to main content

oxframe_core/
slides.rs

1//! Stops and speaker notes for `oxframe present`.
2//!
3//! A scene runs the same way in a render and in a presentation. The stops
4//! are only recorded: `oxframe present` pauses at each one and waits for
5//! the next key press, and `render --slides` takes a frame at each.
6
7use crate::runtime;
8
9/// What a scene recorded for the presentation, in scene time.
10#[derive(Debug, Clone, PartialEq)]
11pub enum SlideMark {
12    /// [`slide_break`]: the presentation pauses here.
13    Break {
14        /// Seconds from the beginning of the scene.
15        at: f64,
16    },
17    /// [`notes`]: speaker notes for the part of the scene around `at`.
18    Notes {
19        /// Seconds from the beginning of the scene.
20        at: f64,
21        /// The notes.
22        text: String,
23    },
24}
25
26/// A stop for `oxframe present`: the presentation pauses here until the
27/// next key press. A render plays straight through, so a scene with stops
28/// is still a video. Every scene also ends with a stop.
29///
30/// ```ignore
31/// title.fade_in().await;
32/// slide_break().await;
33/// list.next().await;
34/// ```
35pub fn slide_break() -> std::future::Ready<()> {
36    runtime::with(|rt| {
37        let at = rt.task_time.get();
38        let mut marks = rt.slides.borrow_mut();
39        // Two breaks at the same time are one stop.
40        let dup = marks.iter().any(
41            |m| matches!(m, SlideMark::Break { at: t } if (t - at).abs() < crate::TIME_EPSILON),
42        );
43        if !dup {
44            marks.push(SlideMark::Break { at });
45        }
46    });
47    std::future::ready(())
48}
49
50/// Speaker notes for the slide being shown: the presenter window of
51/// `oxframe present` shows them until the next stop. Several calls before
52/// one stop are joined.
53pub fn notes(text: impl Into<String>) {
54    let text = text.into();
55    runtime::with(|rt| {
56        let at = rt.task_time.get();
57        rt.slides.borrow_mut().push(SlideMark::Notes { at, text });
58    });
59}