mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-23 22:01:31 +11:00
18a61f1058
* examples: Fix unused `Result` that must be used when initializing console_log * examples: Fix unused imports * Fix unread name field warning in linux x11 ime InputMethod struct * Fix unread name field warning in linux x11 Device struct * Ignore unread field warning in macos/ios MonitorHandle struct * ci: Add `--deny warnings` to `RUSTFLAGS`
59 lines
1.4 KiB
Rust
59 lines
1.4 KiB
Rust
use winit::{
|
|
event::{Event, WindowEvent},
|
|
event_loop::{ControlFlow, EventLoop},
|
|
window::WindowBuilder,
|
|
};
|
|
|
|
pub fn main() {
|
|
let event_loop = EventLoop::new();
|
|
|
|
let window = WindowBuilder::new()
|
|
.with_title("A fantastic window!")
|
|
.build(&event_loop)
|
|
.unwrap();
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
{
|
|
use winit::platform::web::WindowExtWebSys;
|
|
|
|
let canvas = window.canvas();
|
|
|
|
let window = web_sys::window().unwrap();
|
|
let document = window.document().unwrap();
|
|
let body = document.body().unwrap();
|
|
|
|
body.append_child(&canvas)
|
|
.expect("Append canvas to HTML body");
|
|
}
|
|
|
|
event_loop.run(move |event, _, control_flow| {
|
|
*control_flow = ControlFlow::Wait;
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
log::debug!("{:?}", event);
|
|
|
|
match event {
|
|
Event::WindowEvent {
|
|
event: WindowEvent::CloseRequested,
|
|
window_id,
|
|
} if window_id == window.id() => *control_flow = ControlFlow::Exit,
|
|
Event::MainEventsCleared => {
|
|
window.request_redraw();
|
|
}
|
|
_ => (),
|
|
}
|
|
});
|
|
}
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
mod wasm {
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
#[wasm_bindgen(start)]
|
|
pub fn run() {
|
|
console_log::init_with_level(log::Level::Debug).expect("error initializing logger");
|
|
|
|
super::main();
|
|
}
|
|
}
|