2020-12-28 20:26:50 +00:00
|
|
|
use bevy::prelude::*;
|
|
|
|
|
|
|
|
/// This example illustrates how to customize the default window settings
|
|
|
|
fn main() {
|
2021-07-27 20:21:06 +00:00
|
|
|
App::new()
|
2021-01-30 20:55:13 +00:00
|
|
|
.insert_resource(WindowDescriptor {
|
2020-12-28 20:26:50 +00:00
|
|
|
width: 500.,
|
|
|
|
height: 300.,
|
2022-03-01 20:52:09 +00:00
|
|
|
..default()
|
2020-12-28 20:26:50 +00:00
|
|
|
})
|
|
|
|
.add_plugins(DefaultPlugins)
|
2021-07-27 23:42:36 +00:00
|
|
|
.add_startup_system(setup)
|
|
|
|
.add_system(toggle_override)
|
|
|
|
.add_system(change_scale_factor)
|
2020-12-28 20:26:50 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2021-12-14 03:58:23 +00:00
|
|
|
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
2021-03-23 00:23:40 +00:00
|
|
|
// ui camera
|
|
|
|
commands.spawn_bundle(UiCameraBundle::default());
|
|
|
|
// root node
|
2020-12-28 20:26:50 +00:00
|
|
|
commands
|
2021-03-23 00:23:40 +00:00
|
|
|
.spawn_bundle(NodeBundle {
|
2020-12-28 20:26:50 +00:00
|
|
|
style: Style {
|
|
|
|
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
|
|
|
|
justify_content: JustifyContent::SpaceBetween,
|
2022-03-01 20:52:09 +00:00
|
|
|
..default()
|
2020-12-28 20:26:50 +00:00
|
|
|
},
|
2021-12-14 03:58:23 +00:00
|
|
|
color: Color::NONE.into(),
|
2022-03-01 20:52:09 +00:00
|
|
|
..default()
|
2020-12-28 20:26:50 +00:00
|
|
|
})
|
|
|
|
.with_children(|parent| {
|
2021-03-23 00:23:40 +00:00
|
|
|
// left vertical fill (border)
|
2020-12-28 20:26:50 +00:00
|
|
|
parent
|
2021-03-23 00:23:40 +00:00
|
|
|
.spawn_bundle(NodeBundle {
|
2020-12-28 20:26:50 +00:00
|
|
|
style: Style {
|
|
|
|
size: Size::new(Val::Px(200.0), Val::Percent(100.0)),
|
|
|
|
border: Rect::all(Val::Px(2.0)),
|
2022-03-01 20:52:09 +00:00
|
|
|
..default()
|
2020-12-28 20:26:50 +00:00
|
|
|
},
|
2021-12-14 03:58:23 +00:00
|
|
|
color: Color::rgb(0.65, 0.65, 0.65).into(),
|
2022-03-01 20:52:09 +00:00
|
|
|
..default()
|
2020-12-28 20:26:50 +00:00
|
|
|
})
|
|
|
|
.with_children(|parent| {
|
2021-03-23 00:23:40 +00:00
|
|
|
parent.spawn_bundle(TextBundle {
|
2020-12-28 20:26:50 +00:00
|
|
|
style: Style {
|
|
|
|
align_self: AlignSelf::FlexEnd,
|
2022-03-01 20:52:09 +00:00
|
|
|
..default()
|
2020-12-28 20:26:50 +00:00
|
|
|
},
|
2021-01-25 01:07:43 +00:00
|
|
|
text: Text::with_section(
|
|
|
|
"Example text",
|
|
|
|
TextStyle {
|
|
|
|
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
|
2020-12-28 20:26:50 +00:00
|
|
|
font_size: 30.0,
|
|
|
|
color: Color::WHITE,
|
|
|
|
},
|
2021-01-25 01:07:43 +00:00
|
|
|
Default::default(),
|
|
|
|
),
|
2022-03-01 20:52:09 +00:00
|
|
|
..default()
|
2020-12-28 20:26:50 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This system toggles scale factor overrides when enter is pressed
|
|
|
|
fn toggle_override(input: Res<Input<KeyCode>>, mut windows: ResMut<Windows>) {
|
2022-03-08 00:46:04 +00:00
|
|
|
let window = windows.primary_mut();
|
2020-12-28 20:26:50 +00:00
|
|
|
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>) {
|
2022-03-08 00:46:04 +00:00
|
|
|
let window = windows.primary_mut();
|
2020-12-28 20:26:50 +00:00
|
|
|
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.)));
|
|
|
|
}
|
|
|
|
}
|