Smoother animations (#4787)
This makes animations slightly smoother, especially in reactive mode
This commit is contained in:
parent
1059e0e7f1
commit
0be4450e3d
|
|
@ -87,8 +87,8 @@ impl AnimationManager {
|
|||
Some(anim) => {
|
||||
let time_since_toggle = (input.time - anim.toggle_time) as f32;
|
||||
// On the frame we toggle we don't want to return the old value,
|
||||
// so we extrapolate forwards:
|
||||
let time_since_toggle = time_since_toggle + input.predicted_dt;
|
||||
// so we extrapolate forwards by half a frame:
|
||||
let time_since_toggle = time_since_toggle + input.predicted_dt / 2.0;
|
||||
let current_value = remap_clamp(
|
||||
time_since_toggle,
|
||||
0.0..=animation_time,
|
||||
|
|
|
|||
|
|
@ -545,9 +545,10 @@ impl Prepared {
|
|||
|
||||
if self.fade_in {
|
||||
if let Some(last_became_visible_at) = self.state.last_became_visible_at {
|
||||
let age = ctx.input(|i| (i.time - last_became_visible_at) as f32 + i.predicted_dt);
|
||||
let age =
|
||||
ctx.input(|i| (i.time - last_became_visible_at) as f32 + i.predicted_dt / 2.0);
|
||||
let opacity = crate::remap_clamp(age, 0.0..=ctx.style().animation_time, 0.0..=1.0);
|
||||
let opacity = emath::easing::cubic_out(opacity); // slow fade-out = quick fade-in
|
||||
let opacity = emath::easing::quadratic_out(opacity); // slow fade-out = quick fade-in
|
||||
ui.multiply_opacity(opacity);
|
||||
if opacity < 1.0 {
|
||||
ctx.request_repaint();
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ impl ContextImpl {
|
|||
|
||||
fn request_repaint_after(
|
||||
&mut self,
|
||||
delay: Duration,
|
||||
mut delay: Duration,
|
||||
viewport_id: ViewportId,
|
||||
cause: RepaintCause,
|
||||
) {
|
||||
|
|
@ -163,6 +163,11 @@ impl ContextImpl {
|
|||
// Hovering a tooltip is a good example of a case where we want to repaint after a delay.
|
||||
}
|
||||
|
||||
if let Ok(predicted_frame_time) = Duration::try_from_secs_f32(viewport.input.predicted_dt) {
|
||||
// Make it less likely we over-shoot the target:
|
||||
delay = delay.saturating_sub(predicted_frame_time);
|
||||
}
|
||||
|
||||
viewport.repaint.causes.push(cause);
|
||||
|
||||
// We save some CPU time by only calling the callback if we need to.
|
||||
|
|
|
|||
Loading…
Reference in New Issue