diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index 751604d43eb..316d741f524 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -492,6 +492,7 @@ impl ContextImpl { pixels_per_point, self.memory.options.input_options, ); + let repaint_after = viewport.input.wants_repaint_after(); let screen_rect = viewport.input.screen_rect; @@ -553,6 +554,10 @@ impl ContextImpl { } self.update_fonts_mut(); + + if let Some(delay) = repaint_after { + self.request_repaint_after(delay, viewport_id, RepaintCause::new()); + } } /// Load fonts unless already loaded. @@ -2398,10 +2403,7 @@ impl ContextImpl { if repaint_needed { self.request_repaint(ended_viewport_id, RepaintCause::new()); - } else if let Some(delay) = viewport.input.wants_repaint_after() { - self.request_repaint_after(delay, ended_viewport_id, RepaintCause::new()); } - // ------------------- let all_viewport_ids = self.all_viewport_ids(); diff --git a/crates/egui/src/input_state/mod.rs b/crates/egui/src/input_state/mod.rs index c871a84520e..7fd07316746 100644 --- a/crates/egui/src/input_state/mod.rs +++ b/crates/egui/src/input_state/mod.rs @@ -597,10 +597,14 @@ impl InputState { (self.time - self.last_scroll_time) as f32 } - /// The [`crate::Context`] will call this at the end of each frame to see if we need a repaint. + /// The [`crate::Context`] will call this at the beginning of each frame to see if we need a repaint. /// /// Returns how long to wait for a repaint. - pub fn wants_repaint_after(&self) -> Option { + /// + /// NOTE: It's important to call this immediately after [`Self::begin_pass`] since calls to + /// [`Self::consume_key`] will remove events from the vec, meaning those key presses wouldn't + /// cause a repaint. + pub(crate) fn wants_repaint_after(&self) -> Option { if self.pointer.wants_repaint() || self.unprocessed_scroll_delta.abs().max_elem() > 0.2 || self.unprocessed_scroll_delta_for_zoom.abs() > 0.2