diff --git a/examples/multithreaded.rs b/examples/multithreaded.rs index 39f7af3d..e6f3cac4 100644 --- a/examples/multithreaded.rs +++ b/examples/multithreaded.rs @@ -1,16 +1,18 @@ -extern crate env_logger; -use std::{collections::HashMap, sync::mpsc, thread, time::Duration}; - -use winit::{ - event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent}, - event_loop::{ControlFlow, EventLoop}, - window::{CursorIcon, WindowBuilder}, -}; - -const WINDOW_COUNT: usize = 3; -const WINDOW_SIZE: (u32, u32) = (600, 400); - +#[cfg(not(target_arch = "wasm32"))] fn main() { + extern crate env_logger; + + use std::{collections::HashMap, sync::mpsc, thread, time::Duration}; + + use winit::{ + event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent}, + event_loop::{ControlFlow, EventLoop}, + window::{CursorIcon, WindowBuilder}, + }; + + const WINDOW_COUNT: usize = 3; + const WINDOW_SIZE: (u32, u32) = (600, 400); + env_logger::init(); let event_loop = EventLoop::new(); let mut window_senders = HashMap::with_capacity(WINDOW_COUNT); @@ -36,7 +38,7 @@ fn main() { } => { window.set_title(&format!("{:?}", key)); let state = !modifiers.shift; - use self::VirtualKeyCode::*; + use VirtualKeyCode::*; match key { A => window.set_always_on_top(state), C => window.set_cursor_icon(match state { @@ -125,3 +127,8 @@ fn main() { } }) } + +#[cfg(target_arch = "wasm32")] +fn main() { + panic!("Example not supported on Wasm"); +} diff --git a/examples/proxy.rs b/examples/proxy.rs index 06198ecd..6c5bbbc6 100644 --- a/examples/proxy.rs +++ b/examples/proxy.rs @@ -1,10 +1,11 @@ -use winit::{ - event::{Event, WindowEvent}, - event_loop::{ControlFlow, EventLoop}, - window::WindowBuilder, -}; - +#[cfg(not(target_arch = "wasm32"))] fn main() { + use winit::{ + event::{Event, WindowEvent}, + event_loop::{ControlFlow, EventLoop}, + window::WindowBuilder, + }; + let event_loop: EventLoop = EventLoop::new_user_event(); let _window = WindowBuilder::new() @@ -35,3 +36,8 @@ fn main() { } }); } + +#[cfg(target_arch = "wasm32")] +fn main() { + panic!("Example not supported on Wasm"); +} diff --git a/examples/request_redraw.rs b/examples/request_redraw.rs index ac9377e7..b55bd970 100644 --- a/examples/request_redraw.rs +++ b/examples/request_redraw.rs @@ -1,4 +1,5 @@ -use std::time::{Duration, Instant}; +use instant::Instant; +use std::time::Duration; use winit::{ event::{Event, WindowEvent}, diff --git a/examples/timer.rs b/examples/timer.rs index 8d3b9bde..e1e3f290 100644 --- a/examples/timer.rs +++ b/examples/timer.rs @@ -1,4 +1,5 @@ -use std::time::{Duration, Instant}; +use instant::Instant; +use std::time::Duration; use winit::{ event::{Event, StartCause, WindowEvent}, event_loop::{ControlFlow, EventLoop}, diff --git a/examples/window_run_return.rs b/examples/window_run_return.rs index d2516c7a..3598e10c 100644 --- a/examples/window_run_return.rs +++ b/examples/window_run_return.rs @@ -1,11 +1,11 @@ -use winit::{ - event::{Event, WindowEvent}, - event_loop::{ControlFlow, EventLoop}, - platform::desktop::EventLoopExtDesktop, - window::WindowBuilder, -}; - +#[cfg(not(target_arch = "wasm32"))] fn main() { + use winit::{ + event::{Event, WindowEvent}, + event_loop::{ControlFlow, EventLoop}, + platform::desktop::EventLoopExtDesktop, + window::WindowBuilder, + }; let mut event_loop = EventLoop::new(); let window = WindowBuilder::new() @@ -39,3 +39,8 @@ fn main() { println!("Okay we're done now for real."); } + +#[cfg(target_arch = "wasm32")] +fn main() { + panic!("Example not supported on Wasm"); +} diff --git a/src/event_loop.rs b/src/event_loop.rs index 68c6f93d..5230c6cf 100644 --- a/src/event_loop.rs +++ b/src/event_loop.rs @@ -13,9 +13,9 @@ use instant::Instant; use std::ops::Deref; use std::{error, fmt}; -use event::Event; -use monitor::{AvailableMonitorsIter, MonitorHandle}; -use platform_impl; +use crate::event::Event; +use crate::monitor::{AvailableMonitorsIter, MonitorHandle}; +use crate::platform_impl; /// Provides a way to retrieve events from the system and from the windows that were registered to /// the events loop. diff --git a/src/platform_impl/web/error.rs b/src/platform_impl/web/error.rs index 8f85d6cb..6995f2bc 100644 --- a/src/platform_impl/web/error.rs +++ b/src/platform_impl/web/error.rs @@ -4,7 +4,7 @@ use std::fmt; pub struct OsError(pub String); impl fmt::Display for OsError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.0) } } diff --git a/src/platform_impl/web/monitor.rs b/src/platform_impl/web/monitor.rs index 8ac60fb2..1aeaa320 100644 --- a/src/platform_impl/web/monitor.rs +++ b/src/platform_impl/web/monitor.rs @@ -1,4 +1,5 @@ use crate::dpi::{PhysicalPosition, PhysicalSize}; +use crate::monitor::VideoMode; #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Handle; @@ -12,11 +13,16 @@ impl Handle { unimplemented!(); } - pub fn dimensions(&self) -> PhysicalSize { - unimplemented!(); - } - pub fn name(&self) -> Option { unimplemented!(); } + + pub fn size(&self) -> PhysicalSize { + unimplemented!(); + } + + pub fn video_modes(&self) -> impl Iterator { + // TODO: is this possible ? + std::iter::empty() + } } diff --git a/tests/send_objects.rs b/tests/send_objects.rs index 9462d073..252b271a 100644 --- a/tests/send_objects.rs +++ b/tests/send_objects.rs @@ -1,6 +1,7 @@ #[allow(dead_code)] fn needs_send() {} +#[cfg(not(target_arch = "wasm32"))] #[test] fn event_loop_proxy_send() { #[allow(dead_code)] @@ -10,6 +11,7 @@ fn event_loop_proxy_send() { } } +#[cfg(not(target_arch = "wasm32"))] #[test] fn window_send() { // ensures that `winit::Window` implements `Send` diff --git a/tests/sync_object.rs b/tests/sync_object.rs index dad65202..56524cb2 100644 --- a/tests/sync_object.rs +++ b/tests/sync_object.rs @@ -1,6 +1,7 @@ #[allow(dead_code)] fn needs_sync() {} +#[cfg(not(target_arch = "wasm32"))] #[test] fn window_sync() { // ensures that `winit::Window` implements `Sync`