-
Notifications
You must be signed in to change notification settings - Fork 1
/
simple.rs
52 lines (45 loc) · 1.58 KB
/
simple.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! This example demonstrates spawning a single rounded rect masterial node in the center of the screen.
use bevy::prelude::*;
use bevy_round_ui::prelude::*;
fn main() {
App::new()
.add_plugins((DefaultPlugins, BevyRoundUiDefaultPlugins))
.add_systems(Startup, setup)
.run();
}
const PANEL_WIDTH: f32 = 200.0;
const PANEL_HEIGHT: f32 = 200.0;
fn setup(mut commands: Commands, mut materials: ResMut<Assets<RoundRectUiMaterial>>) {
// Camera so we can see UI
commands.spawn(Camera2dBundle::default());
// Add the material
let panel_material = materials.add(RoundRectUiMaterial {
background_color: Srgba::hex("#F76161").unwrap().into(),
border_color: Srgba::hex("#A53A3D").unwrap().into(),
border_radius: RoundUiBorder::all(20.0).into(),
offset: RoundUiOffset::bottom(10.0).into(),
});
// Spawn the material in the middle of the screen
commands
.spawn(NodeBundle {
style: Style {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
},
..default()
})
.with_children(|p| {
p.spawn(MaterialNodeBundle {
material: panel_material,
style: Style {
width: Val::Px(PANEL_WIDTH),
height: Val::Px(PANEL_HEIGHT),
..default()
},
..default()
});
});
}