Fix web errors (#1040)

* Fix old `use` declarations

* Fix hidden lifetime parameter

* Fix missing methods in `web::Monitor`.

Originally fixed by @ryanisaacg in 94387c4bf5bca35f4e24562ce89a4f4badd53aa8.

* Disable some tests and examples on `wasm32`
This commit is contained in:
Héctor Ramón 2019-07-11 00:54:54 +02:00 committed by Osspial
parent 53e646dabc
commit 7b23d190b1
10 changed files with 65 additions and 36 deletions

View file

@ -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");
}

View file

@ -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<i32> = 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");
}

View file

@ -1,4 +1,5 @@
use std::time::{Duration, Instant};
use instant::Instant;
use std::time::Duration;
use winit::{
event::{Event, WindowEvent},

View file

@ -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},

View file

@ -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");
}

View file

@ -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.

View file

@ -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)
}
}

View file

@ -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<String> {
unimplemented!();
}
pub fn size(&self) -> PhysicalSize {
unimplemented!();
}
pub fn video_modes(&self) -> impl Iterator<Item = VideoMode> {
// TODO: is this possible ?
std::iter::empty()
}
}

View file

@ -1,6 +1,7 @@
#[allow(dead_code)]
fn needs_send<T: 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`

View file

@ -1,6 +1,7 @@
#[allow(dead_code)]
fn needs_sync<T: Sync>() {}
#[cfg(not(target_arch = "wasm32"))]
#[test]
fn window_sync() {
// ensures that `winit::Window` implements `Sync`