Skip to content

Commit

Permalink
window: customizable default descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
cart committed Jul 20, 2020
1 parent b1162f0 commit 009141d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,8 @@ path = "examples/window/clear_color.rs"

[[example]]
name = "multiple_windows"
path = "examples/window/multiple_windows.rs"
path = "examples/window/multiple_windows.rs"

[[example]]
name = "window_settings"
path = "examples/window/window_settings.rs"
22 changes: 14 additions & 8 deletions crates/bevy_window/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<WindowDescriptor>,
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,
}
}
Expand All @@ -35,14 +39,16 @@ impl AppPlugin for WindowPlugin {
.add_event::<CursorMoved>()
.init_resource::<Windows>();

if let Some(ref primary_window_descriptor) = self.primary_window {
let mut create_window_event = app
.resources_mut()
.get_mut::<Events<CreateWindow>>()
.unwrap();
if self.add_primary_window {
let resources = app.resources();
let window_descriptor = resources
.get::<WindowDescriptor>()
.map(|descriptor| (*descriptor).clone())
.unwrap_or_else(|| WindowDescriptor::default());
let mut create_window_event = resources.get_mut::<Events<CreateWindow>>().unwrap();
create_window_event.send(CreateWindow {
id: WindowId::new(),
descriptor: primary_window_descriptor.clone(),
descriptor: window_descriptor.clone(),
});
}

Expand Down
4 changes: 2 additions & 2 deletions examples/3d/3d_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)),
Expand Down
13 changes: 13 additions & 0 deletions examples/window/window_settings.rs
Original file line number Diff line number Diff line change
@@ -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();
}
1 change: 1 addition & 0 deletions src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub use crate::{
text::prelude::*,
transform::prelude::*,
type_registry::RegisterType,
window::prelude::*,
ui::prelude::*,
AddDefaultPlugins,
};

0 comments on commit 009141d

Please sign in to comment.