-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
148 additions
and
36 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use std::fmt::Display; | ||
|
||
use crate::{Canvas, Context, LaterHookCondition, RenderFunction}; | ||
|
||
/// Arguments: animation progress (from 0.0 to 1.0), canvas, current ms | ||
pub type AnimationUpdateFunction = dyn Fn(f32, &mut Canvas, usize); | ||
|
||
pub struct Animation { | ||
pub name: String, | ||
// pub keyframes: Vec<Keyframe<C>>, | ||
pub update: Box<AnimationUpdateFunction>, | ||
} | ||
|
||
// pub struct Keyframe<C: Default> { | ||
// pub at: f32, // from 0 to 1 | ||
// pub action: Box<RenderFunction<C>>, | ||
// } | ||
|
||
impl Animation { | ||
/// Example | ||
/// ``` | ||
/// Animation::new("example", &|t, canvas, _| { | ||
/// canvas.root().object("dot").fill(Fill::Translucent(Color::Red, t)) | ||
/// }) | ||
/// ``` | ||
pub fn new<N>(name: N, f: &'static AnimationUpdateFunction) -> Self | ||
where | ||
N: Display, | ||
{ | ||
Self { | ||
name: format!("{}", name), | ||
update: Box::new(f), | ||
} | ||
} | ||
|
||
// /// Example: | ||
// /// ``` | ||
// /// animation.at(50.0, Box::new(|canvas, _| canvas.root().set_background(Color::Black))); | ||
// /// ``` | ||
// pub fn at(&mut self, percent: f32, action: Box<RenderFunction<C>>) { | ||
// self.keyframes.push(Keyframe { | ||
// at: percent / 100.0, | ||
// action, | ||
// }); | ||
// } | ||
} | ||
|
||
impl From<(String, Box<AnimationUpdateFunction>)> for Animation { | ||
fn from((name, f): (String, Box<AnimationUpdateFunction>)) -> Self { | ||
Self { name, update: f } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters