mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
window: customizable default descriptor
This commit is contained in:
parent
b1162f0c29
commit
009141d453
5 changed files with 35 additions and 11 deletions
|
@ -203,3 +203,7 @@ path = "examples/window/clear_color.rs"
|
|||
[[example]]
|
||||
name = "multiple_windows"
|
||||
path = "examples/window/multiple_windows.rs"
|
||||
|
||||
[[example]]
|
||||
name = "window_settings"
|
||||
path = "examples/window/window_settings.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<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,
|
||||
}
|
||||
}
|
||||
|
@ -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(),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
)),
|
||||
|
|
13
examples/window/window_settings.rs
Normal file
13
examples/window/window_settings.rs
Normal file
|
@ -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();
|
||||
}
|
|
@ -14,6 +14,7 @@ pub use crate::{
|
|||
text::prelude::*,
|
||||
transform::prelude::*,
|
||||
type_registry::RegisterType,
|
||||
window::prelude::*,
|
||||
ui::prelude::*,
|
||||
AddDefaultPlugins,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue