1use crate::prelude::font::Font;
2use crate::prelude::{Color, Vector2};
3use wgpu_text::glyph_brush::FontId;
4
5#[derive(Clone, Copy, Debug)]
6pub struct Span<'a> {
7 pub text: &'a str,
8 pub color: Option<Color>,
9 pub size: Option<f32>,
10 pub font_id: Option<FontId>,
11}
12
13impl<'a> Span<'a> {
14 pub const fn new(text: &'a str) -> Self {
15 Self {
16 text,
17 color: None,
18 size: None,
19 font_id: None,
20 }
21 }
22
23 pub const fn with_size(mut self, size: f32) -> Self {
24 self.size = Some(size);
25 self
26 }
27
28 pub const fn with_color(mut self, color: Color) -> Self {
29 self.color = Some(color);
30 self
31 }
32
33 pub const fn with_font(mut self, font: Option<&Font>) -> Self {
34 self.font_id = if let Some(font) = font {
35 Some(font.id)
36 } else {
37 None
38 };
39 self
40 }
41}
42
43#[derive(Clone, Debug)]
45pub(crate) struct SpanRef {
46 pub range: std::ops::Range<usize>, pub color: Color,
48 pub size: f32,
49 pub font_id: FontId,
50}
51
52#[derive(Clone, Debug)]
53pub(crate) struct RichtextSection {
54 pub position: Vector2,
55 pub z: f32,
56 pub spans: std::ops::Range<usize>, }