From 3d7d1d986b5924498b26251d7e2bc78bf0d9e119 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Fri, 27 Sep 2024 21:02:01 +0900 Subject: [PATCH] Update run.rs --- crates/eframe/src/native/run.rs | 38 +++++++++++++++++---------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/crates/eframe/src/native/run.rs b/crates/eframe/src/native/run.rs index 7964a1e9ad44..1f7ebe21ec71 100644 --- a/crates/eframe/src/native/run.rs +++ b/crates/eframe/src/native/run.rs @@ -77,10 +77,25 @@ impl WinitAppWrapper { event_loop: &ActiveEventLoop, event_result: Result, ) { + let now = Instant::now(); let mut exit = false; log::trace!("event_result: {event_result:?}"); + let mut event_result = event_result; + + if cfg!(target_os = "windows") { + match event_result { + Ok(EventResult::RepaintNow(window_id)) => { + // Fix flickering on Windows, see https://github.com/emilk/egui/pull/2280 + let paint_result = self.winit_app.run_ui_and_paint(event_loop, window_id); + self.windows_next_repaint_times.insert(window_id, now); + event_result = paint_result; + } + _ => {} + } + } + let combined_result = event_result.and_then(|event_result| { match event_result { EventResult::Wait => { @@ -90,29 +105,16 @@ impl WinitAppWrapper { EventResult::RepaintNow(window_id) => { log::trace!("RepaintNow of {window_id:?}",); - if cfg!(target_os = "windows") { - // Fix flickering on Windows, see https://github.com/emilk/egui/pull/2280 - self.winit_app.run_ui_and_paint(event_loop, window_id) - } else { - // Fix for https://github.com/emilk/egui/issues/2425 - self.windows_next_repaint_times - .insert(window_id, Instant::now()); - Ok(event_result) - } + self.windows_next_repaint_times.insert(window_id, now); + Ok(event_result) } EventResult::RepaintNext(window_id) => { log::trace!("RepaintNext of {window_id:?}",); - self.windows_next_repaint_times - .insert(window_id, Instant::now()); + self.windows_next_repaint_times.insert(window_id, now); Ok(event_result) } - EventResult::RepaintAt(window_id, repaint_time) => { - self.windows_next_repaint_times.insert( - window_id, - self.windows_next_repaint_times - .get(&window_id) - .map_or(repaint_time, |last| (*last).min(repaint_time)), - ); + EventResult::RepaintAt(window_id, when) => { + self.windows_next_repaint_times.insert(window_id, when); Ok(event_result) } EventResult::Exit => {