![](https://private-user-images.githubusercontent.com/17223924/343008476-2c5c1971-f10e-4766-9252-0ff8194e3e5d.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk2NTUyNTIsIm5iZiI6MTcxOTY1NDk1MiwicGF0aCI6Ii8xNzIyMzkyNC8zNDMwMDg0NzYtMmM1YzE5NzEtZjEwZS00NzY2LTkyNTItMGZmODE5NGUzZTVkLmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI5VDA5NTU1MlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTU4MjViMDI2YmQyMzE3MGQyN2Q3OTQ0ZGU3ODI0NjU5Y2M4Y2ZjMzBjMjA5NWM4MTA0OGMzNzI1NGFjZjMyMjAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.3CXs2h4qfGGqwruKT9G4IJ_s0RJVj0P-RtDdGOPWOxw)
A simple, dependency free library for running interruptable, transition based animations as a function of time.
This library only implements animations & would be most useful along with a GUI library that can do GUI things (like iced).
Embed the state you want to animate in an Animated
struct.
struct MyViewState {
animated_toggle: Animated<bool, Instant>,
}
When you initialize your view state - define the initial state & configure the animation to your liking.
let mut state = MyViewState {
animated_toggle: Animated::new(false)
.duration(300.)
.easing(Easing::EaseOut)
.delay(30.)
.repeat(3),
};
When your state needs an update, call the transition
function on your animated state, passing the current time.
let now = std::time::Instant::now();
state
.animated_toggle
.transition(!state.animated_toggle.value, now);
While rendering a view based on your state - use the animate
function on your state to get the interpolated value for the current frame.
let now = std::time::Instant::now();
// Use the animated float for something like width, height, offset
let animated_width = self.animated_toggle.animate(100., 500., now)
// Or add an `Interpolable` implementation to an object of your choice, like a color
let animated_color = self.animated_toggle.animate(my_color_a, my_color_b, now)