diff --git a/README.md b/README.md index a4429b7..42b7093 100644 --- a/README.md +++ b/README.md @@ -45,12 +45,12 @@ See `examples` for more usage patterns! ### Supported Tags -| Tag | Usage | -| ------------------------ | ----------------------------------------------------------------------------------------- | -| `[b]bold[/b]` | Bold text | -| `[i]italic[/i]` | Italic text | -| `[c=#ff00ff]colored[/c]` | Colored text | -| `[m=foo]test[/m]` | Add a marker component to the `Text` "test", registered via `BbcodeSettings::with_marker` | +- `b`: \[b]**bold**\[/b] text +- `i`: \[i]*italic*\[/i] text +- `c`: \[c=\#ff0000]colored\[/c] text + - Register named colors via `ResMut` and use the names instead of hex values +- `m`: \[m=foo]text with marker component\[/m] + - Register marker components via `BbcodeSettings::with_marker` and use them to update text dynamically ## License diff --git a/examples/dynamic.rs b/examples/dynamic.rs index 492496f..6326847 100644 --- a/examples/dynamic.rs +++ b/examples/dynamic.rs @@ -1,9 +1,13 @@ //! 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. +//! +//! - To update the text content, we use the `[m]` tag. +//! It allows us to assign a marker component to the contained text, +//! which we can then update using queries as usual. +//! - To update the text color, we use the `[c]` tag with named colors. +//! We simply update the color for the given name and it updates everywhere. use bevy::prelude::*; -use bevy_mod_bbcode::{BbcodeBundle, BbcodePlugin, BbcodeSettings}; +use bevy_mod_bbcode::{BbcodeBundle, BbcodePlugin, BbcodeSettings, ColorMap}; #[derive(Component, Clone)] struct TimeMarker; @@ -12,7 +16,7 @@ fn main() { App::new() .add_plugins((DefaultPlugins, BbcodePlugin::new().with_fonts("fonts"))) .add_systems(Startup, setup) - .add_systems(Update, update) + .add_systems(Update, (update_text, update_color)) .run(); } @@ -20,16 +24,22 @@ fn setup(mut commands: Commands) { commands.spawn(Camera2dBundle::default()); commands.spawn(BbcodeBundle::from_content( - "Time passed: [m=time]0.0[/m] s", + "Time passed: [m=time]0.0[/m] s with [c=rainbow]rainbow[/c]", BbcodeSettings::new("Fira Sans", 40., Color::WHITE) // Register the marker component for the `m=time` tag .with_marker("time", TimeMarker), )); } -fn update(time: Res