Skip to content

Commit

Permalink
Update run.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
rustbasic authored Sep 27, 2024
1 parent 59d7183 commit 3d7d1d9
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions crates/eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,25 @@ impl<T: WinitApp> WinitAppWrapper<T> {
event_loop: &ActiveEventLoop,
event_result: Result<EventResult>,
) {
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 => {
Expand All @@ -90,29 +105,16 @@ impl<T: WinitApp> WinitAppWrapper<T> {
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 => {
Expand Down

0 comments on commit 3d7d1d9

Please sign in to comment.