-
Notifications
You must be signed in to change notification settings - Fork 56
/
text_hello.rs
49 lines (39 loc) · 1.02 KB
/
text_hello.rs
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
use notan::prelude::*;
use notan::text::*;
#[derive(AppState)]
struct State {
font: Font,
font2: Font,
}
#[notan_main]
fn main() -> Result<(), String> {
notan::init_with(setup)
.add_config(TextConfig)
.draw(draw)
.build()
}
fn setup(gfx: &mut Graphics) -> State {
let font = gfx
.create_font(include_bytes!("./assets/Ubuntu-B.ttf"))
.unwrap();
let font2 = gfx
.create_font(include_bytes!("./assets/kenney_pixel-webfont.ttf"))
.unwrap();
State { font, font2 }
}
fn draw(gfx: &mut Graphics, state: &mut State) {
let mut text = gfx.create_text();
text.clear_color(Color::BLACK);
text.add("Hello ")
.font(&state.font)
.position(400.0, 30.0)
.h_align_center()
.color(Color::ORANGE)
.size(30.0);
text.chain("Notan! ").size(50.0).color(Color::RED);
text.chain("(Using TextExtension)")
.font(&state.font2)
.size(20.0)
.color(Color::GRAY.with_alpha(0.5));
gfx.render(&text);
}