From 7968614aaf33517c6df30666ea7a1e5eae97348e Mon Sep 17 00:00:00 2001 From: Tim Jentzsch Date: Mon, 22 Jul 2024 18:05:37 +0200 Subject: [PATCH] Use new m tag for dynamic example --- examples/dynamic.rs | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/examples/dynamic.rs b/examples/dynamic.rs index a821a5f..2e384c4 100644 --- a/examples/dynamic.rs +++ b/examples/dynamic.rs @@ -1,8 +1,12 @@ +//! This example demonstrates how parts of the text can be efficiently updated dynamically. +//! To do this, we use the special `[m]` tag, which allows us to assign a marker component to the contained text. +//! We can then query for the marker component as usual and apply our edits. + use bevy::prelude::*; -use bevy_mod_bbcode::{Bbcode, BbcodeBundle, BbcodePlugin, BbcodeSettings}; +use bevy_mod_bbcode::{BbcodeBundle, BbcodePlugin, BbcodeSettings}; -#[derive(Debug, Component)] -struct Marker; +#[derive(Component, Clone)] +struct TimeMarker; fn main() { App::new() @@ -15,27 +19,20 @@ fn main() { fn setup(mut commands: Commands, asset_server: Res) { commands.spawn(Camera2dBundle::default()); - commands.spawn(( - BbcodeBundle::from_content( - // The text will be added later - "", - BbcodeSettings::new(40., Color::WHITE) - .with_regular_font(asset_server.load("fonts/FiraSans-Regular.ttf")) - .with_bold_font(asset_server.load("fonts/FiraSans-Bold.ttf")) - .with_italic_font(asset_server.load("fonts/FiraSans-Italic.ttf")), - ), - Marker, + commands.spawn(BbcodeBundle::from_content( + "Time passed: [m=time]0.0[/m] s", + BbcodeSettings::new(40., Color::WHITE) + .with_regular_font(asset_server.load("fonts/FiraSans-Regular.ttf")) + .with_bold_font(asset_server.load("fonts/FiraSans-Bold.ttf")) + .with_italic_font(asset_server.load("fonts/FiraSans-Italic.ttf")) + // Register the marker component for the `m=time` tag + .with_marker("time", TimeMarker), )); } -fn update(time: Res