-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathapp_open_links.rs
48 lines (40 loc) · 1.08 KB
/
app_open_links.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
use notan::draw::*;
use notan::prelude::*;
#[derive(AppState)]
struct State {
font: Font,
}
#[notan_main]
fn main() -> Result<(), String> {
notan::init_with(setup)
.add_config(DrawConfig)
.draw(draw)
.update(update)
.build()
}
fn setup(gfx: &mut Graphics) -> State {
let font = gfx
.create_font(include_bytes!("assets/Ubuntu-B.ttf"))
.unwrap();
State { font }
}
fn update(app: &mut App) {
if app.keyboard.was_pressed(KeyCode::N) {
app.open_link("https://github.com/Nazariglez/notan");
} else if app.keyboard.was_pressed(KeyCode::R) {
app.open_link("https://www.rust-lang.org");
}
}
fn draw(gfx: &mut Graphics, state: &mut State) {
let mut draw = gfx.create_draw();
draw.clear(Color::BLACK);
draw.text(&state.font, "Press 'n' to open Notan's website")
.position(20.0, 20.0)
.size(40.0)
.color(Color::WHITE);
draw.text(&state.font, "Press 'r' to open rust-lang.org")
.position(20.0, 120.0)
.size(40.0)
.color(Color::WHITE);
gfx.render(&draw);
}