klyff 0.1.3

Text rendering library for games with MSDF support
Documentation
use super::Rect;

/// A glyph that has been processed during [`crate::MeshEncoder::encode`] and is available for
/// [`crate::MaterialEncoder`]s to iterate over in a second pass.
#[derive(Clone, Copy)]
#[non_exhaustive]
pub struct DecodedGlyph {
    /// Font size in pixels.
    pub font_size_px: f32,
    /// Identifier of the [`Text`] this glyph was produced from. Mirrors [`Text::id`].
    pub text_id: u64,
    /// Per-attr-block metadata propagated from the source `cosmic_text::Attrs::metadata(..)`.
    pub metadata: usize,
    /// Index of the glyph within the text it belongs to.
    pub glyph_index_in_text: usize,
    /// Total number of glyphs within the text it belongs to.
    pub total_glyphs_in_text: usize,
    /// The bounding box of this rect.
    pub glyph_rect: Rect,
    /// Pass-through of [`Text::region`].
    /// Unlike [`Self::text_rect_tight`], unused regions in the rect are still included.
    pub text_rect: Rect,
    /// The tight bounding box all glyphs in the text that this glyph belongs to.
    pub text_rect_tight: Rect,
    /// The size of the block of glyphs with the same metadata.
    pub metadata_block_size: glam::Vec2,
    /// Offset of this glyph, within the block of glyphs with the same metadata.
    pub offset_in_metadata_block: glam::Vec2,
    /// Texture atlas region.
    pub uvw: (Rect, u32),
}

/// A low-level view of a text laid out into a [`cosmic_text::Buffer`], suitable for
/// [`crate::MeshEncoder::encode`].
///
/// Borrows its buffer from an owner (typically a [`crate::StyledText`]). Identifies the text with `id`
/// (text-level) and propagates per-attr [`cosmic_text::Attrs::metadata`] onto each
/// [`DecodedGlyph::metadata`] for downstream style routing.
#[derive(Clone, Copy)]
pub struct Text<'a> {
    pub id: u64,
    pub text_buffer: &'a cosmic_text::Buffer,
    pub region: Rect,
    pub scale: f32,
    pub custom_padding: Option<(usize, usize)>,
}