Skip to main content

ranim_anims/
lib.rs

1//! Ranim's built-in animations
2//!
3//! This crate contains the built-in animations for Ranim.
4//!
5//! An **Animation** in ranim is basically a struct that implements the [`ranim_core::animation::Eval`] trait:
6//!
7//! ```rust,ignore
8//! pub trait Eval {
9//!     type Output;
10//!
11//!     /// Evaluates at the given progress value `alpha` in range [0, 1].
12//!     fn eval_alpha(&self, alpha: f64) -> Self::Output;
13//! }
14//! ```
15//!
16//! Every animation self-contains the evaluation process (the trait impl of [`ranim_core::animation::Eval::eval_alpha`])
17//! and the data that the evaluation process needs (the struct it self). Here is the example of [`fading::FadeIn`] animation:
18//!
19//! ```rust,ignore
20//! pub trait FadingRequirement: Opacity + Interpolatable + Clone {}
21//! impl<T: Opacity + Interpolatable + Clone> FadingRequirement for T {}
22//!
23//! pub struct FadeIn<T: FadingRequirement> {
24//!     src: T,
25//!     dst: T,
26//! }
27//!
28//! impl<T: FadingRequirement> FadeIn<T> {
29//!     pub fn new(target: T) -> Self {
30//!         let mut src = target.clone();
31//!         let dst = target.clone();
32//!         src.set_opacity(0.0);
33//!         Self { src, dst }
34//!     }
35//! }
36//!
37//! impl<T: FadingRequirement> Eval for FadeIn<T> {
38//!     type Output = T;
39//!
40//!     fn eval_alpha(&self, alpha: f64) -> Self::Output {
41//!         self.src.lerp(&self.dst, alpha)
42//!     }
43//! }
44//! ```
45//!
46//! In addition, to make the construction of anim for any type that satisfies the requirement,
47//! It is recommended to write a trait like this:
48//!
49//! ```rust,ignore
50//! /// The methods to create animations for `T` that satisfies [`FadingRequirement`]
51//! pub trait FadingAnim<T: FadingRequirement + 'static> {
52//!     fn fade_in(self) -> FadeIn<T>;
53//!     fn fade_out(self) -> FadeOut<T>;
54//! }
55//!
56//! impl<T: FadingRequirement + 'static> FadingAnim<T> for T {
57//!     fn fade_in(self) -> FadeIn<T> {
58//!         FadeIn::new(self.clone())
59//!     }
60//!     fn fade_out(self) -> FadeOut<T> {
61//!         FadeOut::new(self.clone())
62//!     }
63//! }
64//! ```
65#![warn(missing_docs)]
66#![cfg_attr(docsrs, feature(doc_cfg))]
67#![allow(rustdoc::private_intra_doc_links)]
68#![doc(
69    html_logo_url = "https://raw.githubusercontent.com/AzurIce/ranim/refs/heads/main/assets/ranim.svg",
70    html_favicon_url = "https://raw.githubusercontent.com/AzurIce/ranim/refs/heads/main/assets/ranim.svg"
71)]
72
73/// Creation animation
74pub mod creation;
75/// Fading animation
76pub mod fading;
77/// Func animation
78pub mod func;
79/// Lagged animation
80pub mod lagged;
81/// Morph animation
82pub mod morph;
83/// Rotating animation
84pub mod rotating;