From 37dadab745062135284c621d45fb58c63b9ad445 Mon Sep 17 00:00:00 2001 From: Ryan Goldstein Date: Fri, 31 May 2019 21:48:26 -0700 Subject: [PATCH] Add access to the canvas in the Window --- src/platform/mod.rs | 2 ++ src/platform/stdweb.rs | 8 ++++++++ src/platform_impl/stdweb/window.rs | 9 ++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/platform/stdweb.rs diff --git a/src/platform/mod.rs b/src/platform/mod.rs index ba494ac6..da780f4b 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -20,4 +20,6 @@ pub mod macos; pub mod unix; pub mod windows; +pub mod stdweb; + pub mod desktop; diff --git a/src/platform/stdweb.rs b/src/platform/stdweb.rs new file mode 100644 index 00000000..4ffa7dd2 --- /dev/null +++ b/src/platform/stdweb.rs @@ -0,0 +1,8 @@ +#![cfg(feature = "stdweb")] + +use stdweb::web::html_element::CanvasElement; + +pub trait WindowExtStdweb { + fn canvas(&self) -> CanvasElement; +} + diff --git a/src/platform_impl/stdweb/window.rs b/src/platform_impl/stdweb/window.rs index 3008dd58..1ab8a0d2 100644 --- a/src/platform_impl/stdweb/window.rs +++ b/src/platform_impl/stdweb/window.rs @@ -1,8 +1,9 @@ use dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize}; use event::{Event, WindowEvent}; use icon::Icon; +use platform::stdweb::WindowExtStdweb; use monitor::{MonitorHandle as RootMH}; -use window::{CreationError, MouseCursor, WindowAttributes, WindowId as RootWI}; +use window::{CreationError, MouseCursor, Window as RootWindow, WindowAttributes, WindowId as RootWI}; use super::{EventLoopWindowTarget, register}; use std::collections::VecDeque; use std::collections::vec_deque::IntoIter as VecDequeIter; @@ -317,3 +318,9 @@ impl Window { unsafe { WindowId::dummy() } } } + +impl WindowExtStdweb for RootWindow { + fn canvas(&self) -> CanvasElement { + self.window.canvas.clone() + } +}