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, PRES: ProgressResolution + Eq> KramaFrame<BTclasslist, BTreeMap<&'static str, KeyList<TRES, PRES>>>
impl<TRES: TimingResolution, 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], )
Extends the class list with new definitions or replaces existing ones.
§Example
krama.extend_iter_classlist([
("button1", KeyFrameFunction::Linear),
("fade_in", KeyFrameFunction::EaseIn),
]);Examples found in repository?
3fn main() {
4 let mut kramaframe: KramaFrame<BTclasslist, BTframelist<_, i32>> = KramaFrame::default();
5 kramaframe.extend_iter_classlist([("animation1", KeyFrameFunction::Linear)]);
6 kramaframe.insert_new_id("animation1", 1, 1.0);
7 kramaframe.restart_progress("animation1", 1);
8
9 for _ in 0..=121 {
10 kramaframe.update_progress(1. / 120.);
11 println!(
12 "progress= {}, value = {}",
13 kramaframe.get_progress_f32("animation1", 1),
14 kramaframe.get_value_byrange_inclusive("animation1", 1, 80f32..=100f32)
15 );
16 }
17
18 kramaframe.reverse_animate("animation1", 1);
19
20 for _ in 0..=121 {
21 kramaframe.update_progress(1. / 120.);
22 println!(
23 "progress= {}, value = {}",
24 kramaframe.get_progress_f32("animation1", 1),
25 kramaframe.get_value_byrange_inclusive("animation1", 1, 80f32..=100f32)
26 );
27 }
28}More examples
7fn main() {
8 let mut kramaframe: KramaFrame<_, BTframelist<TRES16Bits, i32>> = KramaFrame::default();
9
10 kramaframe.extend_iter_classlist([
11 ("linear", KeyFrameFunction::Linear),
12 ("easein", KeyFrameFunction::EaseIn),
13 ("easeout", KeyFrameFunction::EaseOut),
14 ("easeinout", KeyFrameFunction::EaseInOut),
15 (
16 "cubic",
17 KeyFrameFunction::new_cubic_bezier_f32(0., 1.26, 1., -0.79),
18 ),
19 ("step", KeyFrameFunction::Steps(5)),
20 ]);
21
22 kramaframe.framelist.extend([
23 ("linear", KeyList::new(1, TRES16Bits::from_millis(1000))),
24 ("easein", KeyList::new(1, TRES16Bits::from_millis(1000))),
25 ("easeout", KeyList::new(1, TRES16Bits::from_millis(1000))),
26 ("easeinout", KeyList::new(1, TRES16Bits::from_millis(1000))),
27 ("easeinout", KeyList::new(1, TRES16Bits::from_millis(1000))),
28 ("cubic", KeyList::new(1, TRES16Bits::from_millis(1000))),
29 ("step", KeyList::new(1, TRES16Bits::from_millis(1000))),
30 ]);
31
32 // Linear
33 for _ in 0..=60 {
34 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
35 let linear =
36 kramaframe.animate_by_closure_range("linear", 1, |x| !x, |ongoing| !ongoing, 0..90u32);
37 println!("linear : {} : {}", linear, "█".repeat(linear as usize));
38 }
39 // EaseIn
40 for _ in 0..=90 {
41 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 90));
42 let easein =
43 kramaframe.animate_by_closure_range("easein", 1, |x| !x, |ongoing| !ongoing, 0..90u32);
44 println!("easein : {} : {}", easein, "█".repeat(easein as usize));
45 }
46 // EaseOut
47 for _ in 0..=90 {
48 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 90));
49 let easeout =
50 kramaframe.animate_by_closure_range("easeout", 1, |x| !x, |ongoing| !ongoing, 0..90u32);
51 println!("easeout : {} : {}", easeout, "█".repeat(easeout as usize));
52 }
53 // EaseInOut
54 for _ in 0..=90 {
55 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 90));
56 let easeinout = kramaframe.animate_by_closure_range(
57 "easeinout",
58 1,
59 |x| !x,
60 |ongoing| !ongoing,
61 0..90u32,
62 );
63 println!(
64 "easeinout : {} : {}",
65 easeinout,
66 "█".repeat(easeinout as usize)
67 );
68 }
69 // Cubic
70 for _ in 0..=90 {
71 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 90));
72 let cubic =
73 kramaframe.animate_by_closure_range("cubic", 1, |x| !x, |ongoing| !ongoing, 0..90u32);
74 println!("cubic : {} : {}", cubic, "█".repeat(cubic as usize));
75 }
76 // Steps
77 for _ in 0..=90 {
78 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 90));
79 let steps =
80 kramaframe.animate_by_closure_range("step", 1, |x| !x, |ongoing| !ongoing, 0..90u32);
81 println!("steps : {} : {}", steps, "█".repeat(steps as usize));
82 }
83}7fn main() {
8 let mut kramaframe: KramaFrame<_, BTframelist<TRES16Bits, i32>> = KramaFrame::default();
9
10 kramaframe.extend_iter_classlist([
11 ("linear", KeyFrameFunction::Linear),
12 ("ease", KeyFrameFunction::Ease),
13 (
14 "cubic",
15 KeyFrameFunction::new_cubic_bezier_f32(0., 0.5, 1., -0.35),
16 ),
17 ]);
18
19 kramaframe.framelist.extend([
20 ("linear", KeyList::new(1, TRES16Bits::from_millis(1000))),
21 ("ease", KeyList::new(1, TRES16Bits::from_millis(1000))),
22 ("cubic", KeyList::new(1, TRES16Bits::from_millis(1000))),
23 ]);
24
25 // Linear
26 kramaframe.restart_progress("linear", 1);
27 for _ in 0..=61 {
28 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
29 let linear = kramaframe.get_value_byrange("linear", 1, 0..90u32);
30 println!("linear : {} : {}", linear, "█".repeat(linear as usize));
31 }
32 kramaframe.reverse_animate("linear", 1);
33 for _ in 0..=61 {
34 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
35 let linear = kramaframe.get_value_byrange("linear", 1, 0..90u32);
36 println!("linear : {} : {}", linear, "█".repeat(linear as usize));
37 }
38
39 // Ease
40 kramaframe.restart_progress("ease", 1);
41 for _ in 0..=61 {
42 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
43 let ease = kramaframe.get_value_byrange("ease", 1, 0..90u32);
44 println!("ease : {} : {}", ease, "█".repeat(ease as usize));
45 }
46 kramaframe.reverse_animate("ease", 1);
47 for _ in 0..=61 {
48 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
49 let ease = kramaframe.get_value_byrange("ease", 1, 0..90u32);
50 println!("ease : {} : {}", ease, "█".repeat(ease as usize));
51 }
52
53 // Cubic
54 kramaframe.restart_progress("cubic", 1);
55 for _ in 0..=62 {
56 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
57 let cubic = kramaframe.get_value_byrange("cubic", 1, 0..90u32);
58 println!("cubic : {} : {}", cubic, "█".repeat(cubic as usize));
59 }
60 kramaframe.reverse_animate("cubic", 1);
61 for _ in 0..=62 {
62 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
63 let cubic = kramaframe.get_value_byrange("cubic", 1, 0..90u32);
64 println!("cubic : {} : {}", cubic, "█".repeat(cubic as usize));
65 }
66
67 // Or call reverse_start to jump to the end.
68 kramaframe.reverse_start("linear", 1);
69 for _ in 0..=62 {
70 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
71 let linear = kramaframe.get_value_byrange("linear", 1, 0..90u32);
72 println!("linear : {} : {}", linear, "█".repeat(linear as usize));
73 }
74 kramaframe.reverse_start("ease", 1);
75 for _ in 0..=62 {
76 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
77 let ease = kramaframe.get_value_byrange("ease", 1, 0..90u32);
78 println!("ease : {} : {}", ease, "█".repeat(ease as usize));
79 }
80 kramaframe.reverse_start("cubic", 1);
81 for _ in 0..=62 {
82 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
83 let cubic = kramaframe.get_value_byrange("cubic", 1, 0..90u32);
84 println!("cubic : {} : {}", cubic, "█".repeat(cubic as usize));
85 }
86}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.
Examples found in repository?
3fn main() {
4 let mut animation_instance: KramaFrame<_, BTframelist<_, i16>> = KramaFrame::default();
5 animation_instance
6 .classlist
7 .insert("sample", kramaframe::prelude::KeyFrameFunction::EaseIn);
8 animation_instance.insert_new_id("sample", 1, TRES16Bits::from_millis(600));
9 animation_instance.restart_progress("sample", 1);
10
11 for i in 0..=60 {
12 animation_instance.update_progress(TRES16Bits::from_millis(16));
13 let value = animation_instance.get_value_byrange_inclusive("sample", 1, 100..=10i32);
14 println!("Value at frame {}: {}", i, value);
15 }
16}More examples
59fn main() {
60 let mut animation_instance: KramaFrame<_, BTframelist<_, i16>> = KramaFrame::default();
61 animation_instance
62 .classlist
63 .insert("point", kramaframe::prelude::KeyFrameFunction::EaseIn);
64 animation_instance.insert_new_id("point", 1, TRES16Bits::from_millis(600));
65 animation_instance.restart_progress("point", 1);
66
67 for i in 0..=90 {
68 animation_instance.update_progress(TRES16Bits::from_millis(16));
69 let point_value = animation_instance.get_generic_value_by_rangeinclusive(
70 "point",
71 1,
72 Point::new(3.0, 4.0)..=Point::new(5.0, 6.0),
73 );
74 println!("Frame {} point position is {}", i, point_value)
75 }
76}3fn main() {
4 let mut kramaframe: KramaFrame<BTclasslist, BTframelist<_, i32>> = KramaFrame::default();
5 kramaframe.extend_iter_classlist([("animation1", KeyFrameFunction::Linear)]);
6 kramaframe.insert_new_id("animation1", 1, 1.0);
7 kramaframe.restart_progress("animation1", 1);
8
9 for _ in 0..=121 {
10 kramaframe.update_progress(1. / 120.);
11 println!(
12 "progress= {}, value = {}",
13 kramaframe.get_progress_f32("animation1", 1),
14 kramaframe.get_value_byrange_inclusive("animation1", 1, 80f32..=100f32)
15 );
16 }
17
18 kramaframe.reverse_animate("animation1", 1);
19
20 for _ in 0..=121 {
21 kramaframe.update_progress(1. / 120.);
22 println!(
23 "progress= {}, value = {}",
24 kramaframe.get_progress_f32("animation1", 1),
25 kramaframe.get_value_byrange_inclusive("animation1", 1, 80f32..=100f32)
26 );
27 }
28}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.
Examples found in repository?
3fn main() {
4 let mut animation_instance: KramaFrame<_, BTframelist<_, i16>> = KramaFrame::default();
5 animation_instance
6 .classlist
7 .insert("sample", kramaframe::prelude::KeyFrameFunction::EaseIn);
8 animation_instance.insert_new_id("sample", 1, TRES16Bits::from_millis(600));
9 animation_instance.restart_progress("sample", 1);
10
11 for i in 0..=60 {
12 animation_instance.update_progress(TRES16Bits::from_millis(16));
13 let value = animation_instance.get_value_byrange_inclusive("sample", 1, 100..=10i32);
14 println!("Value at frame {}: {}", i, value);
15 }
16}More examples
59fn main() {
60 let mut animation_instance: KramaFrame<_, BTframelist<_, i16>> = KramaFrame::default();
61 animation_instance
62 .classlist
63 .insert("point", kramaframe::prelude::KeyFrameFunction::EaseIn);
64 animation_instance.insert_new_id("point", 1, TRES16Bits::from_millis(600));
65 animation_instance.restart_progress("point", 1);
66
67 for i in 0..=90 {
68 animation_instance.update_progress(TRES16Bits::from_millis(16));
69 let point_value = animation_instance.get_generic_value_by_rangeinclusive(
70 "point",
71 1,
72 Point::new(3.0, 4.0)..=Point::new(5.0, 6.0),
73 );
74 println!("Frame {} point position is {}", i, point_value)
75 }
76}3fn main() {
4 let mut kramaframe: KramaFrame<BTclasslist, BTframelist<_, i32>> = KramaFrame::default();
5 kramaframe.extend_iter_classlist([("animation1", KeyFrameFunction::Linear)]);
6 kramaframe.insert_new_id("animation1", 1, 1.0);
7 kramaframe.restart_progress("animation1", 1);
8
9 for _ in 0..=121 {
10 kramaframe.update_progress(1. / 120.);
11 println!(
12 "progress= {}, value = {}",
13 kramaframe.get_progress_f32("animation1", 1),
14 kramaframe.get_value_byrange_inclusive("animation1", 1, 80f32..=100f32)
15 );
16 }
17
18 kramaframe.reverse_animate("animation1", 1);
19
20 for _ in 0..=121 {
21 kramaframe.update_progress(1. / 120.);
22 println!(
23 "progress= {}, value = {}",
24 kramaframe.get_progress_f32("animation1", 1),
25 kramaframe.get_value_byrange_inclusive("animation1", 1, 80f32..=100f32)
26 );
27 }
28}7fn main() {
8 let mut kramaframe: KramaFrame<_, BTframelist<TRES16Bits, i32>> = KramaFrame::default();
9
10 kramaframe.extend_iter_classlist([
11 ("linear", KeyFrameFunction::Linear),
12 ("easein", KeyFrameFunction::EaseIn),
13 ("easeout", KeyFrameFunction::EaseOut),
14 ("easeinout", KeyFrameFunction::EaseInOut),
15 (
16 "cubic",
17 KeyFrameFunction::new_cubic_bezier_f32(0., 1.26, 1., -0.79),
18 ),
19 ("step", KeyFrameFunction::Steps(5)),
20 ]);
21
22 kramaframe.framelist.extend([
23 ("linear", KeyList::new(1, TRES16Bits::from_millis(1000))),
24 ("easein", KeyList::new(1, TRES16Bits::from_millis(1000))),
25 ("easeout", KeyList::new(1, TRES16Bits::from_millis(1000))),
26 ("easeinout", KeyList::new(1, TRES16Bits::from_millis(1000))),
27 ("easeinout", KeyList::new(1, TRES16Bits::from_millis(1000))),
28 ("cubic", KeyList::new(1, TRES16Bits::from_millis(1000))),
29 ("step", KeyList::new(1, TRES16Bits::from_millis(1000))),
30 ]);
31
32 // Linear
33 for _ in 0..=60 {
34 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
35 let linear =
36 kramaframe.animate_by_closure_range("linear", 1, |x| !x, |ongoing| !ongoing, 0..90u32);
37 println!("linear : {} : {}", linear, "█".repeat(linear as usize));
38 }
39 // EaseIn
40 for _ in 0..=90 {
41 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 90));
42 let easein =
43 kramaframe.animate_by_closure_range("easein", 1, |x| !x, |ongoing| !ongoing, 0..90u32);
44 println!("easein : {} : {}", easein, "█".repeat(easein as usize));
45 }
46 // EaseOut
47 for _ in 0..=90 {
48 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 90));
49 let easeout =
50 kramaframe.animate_by_closure_range("easeout", 1, |x| !x, |ongoing| !ongoing, 0..90u32);
51 println!("easeout : {} : {}", easeout, "█".repeat(easeout as usize));
52 }
53 // EaseInOut
54 for _ in 0..=90 {
55 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 90));
56 let easeinout = kramaframe.animate_by_closure_range(
57 "easeinout",
58 1,
59 |x| !x,
60 |ongoing| !ongoing,
61 0..90u32,
62 );
63 println!(
64 "easeinout : {} : {}",
65 easeinout,
66 "█".repeat(easeinout as usize)
67 );
68 }
69 // Cubic
70 for _ in 0..=90 {
71 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 90));
72 let cubic =
73 kramaframe.animate_by_closure_range("cubic", 1, |x| !x, |ongoing| !ongoing, 0..90u32);
74 println!("cubic : {} : {}", cubic, "█".repeat(cubic as usize));
75 }
76 // Steps
77 for _ in 0..=90 {
78 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 90));
79 let steps =
80 kramaframe.animate_by_closure_range("step", 1, |x| !x, |ongoing| !ongoing, 0..90u32);
81 println!("steps : {} : {}", steps, "█".repeat(steps as usize));
82 }
83}7fn main() {
8 let mut kramaframe: KramaFrame<_, BTframelist<TRES16Bits, i32>> = KramaFrame::default();
9
10 kramaframe.extend_iter_classlist([
11 ("linear", KeyFrameFunction::Linear),
12 ("ease", KeyFrameFunction::Ease),
13 (
14 "cubic",
15 KeyFrameFunction::new_cubic_bezier_f32(0., 0.5, 1., -0.35),
16 ),
17 ]);
18
19 kramaframe.framelist.extend([
20 ("linear", KeyList::new(1, TRES16Bits::from_millis(1000))),
21 ("ease", KeyList::new(1, TRES16Bits::from_millis(1000))),
22 ("cubic", KeyList::new(1, TRES16Bits::from_millis(1000))),
23 ]);
24
25 // Linear
26 kramaframe.restart_progress("linear", 1);
27 for _ in 0..=61 {
28 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
29 let linear = kramaframe.get_value_byrange("linear", 1, 0..90u32);
30 println!("linear : {} : {}", linear, "█".repeat(linear as usize));
31 }
32 kramaframe.reverse_animate("linear", 1);
33 for _ in 0..=61 {
34 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
35 let linear = kramaframe.get_value_byrange("linear", 1, 0..90u32);
36 println!("linear : {} : {}", linear, "█".repeat(linear as usize));
37 }
38
39 // Ease
40 kramaframe.restart_progress("ease", 1);
41 for _ in 0..=61 {
42 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
43 let ease = kramaframe.get_value_byrange("ease", 1, 0..90u32);
44 println!("ease : {} : {}", ease, "█".repeat(ease as usize));
45 }
46 kramaframe.reverse_animate("ease", 1);
47 for _ in 0..=61 {
48 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
49 let ease = kramaframe.get_value_byrange("ease", 1, 0..90u32);
50 println!("ease : {} : {}", ease, "█".repeat(ease as usize));
51 }
52
53 // Cubic
54 kramaframe.restart_progress("cubic", 1);
55 for _ in 0..=62 {
56 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
57 let cubic = kramaframe.get_value_byrange("cubic", 1, 0..90u32);
58 println!("cubic : {} : {}", cubic, "█".repeat(cubic as usize));
59 }
60 kramaframe.reverse_animate("cubic", 1);
61 for _ in 0..=62 {
62 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
63 let cubic = kramaframe.get_value_byrange("cubic", 1, 0..90u32);
64 println!("cubic : {} : {}", cubic, "█".repeat(cubic as usize));
65 }
66
67 // Or call reverse_start to jump to the end.
68 kramaframe.reverse_start("linear", 1);
69 for _ in 0..=62 {
70 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
71 let linear = kramaframe.get_value_byrange("linear", 1, 0..90u32);
72 println!("linear : {} : {}", linear, "█".repeat(linear as usize));
73 }
74 kramaframe.reverse_start("ease", 1);
75 for _ in 0..=62 {
76 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
77 let ease = kramaframe.get_value_byrange("ease", 1, 0..90u32);
78 println!("ease : {} : {}", ease, "█".repeat(ease as usize));
79 }
80 kramaframe.reverse_start("cubic", 1);
81 for _ in 0..=62 {
82 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
83 let cubic = kramaframe.get_value_byrange("cubic", 1, 0..90u32);
84 println!("cubic : {} : {}", cubic, "█".repeat(cubic as usize));
85 }
86}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.
Examples found in repository?
3fn main() {
4 let mut animation_instance: KramaFrame<_, BTframelist<_, i16>> = KramaFrame::default();
5 animation_instance
6 .classlist
7 .insert("sample", kramaframe::prelude::KeyFrameFunction::EaseIn);
8 animation_instance.insert_new_id("sample", 1, TRES16Bits::from_millis(600));
9 animation_instance.restart_progress("sample", 1);
10
11 for i in 0..=60 {
12 animation_instance.update_progress(TRES16Bits::from_millis(16));
13 let value = animation_instance.get_value_byrange_inclusive("sample", 1, 100..=10i32);
14 println!("Value at frame {}: {}", i, value);
15 }
16}More examples
59fn main() {
60 let mut animation_instance: KramaFrame<_, BTframelist<_, i16>> = KramaFrame::default();
61 animation_instance
62 .classlist
63 .insert("point", kramaframe::prelude::KeyFrameFunction::EaseIn);
64 animation_instance.insert_new_id("point", 1, TRES16Bits::from_millis(600));
65 animation_instance.restart_progress("point", 1);
66
67 for i in 0..=90 {
68 animation_instance.update_progress(TRES16Bits::from_millis(16));
69 let point_value = animation_instance.get_generic_value_by_rangeinclusive(
70 "point",
71 1,
72 Point::new(3.0, 4.0)..=Point::new(5.0, 6.0),
73 );
74 println!("Frame {} point position is {}", i, point_value)
75 }
76}3fn main() {
4 let mut kramaframe: KramaFrame<BTclasslist, BTframelist<_, i32>> = KramaFrame::default();
5 kramaframe.extend_iter_classlist([("animation1", KeyFrameFunction::Linear)]);
6 kramaframe.insert_new_id("animation1", 1, 1.0);
7 kramaframe.restart_progress("animation1", 1);
8
9 for _ in 0..=121 {
10 kramaframe.update_progress(1. / 120.);
11 println!(
12 "progress= {}, value = {}",
13 kramaframe.get_progress_f32("animation1", 1),
14 kramaframe.get_value_byrange_inclusive("animation1", 1, 80f32..=100f32)
15 );
16 }
17
18 kramaframe.reverse_animate("animation1", 1);
19
20 for _ in 0..=121 {
21 kramaframe.update_progress(1. / 120.);
22 println!(
23 "progress= {}, value = {}",
24 kramaframe.get_progress_f32("animation1", 1),
25 kramaframe.get_value_byrange_inclusive("animation1", 1, 80f32..=100f32)
26 );
27 }
28}7fn main() {
8 let mut kramaframe: KramaFrame<_, BTframelist<TRES16Bits, i32>> = KramaFrame::default();
9
10 kramaframe.extend_iter_classlist([
11 ("linear", KeyFrameFunction::Linear),
12 ("ease", KeyFrameFunction::Ease),
13 (
14 "cubic",
15 KeyFrameFunction::new_cubic_bezier_f32(0., 0.5, 1., -0.35),
16 ),
17 ]);
18
19 kramaframe.framelist.extend([
20 ("linear", KeyList::new(1, TRES16Bits::from_millis(1000))),
21 ("ease", KeyList::new(1, TRES16Bits::from_millis(1000))),
22 ("cubic", KeyList::new(1, TRES16Bits::from_millis(1000))),
23 ]);
24
25 // Linear
26 kramaframe.restart_progress("linear", 1);
27 for _ in 0..=61 {
28 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
29 let linear = kramaframe.get_value_byrange("linear", 1, 0..90u32);
30 println!("linear : {} : {}", linear, "█".repeat(linear as usize));
31 }
32 kramaframe.reverse_animate("linear", 1);
33 for _ in 0..=61 {
34 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
35 let linear = kramaframe.get_value_byrange("linear", 1, 0..90u32);
36 println!("linear : {} : {}", linear, "█".repeat(linear as usize));
37 }
38
39 // Ease
40 kramaframe.restart_progress("ease", 1);
41 for _ in 0..=61 {
42 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
43 let ease = kramaframe.get_value_byrange("ease", 1, 0..90u32);
44 println!("ease : {} : {}", ease, "█".repeat(ease as usize));
45 }
46 kramaframe.reverse_animate("ease", 1);
47 for _ in 0..=61 {
48 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
49 let ease = kramaframe.get_value_byrange("ease", 1, 0..90u32);
50 println!("ease : {} : {}", ease, "█".repeat(ease as usize));
51 }
52
53 // Cubic
54 kramaframe.restart_progress("cubic", 1);
55 for _ in 0..=62 {
56 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
57 let cubic = kramaframe.get_value_byrange("cubic", 1, 0..90u32);
58 println!("cubic : {} : {}", cubic, "█".repeat(cubic as usize));
59 }
60 kramaframe.reverse_animate("cubic", 1);
61 for _ in 0..=62 {
62 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
63 let cubic = kramaframe.get_value_byrange("cubic", 1, 0..90u32);
64 println!("cubic : {} : {}", cubic, "█".repeat(cubic as usize));
65 }
66
67 // Or call reverse_start to jump to the end.
68 kramaframe.reverse_start("linear", 1);
69 for _ in 0..=62 {
70 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
71 let linear = kramaframe.get_value_byrange("linear", 1, 0..90u32);
72 println!("linear : {} : {}", linear, "█".repeat(linear as usize));
73 }
74 kramaframe.reverse_start("ease", 1);
75 for _ in 0..=62 {
76 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
77 let ease = kramaframe.get_value_byrange("ease", 1, 0..90u32);
78 println!("ease : {} : {}", ease, "█".repeat(ease as usize));
79 }
80 kramaframe.reverse_start("cubic", 1);
81 for _ in 0..=62 {
82 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
83 let cubic = kramaframe.get_value_byrange("cubic", 1, 0..90u32);
84 println!("cubic : {} : {}", cubic, "█".repeat(cubic as usize));
85 }
86}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.
Examples found in repository?
3fn main() {
4 let mut kramaframe: KramaFrame<BTclasslist, BTframelist<_, i32>> = KramaFrame::default();
5 kramaframe.extend_iter_classlist([("animation1", KeyFrameFunction::Linear)]);
6 kramaframe.insert_new_id("animation1", 1, 1.0);
7 kramaframe.restart_progress("animation1", 1);
8
9 for _ in 0..=121 {
10 kramaframe.update_progress(1. / 120.);
11 println!(
12 "progress= {}, value = {}",
13 kramaframe.get_progress_f32("animation1", 1),
14 kramaframe.get_value_byrange_inclusive("animation1", 1, 80f32..=100f32)
15 );
16 }
17
18 kramaframe.reverse_animate("animation1", 1);
19
20 for _ in 0..=121 {
21 kramaframe.update_progress(1. / 120.);
22 println!(
23 "progress= {}, value = {}",
24 kramaframe.get_progress_f32("animation1", 1),
25 kramaframe.get_value_byrange_inclusive("animation1", 1, 80f32..=100f32)
26 );
27 }
28}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 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.
Examples found in repository?
7fn main() {
8 let mut kramaframe: KramaFrame<_, BTframelist<TRES16Bits, i32>> = KramaFrame::default();
9
10 kramaframe.extend_iter_classlist([
11 ("linear", KeyFrameFunction::Linear),
12 ("ease", KeyFrameFunction::Ease),
13 (
14 "cubic",
15 KeyFrameFunction::new_cubic_bezier_f32(0., 0.5, 1., -0.35),
16 ),
17 ]);
18
19 kramaframe.framelist.extend([
20 ("linear", KeyList::new(1, TRES16Bits::from_millis(1000))),
21 ("ease", KeyList::new(1, TRES16Bits::from_millis(1000))),
22 ("cubic", KeyList::new(1, TRES16Bits::from_millis(1000))),
23 ]);
24
25 // Linear
26 kramaframe.restart_progress("linear", 1);
27 for _ in 0..=61 {
28 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
29 let linear = kramaframe.get_value_byrange("linear", 1, 0..90u32);
30 println!("linear : {} : {}", linear, "█".repeat(linear as usize));
31 }
32 kramaframe.reverse_animate("linear", 1);
33 for _ in 0..=61 {
34 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
35 let linear = kramaframe.get_value_byrange("linear", 1, 0..90u32);
36 println!("linear : {} : {}", linear, "█".repeat(linear as usize));
37 }
38
39 // Ease
40 kramaframe.restart_progress("ease", 1);
41 for _ in 0..=61 {
42 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
43 let ease = kramaframe.get_value_byrange("ease", 1, 0..90u32);
44 println!("ease : {} : {}", ease, "█".repeat(ease as usize));
45 }
46 kramaframe.reverse_animate("ease", 1);
47 for _ in 0..=61 {
48 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
49 let ease = kramaframe.get_value_byrange("ease", 1, 0..90u32);
50 println!("ease : {} : {}", ease, "█".repeat(ease as usize));
51 }
52
53 // Cubic
54 kramaframe.restart_progress("cubic", 1);
55 for _ in 0..=62 {
56 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
57 let cubic = kramaframe.get_value_byrange("cubic", 1, 0..90u32);
58 println!("cubic : {} : {}", cubic, "█".repeat(cubic as usize));
59 }
60 kramaframe.reverse_animate("cubic", 1);
61 for _ in 0..=62 {
62 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
63 let cubic = kramaframe.get_value_byrange("cubic", 1, 0..90u32);
64 println!("cubic : {} : {}", cubic, "█".repeat(cubic as usize));
65 }
66
67 // Or call reverse_start to jump to the end.
68 kramaframe.reverse_start("linear", 1);
69 for _ in 0..=62 {
70 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
71 let linear = kramaframe.get_value_byrange("linear", 1, 0..90u32);
72 println!("linear : {} : {}", linear, "█".repeat(linear as usize));
73 }
74 kramaframe.reverse_start("ease", 1);
75 for _ in 0..=62 {
76 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
77 let ease = kramaframe.get_value_byrange("ease", 1, 0..90u32);
78 println!("ease : {} : {}", ease, "█".repeat(ease as usize));
79 }
80 kramaframe.reverse_start("cubic", 1);
81 for _ in 0..=62 {
82 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
83 let cubic = kramaframe.get_value_byrange("cubic", 1, 0..90u32);
84 println!("cubic : {} : {}", cubic, "█".repeat(cubic as usize));
85 }
86}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.
Examples found in repository?
3fn main() {
4 let mut animation_instance: KramaFrame<_, BTframelist<_, i16>> = KramaFrame::default();
5 animation_instance
6 .classlist
7 .insert("sample", kramaframe::prelude::KeyFrameFunction::EaseIn);
8 animation_instance.insert_new_id("sample", 1, TRES16Bits::from_millis(600));
9 animation_instance.restart_progress("sample", 1);
10
11 for i in 0..=60 {
12 animation_instance.update_progress(TRES16Bits::from_millis(16));
13 let value = animation_instance.get_value_byrange_inclusive("sample", 1, 100..=10i32);
14 println!("Value at frame {}: {}", i, value);
15 }
16}More examples
3fn main() {
4 let mut kramaframe: KramaFrame<BTclasslist, BTframelist<_, i32>> = KramaFrame::default();
5 kramaframe.extend_iter_classlist([("animation1", KeyFrameFunction::Linear)]);
6 kramaframe.insert_new_id("animation1", 1, 1.0);
7 kramaframe.restart_progress("animation1", 1);
8
9 for _ in 0..=121 {
10 kramaframe.update_progress(1. / 120.);
11 println!(
12 "progress= {}, value = {}",
13 kramaframe.get_progress_f32("animation1", 1),
14 kramaframe.get_value_byrange_inclusive("animation1", 1, 80f32..=100f32)
15 );
16 }
17
18 kramaframe.reverse_animate("animation1", 1);
19
20 for _ in 0..=121 {
21 kramaframe.update_progress(1. / 120.);
22 println!(
23 "progress= {}, value = {}",
24 kramaframe.get_progress_f32("animation1", 1),
25 kramaframe.get_value_byrange_inclusive("animation1", 1, 80f32..=100f32)
26 );
27 }
28}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
#[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
#[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.
Examples found in repository?
59fn main() {
60 let mut animation_instance: KramaFrame<_, BTframelist<_, i16>> = KramaFrame::default();
61 animation_instance
62 .classlist
63 .insert("point", kramaframe::prelude::KeyFrameFunction::EaseIn);
64 animation_instance.insert_new_id("point", 1, TRES16Bits::from_millis(600));
65 animation_instance.restart_progress("point", 1);
66
67 for i in 0..=90 {
68 animation_instance.update_progress(TRES16Bits::from_millis(16));
69 let point_value = animation_instance.get_generic_value_by_rangeinclusive(
70 "point",
71 1,
72 Point::new(3.0, 4.0)..=Point::new(5.0, 6.0),
73 );
74 println!("Frame {} point position is {}", i, point_value)
75 }
76}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.
Examples found in repository?
3fn main() {
4 let mut kramaframe: KramaFrame<BTclasslist, BTframelist<_, i32>> = KramaFrame::default();
5 kramaframe.extend_iter_classlist([("animation1", KeyFrameFunction::Linear)]);
6 kramaframe.insert_new_id("animation1", 1, 1.0);
7 kramaframe.restart_progress("animation1", 1);
8
9 for _ in 0..=121 {
10 kramaframe.update_progress(1. / 120.);
11 println!(
12 "progress= {}, value = {}",
13 kramaframe.get_progress_f32("animation1", 1),
14 kramaframe.get_value_byrange_inclusive("animation1", 1, 80f32..=100f32)
15 );
16 }
17
18 kramaframe.reverse_animate("animation1", 1);
19
20 for _ in 0..=121 {
21 kramaframe.update_progress(1. / 120.);
22 println!(
23 "progress= {}, value = {}",
24 kramaframe.get_progress_f32("animation1", 1),
25 kramaframe.get_value_byrange_inclusive("animation1", 1, 80f32..=100f32)
26 );
27 }
28}More examples
7fn main() {
8 let mut kramaframe: KramaFrame<_, BTframelist<TRES16Bits, i32>> = KramaFrame::default();
9
10 kramaframe.extend_iter_classlist([
11 ("linear", KeyFrameFunction::Linear),
12 ("ease", KeyFrameFunction::Ease),
13 (
14 "cubic",
15 KeyFrameFunction::new_cubic_bezier_f32(0., 0.5, 1., -0.35),
16 ),
17 ]);
18
19 kramaframe.framelist.extend([
20 ("linear", KeyList::new(1, TRES16Bits::from_millis(1000))),
21 ("ease", KeyList::new(1, TRES16Bits::from_millis(1000))),
22 ("cubic", KeyList::new(1, TRES16Bits::from_millis(1000))),
23 ]);
24
25 // Linear
26 kramaframe.restart_progress("linear", 1);
27 for _ in 0..=61 {
28 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
29 let linear = kramaframe.get_value_byrange("linear", 1, 0..90u32);
30 println!("linear : {} : {}", linear, "█".repeat(linear as usize));
31 }
32 kramaframe.reverse_animate("linear", 1);
33 for _ in 0..=61 {
34 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
35 let linear = kramaframe.get_value_byrange("linear", 1, 0..90u32);
36 println!("linear : {} : {}", linear, "█".repeat(linear as usize));
37 }
38
39 // Ease
40 kramaframe.restart_progress("ease", 1);
41 for _ in 0..=61 {
42 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
43 let ease = kramaframe.get_value_byrange("ease", 1, 0..90u32);
44 println!("ease : {} : {}", ease, "█".repeat(ease as usize));
45 }
46 kramaframe.reverse_animate("ease", 1);
47 for _ in 0..=61 {
48 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
49 let ease = kramaframe.get_value_byrange("ease", 1, 0..90u32);
50 println!("ease : {} : {}", ease, "█".repeat(ease as usize));
51 }
52
53 // Cubic
54 kramaframe.restart_progress("cubic", 1);
55 for _ in 0..=62 {
56 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
57 let cubic = kramaframe.get_value_byrange("cubic", 1, 0..90u32);
58 println!("cubic : {} : {}", cubic, "█".repeat(cubic as usize));
59 }
60 kramaframe.reverse_animate("cubic", 1);
61 for _ in 0..=62 {
62 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
63 let cubic = kramaframe.get_value_byrange("cubic", 1, 0..90u32);
64 println!("cubic : {} : {}", cubic, "█".repeat(cubic as usize));
65 }
66
67 // Or call reverse_start to jump to the end.
68 kramaframe.reverse_start("linear", 1);
69 for _ in 0..=62 {
70 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
71 let linear = kramaframe.get_value_byrange("linear", 1, 0..90u32);
72 println!("linear : {} : {}", linear, "█".repeat(linear as usize));
73 }
74 kramaframe.reverse_start("ease", 1);
75 for _ in 0..=62 {
76 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
77 let ease = kramaframe.get_value_byrange("ease", 1, 0..90u32);
78 println!("ease : {} : {}", ease, "█".repeat(ease as usize));
79 }
80 kramaframe.reverse_start("cubic", 1);
81 for _ in 0..=62 {
82 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
83 let cubic = kramaframe.get_value_byrange("cubic", 1, 0..90u32);
84 println!("cubic : {} : {}", cubic, "█".repeat(cubic as usize));
85 }
86}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.
Examples found in repository?
7fn main() {
8 let mut kramaframe: KramaFrame<_, BTframelist<TRES16Bits, i32>> = KramaFrame::default();
9
10 kramaframe.extend_iter_classlist([
11 ("linear", KeyFrameFunction::Linear),
12 ("ease", KeyFrameFunction::Ease),
13 (
14 "cubic",
15 KeyFrameFunction::new_cubic_bezier_f32(0., 0.5, 1., -0.35),
16 ),
17 ]);
18
19 kramaframe.framelist.extend([
20 ("linear", KeyList::new(1, TRES16Bits::from_millis(1000))),
21 ("ease", KeyList::new(1, TRES16Bits::from_millis(1000))),
22 ("cubic", KeyList::new(1, TRES16Bits::from_millis(1000))),
23 ]);
24
25 // Linear
26 kramaframe.restart_progress("linear", 1);
27 for _ in 0..=61 {
28 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
29 let linear = kramaframe.get_value_byrange("linear", 1, 0..90u32);
30 println!("linear : {} : {}", linear, "█".repeat(linear as usize));
31 }
32 kramaframe.reverse_animate("linear", 1);
33 for _ in 0..=61 {
34 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
35 let linear = kramaframe.get_value_byrange("linear", 1, 0..90u32);
36 println!("linear : {} : {}", linear, "█".repeat(linear as usize));
37 }
38
39 // Ease
40 kramaframe.restart_progress("ease", 1);
41 for _ in 0..=61 {
42 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
43 let ease = kramaframe.get_value_byrange("ease", 1, 0..90u32);
44 println!("ease : {} : {}", ease, "█".repeat(ease as usize));
45 }
46 kramaframe.reverse_animate("ease", 1);
47 for _ in 0..=61 {
48 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
49 let ease = kramaframe.get_value_byrange("ease", 1, 0..90u32);
50 println!("ease : {} : {}", ease, "█".repeat(ease as usize));
51 }
52
53 // Cubic
54 kramaframe.restart_progress("cubic", 1);
55 for _ in 0..=62 {
56 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
57 let cubic = kramaframe.get_value_byrange("cubic", 1, 0..90u32);
58 println!("cubic : {} : {}", cubic, "█".repeat(cubic as usize));
59 }
60 kramaframe.reverse_animate("cubic", 1);
61 for _ in 0..=62 {
62 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
63 let cubic = kramaframe.get_value_byrange("cubic", 1, 0..90u32);
64 println!("cubic : {} : {}", cubic, "█".repeat(cubic as usize));
65 }
66
67 // Or call reverse_start to jump to the end.
68 kramaframe.reverse_start("linear", 1);
69 for _ in 0..=62 {
70 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
71 let linear = kramaframe.get_value_byrange("linear", 1, 0..90u32);
72 println!("linear : {} : {}", linear, "█".repeat(linear as usize));
73 }
74 kramaframe.reverse_start("ease", 1);
75 for _ in 0..=62 {
76 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
77 let ease = kramaframe.get_value_byrange("ease", 1, 0..90u32);
78 println!("ease : {} : {}", ease, "█".repeat(ease as usize));
79 }
80 kramaframe.reverse_start("cubic", 1);
81 for _ in 0..=62 {
82 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
83 let cubic = kramaframe.get_value_byrange("cubic", 1, 0..90u32);
84 println!("cubic : {} : {}", cubic, "█".repeat(cubic as usize));
85 }
86}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.
Examples found in repository?
7fn main() {
8 let mut kramaframe: KramaFrame<_, BTframelist<TRES16Bits, i32>> = KramaFrame::default();
9
10 kramaframe.extend_iter_classlist([
11 ("linear", KeyFrameFunction::Linear),
12 ("easein", KeyFrameFunction::EaseIn),
13 ("easeout", KeyFrameFunction::EaseOut),
14 ("easeinout", KeyFrameFunction::EaseInOut),
15 (
16 "cubic",
17 KeyFrameFunction::new_cubic_bezier_f32(0., 1.26, 1., -0.79),
18 ),
19 ("step", KeyFrameFunction::Steps(5)),
20 ]);
21
22 kramaframe.framelist.extend([
23 ("linear", KeyList::new(1, TRES16Bits::from_millis(1000))),
24 ("easein", KeyList::new(1, TRES16Bits::from_millis(1000))),
25 ("easeout", KeyList::new(1, TRES16Bits::from_millis(1000))),
26 ("easeinout", KeyList::new(1, TRES16Bits::from_millis(1000))),
27 ("easeinout", KeyList::new(1, TRES16Bits::from_millis(1000))),
28 ("cubic", KeyList::new(1, TRES16Bits::from_millis(1000))),
29 ("step", KeyList::new(1, TRES16Bits::from_millis(1000))),
30 ]);
31
32 // Linear
33 for _ in 0..=60 {
34 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 60));
35 let linear =
36 kramaframe.animate_by_closure_range("linear", 1, |x| !x, |ongoing| !ongoing, 0..90u32);
37 println!("linear : {} : {}", linear, "█".repeat(linear as usize));
38 }
39 // EaseIn
40 for _ in 0..=90 {
41 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 90));
42 let easein =
43 kramaframe.animate_by_closure_range("easein", 1, |x| !x, |ongoing| !ongoing, 0..90u32);
44 println!("easein : {} : {}", easein, "█".repeat(easein as usize));
45 }
46 // EaseOut
47 for _ in 0..=90 {
48 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 90));
49 let easeout =
50 kramaframe.animate_by_closure_range("easeout", 1, |x| !x, |ongoing| !ongoing, 0..90u32);
51 println!("easeout : {} : {}", easeout, "█".repeat(easeout as usize));
52 }
53 // EaseInOut
54 for _ in 0..=90 {
55 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 90));
56 let easeinout = kramaframe.animate_by_closure_range(
57 "easeinout",
58 1,
59 |x| !x,
60 |ongoing| !ongoing,
61 0..90u32,
62 );
63 println!(
64 "easeinout : {} : {}",
65 easeinout,
66 "█".repeat(easeinout as usize)
67 );
68 }
69 // Cubic
70 for _ in 0..=90 {
71 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 90));
72 let cubic =
73 kramaframe.animate_by_closure_range("cubic", 1, |x| !x, |ongoing| !ongoing, 0..90u32);
74 println!("cubic : {} : {}", cubic, "█".repeat(cubic as usize));
75 }
76 // Steps
77 for _ in 0..=90 {
78 kramaframe.update_progress(TRES16Bits::from_millis(1000 / 90));
79 let steps =
80 kramaframe.animate_by_closure_range("step", 1, |x| !x, |ongoing| !ongoing, 0..90u32);
81 println!("steps : {} : {}", steps, "█".repeat(steps as usize));
82 }
83}