-
Notifications
You must be signed in to change notification settings - Fork 1
/
autosize.rs
80 lines (75 loc) · 3.02 KB
/
autosize.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//! This example demonstrates how RoundUiMaterial nodes automaticall adjust when their node size changes.
use bevy::{color::palettes::css, prelude::*};
use bevy_round_ui::prelude::*;
fn main() {
App::new()
.add_plugins((DefaultPlugins, BevyRoundUiDefaultPlugins))
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands, mut materials: ResMut<Assets<RoundRectUiMaterial>>) {
// Camera so we can see UI
commands.spawn(Camera2dBundle::default());
// Spawn two nested panels with flexible sizes in the middle of the window
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: materials.add(RoundRectUiMaterial {
background_color: css::PINK.into(),
border_color: LinearRgba::WHITE,
border_radius: RoundUiBorder::all(20.).into(),
offset: RoundUiOffset::all(6.).into(),
}),
style: Style {
width: Val::Percent(50.),
height: Val::Percent(50.),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
overflow: Overflow::clip(),
padding: UiRect::all(Val::Px(12.)),
..default()
},
..default()
})
.with_children(|p| {
p.spawn(MaterialNodeBundle {
material: materials.add(RoundRectUiMaterial {
background_color: Srgba::hex("5cb3af").unwrap().into(),
border_color: LinearRgba::WHITE,
border_radius: RoundUiBorder::all(20.0).into(),
offset: RoundUiOffset::all(6.0).into(),
}),
style: Style {
width: Val::Percent(50.),
height: Val::Percent(50.),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
overflow: Overflow::clip(),
padding: UiRect::all(Val::Px(12.)),
..default()
},
..default()
})
.with_children(|p| {
p.spawn(TextBundle::from_section(
"Resize the window to see how flexible I am",
TextStyle {
color: Color::WHITE,
font_size: 20.,
..default()
},
));
});
});
});
}