diff --git a/Cargo.toml b/Cargo.toml index 2f8ea26f61..3b284b72f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -202,4 +202,8 @@ path = "examples/window/clear_color.rs" [[example]] name = "multiple_windows" -path = "examples/window/multiple_windows.rs" \ No newline at end of file +path = "examples/window/multiple_windows.rs" + +[[example]] +name = "window_settings" +path = "examples/window/window_settings.rs" \ No newline at end of file diff --git a/crates/bevy_window/src/lib.rs b/crates/bevy_window/src/lib.rs index 854c0dd6d9..20cbda7618 100644 --- a/crates/bevy_window/src/lib.rs +++ b/crates/bevy_window/src/lib.rs @@ -8,18 +8,22 @@ pub use system::*; pub use window::*; pub use windows::*; +pub mod prelude { + pub use crate::{CursorMoved, Window, WindowDescriptor, Windows}; +} + use bevy_app::prelude::*; use bevy_ecs::IntoQuerySystem; pub struct WindowPlugin { - pub primary_window: Option, + pub add_primary_window: bool, pub exit_on_close: bool, } impl Default for WindowPlugin { fn default() -> Self { WindowPlugin { - primary_window: Some(WindowDescriptor::default()), + add_primary_window: true, exit_on_close: true, } } @@ -35,14 +39,16 @@ impl AppPlugin for WindowPlugin { .add_event::() .init_resource::(); - if let Some(ref primary_window_descriptor) = self.primary_window { - let mut create_window_event = app - .resources_mut() - .get_mut::>() - .unwrap(); + if self.add_primary_window { + let resources = app.resources(); + let window_descriptor = resources + .get::() + .map(|descriptor| (*descriptor).clone()) + .unwrap_or_else(|| WindowDescriptor::default()); + let mut create_window_event = resources.get_mut::>().unwrap(); create_window_event.send(CreateWindow { id: WindowId::new(), - descriptor: primary_window_descriptor.clone(), + descriptor: window_descriptor.clone(), }); } diff --git a/examples/3d/3d_scene.rs b/examples/3d/3d_scene.rs index 292e370138..f791d8e05d 100644 --- a/examples/3d/3d_scene.rs +++ b/examples/3d/3d_scene.rs @@ -44,13 +44,13 @@ fn setup( }) // light .spawn(LightComponents { - translation: Translation::new(4.0, 5.0, -4.0), + translation: Translation::new(4.0, 8.0, 4.0), ..Default::default() }) // camera .spawn(Camera3dComponents { transform: Transform::new_sync_disabled(Mat4::face_toward( - Vec3::new(3.0, 5.0, 8.0), + Vec3::new(-3.0, 5.0, 8.0), Vec3::new(0.0, 0.0, 0.0), Vec3::new(0.0, 1.0, 0.0), )), diff --git a/examples/window/window_settings.rs b/examples/window/window_settings.rs new file mode 100644 index 0000000000..856a6c5103 --- /dev/null +++ b/examples/window/window_settings.rs @@ -0,0 +1,13 @@ +use bevy::prelude::*; + +fn main() { + App::build() + .add_resource(WindowDescriptor { + title: "I am a window!".to_string(), + width: 300, + height: 300, + vsync: true, + }) + .add_default_plugins() + .run(); +} diff --git a/src/prelude.rs b/src/prelude.rs index f622f08061..1c476ddea4 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -14,6 +14,7 @@ pub use crate::{ text::prelude::*, transform::prelude::*, type_registry::RegisterType, + window::prelude::*, ui::prelude::*, AddDefaultPlugins, };