Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/crates/bevy_text/src/glyph.rs
9550 views
1
//! This module exports types related to rendering glyphs.
2
3
use bevy_asset::AssetId;
4
use bevy_image::prelude::*;
5
use bevy_math::{Rect, Vec2};
6
use bevy_reflect::Reflect;
7
8
/// A glyph of a font, typically representing a single character, positioned in screen space.
9
///
10
/// Contains information about how and where to render a glyph.
11
///
12
/// Used in [`TextPipeline::update_text_layout_info`](crate::TextPipeline::update_text_layout_info) and [`TextLayoutInfo`](`crate::TextLayoutInfo`) for rendering glyphs.
13
#[derive(Debug, Clone, Reflect)]
14
#[reflect(Clone)]
15
pub struct PositionedGlyph {
16
/// The position of the glyph in the text block's bounding box.
17
pub position: Vec2,
18
/// Information about the glyph's atlas.
19
pub atlas_info: GlyphAtlasInfo,
20
/// The index of the glyph in the [`ComputedTextBlock`](crate::ComputedTextBlock)'s tracked spans.
21
pub span_index: usize,
22
/// The index of the glyph's line.
23
pub line_index: usize,
24
/// The byte index of the glyph in its line.
25
pub byte_index: usize,
26
/// The byte length of the glyph.
27
pub byte_length: usize,
28
}
29
30
/// Information about a glyph in an atlas.
31
///
32
/// Rasterized glyphs are stored as rectangles
33
/// in one or more [`FontAtlas`](crate::FontAtlas)es.
34
///
35
/// Used in [`PositionedGlyph`] and [`FontAtlasSet`](crate::FontAtlasSet).
36
#[derive(Debug, Clone, Reflect)]
37
#[reflect(Clone)]
38
pub struct GlyphAtlasInfo {
39
/// An asset ID to the [`Image`] data for the texture atlas this glyph was placed in.
40
///
41
/// An asset ID of the handle held by the [`FontAtlas`](crate::FontAtlas).
42
pub texture: AssetId<Image>,
43
/// Bounds of the glyph in the atlas texture
44
pub rect: Rect,
45
/// The required offset (relative positioning) when placed
46
pub offset: Vec2,
47
}
48
49
/// The location of a glyph in an atlas,
50
/// and how it should be positioned when placed.
51
///
52
/// Used in [`GlyphAtlasInfo`] and [`FontAtlas`](crate::FontAtlas).
53
#[derive(Debug, Clone, Copy, Reflect)]
54
#[reflect(Clone)]
55
pub struct GlyphAtlasLocation {
56
/// The index of the glyph in the atlas
57
pub glyph_index: usize,
58
/// The required offset (relative positioning) when placed
59
pub offset: Vec2,
60
}
61
62