-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cubic Bezier Animation Easing (ease-in-out) #2717
Conversation
An open question for me, is whether this should be serializable and part of
I also haven't included color animation, though this does seem like a natural extension. It probably makes sense to leave that out of scope, though I would be happy to work on that if it would be valuable. |
We could make the pub trait EasingFunction: Serialize + Deserialize {
fn ease(f32) -> f32;
} So that people have to wrap their easing functions in a marker struct like so: #[derive(Serialize, Deserialize)]
pub struct CustomEasing;
impl EasingFunction for CustomEasing {
fn ease(t: f32) -> f32 { ... }
} |
Is there anything I can do to move this forward? 🙂 If it helps the review process, note that all the substantial changes are in |
Extends the existing animation manager to add cubic Bezier and custom function easing; adds presets from CSS and Material Design, and switches widgets to use easing instead of linear by default.
2023-02-11.22-38-44.mp4
The default animation duration has been bumped up slightly to account for the nonlinear nature of the new easing, with the intent of keeping the perceived snappiness the same, while allowing a bit more time for the smooth deceleration at the end of animations.
I've included some useful presets that are used commonly elsewhere, and in this case I've taken from the W3C spec directly.
The new easing enum:
Implementation Notes
I decided to write a cubic Bezier implementation, instead of reusing the existing Bezier code used for rendering curves. The reasons for this:
t
given the input time on thex
axis, which can then be used to find the output valuey
. I chose Raphson-Newton as this appears to be used in browsers and converges within 1e-7 with <= 8 iterations. More complex methods can be used if needed, but this approach is robust, fast, and simple.