From 6cd35e31f4965bb47d6b14bc63736081c4141bcc Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Fri, 27 Sep 2024 22:26:26 +0900 Subject: [PATCH] Update run.rs --- crates/eframe/src/native/run.rs | 69 +++++++++++++++++---------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/crates/eframe/src/native/run.rs b/crates/eframe/src/native/run.rs index 775e317ebd37..7964a1e9ad44 100644 --- a/crates/eframe/src/native/run.rs +++ b/crates/eframe/src/native/run.rs @@ -77,47 +77,48 @@ 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") { + let combined_result = event_result.and_then(|event_result| { 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; + EventResult::Wait => { + event_loop.set_control_flow(ControlFlow::Wait); + Ok(event_result) } - _ => {} - } - } + EventResult::RepaintNow(window_id) => { + log::trace!("RepaintNow of {window_id:?}",); - let combined_result = event_result.and_then(|event_result| match event_result { - EventResult::Wait => { - event_loop.set_control_flow(ControlFlow::Wait); - Ok(event_result) - } - EventResult::RepaintNow(window_id) => { - log::trace!("RepaintNow of {window_id:?}",); - 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, now); - Ok(event_result) - } - EventResult::RepaintAt(window_id, when) => { - self.windows_next_repaint_times.insert(window_id, when); - Ok(event_result) - } - EventResult::Exit => { - exit = true; - Ok(event_result) + 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) + } + } + EventResult::RepaintNext(window_id) => { + log::trace!("RepaintNext of {window_id:?}",); + self.windows_next_repaint_times + .insert(window_id, Instant::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)), + ); + Ok(event_result) + } + EventResult::Exit => { + exit = true; + Ok(event_result) + } } });