summaryrefslogtreecommitdiff
path: root/src/renderer/text.rs
blob: ec913b886e58f68c354767b31b013fe286129fb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#![allow(unused)]
/// This file handles text-related settings.

#[derive(Debug, Clone, Copy)]
pub struct Color {
    r: u8,
    g: u8,
    b: u8,
    a: u8,
}

impl Color {
    pub fn new(r: u8, g: u8, b: u8, a: u8) -> Self {
        Self { r, g, b, a }
    }
    pub fn new_noa(r: u8, g: u8, b: u8) -> Self {
        Self { r, g, b, a: 1u8 }
    }
}

#[derive(Debug, Clone, Copy)]
pub struct TextStyle {
    bold: bool,
    italic: bool,
    font_size: u16,
}

impl TextStyle {
    pub fn default() -> Self {
        Self {
            bold: false,
            italic: false,
            font_size: 20,
        }
    }

    pub fn default_bold() -> Self {
        Self {
            bold: true,
            ..Self::default()
        }
    }
    pub fn default_italic() -> Self {
        Self {
            italic: true,
            ..Self::default()
        }
    }
}

#[derive(Debug, Clone)]
pub struct TextSpan<'a> {
    pub text: &'a str,
    x: i32,
    y: i32,
    fg: Color,
    bg: Color,
    pub style: TextStyle,
}

impl<'a> TextSpan<'a> {
    pub fn new(text: &'a str, style: TextStyle) -> Self {
        Self {
            text,
            style,
            x: 0,
            y: 0,
            fg: Color::new_noa(255, 0, 0),
            bg: Color::new_noa(0, 0, 0),
        }
    }
}