diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..04bff09 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +indent_style = tab +charset = utf-8 +tab_width = 2 diff --git a/.gitignore b/.gitignore index 4e1bc9b..1ac0b75 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ /target - +.DS_Store .cargo diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..218e203 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1 @@ +hard_tabs = true diff --git a/assets/fonts/fantasque.ttf b/assets/fonts/fantasque.ttf new file mode 100644 index 0000000..fa6be4d Binary files /dev/null and b/assets/fonts/fantasque.ttf differ diff --git a/src/main.rs b/src/main.rs index f0fc227..ddac678 100644 --- a/src/main.rs +++ b/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>, mut exit: EventWriter) { + // 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>) {} diff --git a/src/setup.rs b/src/setup.rs index 9800425..61bf9f5 100644 --- a/src/setup.rs +++ b/src/setup.rs @@ -1,17 +1,59 @@ use bevy::prelude::*; -pub fn system(mut commands: Commands, asset_server: Res, mut materials: ResMut) { - // 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, + mut materials: ResMut>, +) { + // 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() + }); + }); + }); }