use bevy::ecs::system::SystemParam;
use bevy::prelude::*;
use bevy::text::ComputedTextBlock;
use crate::glyph::{Glyph, GlyphOf};
#[derive(Debug, SystemParam)]
pub struct GlyphReader<'w, 's> {
computed: Query<'w, 's, &'static ComputedTextBlock>,
glyphs: Query<'w, 's, (&'static Glyph, &'static GlyphOf)>,
}
impl<'w, 's> GlyphReader<'w, 's> {
pub fn read(&self, glyph: Entity) -> Result<&str> {
Ok(self.glyphs.get(glyph).map(|(glyph, glyph_of)| {
self.computed.get(glyph_of.root()).map(|computed| {
let text = &computed.buffer().lines[glyph.0.line_index].text();
&text[glyph.0.byte_index..glyph.0.byte_index + glyph.0.byte_length]
})
})??)
}
}
#[cfg(test)]
mod test {
}