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) => {
|
Some(anim) => {
|
||||||
let time_since_toggle = (input.time - anim.toggle_time) as f32;
|
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,
|
// On the frame we toggle we don't want to return the old value,
|
||||||
// so we extrapolate forwards:
|
// so we extrapolate forwards by half a frame:
|
||||||
let time_since_toggle = time_since_toggle + input.predicted_dt;
|
let time_since_toggle = time_since_toggle + input.predicted_dt / 2.0;
|
||||||
let current_value = remap_clamp(
|
let current_value = remap_clamp(
|
||||||
time_since_toggle,
|
time_since_toggle,
|
||||||
0.0..=animation_time,
|
0.0..=animation_time,
|
||||||
|
|
|
||||||
|
|
@ -545,9 +545,10 @@ impl Prepared {
|
||||||
|
|
||||||
if self.fade_in {
|
if self.fade_in {
|
||||||
if let Some(last_became_visible_at) = self.state.last_became_visible_at {
|
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 = 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);
|
ui.multiply_opacity(opacity);
|
||||||
if opacity < 1.0 {
|
if opacity < 1.0 {
|
||||||
ctx.request_repaint();
|
ctx.request_repaint();
|
||||||
|
|
|
||||||
|
|
@ -146,7 +146,7 @@ impl ContextImpl {
|
||||||
|
|
||||||
fn request_repaint_after(
|
fn request_repaint_after(
|
||||||
&mut self,
|
&mut self,
|
||||||
delay: Duration,
|
mut delay: Duration,
|
||||||
viewport_id: ViewportId,
|
viewport_id: ViewportId,
|
||||||
cause: RepaintCause,
|
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.
|
// 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);
|
viewport.repaint.causes.push(cause);
|
||||||
|
|
||||||
// We save some CPU time by only calling the callback if we need to.
|
// We save some CPU time by only calling the callback if we need to.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue