mirror of
https://github.com/bevyengine/bevy
synced 2024-11-25 14:10:19 +00:00
Example cleanup (#6131)
Co-authored-by: devil-ira <justthecooldude@gmail.com>
This commit is contained in:
parent
6929d95f7f
commit
3aaf746675
9 changed files with 14 additions and 12 deletions
|
@ -275,8 +275,8 @@ impl Plugin for ColoredMesh2dPlugin {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Register our custom draw function and pipeline, and add our render systems
|
// Register our custom draw function and pipeline, and add our render systems
|
||||||
let render_app = app.get_sub_app_mut(RenderApp).unwrap();
|
app.get_sub_app_mut(RenderApp)
|
||||||
render_app
|
.unwrap()
|
||||||
.add_render_command::<Transparent2d, DrawColoredMesh2d>()
|
.add_render_command::<Transparent2d, DrawColoredMesh2d>()
|
||||||
.init_resource::<ColoredMesh2dPipeline>()
|
.init_resource::<ColoredMesh2dPipeline>()
|
||||||
.init_resource::<SpecializedRenderPipelines<ColoredMesh2dPipeline>>()
|
.init_resource::<SpecializedRenderPipelines<ColoredMesh2dPipeline>>()
|
||||||
|
|
|
@ -16,7 +16,7 @@ fn grab_mouse(
|
||||||
mouse: Res<Input<MouseButton>>,
|
mouse: Res<Input<MouseButton>>,
|
||||||
key: Res<Input<KeyCode>>,
|
key: Res<Input<KeyCode>>,
|
||||||
) {
|
) {
|
||||||
let window = windows.get_primary_mut().unwrap();
|
let window = windows.primary_mut();
|
||||||
if mouse.just_pressed(MouseButton::Left) {
|
if mouse.just_pressed(MouseButton::Left) {
|
||||||
window.set_cursor_visibility(false);
|
window.set_cursor_visibility(false);
|
||||||
window.set_cursor_lock_mode(true);
|
window.set_cursor_lock_mode(true);
|
||||||
|
|
|
@ -13,7 +13,6 @@ use bevy::{
|
||||||
renderer::{RenderContext, RenderDevice},
|
renderer::{RenderContext, RenderDevice},
|
||||||
RenderApp, RenderStage,
|
RenderApp, RenderStage,
|
||||||
},
|
},
|
||||||
window::WindowDescriptor,
|
|
||||||
};
|
};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ struct UiFont(Handle<Font>);
|
||||||
|
|
||||||
impl FromWorld for UiFont {
|
impl FromWorld for UiFont {
|
||||||
fn from_world(world: &mut World) -> Self {
|
fn from_world(world: &mut World) -> Self {
|
||||||
let asset_server = world.get_resource::<AssetServer>().unwrap();
|
let asset_server = world.resource::<AssetServer>();
|
||||||
UiFont(asset_server.load("fonts/FiraSans-Bold.ttf"))
|
UiFont(asset_server.load("fonts/FiraSans-Bold.ttf"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
//! [documentation](https://docs.rs/bevy/latest/bevy/prelude/struct.WindowDescriptor.html#structfield.transparent)
|
//! [documentation](https://docs.rs/bevy/latest/bevy/prelude/struct.WindowDescriptor.html#structfield.transparent)
|
||||||
//! for more details.
|
//! for more details.
|
||||||
|
|
||||||
use bevy::{prelude::*, window::WindowDescriptor};
|
use bevy::prelude::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
|
|
|
@ -65,7 +65,7 @@ fn toggle_resolution(
|
||||||
mut windows: ResMut<Windows>,
|
mut windows: ResMut<Windows>,
|
||||||
resolution: Res<ResolutionSettings>,
|
resolution: Res<ResolutionSettings>,
|
||||||
) {
|
) {
|
||||||
let window = windows.get_primary_mut().unwrap();
|
let window = windows.primary_mut();
|
||||||
|
|
||||||
if keys.just_pressed(KeyCode::Key1) {
|
if keys.just_pressed(KeyCode::Key1) {
|
||||||
let res = resolution.small;
|
let res = resolution.small;
|
||||||
|
@ -87,7 +87,7 @@ fn on_resize_system(
|
||||||
mut q: Query<&mut Text, With<ResolutionText>>,
|
mut q: Query<&mut Text, With<ResolutionText>>,
|
||||||
mut resize_reader: EventReader<WindowResized>,
|
mut resize_reader: EventReader<WindowResized>,
|
||||||
) {
|
) {
|
||||||
let mut text = q.get_single_mut().unwrap();
|
let mut text = q.single_mut();
|
||||||
for e in resize_reader.iter() {
|
for e in resize_reader.iter() {
|
||||||
// When resolution is being changed
|
// When resolution is being changed
|
||||||
text.sections[0].value = format!("{:.1} x {:.1}", e.width, e.height);
|
text.sections[0].value = format!("{:.1} x {:.1}", e.width, e.height);
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
//! Illustrates how to change window settings and shows how to affect
|
//! Illustrates how to change window settings and shows how to affect
|
||||||
//! the mouse pointer in various ways.
|
//! the mouse pointer in various ways.
|
||||||
|
|
||||||
use bevy::{prelude::*, window::PresentMode};
|
use bevy::{
|
||||||
use bevy_internal::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
|
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
|
||||||
|
prelude::*,
|
||||||
|
window::PresentMode,
|
||||||
|
};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
|
|
|
@ -19,7 +19,7 @@ fn main() {
|
||||||
|
|
||||||
fn minimise_automatically(mut windows: ResMut<Windows>, mut frames: Local<u32>) {
|
fn minimise_automatically(mut windows: ResMut<Windows>, mut frames: Local<u32>) {
|
||||||
if *frames == 60 {
|
if *frames == 60 {
|
||||||
windows.get_primary_mut().unwrap().set_minimized(true);
|
windows.primary_mut().set_minimized(true);
|
||||||
} else {
|
} else {
|
||||||
*frames += 1;
|
*frames += 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ fn change_window_size(
|
||||||
|
|
||||||
fn sync_dimensions(dim: Res<Dimensions>, mut windows: ResMut<Windows>) {
|
fn sync_dimensions(dim: Res<Dimensions>, mut windows: ResMut<Windows>) {
|
||||||
if dim.is_changed() {
|
if dim.is_changed() {
|
||||||
windows.get_primary_mut().unwrap().set_resolution(
|
windows.primary_mut().set_resolution(
|
||||||
dim.width.try_into().unwrap(),
|
dim.width.try_into().unwrap(),
|
||||||
dim.height.try_into().unwrap(),
|
dim.height.try_into().unwrap(),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue