Fix missing repaint after `consume_key` (#7134)

Usually input events automatically trigger a repaint. But since
consume_key would remove the event egui would think there were no events
and not trigger a repaint. This fixes it by setting a flag on InputState
on consume_key.

* related: https://github.com/rerun-io/rerun/issues/10165
This commit is contained in:
Lucas Meurer 2025-06-13 14:06:50 +02:00 committed by GitHub
parent 5bc19f3ca3
commit 4c04996a72
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 5 deletions

View File

@ -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();

View File

@ -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<Duration> {
///
/// 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<Duration> {
if self.pointer.wants_repaint()
|| self.unprocessed_scroll_delta.abs().max_elem() > 0.2
|| self.unprocessed_scroll_delta_for_zoom.abs() > 0.2