Skip to content

Commit

Permalink
feat: centered menu on screen
Browse files Browse the repository at this point in the history
  • Loading branch information
roboteng committed Oct 13, 2023
1 parent 54250b7 commit 00926ee
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions game/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,50 @@ impl Plugin for BasePlugin {
}
}

fn c_centers(node: &mut NodeBundle) {
node.style.display = Display::Flex;
node.style.align_content = AlignContent::SpaceAround;
node.style.justify_content = JustifyContent::SpaceAround;
node.style.align_items = AlignItems::Center;
node.style.justify_items = JustifyItems::Center;
}

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);
node.style.height = Val::Percent(100.0);
node.style.width = Val::Percent(100.0);
}

fn c_m(node: &mut NodeBundle) {
node.background_color = Color::MIDNIGHT_BLUE.into();
node.style.padding = UiRect::all(Val::Px(20.0));
node.style.flex_direction = FlexDirection::Column;
node.style.align_items = AlignItems::Center;
node.style.justify_content = JustifyContent::Start;
node.style.column_gap = Val::Px(10.0);
}

fn c_child(node: &mut NodeBundle) {
node.background_color = Color::ORANGE_RED.into();
}

fn c_button_text(_b: &AssetServer, a: &mut TextStyle) {
a.color = Color::BLACK.into();
}

fn draw_main_menu(mut commands: Commands, assets: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());

root(c_background, &assets, &mut commands, |p| {
text("Hello, DSL", (), (), p);
root((c_background, c_centers), &assets, &mut commands, |p| {
node(c_m, p, |p| {
text("Hello, DSL", (), (), p);
node(c_child, p, |p| {
text("Goodbye, DSL", (), (), p);
});
button((), p, |p| {
text("Hello, button", (), c_button_text, p);
});
});
});
}

Expand Down

0 comments on commit 00926ee

Please sign in to comment.