Skip to content

Commit

Permalink
use winit::window::{Window, WindowId};
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Nov 12, 2023
1 parent 115e10b commit df78a2d
Showing 1 changed file with 43 additions and 43 deletions.
86 changes: 43 additions & 43 deletions crates/eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
use std::{cell::RefCell, rc::Rc, sync::Arc, time::Instant};

use raw_window_handle::{HasRawDisplayHandle as _, HasRawWindowHandle as _};
use winit::event_loop::{
ControlFlow, EventLoop, EventLoopBuilder, EventLoopProxy, EventLoopWindowTarget,
use winit::{
event_loop::{ControlFlow, EventLoop, EventLoopBuilder, EventLoopProxy, EventLoopWindowTarget},
window::{Window, WindowId},
};

use egui::{epaint::ahash::HashMap, ViewportBuilder, ViewportId};
Expand Down Expand Up @@ -71,14 +72,14 @@ enum EventResult {
///
/// `RepaintNow` creates a new frame synchronously, and should therefore
/// only be used for extremely urgent repaints.
RepaintNow(winit::window::WindowId),
RepaintNow(WindowId),

/// Queues a repaint for once the event loop handles its next redraw. Exists
/// so that multiple input events can be handled in one frame. Does not
/// cause any delay like `RepaintNow`.
RepaintNext(winit::window::WindowId),
RepaintNext(WindowId),

RepaintAt(winit::window::WindowId, Instant),
RepaintAt(WindowId, Instant),

Exit,
}
Expand All @@ -87,19 +88,19 @@ trait WinitApp {
/// The current frame number, as reported by egui.
fn frame_nr(&self, viewport_id: ViewportId) -> u64;

fn is_focused(&self, window_id: winit::window::WindowId) -> bool;
fn is_focused(&self, window_id: WindowId) -> bool;

fn integration(&self) -> Option<&EpiIntegration>;

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

fn window_id_from_viewport_id(&self, id: ViewportId) -> Option<winit::window::WindowId>;
fn window_id_from_viewport_id(&self, id: ViewportId) -> Option<WindowId>;

fn viewport_id_from_window_id(&self, id: &winit::window::WindowId) -> Option<ViewportId>;
fn viewport_id_from_window_id(&self, id: &WindowId) -> Option<ViewportId>;

fn save_and_destroy(&mut self);

fn run_ui_and_paint(&mut self, window_id: winit::window::WindowId) -> EventResult;
fn run_ui_and_paint(&mut self, window_id: WindowId) -> EventResult;

fn on_event(
&mut self,
Expand Down Expand Up @@ -443,18 +444,17 @@ fn run_and_exit(event_loop: EventLoop<UserEvent>, mut winit_app: impl WinitApp +
/// Run an egui app
#[cfg(feature = "glow")]
mod glow_integration {
use glutin::{
display::GetGlDisplay,
prelude::{GlDisplay, NotCurrentGlContextSurfaceAccessor, PossiblyCurrentGlContext},
surface::GlSurface,
};

use egui::{
epaint::ahash::HashMap, NumExt as _, ViewportIdMap, ViewportIdPair, ViewportIdSet,
ViewportOutput, ViewportUiCallback,
};
use egui_winit::{create_winit_window_builder, process_viewport_commands, EventResponse};
use glutin::{
display::GetGlDisplay,
prelude::{GlDisplay, NotCurrentGlContextSurfaceAccessor, PossiblyCurrentGlContext},
surface::GlSurface,
};
use winit::window::WindowId;

use super::*;

Expand Down Expand Up @@ -485,7 +485,7 @@ mod glow_integration {

struct Viewport {
gl_surface: Option<glutin::surface::Surface<glutin::surface::WindowSurface>>,
window: Option<Rc<winit::window::Window>>,
window: Option<Rc<Window>>,
id_pair: ViewportIdPair,

/// The user-callback that shows the ui.
Expand Down Expand Up @@ -832,7 +832,7 @@ mod glow_integration {
.expect("viewport doesn't exist")
}

fn window(&self, viewport_id: ViewportId) -> Rc<winit::window::Window> {
fn window(&self, viewport_id: ViewportId) -> Rc<Window> {
self.viewport(viewport_id)
.borrow()
.window
Expand Down Expand Up @@ -1264,11 +1264,11 @@ mod glow_integration {

let viewport = &mut *viewport.borrow_mut();
let Some(winit_state) = &mut viewport.egui_winit else {
return;
};
return;
};
let Some(window) = &viewport.window else {
return;
};
return;
};

let mut input = winit_state.take_egui_input(window, id_pair);
input.time = Some(beginning.elapsed().as_secs_f64());
Expand Down Expand Up @@ -1365,7 +1365,7 @@ mod glow_integration {
self.running.as_ref().map(|r| &r.integration)
}

fn window(&self, window_id: WindowId) -> Option<Rc<winit::window::Window>> {
fn window(&self, window_id: WindowId) -> Option<Rc<Window>> {
let running = self.running.as_ref()?;
let glutin_ctx = running.glutin_ctx.borrow();
let viewport_id = *glutin_ctx.viewport_maps.get(&window_id)?;
Expand Down Expand Up @@ -1829,7 +1829,7 @@ mod wgpu_integration {

#[derive(Clone)]
pub struct Viewport {
window: Option<Rc<winit::window::Window>>,
window: Option<Rc<Window>>,

egui_winit: Rc<RefCell<Option<egui_winit::State>>>,

Expand All @@ -1848,7 +1848,7 @@ mod wgpu_integration {
viewports: Viewports,
builders: ViewportIdMap<ViewportBuilder>,
painter: egui_wgpu::winit::Painter,
viewport_maps: HashMap<winit::window::WindowId, ViewportId>,
viewport_maps: HashMap<WindowId, ViewportId>,
}

/// State that is initialized when the application is first starts running via
Expand Down Expand Up @@ -1954,7 +1954,7 @@ mod wgpu_integration {
&mut self,
event_loop: &EventLoopWindowTarget<UserEvent>,
storage: Option<Box<dyn epi::Storage>>,
window: winit::window::Window,
window: Window,
builder: ViewportBuilder,
) -> Result<(), egui_wgpu::WgpuError> {
crate::profile_function!();
Expand Down Expand Up @@ -2112,7 +2112,7 @@ mod wgpu_integration {
storage: Option<&dyn epi::Storage>,
title: &str,
native_options: &mut NativeOptions,
) -> Result<(winit::window::Window, ViewportBuilder), winit::error::OsError> {
) -> Result<(Window, ViewportBuilder), winit::error::OsError> {
crate::profile_function!();

let window_settings = epi_integration::load_window_settings(storage);
Expand All @@ -2129,9 +2129,9 @@ mod wgpu_integration {
fn init_window(
id: ViewportId,
builder: &ViewportBuilder,
windows_id: &mut HashMap<winit::window::WindowId, ViewportId>,
windows_id: &mut HashMap<WindowId, ViewportId>,
painter: &mut egui_wgpu::winit::Painter,
window: &mut Option<Rc<winit::window::Window>>,
window: &mut Option<Rc<Window>>,
egui_winit: &mut Option<egui_winit::State>,
event_loop: &EventLoopWindowTarget<UserEvent>,
) {
Expand Down Expand Up @@ -2214,11 +2214,11 @@ mod wgpu_integration {
let viewport = viewports.get(&id_pair.this).cloned();
let Some(viewport) = viewport else { return };
let Some(winit_state) = &mut *viewport.egui_winit.borrow_mut() else {
return;
};
return;
};
let Some(window) = viewport.window else {
return;
};
return;
};

let mut input = winit_state.take_egui_input(&window, id_pair);
input.time = Some(beginning.elapsed().as_secs_f64());
Expand All @@ -2242,11 +2242,11 @@ mod wgpu_integration {
let viewport = viewports.get(&id_pair.this).cloned();
let Some(viewport) = viewport else { return };
let Some(winit_state) = &mut *viewport.egui_winit.borrow_mut() else {
return;
};
return;
};
let Some(window) = viewport.window else {
return;
};
return;
};

if let Err(err) = pollster::block_on(painter.set_window(id_pair.this, Some(&window))) {
log::error!(
Expand Down Expand Up @@ -2276,7 +2276,7 @@ mod wgpu_integration {
.map_or(0, |r| r.integration.egui_ctx.frame_nr_for(viewport_id))
}

fn is_focused(&self, window_id: winit::window::WindowId) -> bool {
fn is_focused(&self, window_id: WindowId) -> bool {
if let Some(focus) = self.focused_viewport {
self.viewport_id_from_window_id(&window_id)
.map_or(false, |i| i == focus)
Expand All @@ -2289,7 +2289,7 @@ mod wgpu_integration {
self.running.as_ref().map(|r| &r.integration)
}

fn window(&self, window_id: winit::window::WindowId) -> Option<Rc<winit::window::Window>> {
fn window(&self, window_id: WindowId) -> Option<Rc<Window>> {
self.running
.as_ref()
.and_then(|r| {
Expand All @@ -2302,7 +2302,7 @@ mod wgpu_integration {
.flatten()
}

fn window_id_from_viewport_id(&self, id: ViewportId) -> Option<winit::window::WindowId> {
fn window_id_from_viewport_id(&self, id: ViewportId) -> Option<WindowId> {
self.running.as_ref().and_then(|r| {
r.shared
.borrow()
Expand Down Expand Up @@ -2333,7 +2333,7 @@ mod wgpu_integration {
}
}

fn run_ui_and_paint(&mut self, window_id: winit::window::WindowId) -> EventResult {
fn run_ui_and_paint(&mut self, window_id: WindowId) -> EventResult {
let Some(running) = &mut self.running else {
return EventResult::Wait;
};
Expand Down Expand Up @@ -2755,7 +2755,7 @@ mod wgpu_integration {
})
}

fn viewport_id_from_window_id(&self, id: &winit::window::WindowId) -> Option<ViewportId> {
fn viewport_id_from_window_id(&self, id: &WindowId) -> Option<ViewportId> {
self.running
.as_ref()
.and_then(|r| r.shared.borrow().viewport_maps.get(id).copied())
Expand Down Expand Up @@ -2787,7 +2787,7 @@ pub use wgpu_integration::run_wgpu;

// ----------------------------------------------------------------------------

fn system_theme(window: &winit::window::Window, options: &NativeOptions) -> Option<crate::Theme> {
fn system_theme(window: &Window, options: &NativeOptions) -> Option<crate::Theme> {
if options.follow_system_theme {
window
.theme()
Expand Down

0 comments on commit df78a2d

Please sign in to comment.