diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index 7e1813b9ea9..f1722418adc 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -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.