|
|
|
|
@ -27,6 +27,7 @@ fn main() {
|
|
|
|
|
.add_startup_system(load_fonts)
|
|
|
|
|
.add_startup_system(init_ui)
|
|
|
|
|
.add_system(manage_buttons)
|
|
|
|
|
.add_system(manage_animation_button)
|
|
|
|
|
.add_system(manage_fonts)
|
|
|
|
|
.add_system(mouse_cursor)
|
|
|
|
|
.add_system(manage_animation)
|
|
|
|
|
@ -36,9 +37,6 @@ fn main() {
|
|
|
|
|
#[derive(Resource)]
|
|
|
|
|
struct Fonts(Vec<Handle<Font>>);
|
|
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
struct Marker;
|
|
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
struct PreviewText;
|
|
|
|
|
|
|
|
|
|
@ -48,6 +46,9 @@ struct ButtonShelf;
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
struct FontButton(Handle<Font>);
|
|
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
struct AnimationButton;
|
|
|
|
|
|
|
|
|
|
fn load_fonts(mut commands: Commands, server: Res<AssetServer>) {
|
|
|
|
|
let handles = server
|
|
|
|
|
.load_folder("fonts")
|
|
|
|
|
@ -62,17 +63,14 @@ fn init_ui(mut commands: Commands) {
|
|
|
|
|
commands.spawn(Camera2dBundle { ..default() });
|
|
|
|
|
|
|
|
|
|
commands
|
|
|
|
|
.spawn((
|
|
|
|
|
NodeBundle {
|
|
|
|
|
style: Style {
|
|
|
|
|
size: Size::all(Val::Percent(100.0)),
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
background_color: BackgroundColor(Color::BLACK),
|
|
|
|
|
.spawn(NodeBundle {
|
|
|
|
|
style: Style {
|
|
|
|
|
size: Size::all(Val::Percent(100.0)),
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
Marker,
|
|
|
|
|
))
|
|
|
|
|
background_color: BackgroundColor(Color::BLACK),
|
|
|
|
|
..default()
|
|
|
|
|
})
|
|
|
|
|
.with_children(|parent| {
|
|
|
|
|
parent.spawn((
|
|
|
|
|
NodeBundle {
|
|
|
|
|
@ -89,18 +87,81 @@ fn init_ui(mut commands: Commands) {
|
|
|
|
|
background_color: BackgroundColor(Color::BLACK),
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
Marker,
|
|
|
|
|
ButtonShelf,
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
parent.spawn((
|
|
|
|
|
AnimatedTextBundle {
|
|
|
|
|
text_bundle: TextBundle { ..default() },
|
|
|
|
|
text_bundle: TextBundle {
|
|
|
|
|
text: Text {
|
|
|
|
|
sections: LOREM
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|&line| TextSection {
|
|
|
|
|
value: line.into(),
|
|
|
|
|
style: TextStyle {
|
|
|
|
|
font_size: 18.0,
|
|
|
|
|
color: Color::WHITE,
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
.collect(),
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
style: Style {
|
|
|
|
|
size: Size {
|
|
|
|
|
width: Val::Px(400.0),
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
animated_text: AnimatedText::new(TextAnimationType::Typing(12.0)),
|
|
|
|
|
},
|
|
|
|
|
Marker,
|
|
|
|
|
PreviewText,
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
parent
|
|
|
|
|
.spawn((
|
|
|
|
|
ButtonBundle {
|
|
|
|
|
style: Style {
|
|
|
|
|
align_self: AlignSelf::FlexEnd,
|
|
|
|
|
position_type: PositionType::Absolute,
|
|
|
|
|
position: UiRect {
|
|
|
|
|
bottom: Val::Px(5.0),
|
|
|
|
|
left: Val::Px(5.0),
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
size: Size {
|
|
|
|
|
width: Val::Px(200.0),
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
background_color: BackgroundColor(Color::default().with_a(0.0)),
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
AnimationButton,
|
|
|
|
|
))
|
|
|
|
|
.with_children(|parent| {
|
|
|
|
|
parent.spawn((
|
|
|
|
|
TextBundle {
|
|
|
|
|
text: Text {
|
|
|
|
|
sections: vec![TextSection {
|
|
|
|
|
value: "Toggle Animation".into(),
|
|
|
|
|
style: TextStyle {
|
|
|
|
|
font_size: 12.0,
|
|
|
|
|
color: Color::WHITE,
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
}],
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
AnimationButton,
|
|
|
|
|
));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -109,10 +170,10 @@ fn manage_buttons(
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
fonts: Res<Fonts>,
|
|
|
|
|
server: Res<AssetServer>,
|
|
|
|
|
query: Query<Entity, (With<Marker>, With<ButtonShelf>)>,
|
|
|
|
|
shelf_query: Query<Entity, With<ButtonShelf>>,
|
|
|
|
|
) {
|
|
|
|
|
if fonts.is_added() || fonts.is_changed() {
|
|
|
|
|
let root = query.get_single().expect("Fetching root UI node");
|
|
|
|
|
let root = shelf_query.get_single().expect("Fetching root UI node");
|
|
|
|
|
let mut root_cmd = commands.get_entity(root).expect("Root UI node commands");
|
|
|
|
|
|
|
|
|
|
root_cmd.clear_children();
|
|
|
|
|
@ -149,11 +210,10 @@ fn manage_buttons(
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
FontButton(font.clone()),
|
|
|
|
|
Marker,
|
|
|
|
|
))
|
|
|
|
|
.with_children(|parent| {
|
|
|
|
|
info!("Adding {} button", fname);
|
|
|
|
|
parent.spawn((TextBundle::from_section(fname, style), Marker));
|
|
|
|
|
parent.spawn(TextBundle::from_section(fname, style));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
@ -161,7 +221,7 @@ fn manage_buttons(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn manage_fonts(
|
|
|
|
|
mut texts: Query<&mut Text, (With<Marker>, With<PreviewText>)>,
|
|
|
|
|
mut texts: Query<&mut Text, With<PreviewText>>,
|
|
|
|
|
interaction: Query<(&Interaction, &FontButton), Changed<Interaction>>,
|
|
|
|
|
) {
|
|
|
|
|
for (i, f) in interaction.iter() {
|
|
|
|
|
@ -176,6 +236,24 @@ fn manage_fonts(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn manage_animation_button(
|
|
|
|
|
mut animation_button: Query<&mut Text, With<AnimationButton>>,
|
|
|
|
|
interaction: Query<(&Interaction, &FontButton), Changed<Interaction>>,
|
|
|
|
|
) {
|
|
|
|
|
for (i, f) in interaction.iter() {
|
|
|
|
|
match (i, f) {
|
|
|
|
|
(Interaction::Clicked, FontButton(font)) => {
|
|
|
|
|
animation_button
|
|
|
|
|
.single_mut()
|
|
|
|
|
.sections
|
|
|
|
|
.iter_mut()
|
|
|
|
|
.for_each(|section| section.style.font = font.clone());
|
|
|
|
|
}
|
|
|
|
|
_ => (),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn mouse_cursor(
|
|
|
|
|
mut windows: Query<&mut Window>,
|
|
|
|
|
interactions: Query<&Interaction, (Changed<Interaction>, With<Button>)>,
|
|
|
|
|
@ -191,16 +269,16 @@ fn mouse_cursor(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn manage_animation(
|
|
|
|
|
mut texts: Query<&mut Text, (With<Marker>, With<PreviewText>)>,
|
|
|
|
|
mut animated_texts: Query<&mut AnimatedText, With<PreviewText>>,
|
|
|
|
|
interactions: Query<&Interaction, (Changed<Interaction>, With<FontButton>)>,
|
|
|
|
|
time: Res<Time>,
|
|
|
|
|
mut duration: Local<Duration>,
|
|
|
|
|
mut desired: Local<Vec<String>>,
|
|
|
|
|
) {
|
|
|
|
|
for interaction in interactions.iter() {
|
|
|
|
|
match interaction {
|
|
|
|
|
Interaction::Clicked => {
|
|
|
|
|
// Start playing animation
|
|
|
|
|
let mut preview = animated_texts
|
|
|
|
|
.get_single_mut()
|
|
|
|
|
.expect("Loading animated text");
|
|
|
|
|
preview.play();
|
|
|
|
|
}
|
|
|
|
|
_ => (),
|
|
|
|
|
}
|
|
|
|
|
|