From 9a82d32570823bfbf11822b2e00e0eade6f607ab Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Thu, 3 Oct 2024 02:40:44 +0900 Subject: [PATCH] Update run.rs --- crates/eframe/src/native/run.rs | 71 ++++++++++++++++----------------- 1 file changed, 34 insertions(+), 37 deletions(-) diff --git a/crates/eframe/src/native/run.rs b/crates/eframe/src/native/run.rs index 7964a1e9ad4..b661cdb8efe 100644 --- a/crates/eframe/src/native/run.rs +++ b/crates/eframe/src/native/run.rs @@ -77,48 +77,45 @@ impl WinitAppWrapper { event_loop: &ActiveEventLoop, event_result: Result, ) { + let now = Instant::now(); let mut exit = false; log::trace!("event_result: {event_result:?}"); - 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:?}",); + let mut event_result = 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) - } + if cfg!(target_os = "windows") { + if let Ok(EventResult::RepaintNow(window_id)) = event_result { + log::info!("RepaintNow of {window_id:?}",); + self.windows_next_repaint_times.insert(window_id, now); + + // Fix flickering on Windows, see https://github.com/emilk/egui/pull/2280 + event_result = self.winit_app.run_ui_and_paint(event_loop, window_id); + } + } + + let combined_result = event_result.map(|event_result| match event_result { + EventResult::Wait => { + event_loop.set_control_flow(ControlFlow::Wait); + event_result + } + EventResult::RepaintNow(window_id) => { + log::trace!("RepaintNow of {window_id:?}",); + self.windows_next_repaint_times.insert(window_id, now); + event_result + } + EventResult::RepaintNext(window_id) => { + log::trace!("RepaintNext of {window_id:?}",); + self.windows_next_repaint_times.insert(window_id, now); + event_result + } + EventResult::RepaintAt(window_id, when) => { + self.windows_next_repaint_times.insert(window_id, when); + event_result + } + EventResult::Exit => { + exit = true; + event_result } });