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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#![recursion_limit = "512"]
#[cfg(target_arch = "wasm32")]
#[macro_use]
extern crate stdweb;
#[cfg(target_arch = "wasm32")]
#[path = "web_app.rs"]
pub mod sys;
#[cfg(target_arch = "wasm32")]
#[path = "web_fs.rs"]
pub mod fs;
#[cfg(not(target_arch = "wasm32"))]
extern crate glutin;
#[cfg(not(target_arch = "wasm32"))]
extern crate time;
#[cfg(not(target_arch = "wasm32"))]
#[path = "native_app.rs"]
pub mod sys;
#[cfg(not(target_arch = "wasm32"))]
#[path = "native_fs.rs"]
pub mod fs;
pub use self::fs::*;
pub use self::sys::*;
pub struct AppConfig {
pub title: String,
pub size: (u32, u32),
pub vsync: bool,
pub headless: bool,
pub fullscreen: bool,
pub resizable: bool,
pub show_cursor: bool,
}
impl AppConfig {
pub fn new<T: Into<String>>(title: T, size: (u32, u32)) -> AppConfig {
AppConfig {
title: title.into(),
size,
vsync: true,
headless: false,
fullscreen: false,
resizable: true,
show_cursor: true,
}
}
}
pub mod events {
use std::fmt;
#[derive(Debug, Clone)]
pub struct MouseButtonEvent {
pub button: usize,
}
#[derive(Clone)]
pub struct KeyDownEvent {
pub code: String,
pub key: String,
pub shift: bool,
pub alt: bool,
pub ctrl: bool,
}
#[derive(Clone)]
pub struct KeyUpEvent {
pub code: String,
pub key: String,
pub shift: bool,
pub alt: bool,
pub ctrl: bool,
}
impl fmt::Debug for KeyUpEvent {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{} {} {} {} {}",
if self.shift { "shift" } else { "" },
if self.alt { "alt" } else { "" },
if self.ctrl { "ctrl" } else { "" },
self.code,
self.key,
)
}
}
impl fmt::Debug for KeyDownEvent {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{} {} {} {} {}",
if self.shift { "shift" } else { "" },
if self.alt { "alt" } else { "" },
if self.ctrl { "ctrl" } else { "" },
self.code,
self.key,
)
}
}
}
pub use events::*;
#[derive(Debug, Clone)]
pub enum AppEvent {
MouseDown(MouseButtonEvent),
MouseUp(MouseButtonEvent),
KeyDown(KeyDownEvent),
KeyUp(KeyUpEvent),
Resized((u32, u32)),
MousePos((f64, f64)),
}