### Run showcase and demo examples Source: https://github.com/void-scape/pretty-text/blob/master/README.md Commands to execute the library's built-in demonstration binaries. ```bash cargo run --bin showcase ``` ```bash cargo run --bin typewriter ``` ```bash cargo run --bin demo ``` -------------------------------- ### Spawn pretty text entities Source: https://github.com/void-scape/pretty-text/blob/master/README.md Examples of spawning text with wave effects, typewriter animations, custom styles, and rich text parsing. ```rust fn spawn_text(mut commands: Commands, mut materials: ResMut>) { // Spawn wavy `Text`. commands.spawn(( Text::new("Hello, World!"), Wave::default(), TextFont::from_font_size(52.0), )); // Use the typewriter. commands.spawn(( Typewriter::new(30.), Text2d::new("My text is revealed one glyph at a time"), Transform::from_xyz(0., 200., 0.), TextFont::from_font_size(36.0), )); // Spawn a style entity. commands.spawn(( PrettyStyle("my_style"), TextFont::from_font_size(48.0), effects![ PrettyTextMaterial(materials.add(Rainbow::default())), Wave::default(), ], )); // Parse rich text and use custom style. commands.spawn(( pretty!("I am |1|<0.8>*sniff*|1|<1.2> very [pretty](my_style)!|3|<1>"), Typewriter::new(10.0), TextFont::from_font_size(52.0), Node { position_type: PositionType::Absolute, left: Val::Px(0.0), bottom: Val::Px(0.0), ..Default::default() }, )); } ``` -------------------------------- ### Spawn Typewriter Component Source: https://context7.com/void-scape/pretty-text/llms.txt Spawns entities with the Typewriter component for progressive text reveals. Configure speed, reveal mode (character/word), and sequencing with pauses and speed multipliers. Includes examples for observing reveal events and handling completion. ```rust use bevy::prelude::* use bevy_pretty_text::prelude::* fn spawn_typewriter(mut commands: Commands, server: Res) { // Basic typewriter (30 glyphs per second) commands.spawn(( Typewriter::new(30.0), Text::new("My text is revealed one glyph at a time"), TextFont::from_font_size(36.0), )); // Word-by-word reveal (2 words per second) commands.spawn(( Typewriter::new(2.0), TypewriterIndex::word(), Text::new("Revealed word by word"), )); // Typewriter with sequencing: pauses |seconds|, speed changes commands .spawn(( Typewriter::new(20.0), pretty!("I can [pause](red),|1| <2>[speed up](green),|0.5| <0.5>[slow down](yellow)"), TextFont::from_font_size(52.0), )) // Play sound on each character reveal .observe( |_: On>, mut commands: Commands, server: Res| { commands.spawn(( AudioPlayer::new(server.load("glyph.wav")), PlaybackSettings::DESPAWN, )); }, ) // Handle typewriter completion .observe(|finished: On, mut commands: Commands| { // Restart the typewriter commands .entity(finished.event().entity) .insert(Typewriter::new(15.0)); }); } ``` -------------------------------- ### Initialize PrettyTextPlugin Source: https://context7.com/void-scape/pretty-text/llms.txt Registers the core plugin and systems required for text rendering and effects. ```rust use bevy::prelude::*; use bevy_pretty_text::prelude::*; fn main() { App::default() .add_plugins((DefaultPlugins, PrettyTextPlugin)) .add_systems(Startup, spawn_text) .run(); } fn spawn_text(mut commands: Commands) { commands.spawn(Camera2d); // Spawn simple wavy text commands.spawn(( Text::new("Hello, World!"), Wave::default(), TextFont::from_font_size(52.0), )); } ``` -------------------------------- ### Register PrettyTextPlugin Source: https://github.com/void-scape/pretty-text/blob/master/README.md Initialize the plugin within the Bevy App builder. ```rust use bevy::prelude::*; use bevy_pretty_text::prelude::*; fn main() { App::default() .add_plugins((DefaultPlugins, PrettyTextPlugin)) .run(); } ``` -------------------------------- ### Register PrettyStyle Components Source: https://context7.com/void-scape/pretty-text/llms.txt Spawns entities with `PrettyStyle` components to register custom text styles. These styles can include colors, fonts, and effects, and are referenced by name in parsed text. ```rust use bevy::prelude::* use bevy::color::palettes::css::RED; use bevy_pretty_text::prelude::* fn spawn_styles(mut commands: Commands, mut materials: ResMut>) { // Simple color style commands.spawn(( PrettyStyle("highlight"), TextColor(RED.into()), )); // Style with font and effects commands.spawn(( PrettyStyle("large_red"), TextFont { font_size: 52.0, ..Default::default() }, TextColor(RED.into()), effects![Wave::default()], )); // Style with shader material effect commands.spawn(( PrettyStyle("my_rainbow"), TextFont::from_font_size(48.0), effects![ PrettyTextMaterial(materials.add(Rainbow::default())), Wave::default(), ], )); } ``` -------------------------------- ### Implement AudioPlayer new function Source: https://github.com/void-scape/pretty-text/blob/master/crates/bevy_pretty_text/docs/audio_player.txt Provides a constructor for the AudioPlayer component. It takes a Handle as an argument. ```rust fn new(_: Handle) -> Self { Self } ``` -------------------------------- ### Use Registered PrettyStyles Source: https://context7.com/void-scape/pretty-text/llms.txt Spawns entities with parsed text that references registered `PrettyStyle` components by name. This allows for reusable and complex text styling. ```rust fn use_styles(mut commands: Commands) { // Reference registered styles by name commands.spawn(pretty!("[Highlighted text](highlight)")); commands.spawn(pretty!("[Large red wavy text](large_red)")); commands.spawn(pretty!("[Rainbow wave](my_rainbow)")); } ``` -------------------------------- ### Spawn Built-in Appearance Effects Source: https://context7.com/void-scape/pretty-text/llms.txt Demonstrates spawning entities with different built-in appearance effects like FadeIn, Scramble, and Spread. Ensure Typewriter and the desired effect component are added to the entity. ```rust use bevy::prelude::* use bevy_pretty_text::prelude::* fn spawn_appearance_effects(mut commands: Commands) { commands.spawn(Camera2d); // FadeIn - glyphs fade in when revealed commands.spawn(( Typewriter::new(10.0), pretty!("[FADE IN](fade_in)"), )); // Scramble - glyphs show random characters before settling commands.spawn(( Typewriter::new(10.0), pretty!("[SCRAMBLE](scramble)"), // default )); commands.spawn(( Typewriter::new(10.0), pretty!("[SCRAMBLE](scramble(12, always))"), // iterations, lifetime )); // Spread - glyphs spread from a point when revealed commands.spawn(( Typewriter::new(10.0), Text::new("SPREAD EFFECT"), Spread::default(), )); } ``` -------------------------------- ### Typewriter with Custom Events and Callbacks Source: https://context7.com/void-scape/pretty-text/llms.txt Illustrates how to use TypewriterEvent for custom sequencing and callbacks during typewriter playback. This includes observing custom events, character/word reveals, and using inline or named callback functions. ```rust use bevy::prelude::* use bevy_pretty_text::prelude::* use bevy_pretty_text::typewriter::hierarchy::TypewriterEvent; fn spawn_typewriter_with_events(mut commands: Commands, server: Res) { commands .spawn(( Typewriter::new(20.0), pretty!( // {event_name} emits TypewriterEvent // {} triggers a callback system "first span {my_event}second span {}third span", // Inline callback system |mut commands: Commands, server: Res| { commands.spawn(AudioPlayer::new(server.load("sound.wav"))); }, ), TextFont::from_font_size(52.0), )) // Observe custom events .observe(|event: On>| { if event.event().0 == "my_event" { println!("Custom event triggered!"); } }) // Observe character reveals .observe(|revealed: On>| { println!("Character revealed: {}", revealed.event().text); }) // Observe word reveals .observe(|revealed: On>| { println!("Word revealed: {}", revealed.event().text); }); } // Named callback function fn play_sound(mut commands: Commands, server: Res) { commands.spawn(AudioPlayer::new(server.load("callback.ogg"))); } fn spawn_with_named_callback(mut commands: Commands) { commands.spawn(( Typewriter::new(30.0), pretty!( "sound not played... {}sound played!", play_sound, ), )); } ``` -------------------------------- ### Add dependency to Cargo.toml Source: https://github.com/void-scape/pretty-text/blob/master/README.md Include the library in your project's dependency list. ```toml [dependencies] bevy_pretty_text = "0.4" ``` -------------------------------- ### Spawn Shader Material Effects Source: https://context7.com/void-scape/pretty-text/llms.txt Shows how to spawn entities with shader-based material effects like Rainbow and Glitch. You can customize parameters like speed and saturation for Rainbow, or combine material effects with ECS effects. ```rust use bevy::prelude::* use bevy_pretty_text::prelude::* fn spawn_material_effects(mut commands: Commands, mut materials: ResMut>) { commands.spawn(Camera2d); // Rainbow - color cycling effect commands.spawn(pretty!("[RAINBOW](rainbow)")); commands.spawn(pretty!("[custom rainbow](rainbow(1, 0.5))")); // speed, saturation // Glitch - digital glitch effect commands.spawn(pretty!("[GLITCH](glitch)")); // Using material handle directly in style commands.spawn(( PrettyStyle("my_rainbow_style"), effects![ PrettyTextMaterial(materials.add(Rainbow::default())), ], )); // Combine material effect with ECS effects commands.spawn(pretty!("[rainbow wave](rainbow, wave)")); } ``` -------------------------------- ### Utilize Built-in Color Styles Source: https://context7.com/void-scape/pretty-text/llms.txt Spawn text entities using pre-defined color styles and effects. These styles can be combined with effects like 'shake' or 'wave'. ```rust use bevy::prelude::* use bevy_pretty_text::prelude::* fn use_builtin_colors(mut commands: Commands) { // All built-in color styles commands.spawn(pretty!("[aqua](aqua) [black](black) [blue](blue)")); commands.spawn(pretty!("[fuchsia](fuchsia) [gray](gray) [green](green)")); commands.spawn(pretty!("[lime](lime) [maroon](maroon) [navy](navy)")); commands.spawn(pretty!("[olive](olive) [purple](purple) [red](red)")); commands.spawn(pretty!("[silver](silver) [teal](teal) [white](white)")); commands.spawn(pretty!("[yellow](yellow)")); // Combine colors with effects commands.spawn(pretty!("[Red and shaky](red, shake)")); commands.spawn(pretty!("[Blue wave](blue, wave)")); } ``` -------------------------------- ### Parse UI Text with pretty! Macro Source: https://context7.com/void-scape/pretty-text/llms.txt Statically parses rich text into UI Text components using markdown-like syntax for styles and effects. ```rust use bevy::prelude::*; use bevy_pretty_text::prelude::*; fn spawn_styled_text(mut commands: Commands) { // Basic styled text with color commands.spawn(pretty!("[my red text](red)")); // Multiple effects on text commands.spawn(pretty!("[shaking wavy text](shake, wave)")); // Nested styles with effects commands.spawn(pretty!("[To [Single](rainbow) or Not To [Single](rainbow)](wobble)")); // Effect with custom arguments (positional or named) commands.spawn(pretty!("[intense shake](shake(2, 3))")); commands.spawn(pretty!("[custom wave](wave(frequency=2, height=1.5))")); // Complex rich text with typewriter commands commands.spawn(( pretty!("I am |1|<0.8>*sniff*|1|<1.2> very [pretty](red, wave)!|3|<1>"), Typewriter::new(10.0), TextFont::from_font_size(52.0), )); } ``` -------------------------------- ### Parse 2D World Text with pretty2d! Macro Source: https://context7.com/void-scape/pretty-text/llms.txt Statically parses rich text into Text2d components for rendering in 2D world space. ```rust use bevy::prelude::*; use bevy_pretty_text::prelude::*; fn spawn_2d_text(mut commands: Commands) { commands.spawn(Camera2d); // Basic 2D world text commands.spawn(pretty2d!("my pretty 2d text")); // 2D text with effects and positioning commands.spawn(( pretty2d!("[RAINBOW TEXT](rainbow)"), TextFont::from_font_size(38.0), Transform::from_xyz(0.0, 200.0, 0.0), )); // Complex 2D text with nested effects commands.spawn(( pretty2d!( "[[EVERYTHING](red, scramble(12, always), shake) AS ENTITIES](wave)" ), TextFont::from_font_size(38.0), )); } ``` -------------------------------- ### Define PlaybackSettings Component Source: https://github.com/void-scape/pretty-text/blob/master/crates/bevy_pretty_text/docs/audio_player.txt Defines a deriveable component for PlaybackSettings. It includes a constant for DESPAWN. ```rust #[derive(Component)] # struct PlaybackSettings; # impl PlaybackSettings { # const DESPAWN: Self = Self; # } ``` -------------------------------- ### Parse Text at Runtime with PrettyParser Source: https://context7.com/void-scape/pretty-text/llms.txt Dynamically parses text into components when content is unknown at compile time. ```rust use bevy::prelude::*; use bevy_pretty_text::prelude::*; fn spawn_dynamic_text(mut commands: Commands) { // Parse and spawn as bundle commands.spawn(PrettyParser::bundle("my pretty text").unwrap()); // Parse into spans for later use let spans = PrettyParser::spans("[dynamic red text](red)").unwrap(); commands.spawn(spans); // Convert spans to bundle explicitly let spans = PrettyParser::spans("[wavy text](wave)").unwrap(); commands.spawn(spans.into_bundle()); } // For 2D world text, use PrettyParser2d fn spawn_dynamic_2d_text(mut commands: Commands) { commands.spawn(PrettyParser2d::bundle("[2D world text](shake)").unwrap()); } ``` -------------------------------- ### Spawn Entities with Built-in Behavior Effects Source: https://context7.com/void-scape/pretty-text/llms.txt Spawns entities with various built-in behavior effects applied to text. These effects modify the visual appearance of glyphs continuously. ```rust use bevy::prelude::* use bevy_pretty_text::prelude::* fn spawn_behavior_effects(mut commands: Commands) { commands.spawn(Camera2d); // Wave - oscillating motion along y-axis commands.spawn((Text::new("WAVING"), Wave::default())); commands.spawn(pretty!("[custom wave](wave(2, 1.5))")); // frequency, height // Shake - random motion within radius commands.spawn((Text::new("SHAKING"), Shake::default())); commands.spawn(pretty!("[intense shake](shake(2, 3))")); // speed, radius // Bounce - bouncing motion commands.spawn((Text::new("BOUNCE"), Bounce::default())); // Wobble - oscillating rotation commands.spawn((Text::new("WOBBLE"), Wobble::default())); // Breathe - scaling in and out commands.spawn((Text::new("BREATHING"), Breathe::default())); // Spin - continuous rotation commands.spawn((Text::new("SPINNING"), Spin::default())); // Pivot - rotation around a point commands.spawn((Text::new("PIVOT"), Pivot::default())); // Fade - oscillating opacity commands.spawn((Text::new("FADE"), Fade::default())); // Combine multiple effects commands.spawn(pretty!("[COMBO](shake, wave, bounce)")); } ``` -------------------------------- ### Combine Effects with effects! Macro Source: https://context7.com/void-scape/pretty-text/llms.txt Demonstrates using the effects! macro to combine multiple ECS effects, material effects, or vertex-masked effects onto a single entity. This allows for complex visual layering and targeted application of effects. ```rust use bevy::prelude::* use bevy_pretty_text::prelude::* use bevy_pretty_text::glyph::VertexMask; fn spawn_combined_effects(mut commands: Commands, mut materials: ResMut>) { // Multiple ECS effects commands.spawn(( PrettyStyle("combo"), effects![ Wave::default(), Shake { speed: 1.5, radius: 2.0 }, ], )); // Material effect with ECS effects commands.spawn(( PrettyStyle("rainbow_wave"), effects![ PrettyTextMaterial(materials.add(Rainbow::default())), Wave::default(), ], )); // Vertex-masked effects (apply to specific corners) commands.spawn(( PrettyStyle("dance"), effects![ (Wave::default(), VertexMask::TL), // top-left only (Pivot::default(), VertexMask::BR), // bottom-right only ], )); } ``` -------------------------------- ### Control Typewriter Animation Completion Source: https://context7.com/void-scape/pretty-text/llms.txt Commands to control the typewriter animation's completion behavior. Use FinishTypewriter to trigger events or ShortCircuitTypewriter to skip them. ```rust use bevy::prelude::* use bevy_pretty_text::prelude::* fn finish_typewriter(mut commands: Commands, typewriter: Single>) { // Finish normally - reveals all glyphs AND triggers remaining events/callbacks commands.entity(*typewriter).insert(FinishTypewriter); } fn skip_typewriter(mut commands: Commands, typewriter: Single>) { // Short circuit - reveals all glyphs but SKIPS events and callbacks commands.entity(*typewriter).insert(ShortCircuitTypewriter); } fn pause_with_delay(mut commands: Commands, typewriter: Single>) { // Pause for a specific duration (in seconds) commands.entity(*typewriter).insert(DelayTypewriter::from_seconds(2.0)); } ``` -------------------------------- ### Define AudioPlayer Component Source: https://github.com/void-scape/pretty-text/blob/master/crates/bevy_pretty_text/docs/audio_player.txt Defines a deriveable component for an AudioPlayer. This is a basic struct definition. ```rust #[derive(Component)] # struct AudioPlayer; # // this sucks # impl AudioPlayer { # fn new(_: Handle) -> Self { Self } # } ``` -------------------------------- ### Modify Text Styles at Runtime Source: https://context7.com/void-scape/pretty-text/llms.txt Use StyleUiWriter to replace, add, or clear styles from text spans. Ensure the target entity has a Text component. ```rust use bevy::prelude::* use bevy_pretty_text::prelude::* fn modify_styles(target: Single>, mut writer: StyleUiWriter) -> Result { // Replace a style across all text spans writer .iter_spans_mut(*target)? .replace("old_style", "new_style"); Ok(()) } fn push_style(target: Single>, mut writer: StyleUiWriter) -> Result { // Add a style to all spans writer .iter_spans_mut(*target)? .push("highlight"); Ok(()) } fn clear_styles(target: Single>, mut writer: StyleUiWriter) -> Result { // Remove all styles writer .iter_spans_mut(*target)? .clear(); Ok(()) } ``` -------------------------------- ### Define DESPAWN constant for PlaybackSettings Source: https://github.com/void-scape/pretty-text/blob/master/crates/bevy_pretty_text/docs/audio_player.txt Declares a constant named DESPAWN within the PlaybackSettings implementation. This constant is of type Self. ```rust const DESPAWN: Self = Self; ``` -------------------------------- ### Pause and Resume Typewriter Source: https://context7.com/void-scape/pretty-text/llms.txt Toggles the pause state of a Typewriter component using the Space key. Inserts or removes the `PauseTypewriter` component to control the typewriter's animation. ```rust fn toggle_pause( mut commands: Commands, input: Res>, typewriter: Option>>, mut paused: Local, ) { let Some(typewriter) = typewriter else { return }; if input.just_pressed(KeyCode::Space) { if *paused { commands.entity(*typewriter).remove::(); } else { commands.entity(*typewriter).insert(PauseTypewriter); } *paused = !*paused; } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.