Motion
The look’s motion tokens: three speeds and a set of curves the components animate with, all of them still when the app asks for reduced motion.
Speeds
let id = ui.scope_id().with(("speed", name));
let t = motion::animate_bool(ui, id, state.moved, speed, Curve::EaseOut);
Reduced motion
// An app that asks for reduced motion sets egui's animation time
// to zero: `ctx.all_styles_mut(|style| style.animation_time = 0.0)`.
// Here only this area does.
ui.scope(|ui| {
if state.still {
ui.style_mut().animation_time = 0.0;
}
let id = ui.scope_id().with("reduced");
let t = motion::animate_bool(ui, id, state.moved, Speed::Slow, Curve::EaseOut);
track(ui, t);
});
A value gliding to its target
let target = if state.moved { 1.0 } else { 0.0 };
let t = motion::animate(ui, ui.scope_id().with("value"), target, Speed::Standard);
The story above is gallery/src/stories/motion.rs, running in your browser. Every snippet on this page is cut from it.