-
-
Notifications
You must be signed in to change notification settings - Fork 476
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add sealed
trait GlutinEventLoop
to abstract over `{,Active}E…
…ventLoop` in `winit` 0.30.0 Co-Authored-By: Erich Gubler <[email protected]>
- Loading branch information
1 parent
b12c7ee
commit bd053c1
Showing
3 changed files
with
66 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use raw_window_handle::{DisplayHandle, HandleError, HasDisplayHandle}; | ||
use winit::error::OsError; | ||
use winit::event_loop::{ActiveEventLoop, EventLoop}; | ||
use winit::window::{Window, WindowAttributes}; | ||
|
||
use crate::private::Sealed; | ||
|
||
/// [`ActiveEventLoop`] is the recommended way to interact with the event | ||
/// loop, but for compatibility purposes [`EventLoop`] is also supported | ||
/// although not recommended anymore as it has been deprecated by Winit. | ||
pub trait GlutinEventLoop: Sealed { | ||
/// Create the window. | ||
/// | ||
/// Possible causes of error include denied permission, incompatible system, | ||
/// and lack of memory. | ||
/// | ||
/// ## Platform-specific | ||
/// | ||
/// - **Web:** The window is created but not inserted into the web page | ||
/// automatically. Please see the web platform module for more | ||
/// information. | ||
fn create_window(&self, window_attributes: WindowAttributes) -> Result<Window, OsError>; | ||
|
||
/// Get a handle to the display controller of the windowing system. | ||
fn glutin_display_handle(&self) -> Result<DisplayHandle<'_>, HandleError>; | ||
} | ||
|
||
impl Sealed for ActiveEventLoop {} | ||
|
||
impl GlutinEventLoop for ActiveEventLoop { | ||
fn create_window(&self, window_attributes: WindowAttributes) -> Result<Window, OsError> { | ||
self.create_window(window_attributes) | ||
} | ||
|
||
fn glutin_display_handle(&self) -> Result<DisplayHandle<'_>, HandleError> { | ||
self.display_handle() | ||
} | ||
} | ||
|
||
impl<T> Sealed for EventLoop<T> {} | ||
|
||
impl<T> GlutinEventLoop for EventLoop<T> { | ||
#[allow(deprecated)] | ||
fn create_window(&self, window_attributes: WindowAttributes) -> Result<Window, OsError> { | ||
self.create_window(window_attributes) | ||
} | ||
|
||
fn glutin_display_handle(&self) -> Result<DisplayHandle<'_>, HandleError> { | ||
self.display_handle() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters