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 super::*;
pub enum CursorType {
Default,
Pointer,
Drag,
}
impl Window {
pub fn set_cursor_type(&self, cursor_type: CursorType) {
#[cfg(target_arch = "wasm32")]
{
let cursor_type = match cursor_type {
CursorType::Default => "initial",
CursorType::Pointer => "pointer",
CursorType::Drag => "all-scroll",
};
web_sys::window()
.unwrap()
.document()
.unwrap()
.body()
.unwrap()
.style()
.set_property("cursor", cursor_type);
}
#[cfg(not(target_arch = "wasm32"))]
{
use glutin::window::CursorIcon as GC;
self.glutin_window
.window()
.set_cursor_icon(match cursor_type {
CursorType::Default => GC::Default,
CursorType::Pointer => GC::Hand,
CursorType::Drag => GC::AllScroll,
});
};
}
pub fn set_cursor_position(&self, position: Vec2<f64>) {
#![allow(unused_variables)]
#[cfg(target_arch = "wasm32")]
unimplemented!();
#[cfg(not(target_arch = "wasm32"))]
self.glutin_window
.window()
.set_cursor_position(glutin::dpi::PhysicalPosition::new(position.x, position.y))
.expect("Failed to set cursor position");
}
pub fn cursor_position(&self) -> Vec2<f64> {
self.mouse_pos.get()
}
}