Skip to main content

windows_animation/
storyboard.rs

1use super::*;
2
3/// Opaque handle to a point in a storyboard timeline.
4#[derive(Clone, Copy)]
5pub struct Keyframe(UI_ANIMATION_KEYFRAME);
6
7/// Sequences one or more transitions on variables.
8#[derive(Clone)]
9pub struct Storyboard(pub(crate) IUIAnimationStoryboard2);
10
11impl Storyboard {
12    /// Adds a transition on a variable and returns a keyframe marking its end.
13    pub fn add_transition(&self, variable: &Variable, transition: &Transition) -> Result<Keyframe> {
14        unsafe {
15            self.0.AddTransition(&variable.0, &transition.0).ok()?;
16            let kf = self.0.AddKeyframeAfterTransition(&transition.0)?;
17            Ok(Keyframe(kf))
18        }
19    }
20
21    /// Adds a transition that starts at the specified keyframe.
22    pub fn add_transition_at_keyframe(
23        &self,
24        variable: &Variable,
25        transition: &Transition,
26        keyframe: Keyframe,
27    ) -> Result<()> {
28        unsafe {
29            self.0
30                .AddTransitionAtKeyframe(&variable.0, &transition.0, keyframe.0)
31                .ok()
32        }
33    }
34
35    /// Schedules the storyboard to begin at the specified time in seconds.
36    pub fn schedule(&self, time: f64) -> Result<()> {
37        unsafe { self.0.Schedule(time, None) }.ok()?;
38        Ok(())
39    }
40}