mirror of
https://github.com/bevyengine/bevy
synced 2024-11-26 14:40:19 +00:00
ffecb05a0a
This makes the [New Bevy Renderer](#2535) the default (and only) renderer. The new renderer isn't _quite_ ready for the final release yet, but I want as many people as possible to start testing it so we can identify bugs and address feedback prior to release. The examples are all ported over and operational with a few exceptions: * I removed a good portion of the examples in the `shader` folder. We still have some work to do in order to make these examples possible / ergonomic / worthwhile: #3120 and "high level shader material plugins" are the big ones. This is a temporary measure. * Temporarily removed the multiple_windows example: doing this properly in the new renderer will require the upcoming "render targets" changes. Same goes for the render_to_texture example. * Removed z_sort_debug: entity visibility sort info is no longer available in app logic. we could do this on the "render app" side, but i dont consider it a priority.
81 lines
3 KiB
Rust
81 lines
3 KiB
Rust
use bevy::prelude::*;
|
|
|
|
/// This example illustrates how to customize the default window settings
|
|
fn main() {
|
|
App::new()
|
|
.insert_resource(WindowDescriptor {
|
|
width: 500.,
|
|
height: 300.,
|
|
..Default::default()
|
|
})
|
|
.add_plugins(DefaultPlugins)
|
|
.add_startup_system(setup)
|
|
.add_system(toggle_override)
|
|
.add_system(change_scale_factor)
|
|
.run();
|
|
}
|
|
|
|
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|
// ui camera
|
|
commands.spawn_bundle(UiCameraBundle::default());
|
|
// root node
|
|
commands
|
|
.spawn_bundle(NodeBundle {
|
|
style: Style {
|
|
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
|
|
justify_content: JustifyContent::SpaceBetween,
|
|
..Default::default()
|
|
},
|
|
color: Color::NONE.into(),
|
|
..Default::default()
|
|
})
|
|
.with_children(|parent| {
|
|
// left vertical fill (border)
|
|
parent
|
|
.spawn_bundle(NodeBundle {
|
|
style: Style {
|
|
size: Size::new(Val::Px(200.0), Val::Percent(100.0)),
|
|
border: Rect::all(Val::Px(2.0)),
|
|
..Default::default()
|
|
},
|
|
color: Color::rgb(0.65, 0.65, 0.65).into(),
|
|
..Default::default()
|
|
})
|
|
.with_children(|parent| {
|
|
parent.spawn_bundle(TextBundle {
|
|
style: Style {
|
|
align_self: AlignSelf::FlexEnd,
|
|
..Default::default()
|
|
},
|
|
text: Text::with_section(
|
|
"Example text",
|
|
TextStyle {
|
|
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
|
|
font_size: 30.0,
|
|
color: Color::WHITE,
|
|
},
|
|
Default::default(),
|
|
),
|
|
..Default::default()
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
/// This system toggles scale factor overrides when enter is pressed
|
|
fn toggle_override(input: Res<Input<KeyCode>>, mut windows: ResMut<Windows>) {
|
|
let window = windows.get_primary_mut().unwrap();
|
|
if input.just_pressed(KeyCode::Return) {
|
|
window.set_scale_factor_override(window.scale_factor_override().xor(Some(1.)));
|
|
}
|
|
}
|
|
|
|
/// This system changes the scale factor override when up or down is pressed
|
|
fn change_scale_factor(input: Res<Input<KeyCode>>, mut windows: ResMut<Windows>) {
|
|
let window = windows.get_primary_mut().unwrap();
|
|
if input.just_pressed(KeyCode::Up) {
|
|
window.set_scale_factor_override(window.scale_factor_override().map(|n| n + 1.));
|
|
} else if input.just_pressed(KeyCode::Down) {
|
|
window.set_scale_factor_override(window.scale_factor_override().map(|n| (n - 1.).max(1.)));
|
|
}
|
|
}
|