Skip to main content

nightshade_text/
text_data.rs

1//! Generated text geometry owned by the render layer.
2
3use nalgebra_glm::{Vec2, Vec3};
4
5/// Triangulated glyph geometry for a laid-out string.
6#[derive(Clone, Debug, Default)]
7pub struct TextMesh {
8    /// Glyph quad vertices.
9    pub vertices: Vec<TextVertex>,
10    /// Triangle indices into `vertices`.
11    pub indices: Vec<u32>,
12    /// Width and height of the laid-out text in local units.
13    pub bounds: Vec2,
14}
15
16/// A single text glyph vertex in the layout for GPU upload.
17#[repr(C)]
18#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)]
19pub struct TextVertex {
20    /// Local-space position.
21    pub position: Vec3,
22    /// Atlas texture coordinates.
23    pub tex_coords: Vec2,
24    /// Index of the source character within the string.
25    pub character_index: u32,
26    /// Padding to a 16-byte stride.
27    pub _padding: u32,
28}
29
30/// Font family a run of text is rendered with.
31#[derive(
32    Clone,
33    Copy,
34    Debug,
35    Default,
36    PartialEq,
37    Eq,
38    Hash,
39    serde::Serialize,
40    serde::Deserialize,
41    enum2schema::Schema,
42)]
43#[schema(string_enum)]
44pub enum FontKind {
45    /// Default proportional font.
46    #[default]
47    Default,
48    /// Monospaced font.
49    Mono,
50    /// Material Design icon glyphs.
51    IconsMaterial,
52    /// Lucide icon glyphs.
53    IconsLucide,
54}
55
56/// Horizontal alignment of text within its bounds.
57#[derive(
58    Clone, Copy, Debug, PartialEq, serde::Serialize, serde::Deserialize, enum2schema::Schema,
59)]
60#[schema(string_enum)]
61pub enum TextAlignment {
62    /// Align to the left edge.
63    Left,
64    /// Center horizontally.
65    Center,
66    /// Align to the right edge.
67    Right,
68}
69
70/// Vertical alignment of text within its bounds.
71#[derive(
72    Clone, Copy, Debug, PartialEq, serde::Serialize, serde::Deserialize, enum2schema::Schema,
73)]
74#[schema(string_enum)]
75pub enum VerticalAlignment {
76    /// Align to the top edge.
77    Top,
78    /// Center vertically.
79    Middle,
80    /// Align to the bottom edge.
81    Bottom,
82    /// Align the first line's baseline to the origin.
83    Baseline,
84}