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
use crate::*;

#[derive(Clone, Debug)]
pub struct TextParams {
    pub font: egui::FontId,
    pub rotation: f32,
    pub color: Color,
}

impl Default for TextParams {
    fn default() -> TextParams {
        TextParams {
            font: egui::FontId::new(20.0, egui::FontFamily::Monospace),
            color: WHITE,
            rotation: 0.0,
        }
    }
}

pub fn draw_text_ex(
    text: &str,
    position: Vec2,
    align: TextAlign,
    params: TextParams,
) {
    let _span = span!("draw_text_ex");

    GLOBAL_STATE.borrow_mut().text_queue.push(DrawText {
        text: text.to_string(),
        position,
        color: params.color,
        font: params.font,
        align,
    });
}

pub fn draw_text(text: &str, position: Vec2, color: Color, align: TextAlign) {
    GLOBAL_STATE.borrow_mut().text_queue.push(DrawText {
        text: text.to_string(),
        position,
        color,
        font: TextParams::default().font,
        align,
    });
}

pub struct DrawText {
    pub text: String,
    pub position: Vec2,
    pub font: egui::FontId,
    pub color: Color,
    pub align: TextAlign,
}

#[derive(Copy, Clone, Debug)]
pub enum TextAlign {
    TopLeft,
    TopRight,
    BottomLeft,
    BottomRight,
    Center,
}