Refactor setup into plugin, add MacOS exit keybinds
This commit is contained in:
parent
b745642054
commit
65bf182942
|
@ -0,0 +1,8 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
indent_style = tab
|
||||
charset = utf-8
|
||||
tab_width = 2
|
|
@ -1,3 +1,3 @@
|
|||
/target
|
||||
|
||||
.DS_Store
|
||||
.cargo
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
hard_tabs = true
|
Binary file not shown.
37
src/main.rs
37
src/main.rs
|
@ -1,18 +1,35 @@
|
|||
use bevy::app::AppExit;
|
||||
use bevy::prelude::*;
|
||||
use bevy_egui::EguiPlugin;
|
||||
use std::env::consts::OS;
|
||||
|
||||
const VERSION: &'static str = "0.0-a1";
|
||||
|
||||
mod setup;
|
||||
|
||||
fn main() {
|
||||
App::build()
|
||||
.insert_resource(WindowDescriptor {
|
||||
width: 500.,
|
||||
height: 300.,
|
||||
title: format!("Lily {}", VERSION),
|
||||
vsync: false,
|
||||
..Default::default()
|
||||
})
|
||||
.add_startup_system(setup::system.system())
|
||||
.run();
|
||||
App::build()
|
||||
.insert_resource(WindowDescriptor {
|
||||
width: 1600.,
|
||||
height: 1200.,
|
||||
title: format!("Lily {}", VERSION),
|
||||
vsync: false,
|
||||
..Default::default()
|
||||
})
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugin(EguiPlugin)
|
||||
.add_plugin(setup::SetupPlugin)
|
||||
.add_system(keyboard_exit.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
fn keyboard_exit(keys: Res<Input<KeyCode>>, mut exit: EventWriter<AppExit>) {
|
||||
// Cmd+W or Cmd+Q do the same here
|
||||
if OS == "macos"
|
||||
&& (keys.pressed(KeyCode::LWin) && (keys.pressed(KeyCode::W) || keys.pressed(KeyCode::Q)))
|
||||
{
|
||||
exit.send(AppExit);
|
||||
}
|
||||
}
|
||||
|
||||
fn test_egui(mut parent_query: Query<(Entity, &Children), With<Node>>) {}
|
||||
|
|
70
src/setup.rs
70
src/setup.rs
|
@ -1,17 +1,59 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
pub fn system(mut commands: Commands, asset_server: Res<AssetServer>, mut materials: ResMut<Assets<ColorMaterial>) {
|
||||
// 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)),
|
||||
justify_content: JustifyContent::SpaceBetween,
|
||||
..Default::default()
|
||||
},
|
||||
material: materials.add(Color::NONE.into()),
|
||||
..Default::default()
|
||||
})
|
||||
pub struct SetupPlugin;
|
||||
|
||||
impl Plugin for SetupPlugin {
|
||||
fn build(&self, app: &mut AppBuilder) {
|
||||
app.add_startup_system(system.system());
|
||||
}
|
||||
}
|
||||
|
||||
fn system(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||
) {
|
||||
// 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()
|
||||
},
|
||||
material: materials.add(Color::NONE.into()),
|
||||
..Default::default()
|
||||
})
|
||||
.with_children(|parent| {
|
||||
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()
|
||||
},
|
||||
material: materials.add(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(
|
||||
"Ëxample text",
|
||||
TextStyle {
|
||||
font: asset_server.load("fonts/fantasque.ttf"),
|
||||
font_size: 30.0,
|
||||
..Default::default()
|
||||
},
|
||||
Default::default(),
|
||||
),
|
||||
..Default::default()
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue