windows-animation 0.100.0

Windows animation library
Documentation
use super::*;

/// Coordinates variables, transitions, and storyboards.
#[derive(Clone)]
pub struct Manager(pub(crate) IUIAnimationManager2);

impl Manager {
    /// Creates a new animation manager.
    pub fn new() -> Result<Self> {
        unsafe {
            let mut ptr = core::ptr::null_mut();
            CoCreateInstance(
                &UIAnimationManager2,
                core::ptr::null_mut(),
                CLSCTX_INPROC_SERVER,
                &IUIAnimationManager2::IID,
                &mut ptr,
            )
            .ok()?;
            Ok(Self(windows_core::imp::Type::from_abi(ptr)?))
        }
    }

    /// Creates a new animation variable with the given initial value.
    pub fn create_variable(&self, initial_value: f64) -> Result<Variable> {
        unsafe { Ok(Variable(self.0.CreateAnimationVariable(initial_value)?)) }
    }

    /// Creates a new storyboard for sequencing transitions.
    pub fn create_storyboard(&self) -> Result<Storyboard> {
        unsafe { Ok(Storyboard(self.0.CreateStoryboard()?)) }
    }

    /// Advances the animation manager to the specified time in seconds.
    pub fn update(&self, time: f64) -> Result<()> {
        unsafe { self.0.Update(time, None) }.ok()?;
        Ok(())
    }

    /// Schedules a transition on a variable, starting at the specified time in seconds.
    pub fn schedule_transition(
        &self,
        variable: &Variable,
        transition: &Transition,
        time: f64,
    ) -> Result<()> {
        unsafe { self.0.ScheduleTransition(&variable.0, &transition.0, time) }.ok()
    }
}