2016-02-23 22:56:23 +11:00
|
|
|
extern crate winit;
|
2019-06-04 15:51:01 +10:00
|
|
|
#[cfg(feature = "stdweb")]
|
2019-03-10 13:54:29 +11:00
|
|
|
#[macro_use]
|
|
|
|
extern crate stdweb;
|
2019-06-04 15:51:01 +10:00
|
|
|
#[cfg(feature = "wasm-bindgen")]
|
2019-06-05 16:08:09 +10:00
|
|
|
extern crate wasm_bindgen;
|
2019-06-06 15:58:11 +10:00
|
|
|
#[cfg(feature = "wasm-bindgen")]
|
|
|
|
extern crate web_sys;
|
2019-03-10 13:54:29 +11:00
|
|
|
|
2019-02-06 02:30:33 +11:00
|
|
|
use winit::window::WindowBuilder;
|
|
|
|
use winit::event::{Event, WindowEvent};
|
|
|
|
use winit::event_loop::{EventLoop, ControlFlow};
|
2019-06-06 15:58:11 +10:00
|
|
|
use wasm_bindgen::{prelude::*, JsValue};
|
|
|
|
use web_sys::console;
|
2014-07-27 18:55:37 +10:00
|
|
|
|
2019-06-06 15:58:11 +10:00
|
|
|
#[wasm_bindgen(start)]
|
|
|
|
pub fn main() {
|
|
|
|
console::log_1(&JsValue::from_str("main"));
|
2019-02-06 02:30:33 +11:00
|
|
|
let event_loop = EventLoop::new();
|
2017-01-29 01:01:59 +11:00
|
|
|
|
2019-02-06 02:30:33 +11:00
|
|
|
let _window = WindowBuilder::new()
|
2016-11-11 22:08:46 +11:00
|
|
|
.with_title("A fantastic window!")
|
2019-02-06 02:30:33 +11:00
|
|
|
.build(&event_loop)
|
2016-11-11 22:08:46 +11:00
|
|
|
.unwrap();
|
2019-06-06 15:58:11 +10:00
|
|
|
console::log_1(&JsValue::from_str("Created window"));
|
2014-07-27 18:55:37 +10:00
|
|
|
|
2019-02-06 02:30:33 +11:00
|
|
|
event_loop.run(|event, _, control_flow| {
|
2019-06-06 15:58:11 +10:00
|
|
|
console::log_1(&JsValue::from_str(&format!("{:?}", event)));
|
2015-06-16 21:48:08 +10:00
|
|
|
|
|
|
|
match event {
|
2019-02-06 02:30:33 +11:00
|
|
|
Event::WindowEvent {
|
|
|
|
event: WindowEvent::CloseRequested,
|
2018-04-25 06:20:40 +10:00
|
|
|
..
|
2019-02-06 02:30:33 +11:00
|
|
|
} => *control_flow = ControlFlow::Exit,
|
2019-06-24 07:38:16 +10:00
|
|
|
_ => ()
|
2015-06-16 21:48:08 +10:00
|
|
|
}
|
2017-01-29 01:01:59 +11:00
|
|
|
});
|
2019-06-06 15:58:11 +10:00
|
|
|
}
|