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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use bevy::prelude::*;
use bevy_material_ui::{
loading_indicator::{LoadingIndicatorBuilder, ShapeMorphMaterial, SpawnLoadingIndicatorChild},
prelude::*,
};
fn main() {
App::new()
.add_plugins((DefaultPlugins, MaterialUiPlugin, TelemetryPlugin))
.add_systems(Startup, setup)
.run();
}
fn setup(
mut commands: Commands,
theme: Res<MaterialTheme>,
mut materials: ResMut<Assets<ShapeMorphMaterial>>,
) {
commands.spawn(Camera2d);
commands
.spawn(Node {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
flex_direction: FlexDirection::Column,
row_gap: Val::Px(16.0),
..default()
})
.with_children(|parent| {
parent
.spawn(Node {
flex_direction: FlexDirection::Column,
row_gap: Val::Px(16.0),
width: Val::Percent(100.0),
max_width: Val::Px(420.0),
margin: UiRect::vertical(Val::Px(8.0)),
..default()
})
.with_children(|col| {
// Default
col.spawn((
Text::new("Loading indicator"),
TextFont {
font_size: 14.0,
..default()
},
TextColor(theme.on_surface_variant),
));
col.spawn_loading_indicator(&theme, &mut materials);
// Contained
col.spawn((
Text::new("Loading indicator with container"),
TextFont {
font_size: 14.0,
..default()
},
TextColor(theme.on_surface_variant),
));
col.spawn_loading_indicator_with(
&theme,
&mut materials,
LoadingIndicatorBuilder::new().contained(),
);
// Multi-color
col.spawn((
Text::new("Loading indicator with multiple colors"),
TextFont {
font_size: 14.0,
..default()
},
TextColor(theme.on_surface_variant),
));
col.spawn_loading_indicator_with(
&theme,
&mut materials,
LoadingIndicatorBuilder::new().multi_color(),
);
// Small
col.spawn((
Text::new("Small loading indicator"),
TextFont {
font_size: 14.0,
..default()
},
TextColor(theme.on_surface_variant),
));
col.spawn_loading_indicator_with(
&theme,
&mut materials,
LoadingIndicatorBuilder::new().size(36.0),
);
// Large + fast
col.spawn((
Text::new("Large loading indicator (fast)"),
TextFont {
font_size: 14.0,
..default()
},
TextColor(theme.on_surface_variant),
));
col.spawn_loading_indicator_with(
&theme,
&mut materials,
LoadingIndicatorBuilder::new().size(64.0).speed(2.0),
);
});
});
}