-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathinput_mouse_wheel.rs
57 lines (47 loc) · 1.19 KB
/
input_mouse_wheel.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
use notan::draw::*;
use notan::prelude::*;
#[derive(AppState)]
struct State {
font: Font,
x: f32,
y: f32,
}
#[notan_main]
fn main() -> Result<(), String> {
notan::init_with(setup)
.add_config(DrawConfig)
.update(update)
.draw(draw)
.build()
}
fn setup(gfx: &mut Graphics) -> State {
let font = gfx
.create_font(include_bytes!("assets/Ubuntu-B.ttf"))
.unwrap();
State {
font,
x: 400.0,
y: 300.0,
}
}
fn update(app: &mut App, state: &mut State) {
if app.mouse.is_scrolling() {
let delta_x = app.mouse.wheel_delta.x;
let delta_y = app.mouse.wheel_delta.y;
state.x = (state.x + delta_x).max(0.0).min(800.0);
state.y = (state.y + delta_y).max(0.0).min(600.0);
}
}
fn draw(gfx: &mut Graphics, state: &mut State) {
let mut draw = gfx.create_draw();
draw.clear(Color::BLACK);
draw.text(&state.font, "Scroll with your mouse's wheel or touchpad")
.position(400.0, 300.0)
.size(40.0)
.h_align_center()
.v_align_middle();
draw.circle(30.0)
.position(state.x, state.y)
.color(Color::RED);
gfx.render(&draw);
}