use std::ops::Range;
use bevy::{color::Color, reflect::Reflect};
#[derive(Default, Debug, Clone, Reflect, PartialEq)]
pub struct ColorText {
pub color: Color,
pub range: Range<usize>,
}
#[derive(Debug, Default, Clone, Reflect, PartialEq)]
pub struct Highlighted {
pub color_text: Vec<ColorText>,
}
#[derive(Default, Debug, Clone, Reflect)]
pub struct RichText {
pub(crate) text: String,
pub(crate) highlighted: Highlighted,
current_index: usize,
}
impl RichText {
pub fn new() -> Self {
Self {
text: String::new(),
highlighted: Highlighted::default(),
current_index: 0,
}
}
pub fn from_hightlighted(text: &str, highlighted: Highlighted) -> Self {
Self {
text: text.to_string(),
highlighted,
current_index: 0,
}
}
pub fn with_color_text(mut self, text: &str, color: bevy::prelude::Color) -> Self {
self.text = format!("{}{}", self.text, text);
self.highlighted.color_text.push(ColorText {
color,
range: self.current_index..text.len(),
});
self.current_index += text.len();
self
}
}