-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow calling winit with the 'run_return' variant of the run function (…
…#243) This adds a new WinitConfig resource that can be used to configure the behavior of winit. When `return_from_run` is set to `true`, `App::run()` will return on `target_os` configurations that support it. Closes #167.
- Loading branch information
Showing
4 changed files
with
104 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
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,15 @@ | ||
/// A resource for configuring usage of the `rust_winit` library. | ||
#[derive(Default)] | ||
pub struct WinitConfig { | ||
/// Configures the winit library to return control to the main thread after | ||
/// the [run](bevy_app::App::run) loop is exited. Winit strongly recommends | ||
/// avoiding this when possible. Before using this please read and understand | ||
/// the [caveats](winit::platform::desktop::EventLoopExtDesktop::run_return) | ||
/// in the winit documentation. | ||
/// | ||
/// This feature is only available on desktop `target_os` configurations. | ||
/// Namely `windows`, `macos`, `linux`, `dragonfly`, `freebsd`, `netbsd`, and | ||
/// `openbsd`. If set to true on an unsupported platform | ||
/// [run](bevy_app::App::run) will panic. | ||
pub return_from_run: bool, | ||
} |
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,21 @@ | ||
use bevy::{prelude::*, render::pass::ClearColor, winit::WinitConfig}; | ||
|
||
fn main() { | ||
println!("Running first App."); | ||
App::build() | ||
.add_resource(WinitConfig { | ||
return_from_run: true, | ||
}) | ||
.add_resource(ClearColor(Color::rgb(0.2, 0.2, 0.8))) | ||
.add_default_plugins() | ||
.run(); | ||
println!("Running another App."); | ||
App::build() | ||
.add_resource(WinitConfig { | ||
return_from_run: true, | ||
}) | ||
.add_resource(ClearColor(Color::rgb(0.2, 0.8, 0.2))) | ||
.add_default_plugins() | ||
.run(); | ||
println!("Done."); | ||
} |