Skip to content

Commit

Permalink
When asking for a repaint with a delay, subtract the frame time
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Jul 5, 2024
1 parent feda55f commit 3e200cd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl ContextImpl {

fn request_repaint_after(
&mut self,
delay: Duration,
mut delay: Duration,
viewport_id: ViewportId,
cause: RepaintCause,
) {
Expand All @@ -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.
Expand Down

0 comments on commit 3e200cd

Please sign in to comment.