From fd4db4000c7b68d736906870d7fb157835b1d67f Mon Sep 17 00:00:00 2001 From: Ryan Goldstein Date: Tue, 12 Feb 2019 20:47:31 -0500 Subject: [PATCH] Create the type layout Everything typechecks, but nothing is implemented --- Cargo.toml | 4 + src/platform_impl/mod.rs | 6 +- src/platform_impl/stdweb/mod.rs | 245 ++++++++++++++++++++++++++++++++ 3 files changed, 254 insertions(+), 1 deletion(-) create mode 100644 src/platform_impl/stdweb/mod.rs diff --git a/Cargo.toml b/Cargo.toml index 7017dc95..baa0d4ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -72,3 +72,7 @@ percent-encoding = "1.0" [target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd", target_os = "windows"))'.dependencies.parking_lot] version = "0.7" + +[target.'cfg(target_arch = "wasm32")'.dependencies.stdweb] +version = "0.4.13" +optional = true diff --git a/src/platform_impl/mod.rs b/src/platform_impl/mod.rs index be968785..2a8ccd62 100644 --- a/src/platform_impl/mod.rs +++ b/src/platform_impl/mod.rs @@ -18,9 +18,13 @@ mod platform; #[cfg(target_os = "emscripten")] #[path="emscripten/mod.rs"] mod platform; +#[cfg(feature = "stdweb")] +#[path="stdweb/mod.rs"] +mod platform; #[cfg(all(not(target_os = "ios"), not(target_os = "windows"), not(target_os = "linux"), not(target_os = "macos"), not(target_os = "android"), not(target_os = "dragonfly"), not(target_os = "freebsd"), not(target_os = "netbsd"), not(target_os = "openbsd"), - not(target_os = "emscripten")))] + not(target_os = "emscripten"), + not(feature = "stdweb")))] compile_error!("The platform you're compiling for is not supported by winit"); diff --git a/src/platform_impl/stdweb/mod.rs b/src/platform_impl/stdweb/mod.rs new file mode 100644 index 00000000..7d9d3cfe --- /dev/null +++ b/src/platform_impl/stdweb/mod.rs @@ -0,0 +1,245 @@ +use dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize}; +use event::Event; +use event_loop::{ControlFlow, EventLoopWindowTarget as RootELW, EventLoopClosed}; +use icon::Icon; +use monitor::{MonitorHandle as RootMH}; +use window::{CreationError, MouseCursor, WindowAttributes}; + +use std::collections::vec_deque::IntoIter as VecDequeIter; +use std::marker::PhantomData; + +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct DeviceId; + +impl DeviceId { + pub unsafe fn dummy() -> Self { + DeviceId + } +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct MonitorHandle; + +impl MonitorHandle { + pub fn get_hidpi_factor(&self) -> f64 { + unimplemented!(); + } + + pub fn get_position(&self) -> PhysicalPosition { + unimplemented!(); + } + + pub fn get_dimensions(&self) -> PhysicalSize { + unimplemented!(); + } + + pub fn get_name(&self) -> Option { + unimplemented!(); + } +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct WindowId; + +impl WindowId { + pub unsafe fn dummy() -> WindowId { + WindowId + } +} + +pub struct Window; + +impl Window { + // TODO: type of window_target + pub fn new(target: &EventLoopWindowTarget, window: WindowAttributes, platform: PlatformSpecificWindowBuilderAttributes) -> Result { + unimplemented!(); + } + + pub fn set_title(&self, title: &str) { + unimplemented!(); + } + + pub fn show(&self) { + unimplemented!(); + } + + pub fn hide(&self) { + unimplemented!(); + } + + pub fn request_redraw(&self) { + unimplemented!(); + } + + pub fn get_position(&self) -> Option { + unimplemented!(); + } + + pub fn get_inner_position(&self) -> Option { + unimplemented!(); + } + + pub fn set_position(&self, position: LogicalPosition) { + unimplemented!(); + } + + #[inline] + pub fn get_inner_size(&self) -> Option { + unimplemented!(); + } + + #[inline] + pub fn get_outer_size(&self) -> Option { + unimplemented!(); + } + + #[inline] + pub fn set_inner_size(&self, size: LogicalSize) { + unimplemented!(); + } + + #[inline] + pub fn set_min_dimensions(&self, dimensions: Option) { + unimplemented!(); + } + + #[inline] + pub fn set_max_dimensions(&self, dimensions: Option) { + unimplemented!(); + } + + #[inline] + pub fn set_resizable(&self, resizable: bool) { + unimplemented!(); + } + + #[inline] + pub fn get_hidpi_factor(&self) -> f64 { + unimplemented!(); + } + + #[inline] + pub fn set_cursor(&self, cursor: MouseCursor) { + unimplemented!(); + } + + #[inline] + pub fn set_cursor_position(&self, position: LogicalPosition) -> Result<(), String> { + unimplemented!(); + } + + #[inline] + pub fn grab_cursor(&self, grab: bool) -> Result<(), String> { + unimplemented!(); + } + + #[inline] + pub fn hide_cursor(&self, hide: bool) { + unimplemented!(); + } + + #[inline] + pub fn set_maximized(&self, maximized: bool) { + unimplemented!(); + } + + #[inline] + pub fn set_fullscreen(&self, monitor: Option) { + unimplemented!(); + } + + #[inline] + pub fn set_decorations(&self, decorations: bool) { + unimplemented!(); + } + + #[inline] + pub fn set_always_on_top(&self, always_on_top: bool) { + unimplemented!(); + } + + #[inline] + pub fn set_window_icon(&self, window_icon: Option) { + unimplemented!(); + } + + #[inline] + pub fn set_ime_spot(&self, position: LogicalPosition) { + unimplemented!(); + } + + #[inline] + pub fn get_current_monitor(&self) -> RootMH { + unimplemented!(); + } + + #[inline] + pub fn get_available_monitors(&self) -> VecDequeIter { + unimplemented!(); + } + + #[inline] + pub fn get_primary_monitor(&self) -> MonitorHandle { + unimplemented!(); + } + + #[inline] + pub fn id(&self) -> WindowId { + unimplemented!(); + } +} + +pub struct EventLoop { + _phantom: PhantomData +} + +impl EventLoop { + pub fn new() -> Self { + unimplemented!(); + } + + pub fn get_available_monitors(&self) -> VecDequeIter { + unimplemented!(); + } + + pub fn get_primary_monitor(&self) -> MonitorHandle { + unimplemented!(); + } + + pub fn run(mut self, event_handler: F) -> ! + where F: 'static + FnMut(Event, &RootELW, &mut ControlFlow) + { + unimplemented!(); + } + + pub fn create_proxy(&self) -> EventLoopProxy { + unimplemented!(); + } + + pub fn window_target(&self) -> &RootELW { + unimplemented!(); + /*&EventLoopWindowTarget { + p: self.event_loop.window_target(), + _marker: std::marker::PhantomData + }*/ + } +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct EventLoopProxy { + _phantom: PhantomData +} + +impl EventLoopProxy { + pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed> { + unimplemented!(); + } +} + +pub struct EventLoopWindowTarget { + _phantom: PhantomData +} + +#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct PlatformSpecificWindowBuilderAttributes; +