-
Notifications
You must be signed in to change notification settings - Fork 55
/
input_mouse_events.rs
70 lines (62 loc) · 1.6 KB
/
input_mouse_events.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use notan::app::Event;
use notan::draw::*;
use notan::prelude::*;
#[derive(AppState)]
struct State {
font: Font,
text: String,
color: Color,
}
#[notan_main]
fn main() -> Result<(), String> {
notan::init_with(setup)
.add_config(DrawConfig)
.event(event)
.draw(draw)
.build()
}
fn setup(gfx: &mut Graphics) -> State {
let font = gfx
.create_font(include_bytes!("assets/Ubuntu-B.ttf"))
.unwrap();
State {
font,
color: Color::BLACK,
text: String::from(""),
}
}
fn event(state: &mut State, evt: Event) {
match evt {
Event::MouseMove { .. } => {
state.text = "Moving...".to_string();
}
Event::MouseDown { button, .. } => {
state.text = format!("{button:?} pressed...");
}
Event::MouseUp { button, .. } => {
state.text = format!("{button:?} released...");
}
Event::MouseEnter { .. } => {
state.text = "Entered...".to_string();
state.color = Color::BLACK;
}
Event::MouseLeft { .. } => {
state.text = "Outside...".to_string();
state.color = Color::ORANGE;
}
Event::MouseWheel { .. } => {
state.text = "Using Wheel...".to_string();
}
_ => {}
}
}
fn draw(gfx: &mut Graphics, state: &mut State) {
let mut draw = gfx.create_draw();
draw.clear(state.color);
draw.text(&state.font, &state.text)
.position(400.0, 300.0)
.size(80.0)
.h_align_center()
.v_align_middle();
gfx.render(&draw);
}