mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 22:00:03 -04:00
Expose Raw Window and Display Handles (#3073)
* Expose raw window and display handles in eframe * Ensure that no one implements `Clone` in the future * Cleanup --------- Co-authored-by: Matti Virkkunen <mvirkkunen@gmail.com>
This commit is contained in:
@@ -19,6 +19,13 @@ use std::any::Any;
|
||||
#[cfg(any(feature = "glow", feature = "wgpu"))]
|
||||
pub use crate::native::run::UserEvent;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use raw_window_handle::{
|
||||
HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle,
|
||||
};
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use static_assertions::assert_not_impl_any;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[cfg(any(feature = "glow", feature = "wgpu"))]
|
||||
pub use winit::event_loop::EventLoopBuilder;
|
||||
@@ -64,6 +71,34 @@ pub struct CreationContext<'s> {
|
||||
/// Can be used to manage GPU resources for custom rendering with WGPU using [`egui::PaintCallback`]s.
|
||||
#[cfg(feature = "wgpu")]
|
||||
pub wgpu_render_state: Option<egui_wgpu::RenderState>,
|
||||
|
||||
/// Raw platform window handle
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) raw_window_handle: RawWindowHandle,
|
||||
|
||||
/// Raw platform display handle for window
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) raw_display_handle: RawDisplayHandle,
|
||||
}
|
||||
|
||||
// Implementing `Clone` would violate the guarantees of `HasRawWindowHandle` and `HasRawDisplayHandle`.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
assert_not_impl_any!(CreationContext<'_>: Clone);
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
unsafe impl HasRawWindowHandle for CreationContext<'_> {
|
||||
fn raw_window_handle(&self) -> RawWindowHandle {
|
||||
self.raw_window_handle
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
unsafe impl HasRawDisplayHandle for CreationContext<'_> {
|
||||
fn raw_display_handle(&self) -> RawDisplayHandle {
|
||||
self.raw_display_handle
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -695,6 +730,34 @@ pub struct Frame {
|
||||
/// such that it can be retrieved during [`App::post_rendering`] with [`Frame::screenshot`]
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) screenshot: std::cell::Cell<Option<egui::ColorImage>>,
|
||||
|
||||
/// Raw platform window handle
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) raw_window_handle: RawWindowHandle,
|
||||
|
||||
/// Raw platform display handle for window
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) raw_display_handle: RawDisplayHandle,
|
||||
}
|
||||
|
||||
// Implementing `Clone` would violate the guarantees of `HasRawWindowHandle` and `HasRawDisplayHandle`.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
assert_not_impl_any!(Frame: Clone);
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
unsafe impl HasRawWindowHandle for Frame {
|
||||
fn raw_window_handle(&self) -> RawWindowHandle {
|
||||
self.raw_window_handle
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
unsafe impl HasRawDisplayHandle for Frame {
|
||||
fn raw_display_handle(&self) -> RawDisplayHandle {
|
||||
self.raw_display_handle
|
||||
}
|
||||
}
|
||||
|
||||
impl Frame {
|
||||
|
||||
Reference in New Issue
Block a user