From 43281fbf129c07218fa56ed530c5f240b7323e44 Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Fri, 30 Jun 2023 18:30:50 -0700 Subject: [PATCH] saving my place; cool but slow text effect --- bin/text-inspect.rs | 89 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 67 insertions(+), 22 deletions(-) diff --git a/bin/text-inspect.rs b/bin/text-inspect.rs index d74093e..8f65cba 100644 --- a/bin/text-inspect.rs +++ b/bin/text-inspect.rs @@ -1,4 +1,4 @@ -use bevy::prelude::*; +use bevy::{diagnostic::FrameTimeDiagnosticsPlugin, prelude::*}; const LOREM: [&str; 5] = [ "Ullam nostrum aut amet adipisci consequuntur quisquam nemo consequatur. Vel eum et ullam ullam aperiam earum voluptas consequuntur. Blanditiis earum voluptatem voluptas animi dolorum fuga aliquam ea.\n", @@ -12,7 +12,7 @@ fn main() { App::new() .add_plugins(DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { - title: "Text WTF".into(), + title: "Text Inspect".into(), resolution: (640., 480.).into(), ..default() }), @@ -23,6 +23,8 @@ fn main() { .add_system(manage_buttons) .add_system(update) .add_system(mouse_cursor) + .add_system(play) + .add_system(framerate) .run(); } @@ -86,19 +88,24 @@ fn init_ui(mut commands: Commands) { ButtonShelf, )); - { - parent.spawn(( - TextBundle::from_sections(LOREM.iter().map(|§ion| TextSection { - value: section.into(), - style: TextStyle { - font_size: 50.0, - ..default() - }, - })), - Marker, - PreviewText, - )); - } + parent.spawn(( + TextBundle::from_sections(LOREM.iter().map(|§ion| TextSection { + value: section.into(), + style: TextStyle { + font_size: 50.0, + ..default() + }, + })) + .with_style(Style { + max_size: Size { + width: Val::Px(500.), + height: Val::Undefined, + }, + ..default() + }), + Marker, + PreviewText, + )); }); } @@ -166,13 +173,15 @@ fn update( match (i, f) { (Interaction::Clicked, FontButton(font)) => { let mut text = texts.single_mut(); - *text = Text::from_sections(LOREM.iter().map(|&s| TextSection { - value: s.into(), - style: TextStyle { - font: font.clone(), - font_size: 50.0, - ..default() - }, + *text = Text::from_sections(LOREM.iter().flat_map(|&l| { + l.chars().map(|c| TextSection { + value: c.into(), + style: TextStyle { + font: font.clone(), + font_size: 50.0, + ..default() + }, + }) })); } _ => (), @@ -193,3 +202,39 @@ fn mouse_cursor( } } } + +fn play( + mut texts: Query<&mut Text, (With, With)>, + interactions: Query<&Interaction, (Changed, With)>, + mut playing: Local, + time: Res