Skip to content

Commit 4c04996

Browse files
authored
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: rerun-io/rerun#10165
1 parent 5bc19f3 commit 4c04996

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

crates/egui/src/context.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ impl ContextImpl {
492492
pixels_per_point,
493493
self.memory.options.input_options,
494494
);
495+
let repaint_after = viewport.input.wants_repaint_after();
495496

496497
let screen_rect = viewport.input.screen_rect;
497498

@@ -553,6 +554,10 @@ impl ContextImpl {
553554
}
554555

555556
self.update_fonts_mut();
557+
558+
if let Some(delay) = repaint_after {
559+
self.request_repaint_after(delay, viewport_id, RepaintCause::new());
560+
}
556561
}
557562

558563
/// Load fonts unless already loaded.
@@ -2398,10 +2403,7 @@ impl ContextImpl {
23982403

23992404
if repaint_needed {
24002405
self.request_repaint(ended_viewport_id, RepaintCause::new());
2401-
} else if let Some(delay) = viewport.input.wants_repaint_after() {
2402-
self.request_repaint_after(delay, ended_viewport_id, RepaintCause::new());
24032406
}
2404-
24052407
// -------------------
24062408

24072409
let all_viewport_ids = self.all_viewport_ids();

crates/egui/src/input_state/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,10 +597,14 @@ impl InputState {
597597
(self.time - self.last_scroll_time) as f32
598598
}
599599

600-
/// The [`crate::Context`] will call this at the end of each frame to see if we need a repaint.
600+
/// The [`crate::Context`] will call this at the beginning of each frame to see if we need a repaint.
601601
///
602602
/// Returns how long to wait for a repaint.
603-
pub fn wants_repaint_after(&self) -> Option<Duration> {
603+
///
604+
/// NOTE: It's important to call this immediately after [`Self::begin_pass`] since calls to
605+
/// [`Self::consume_key`] will remove events from the vec, meaning those key presses wouldn't
606+
/// cause a repaint.
607+
pub(crate) fn wants_repaint_after(&self) -> Option<Duration> {
604608
if self.pointer.wants_repaint()
605609
|| self.unprocessed_scroll_delta.abs().max_elem() > 0.2
606610
|| self.unprocessed_scroll_delta_for_zoom.abs() > 0.2

0 commit comments

Comments
 (0)