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<T> {
9//!     /// Evaluates at the given progress value `alpha` in range [0, 1].
10//!     fn eval_alpha(&self, alpha: f64) -> T;
11//! }
12//! ```
13//!
14//! Every animation self-contains the evaluation process (the trait impl of [`ranim_core::animation::Eval::eval_alpha`])
15//! and the data that the evaluation process needs (the struct it self). Here is the example of [`fading::FadeIn`] animation:
16//!
17//! ```rust,ignore
18//! pub trait FadingRequirement: Opacity + Interpolatable + Clone {}
19//! impl<T: Opacity + Interpolatable + Clone> FadingRequirement for T {}
20//!
21//! pub struct FadeIn<T: FadingRequirement> {
22//!     src: T,
23//!     dst: T,
24//! }
25//!
26//! impl<T: FadingRequirement> FadeIn<T> {
27//!     pub fn new(target: T) -> Self {
28//!         let mut src = target.clone();
29//!         let dst = target.clone();
30//!         src.set_opacity(0.0);
31//!         Self { src, dst }
32//!     }
33//! }
34//!
35//! impl<T: FadingRequirement> Eval<T> for FadeIn<T> {
36//!     fn eval_alpha(&self, alpha: f64) -> T {
37//!         self.src.lerp(&self.dst, alpha)
38//!     }
39//! }
40//! ```
41//!
42//! In addition, to make the construction of anim for any type that satisfies the requirement,
43//! It is recommended to write a trait like this:
44//!
45//! ```rust,ignore
46//! /// The methods to create animations for `T` that satisfies [`FadingRequirement`]
47//! pub trait FadingAnim<T: FadingRequirement + 'static> {
48//!     fn fade_in(self) -> AnimationCell<T>;
49//!     fn fade_out(self) -> AnimationCell<T>;
50//! }
51//!
52//! impl<T: FadingRequirement + 'static> FadingAnim<T> for T {
53//!     fn fade_in(self) -> AnimationSpan<T> {
54//!         FadeIn::new(self.clone())
55//!             .into_animation_cell()
56//!             .with_rate_func(smooth)
57//!     }
58//!     fn fade_out(self) -> AnimationSpan<T> {
59//!         FadeOut::new(self.clone())
60//!             .into_animation_cell()
61//!             .with_rate_func(smooth)
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;