use waterui::animation::Animation;
use crate::reactive::WuiWatcherMetadata;
use crate::IntoFFI;
#[repr(C)]
#[derive(Debug)]
pub enum WuiAnimation {
None,
Bezier {
duration_ms: u64,
x1: f32,
y1: f32,
x2: f32,
y2: f32,
},
Spring {
stiffness: f32,
damping: f32,
},
}
impl IntoFFI for Animation {
type FFI = WuiAnimation;
fn into_ffi(self) -> Self::FFI {
match self {
Self::Default => WuiAnimation::Bezier {
duration_ms: 250,
x1: 0.42,
y1: 0.0,
x2: 0.58,
y2: 1.0,
},
Self::Bezier {
duration,
x1,
y1,
x2,
y2,
} => WuiAnimation::Bezier {
duration_ms: u64::try_from(duration.as_millis())
.expect("Animation duration exceeds u64::MAX milliseconds"),
x1,
y1,
x2,
y2,
},
Self::Spring { stiffness, damping } => WuiAnimation::Spring { stiffness, damping },
}
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn waterui_get_animation(
metadata: *const WuiWatcherMetadata,
) -> WuiAnimation {
unsafe {
(*metadata)
.try_get::<Animation>()
.map_or(WuiAnimation::None, IntoFFI::into_ffi)
}
}