|
6 | 6 |
|
7 | 7 | #![warn(missing_docs)] // Let's keep `epi` well-documented.
|
8 | 8 |
|
| 9 | +#[cfg(not(target_arch = "wasm32"))] |
| 10 | +pub use crate::native::run::RequestRepaintEvent; |
| 11 | +#[cfg(not(target_arch = "wasm32"))] |
| 12 | +pub use winit::event_loop::EventLoopBuilder; |
| 13 | + |
| 14 | +/// Hook into the building of an event loop before it is run |
| 15 | +/// |
| 16 | +/// You can configure any platform specific details required on top of the default configuration |
| 17 | +/// done by `EFrame`. |
| 18 | +#[cfg(not(target_arch = "wasm32"))] |
| 19 | +pub type EventLoopBuilderHook = Box<dyn FnOnce(&mut EventLoopBuilder<RequestRepaintEvent>)>; |
| 20 | + |
9 | 21 | /// This is how your app is created.
|
10 | 22 | ///
|
11 | 23 | /// You can use the [`CreationContext`] to setup egui, restore state, setup OpenGL things, etc.
|
@@ -177,7 +189,6 @@ pub enum HardwareAcceleration {
|
177 | 189 | ///
|
178 | 190 | /// Only a single native window is currently supported.
|
179 | 191 | #[cfg(not(target_arch = "wasm32"))]
|
180 |
| -#[derive(Clone)] |
181 | 192 | pub struct NativeOptions {
|
182 | 193 | /// Sets whether or not the window will always be on top of other windows.
|
183 | 194 | pub always_on_top: bool,
|
@@ -292,6 +303,25 @@ pub struct NativeOptions {
|
292 | 303 | /// When `true`, [`winit::platform::run_return::EventLoopExtRunReturn::run_return`] is used.
|
293 | 304 | /// When `false`, [`winit::event_loop::EventLoop::run`] is used.
|
294 | 305 | pub run_and_return: bool,
|
| 306 | + |
| 307 | + /// Hook into the building of an event loop before it is run. |
| 308 | + /// |
| 309 | + /// Specify a callback here in case you need to make platform specific changes to the |
| 310 | + /// event loop before it is run. |
| 311 | + /// |
| 312 | + /// Note: A [`NativeOptions`] clone will not include any `event_loop_builder` hook. |
| 313 | + pub event_loop_builder: Option<EventLoopBuilderHook>, |
| 314 | +} |
| 315 | + |
| 316 | +#[cfg(not(target_arch = "wasm32"))] |
| 317 | +impl Clone for NativeOptions { |
| 318 | + fn clone(&self) -> Self { |
| 319 | + Self { |
| 320 | + icon_data: self.icon_data.clone(), |
| 321 | + event_loop_builder: None, // Skip any builder callbacks if cloning |
| 322 | + ..*self |
| 323 | + } |
| 324 | + } |
295 | 325 | }
|
296 | 326 |
|
297 | 327 | #[cfg(not(target_arch = "wasm32"))]
|
@@ -319,6 +349,7 @@ impl Default for NativeOptions {
|
319 | 349 | follow_system_theme: cfg!(target_os = "macos") || cfg!(target_os = "windows"),
|
320 | 350 | default_theme: Theme::Dark,
|
321 | 351 | run_and_return: true,
|
| 352 | + event_loop_builder: None, |
322 | 353 | }
|
323 | 354 | }
|
324 | 355 | }
|
|
0 commit comments