diff --git a/Cargo.lock b/Cargo.lock index a0d7535..3409c23 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -303,6 +303,20 @@ dependencies = [ "bevy_internal", ] +[[package]] +name = "bevy-ui-dsl" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "786bd547ec90da38c01dc91ee69f56c1c4d095ead38e3620ad3eafa0e3660738" +dependencies = [ + "bevy_asset", + "bevy_ecs", + "bevy_hierarchy", + "bevy_render", + "bevy_text", + "bevy_ui", +] + [[package]] name = "bevy_a11y" version = "0.11.3" @@ -1891,6 +1905,7 @@ name = "game" version = "0.1.0" dependencies = [ "bevy", + "bevy-ui-dsl", ] [[package]] diff --git a/game/Cargo.toml b/game/Cargo.toml index 8d5b0d3..8573c16 100644 --- a/game/Cargo.toml +++ b/game/Cargo.toml @@ -7,3 +7,4 @@ edition = "2021" [dependencies] bevy = "0.11.3" +bevy-ui-dsl = "0.6.1" diff --git a/game/src/lib.rs b/game/src/lib.rs index b5f2d57..ced7780 100644 --- a/game/src/lib.rs +++ b/game/src/lib.rs @@ -1,4 +1,5 @@ use bevy::prelude::*; +use bevy_ui_dsl::*; pub struct BasePlugin; @@ -9,38 +10,19 @@ impl Plugin for BasePlugin { } } -fn draw_main_menu(mut commands: Commands) { +fn c_background(node: &mut NodeBundle) { + node.background_color = Color::DARK_GREEN.into(); + let style = &mut node.style; + style.flex_direction = FlexDirection::Column; + style.width = Val::Vw(100.0); +} + +fn draw_main_menu(mut commands: Commands, assets: Res) { commands.spawn(Camera2dBundle::default()); - commands - .spawn(NodeBundle { - style: Style { - flex_direction: FlexDirection::Column, - width: Val::Vw(100.0), - ..Default::default() - }, - background_color: Color::DARK_GREEN.into(), - ..Default::default() - }) - .with_children(|builder| { - builder.spawn(TextBundle::from_section( - "Hello, World!", - TextStyle::default(), - )); - builder - .spawn(ButtonBundle { - ..Default::default() - }) - .with_children(|builder| { - builder.spawn(TextBundle::from_section( - "Hello, Button!", - TextStyle { - color: Color::BLACK, - ..Default::default() - }, - )); - }); - }); + root(c_background, &assets, &mut commands, |p| { + text("Hello, DSL", (), (), p); + }); } #[derive(Debug, Default, Hash, PartialEq, Eq, Clone, States)]