pub fn transition<'a, Message, Theme, Renderer, P, E>(
value: P::Value,
init: impl Fn() -> P + 'a,
view: impl Fn(&P, Instant) -> E + 'a,
) -> Transition<'a, Message, Theme, Renderer, P>Expand description
Creates a new Transition.
The init closure will be used to initialize an implementor of Program. This is normally
an Animation, but you can implement Program on your own types
as well.
The view closure will receive the Program and the current Instant, which can be used for interpolating values.
When the value changes, this will be called every frame, until the Program stops animating.
ยงExample
Here is how you could implement a smooth progress bar:
use iced::widget::{transition, progress_bar};
use iced::Animation;
fn smooth_progress_bar<'a, Message: 'a>(progress: f32) -> Element<'a, Message> {
transition(progress, || Animation::new(0.).quick(), |animation, now| {
progress_bar(0.0..=1.0, animation.interpolate_with(std::convert::identity, now))
}).into()
}