Skip to content

Commit

Permalink
When animation, extrapolate only by half a frame
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Jul 5, 2024
1 parent 1059e0e commit feda55f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions crates/egui/src/animation_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion crates/egui/src/containers/area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,8 @@ 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
ui.multiply_opacity(opacity);
Expand Down

0 comments on commit feda55f

Please sign in to comment.