| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
use bevy::{ |
| 7 |
color::palettes::basic::{BLUE, GRAY, LIME, PURPLE, RED, YELLOW}, |
| 8 |
prelude::*, |
| 9 |
}; |
| 10 |
|
| 11 |
fn main() { |
| 12 |
App::new() |
| 13 |
.insert_resource(ClearColor(Color::BLACK)) |
| 14 |
.add_plugins(DefaultPlugins) |
| 15 |
.add_systems(Startup, setup) |
| 16 |
.run(); |
| 17 |
} |
| 18 |
|
| 19 |
fn setup(mut commands: Commands) { |
| 20 |
commands.spawn(Camera2d); |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
commands |
| 26 |
.spawn(Node { |
| 27 |
width: percent(100), |
| 28 |
height: percent(100), |
| 29 |
align_items: AlignItems::Center, |
| 30 |
justify_content: JustifyContent::Center, |
| 31 |
..default() |
| 32 |
}) |
| 33 |
.with_children(|parent| { |
| 34 |
parent |
| 35 |
.spawn(( |
| 36 |
Node { |
| 37 |
width: px(180), |
| 38 |
height: px(100), |
| 39 |
..default() |
| 40 |
}, |
| 41 |
BackgroundColor(GRAY.into()), |
| 42 |
)) |
| 43 |
.with_children(|parent| { |
| 44 |
|
| 45 |
parent.spawn(( |
| 46 |
Node { |
| 47 |
position_type: PositionType::Absolute, |
| 48 |
left: px(10), |
| 49 |
bottom: px(40), |
| 50 |
width: px(100), |
| 51 |
height: px(50), |
| 52 |
..default() |
| 53 |
}, |
| 54 |
BackgroundColor(RED.into()), |
| 55 |
)); |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
parent.spawn(( |
| 60 |
Node { |
| 61 |
position_type: PositionType::Absolute, |
| 62 |
left: px(45), |
| 63 |
bottom: px(30), |
| 64 |
width: px(100), |
| 65 |
height: px(50), |
| 66 |
..default() |
| 67 |
}, |
| 68 |
ZIndex(2), |
| 69 |
BackgroundColor(BLUE.into()), |
| 70 |
)); |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
parent.spawn(( |
| 75 |
Node { |
| 76 |
position_type: PositionType::Absolute, |
| 77 |
left: px(70), |
| 78 |
bottom: px(20), |
| 79 |
width: px(100), |
| 80 |
height: px(75), |
| 81 |
..default() |
| 82 |
}, |
| 83 |
ZIndex(-1), |
| 84 |
BackgroundColor(LIME.into()), |
| 85 |
)); |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
parent.spawn(( |
| 91 |
Node { |
| 92 |
position_type: PositionType::Absolute, |
| 93 |
left: px(15), |
| 94 |
bottom: px(10), |
| 95 |
width: px(100), |
| 96 |
height: px(60), |
| 97 |
..default() |
| 98 |
}, |
| 99 |
BackgroundColor(PURPLE.into()), |
| 100 |
GlobalZIndex(1), |
| 101 |
)); |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
parent.spawn(( |
| 107 |
Node { |
| 108 |
position_type: PositionType::Absolute, |
| 109 |
left: px(-15), |
| 110 |
bottom: px(-15), |
| 111 |
width: px(100), |
| 112 |
height: px(125), |
| 113 |
..default() |
| 114 |
}, |
| 115 |
BackgroundColor(YELLOW.into()), |
| 116 |
GlobalZIndex(-1), |
| 117 |
)); |
| 118 |
}); |
| 119 |
}); |
| 120 |
} |