-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathinput_touches.rs
55 lines (46 loc) · 1.17 KB
/
input_touches.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
50
51
52
53
54
55
use notan::draw::*;
use notan::prelude::*;
use std::ops::Rem;
const COLORS: [Color; 8] = [
Color::RED,
Color::ORANGE,
Color::OLIVE,
Color::BLUE,
Color::GREEN,
Color::SILVER,
Color::PURPLE,
Color::PINK,
];
#[derive(AppState)]
struct State {
font: Font,
}
#[notan_main]
fn main() -> Result<(), String> {
notan::init_with(setup)
.add_config(DrawConfig)
.draw(draw)
.build()
}
fn setup(gfx: &mut Graphics) -> State {
let font = gfx
.create_font(include_bytes!("assets/Ubuntu-B.ttf"))
.unwrap();
State { font }
}
fn draw(app: &mut App, gfx: &mut Graphics, state: &mut State) {
let mut draw = gfx.create_draw();
draw.clear(Color::BLACK);
app.touch.down.iter().for_each(|(&index, _)| {
if let Some((x, y)) = app.touch.position(index) {
draw.circle(12.0)
.position(x, y)
.color(COLORS[(index as usize).rem(COLORS.len())]);
draw.text(&state.font, &format!("{index} -> {x:.0}x{y:.0}"))
.position(x, y - 16.0)
.h_align_center()
.v_align_bottom();
}
});
gfx.render(&draw);
}