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

pub(crate) struct TextPlugin;

impl Plugin for TextPlugin {
    fn build(&self, app: &mut App) {
        app.add_systems(Update, setup.run_if(not(resource_exists::<TextProps>)));
    }
}

/// Resource handling text properties throughout the app.
#[derive(Resource)]
pub struct TextProps(Handle<Font>);

impl TextProps {
    pub(crate) fn button_text_style(&self) -> TextStyle {
        TextStyle {
            font: self.font(),
            font_size: 40.0,
            color: Color::rgb(0.9, 0.9, 0.9),
        }
    }

    pub(crate) fn label_text_style(&self) -> TextStyle {
        TextStyle {
            font: self.font(),
            font_size: 35.0,
            color: Color::rgb(0.9, 0.9, 0.9),
        }
    }

    pub(crate) fn input_text_style(&self) -> TextStyle {
        TextStyle {
            font: self.font(),
            font_size: 30.0,
            color: Color::BLACK,
        }
    }

    pub(crate) fn toast_text_style(&self) -> TextStyle {
        TextStyle {
            font: self.font(),
            font_size: 30.0,
            color: Color::BLACK,
        }
    }

    pub(crate) fn body_text_style(&self) -> TextStyle {
        TextStyle {
            font: self.font(),
            font_size: 16.0,
            color: Color::rgb(0.9, 0.9, 0.9),
        }
    }

    fn font(&self) -> Handle<Font> {
        self.0.clone()
    }
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    let font = asset_server.load("fonts/Fira_Mono/FiraMono-Medium.ttf");
    commands.insert_resource(TextProps(font));
}