pub struct KramaFrame<CL, FL> {
pub classlist: CL,
pub framelist: FL,
}Expand description
The main animation controller.
KramaFrame manages a collection of animation “classes” and their corresponding animation “frames”.
A class defines an animation behavior (e.g., easing function), while a frame represents a specific
instance of an animation with its own timing and progress.
CL: The type for the class list, typically a map from a class name to aKeyFrameFunction.FL: The type for the frame list, typically a map from a class name to aKeyList.
Fields§
§classlist: CLA list of animation classes, mapping class names to keyframe functions (e.g., “linear”, “ease-in”).
framelist: FLA list of animation frames, mapping class names to KeyLists, which track individual animation instances.
Implementations§
Source§impl<TRES: TimingResolution + Clone, PRES: ProgressResolution + Eq> KramaFrame<BTclasslist, BTreeMap<&'static str, KeyList<TRES, PRES>>>
impl<TRES: TimingResolution + Clone, PRES: ProgressResolution + Eq> KramaFrame<BTclasslist, BTreeMap<&'static str, KeyList<TRES, PRES>>>
Sourcepub fn extend_iter_classlist<const N: usize>(
&mut self,
classlist: [(&'static str, KeyFrameFunction); N],
)
pub fn extend_iter_classlist<const N: usize>( &mut self, classlist: [(&'static str, KeyFrameFunction); N], )
Sourcepub fn insert_new_class(&mut self, classname: &'static str)
pub fn insert_new_class(&mut self, classname: &'static str)
Inserts a new class with a default KeyFrameFunction.
If the class name already exists, its keyframe function will be updated to the default.
Sourcepub fn insert_new_id(&mut self, on_classname: &'static str, id: u32, time: TRES)
pub fn insert_new_id(&mut self, on_classname: &'static str, id: u32, time: TRES)
Inserts a new animation instance (identified by id) for a given class.
If the class name does not exist in the framelist, a new KeyList will be created for it.
Sourcepub fn change_timing(
&mut self,
on_classname: &'static str,
id: u32,
new_timing: TRES,
)
pub fn change_timing( &mut self, on_classname: &'static str, id: u32, new_timing: TRES, )
Changes the total duration (new_timing) for a specific animation instance.
Sourcepub fn update_progress(&mut self, delta_time: TRES)
pub fn update_progress(&mut self, delta_time: TRES)
Updates the progress of all active animations.
This function should be called in your application’s main loop (e.g., once per frame).
It iterates through all registered classes and updates the progress of their associated
animation instances based on the elapsed time (delta_time).
§Arguments
delta_time: The time elapsed since the last update, typically in seconds.
Sourcepub fn restart_progress(&mut self, classname: &'static str, id: u32)
pub fn restart_progress(&mut self, classname: &'static str, id: u32)
Restarts the progress of a specific animation instance.
This sets its internal timer back to zero.
Sourcepub fn get_progress_f32(&self, classname: &'static str, id: u32) -> f32
pub fn get_progress_f32(&self, classname: &'static str, id: u32) -> f32
Gets the current progress of a specific animation instance as a value between 0.0 and 1.0.
Returns 0.0 if the class name or id is not found.
Note: This is the raw progress, not yet modified by a KeyFrameFunction.
pub fn remove_classname(&mut self, classname: &'static str)
pub fn replace_classname( &mut self, old_classname: &'static str, new_classname: &'static str, )
pub fn set_timing(&mut self, classname: &'static str, id: u32, timing: TRES)
pub fn get_timing(&self, classname: &'static str, id: u32) -> TRES
pub fn is_reversed(&self, classname: &'static str, id: u32) -> bool
pub fn is_any_animation_inprogress(&self) -> bool
Sourcepub fn get_time_f32(&self, classname: &'static str, id: u32) -> f32
pub fn get_time_f32(&self, classname: &'static str, id: u32) -> f32
Gets the current elapsed time of a specific animation instance in seconds.
Returns 0.0 if the class name or id is not found.
Sourcepub fn from_range<T>(
&self,
on_classname: &'static str,
id: u32,
range: impl RangeBounds<T>,
) -> T
pub fn from_range<T>( &self, on_classname: &'static str, id: u32, range: impl RangeBounds<T>, ) -> T
rangebounded interpolated to get value from range bound such as start..end, start..=end, ..end and ..=end but it return default value if range is start.., .., =.. and start=..
pub fn is_classname(&self, classname: &'static str) -> bool
pub fn is_id(&self, on_classname: &'static str, id: u32) -> bool
Sourcepub fn get_value_byrange<T>(
&self,
on_classname: &'static str,
id: u32,
range: Range<T>,
) -> Twhere
ProgressList<TRES, PRES>: GetValueByRange<T>,
pub fn get_value_byrange<T>(
&self,
on_classname: &'static str,
id: u32,
range: Range<T>,
) -> Twhere
ProgressList<TRES, PRES>: GetValueByRange<T>,
Calculates and returns an interpolated value for an animation within a given Range.
The interpolation is based on the animation’s current progress and its class’s KeyFrameFunction.
This method is suitable for types that support the necessary arithmetic operations (Add, Sub, Mul<f32>).
Returns the range.start value if the class name or id is not found.
Sourcepub fn get_value_byrange_inclusive<T>(
&self,
on_classname: &'static str,
id: u32,
range: RangeInclusive<T>,
) -> T
pub fn get_value_byrange_inclusive<T>( &self, on_classname: &'static str, id: u32, range: RangeInclusive<T>, ) -> T
Calculates and returns an interpolated value for an animation within a given RangeInclusive.
The interpolation is based on the animation’s current progress and its class’s KeyFrameFunction.
This method is suitable for types that support the necessary arithmetic operations (Add, Sub, Mul<f32>).
Returns the range.start() value if the class name or id is not found.
Sourcepub fn from_range_generic<T>(
&self,
on_classname: &'static str,
id: u32,
range: impl RangeBounds<T>,
) -> T
pub fn from_range_generic<T>( &self, on_classname: &'static str, id: u32, range: impl RangeBounds<T>, ) -> T
rangebounded interpolated to get value from range bound such as start..end, start..=end, ..end and ..=end but it return default value if range is start.., .., =.. and start=..
Sourcepub fn get_generic_byrange<T>(
&self,
on_classname: &'static str,
id: u32,
range: Range<T>,
) -> T
pub fn get_generic_byrange<T>( &self, on_classname: &'static str, id: u32, range: Range<T>, ) -> T
Gets a value from a Range based on animation progress, for generic types.
This method is intended for types that might not support arithmetic interpolation (e.g., enums).
It relies on the GetValueByGeneric trait to determine the value based on progress.
NOTE: Generic should be implemented with
- Clone, Copy
- Add<Output = Self>, Sub<Output = Self>
- Mul<f32, Output = Self>
§Example of implementation
use std::ops::{Add, Sub, Mul};
#[derive(Clone, Copy)]
struct Point {
x: f32,
y: f32,
}
impl Add for Point {
type Output = Self;
fn add(self, other: Self) -> Self {
Point {
x: self.x + other.x,
y: self.y + other.y,
}
}
}
impl Sub for Point {
type Output = Self;
fn sub(self, other: Self) -> Self {
Point {
x: self.x - other.x,
y: self.y - other.y,
}
}
}
impl Mul<f32> for Point {
type Output = Self;
fn mul(self, scalar: f32) -> Self {
Point {
x: self.x * scalar,
y: self.y * scalar,
}
}
}Returns range.start if the class name or id is not found.
Sourcepub fn get_generic_value_by_rangeinclusive<T>(
&self,
on_classname: &'static str,
id: u32,
range: RangeInclusive<T>,
) -> T
pub fn get_generic_value_by_rangeinclusive<T>( &self, on_classname: &'static str, id: u32, range: RangeInclusive<T>, ) -> T
Gets a value from a RangeInclusive based on animation progress, for generic types.
This method is intended for types that might not support arithmetic interpolation (e.g., enums).
It relies on the GetValueByGeneric trait to determine the value based on progress.
NOTE: Generic should be implemented with
- Clone, Copy
- Add<Output = Self>, Sub<Output = Self>
- Mul<f32, Output = Self>
§Example of implementation
use std::ops::{Add, Sub, Mul};
#[derive(Clone, Copy)]
struct Point {
x: f32,
y: f32,
}
impl Add for Point {
type Output = Self;
fn add(self, other: Self) -> Self {
Point {
x: self.x + other.x,
y: self.y + other.y,
}
}
}
impl Sub for Point {
type Output = Self;
fn sub(self, other: Self) -> Self {
Point {
x: self.x - other.x,
y: self.y - other.y,
}
}
}
impl Mul<f32> for Point {
type Output = Self;
fn mul(self, scalar: f32) -> Self {
Point {
x: self.x * scalar,
y: self.y * scalar,
}
}
}Returns range.start if the class name or id is not found.
Sourcepub fn reverse_animate(&mut self, on_classname: &'static str, id: u32)
pub fn reverse_animate(&mut self, on_classname: &'static str, id: u32)
Reverses the direction of a specific animation instance.
If it was playing forwards, it will now play backwards, and vice-versa.
Sourcepub fn reverse_start(&mut self, on_classname: &'static str, id: u32)
pub fn reverse_start(&mut self, on_classname: &'static str, id: u32)
Reverses the direction of a specific animation instance and starts it.
If it was playing forwards, it will now play backwards, and vice-versa.
Sourcepub fn is_animating(&self, on_classname: &'static str, id: u32) -> bool
pub fn is_animating(&self, on_classname: &'static str, id: u32) -> bool
Checks if a specific animation instance is currently playing.
Returns true if the animation is playing, false otherwise.
Sourcepub fn animate_by_closure_rangegeneric<T>(
&mut self,
on_classname: &'static str,
id: u32,
direction: fn(bool) -> bool,
start: fn(bool) -> bool,
range: Range<T>,
) -> T
pub fn animate_by_closure_rangegeneric<T>( &mut self, on_classname: &'static str, id: u32, direction: fn(bool) -> bool, start: fn(bool) -> bool, range: Range<T>, ) -> T
A flexible method to control an animation’s state using closures and retrieve its current value.
This function allows you to dynamically control the start and direction of an animation
while also getting its current interpolated value from a Range. It is designed for generic types
that may not support arithmetic interpolation.
§Arguments
on_classname: The name of the animation class.id: The unique identifier for the animation instance.direction: A closure that receives the current reverse state (trueif playing backwards) and returns the desired direction (truefor forward,falsefor reverse).start: A closure that receives the current animating state (trueif progress is between 0.0 and 1.0) and returns whether the animation should be restarted (trueto restart).range: TheRange<T>of values to animate between.
§Returns
The calculated value for the current frame, before state changes from the closures are applied.
Sourcepub fn animate_by_closure_range<T>(
&mut self,
on_classname: &'static str,
id: u32,
direction: fn(bool) -> bool,
start: fn(bool) -> bool,
range: Range<T>,
) -> Twhere
ProgressList<TRES, PRES>: GetValueByRange<T>,
pub fn animate_by_closure_range<T>(
&mut self,
on_classname: &'static str,
id: u32,
direction: fn(bool) -> bool,
start: fn(bool) -> bool,
range: Range<T>,
) -> Twhere
ProgressList<TRES, PRES>: GetValueByRange<T>,
A flexible method to control an animation’s state using closures and retrieve its current value.
This function allows you to dynamically control the start and direction of an animation
while also getting its current interpolated value from a Range. It is designed for types
that support arithmetic operations for smooth interpolation.
§Arguments
on_classname: The name of the animation class.id: The unique identifier for the animation instance.direction: A closure that receives the current reverse state (trueif playing backwards) and returns the desired direction (truefor forward,falsefor reverse).start: A closure that receives the current animating state (trueif progress is between 0.0 and 1.0) and returns whether the animation should be restarted (trueto restart).range: TheRange<T>of values to animate between.
§Returns
The calculated value for the current frame, before state changes from the closures are applied.
Source§impl<'a, const N: usize, UN: Eq, TRES: TimingResolution + Clone, PRES: ProgressResolution + Eq> KramaFrame<UClassList<N>, UFrameList<'a, N, UN, TRES, PRES>>
impl<'a, const N: usize, UN: Eq, TRES: TimingResolution + Clone, PRES: ProgressResolution + Eq> KramaFrame<UClassList<N>, UFrameList<'a, N, UN, TRES, PRES>>
Sourcepub fn change_keyframefunction(
&mut self,
classname: &'static str,
new: KeyFrameFunction,
)
pub fn change_keyframefunction( &mut self, classname: &'static str, new: KeyFrameFunction, )
Sourcepub fn update_progress(&mut self, delta_time: TRES)
pub fn update_progress(&mut self, delta_time: TRES)
Sourcepub fn restart_progress(&mut self, classname: &'static str, id: UN)
pub fn restart_progress(&mut self, classname: &'static str, id: UN)
Sourcepub fn get_progress_f32(&mut self, classname: &'static str, id: UN) -> f32
pub fn get_progress_f32(&mut self, classname: &'static str, id: UN) -> f32
Sourcepub fn set_timing(&mut self, classname: &'static str, id: UN, timing: TRES)
pub fn set_timing(&mut self, classname: &'static str, id: UN, timing: TRES)
Sourcepub fn get_timing(&mut self, classname: &'static str, id: UN) -> TRES
pub fn get_timing(&mut self, classname: &'static str, id: UN) -> TRES
Sourcepub fn is_reversed(&mut self, classname: &'static str, id: UN) -> bool
pub fn is_reversed(&mut self, classname: &'static str, id: UN) -> bool
Sourcepub fn is_any_animation_inprogress(&mut self) -> bool
pub fn is_any_animation_inprogress(&mut self) -> bool
Sourcepub fn get_time_f32(&mut self, classname: &'static str, id: UN) -> f32
pub fn get_time_f32(&mut self, classname: &'static str, id: UN) -> f32
Sourcepub fn from_range<T>(
&self,
on_classname: &'static str,
id: UN,
range: impl RangeBounds<T>,
) -> T
pub fn from_range<T>( &self, on_classname: &'static str, id: UN, range: impl RangeBounds<T>, ) -> T
rangebounded interpolated to get value from range bound such as start..end, start..=end, ..end and ..=end but it return default value if range is start.., .., =.. and start=..
Sourcepub fn get_value_byrange<T>(
&self,
classname: &'static str,
id: UN,
range: Range<T>,
) -> Twhere
ProgressList<TRES, PRES>: GetValueByRange<T>,
pub fn get_value_byrange<T>(
&self,
classname: &'static str,
id: UN,
range: Range<T>,
) -> Twhere
ProgressList<TRES, PRES>: GetValueByRange<T>,
Sourcepub fn get_value_byrange_inclusive<T>(
&self,
classname: &'static str,
id: UN,
range: RangeInclusive<T>,
) -> T
pub fn get_value_byrange_inclusive<T>( &self, classname: &'static str, id: UN, range: RangeInclusive<T>, ) -> T
Sourcepub fn from_range_generic<T>(
&self,
on_classname: &'static str,
id: UN,
range: impl RangeBounds<T>,
) -> T
pub fn from_range_generic<T>( &self, on_classname: &'static str, id: UN, range: impl RangeBounds<T>, ) -> T
rangebounded interpolated to get generic value from range bound such as start..end, start..=end, ..end and ..=end but it return default value if range is start.., .., =.. and start=..
Sourcepub fn get_generic_byrange<T>(
&self,
classname: &'static str,
id: UN,
range: Range<T>,
) -> T
pub fn get_generic_byrange<T>( &self, classname: &'static str, id: UN, range: Range<T>, ) -> T
Sourcepub fn get_generic_value_by_rangeinclusive<T>(
&self,
classname: &'static str,
id: UN,
range: RangeInclusive<T>,
) -> T
pub fn get_generic_value_by_rangeinclusive<T>( &self, classname: &'static str, id: UN, range: RangeInclusive<T>, ) -> T
Sourcepub fn reverse_animate(&mut self, classname: &'static str, id: UN)
pub fn reverse_animate(&mut self, classname: &'static str, id: UN)
Sourcepub fn reverse_start(&mut self, classname: &'static str, id: UN)
pub fn reverse_start(&mut self, classname: &'static str, id: UN)
Trait Implementations§
Source§impl<TRES: TimingResolution + Clone, PRES: ProgressResolution + Eq> Default for KramaFrame<BTreeMap<&'static str, KeyFrameFunction>, BTframelist<TRES, PRES>>
Available on crate features std or alloc only.
impl<TRES: TimingResolution + Clone, PRES: ProgressResolution + Eq> Default for KramaFrame<BTreeMap<&'static str, KeyFrameFunction>, BTframelist<TRES, PRES>>
std or alloc only.