mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 14:49:06 -04:00
Add winit window access to eframe::Frame and CreationContext (#8205)
* Related: https://github.com/emilk/egui/issues/7798
This commit is contained in:
@@ -83,6 +83,10 @@ pub struct CreationContext<'s> {
|
||||
#[cfg(feature = "wgpu_no_default_features")]
|
||||
pub wgpu_render_state: Option<egui_wgpu::RenderState>,
|
||||
|
||||
/// The root [`winit::window::Window`].
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) window: Option<std::sync::Arc<winit::window::Window>>,
|
||||
|
||||
/// Raw platform window handle
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) raw_window_handle: Result<RawWindowHandle, HandleError>,
|
||||
@@ -125,11 +129,21 @@ impl CreationContext<'_> {
|
||||
#[cfg(feature = "wgpu_no_default_features")]
|
||||
wgpu_render_state: None,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
window: None,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
raw_window_handle: Err(HandleError::NotSupported),
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
raw_display_handle: Err(HandleError::NotSupported),
|
||||
}
|
||||
}
|
||||
|
||||
/// Access to the root [`winit::window::Window`].
|
||||
///
|
||||
/// `None` for headless (tests etc).
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn winit_window(&self) -> Option<&std::sync::Arc<winit::window::Window>> {
|
||||
self.window.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -659,6 +673,10 @@ pub struct Frame {
|
||||
#[doc(hidden)]
|
||||
pub wgpu_render_state: Option<egui_wgpu::RenderState>,
|
||||
|
||||
/// The current [`winit::window::Window`] (i.e. the one the active viewport is rendered to).
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) window: Option<std::sync::Arc<winit::window::Window>>,
|
||||
|
||||
/// Raw platform window handle
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) raw_window_handle: Result<RawWindowHandle, HandleError>,
|
||||
@@ -704,6 +722,8 @@ impl Frame {
|
||||
raw_display_handle: Err(HandleError::NotSupported),
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
raw_window_handle: Err(HandleError::NotSupported),
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
window: None,
|
||||
storage: None,
|
||||
#[cfg(feature = "wgpu_no_default_features")]
|
||||
wgpu_render_state: None,
|
||||
@@ -733,6 +753,14 @@ impl Frame {
|
||||
self.storage.as_deref_mut()
|
||||
}
|
||||
|
||||
/// Access to the current [`winit::window::Window`] (i.e. the one the active viewport is rendered to).
|
||||
///
|
||||
/// `None` for headless (tests etc).
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn winit_window(&self) -> Option<&std::sync::Arc<winit::window::Window>> {
|
||||
self.window.as_ref()
|
||||
}
|
||||
|
||||
/// A reference to the underlying [`glow`] (OpenGL) context.
|
||||
///
|
||||
/// This can be used, for instance, to:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use web_time::Instant;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
use winit::event_loop::ActiveEventLoop;
|
||||
|
||||
use raw_window_handle::{HasDisplayHandle as _, HasWindowHandle as _};
|
||||
@@ -171,7 +171,7 @@ impl EpiIntegration {
|
||||
#[allow(clippy::allow_attributes, clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
egui_ctx: egui::Context,
|
||||
window: &winit::window::Window,
|
||||
window: &Arc<winit::window::Window>,
|
||||
app_name: &str,
|
||||
native_options: &crate::NativeOptions,
|
||||
storage: Option<Box<dyn epi::Storage>>,
|
||||
@@ -192,6 +192,7 @@ impl EpiIntegration {
|
||||
glow_register_native_texture,
|
||||
#[cfg(feature = "wgpu_no_default_features")]
|
||||
wgpu_render_state,
|
||||
window: Some(Arc::clone(window)),
|
||||
raw_display_handle: window.display_handle().map(|h| h.as_raw()),
|
||||
raw_window_handle: window.window_handle().map(|h| h.as_raw()),
|
||||
};
|
||||
|
||||
@@ -314,6 +314,7 @@ impl<'app> GlowWinitApp<'app> {
|
||||
get_proc_address: Some(Arc::new(get_proc_address)),
|
||||
#[cfg(feature = "wgpu_no_default_features")]
|
||||
wgpu_render_state: None,
|
||||
window: Some(Arc::clone(&window)),
|
||||
raw_display_handle: window.display_handle().map(|h| h.as_raw()),
|
||||
raw_window_handle: window.window_handle().map(|h| h.as_raw()),
|
||||
};
|
||||
|
||||
@@ -300,6 +300,7 @@ impl<'app> WgpuWinitApp<'app> {
|
||||
#[cfg(feature = "glow")]
|
||||
get_proc_address: None,
|
||||
wgpu_render_state,
|
||||
window: Some(Arc::clone(&window)),
|
||||
raw_display_handle: window.display_handle().map(|h| h.as_raw()),
|
||||
raw_window_handle: window.window_handle().map(|h| h.as_raw()),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user