From 548d6ed0f4ca4694033a467c295928673daccec6 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 5 Feb 2024 14:37:00 +0100 Subject: [PATCH] Fix calling request_repaint_after every frame causing immediate repaint --- crates/egui/src/context.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index 361339312a2..54f01e99603 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -148,9 +148,16 @@ impl ContextImpl { ) { let viewport = self.viewports.entry(viewport_id).or_default(); - // Each request results in two repaints, just to give some things time to settle. - // This solves some corner-cases of missing repaints on frame-delayed responses. - viewport.repaint.outstanding = 1; + if delay == Duration::ZERO { + // Each request results in two repaints, just to give some things time to settle. + // This solves some corner-cases of missing repaints on frame-delayed responses. + viewport.repaint.outstanding = 1; + } else { + // For non-zero delays, we only repaint once, because + // otherwise we would just schedule an immediate repaint _now_, + // which would then clear the delay and repaint again. + // Hovering a tooltip is a good example of a case where we want to repaint after a delay. + } viewport.repaint.causes.push(cause);