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
|
@ -202,4 +202,8 @@ path = "examples/window/clear_color.rs"
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "multiple_windows"
|
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"
|
|
@ -8,18 +8,22 @@ pub use system::*;
|
||||||
pub use window::*;
|
pub use window::*;
|
||||||
pub use windows::*;
|
pub use windows::*;
|
||||||
|
|
||||||
|
pub mod prelude {
|
||||||
|
pub use crate::{CursorMoved, Window, WindowDescriptor, Windows};
|
||||||
|
}
|
||||||
|
|
||||||
use bevy_app::prelude::*;
|
use bevy_app::prelude::*;
|
||||||
use bevy_ecs::IntoQuerySystem;
|
use bevy_ecs::IntoQuerySystem;
|
||||||
|
|
||||||
pub struct WindowPlugin {
|
pub struct WindowPlugin {
|
||||||
pub primary_window: Option<WindowDescriptor>,
|
pub add_primary_window: bool,
|
||||||
pub exit_on_close: bool,
|
pub exit_on_close: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for WindowPlugin {
|
impl Default for WindowPlugin {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
WindowPlugin {
|
WindowPlugin {
|
||||||
primary_window: Some(WindowDescriptor::default()),
|
add_primary_window: true,
|
||||||
exit_on_close: true,
|
exit_on_close: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,14 +39,16 @@ impl AppPlugin for WindowPlugin {
|
||||||
.add_event::<CursorMoved>()
|
.add_event::<CursorMoved>()
|
||||||
.init_resource::<Windows>();
|
.init_resource::<Windows>();
|
||||||
|
|
||||||
if let Some(ref primary_window_descriptor) = self.primary_window {
|
if self.add_primary_window {
|
||||||
let mut create_window_event = app
|
let resources = app.resources();
|
||||||
.resources_mut()
|
let window_descriptor = resources
|
||||||
.get_mut::<Events<CreateWindow>>()
|
.get::<WindowDescriptor>()
|
||||||
.unwrap();
|
.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 {
|
create_window_event.send(CreateWindow {
|
||||||
id: WindowId::new(),
|
id: WindowId::new(),
|
||||||
descriptor: primary_window_descriptor.clone(),
|
descriptor: window_descriptor.clone(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,13 +44,13 @@ fn setup(
|
||||||
})
|
})
|
||||||
// light
|
// light
|
||||||
.spawn(LightComponents {
|
.spawn(LightComponents {
|
||||||
translation: Translation::new(4.0, 5.0, -4.0),
|
translation: Translation::new(4.0, 8.0, 4.0),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
// camera
|
// camera
|
||||||
.spawn(Camera3dComponents {
|
.spawn(Camera3dComponents {
|
||||||
transform: Transform::new_sync_disabled(Mat4::face_toward(
|
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, 0.0, 0.0),
|
||||||
Vec3::new(0.0, 1.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::*,
|
text::prelude::*,
|
||||||
transform::prelude::*,
|
transform::prelude::*,
|
||||||
type_registry::RegisterType,
|
type_registry::RegisterType,
|
||||||
|
window::prelude::*,
|
||||||
ui::prelude::*,
|
ui::prelude::*,
|
||||||
AddDefaultPlugins,
|
AddDefaultPlugins,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue