Skip to content

Commit

Permalink
Refactor WinitApp slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Sep 13, 2024
1 parent f8ffa5c commit 4c035a3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
6 changes: 2 additions & 4 deletions crates/eframe/src/native/glow_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,8 @@ impl<'app> GlowWinitApp<'app> {
}

impl<'app> WinitApp for GlowWinitApp<'app> {
fn cumulative_pass_nr(&self, viewport_id: ViewportId) -> u64 {
self.running.as_ref().map_or(0, |r| {
r.integration.egui_ctx.cumulative_pass_nr_for(viewport_id)
})
fn egui_ctx(&self) -> Option<&egui::Context> {
self.running.as_ref().map(|r| &r.integration.egui_ctx)
}

fn window(&self, window_id: WindowId) -> Option<Arc<Window>> {
Expand Down
5 changes: 4 additions & 1 deletion crates/eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,10 @@ impl<T: WinitApp> ApplicationHandler<UserEvent> for WinitAppWrapper<T> {
cumulative_pass_nr,
viewport_id,
} => {
let current_pass_nr = self.winit_app.cumulative_pass_nr(viewport_id);
let current_pass_nr = self
.winit_app
.egui_ctx()
.map_or(0, |ctx| ctx.cumulative_pass_nr_for(viewport_id));
if current_pass_nr == cumulative_pass_nr
|| current_pass_nr == cumulative_pass_nr + 1
{
Expand Down
6 changes: 2 additions & 4 deletions crates/eframe/src/native/wgpu_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,8 @@ impl<'app> WgpuWinitApp<'app> {
}

impl<'app> WinitApp for WgpuWinitApp<'app> {
fn cumulative_pass_nr(&self, viewport_id: ViewportId) -> u64 {
self.running.as_ref().map_or(0, |r| {
r.integration.egui_ctx.cumulative_pass_nr_for(viewport_id)
})
fn egui_ctx(&self) -> Option<&egui::Context> {
self.running.as_ref().map(|r| &r.integration.egui_ctx)
}

fn window(&self, window_id: WindowId) -> Option<Arc<Window>> {
Expand Down
3 changes: 1 addition & 2 deletions crates/eframe/src/native/winit_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ impl From<accesskit_winit::Event> for UserEvent {
}

pub trait WinitApp {
/// The current frame number, as reported by egui.
fn cumulative_pass_nr(&self, viewport_id: ViewportId) -> u64;
fn egui_ctx(&self) -> Option<&egui::Context>;

fn window(&self, window_id: WindowId) -> Option<Arc<Window>>;

Expand Down

0 comments on commit 4c035a3

Please sign in to comment.