2019-08-14 11:20:05 +03:00
|
|
|
#![cfg(target_arch = "wasm32")]
|
|
|
|
|
|
2019-09-24 19:33:32 -04:00
|
|
|
//! The web target does not automatically insert the canvas element object into the web page, to
|
|
|
|
|
//! allow end users to determine how the page should be laid out. Use the `WindowExtStdweb` or
|
|
|
|
|
//! `WindowExtWebSys` traits (depending on your web backend) to retrieve the canvas from the
|
2020-01-15 21:20:14 -05:00
|
|
|
//! Window. Alternatively, use the `WindowBuilderExtStdweb` or `WindowBuilderExtWebSys` to provide
|
|
|
|
|
//! your own canvas.
|
|
|
|
|
|
|
|
|
|
use crate::window::WindowBuilder;
|
2019-09-24 19:33:32 -04:00
|
|
|
|
2019-07-01 20:43:54 +02:00
|
|
|
#[cfg(feature = "stdweb")]
|
2019-06-25 03:15:34 +02:00
|
|
|
use stdweb::web::html_element::CanvasElement;
|
|
|
|
|
|
2019-07-01 20:43:54 +02:00
|
|
|
#[cfg(feature = "stdweb")]
|
2019-06-25 03:15:34 +02:00
|
|
|
pub trait WindowExtStdweb {
|
|
|
|
|
fn canvas(&self) -> CanvasElement;
|
2020-02-17 20:25:27 +01:00
|
|
|
|
|
|
|
|
/// Whether the browser reports the preferred color scheme to be "dark".
|
|
|
|
|
fn is_dark_mode(&self) -> bool;
|
2019-06-25 03:15:34 +02:00
|
|
|
}
|
|
|
|
|
|
2019-07-01 20:43:54 +02:00
|
|
|
#[cfg(feature = "web-sys")]
|
2019-06-25 03:15:34 +02:00
|
|
|
use web_sys::HtmlCanvasElement;
|
|
|
|
|
|
2019-07-01 20:43:54 +02:00
|
|
|
#[cfg(feature = "web-sys")]
|
2019-06-25 03:15:34 +02:00
|
|
|
pub trait WindowExtWebSys {
|
|
|
|
|
fn canvas(&self) -> HtmlCanvasElement;
|
2020-02-17 20:25:27 +01:00
|
|
|
|
|
|
|
|
/// Whether the browser reports the preferred color scheme to be "dark".
|
|
|
|
|
fn is_dark_mode(&self) -> bool;
|
2019-06-25 03:15:34 +02:00
|
|
|
}
|
2020-01-15 21:20:14 -05:00
|
|
|
|
|
|
|
|
#[cfg(feature = "stdweb")]
|
|
|
|
|
pub trait WindowBuilderExtStdweb {
|
|
|
|
|
fn with_canvas(self, canvas: Option<CanvasElement>) -> Self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "stdweb")]
|
|
|
|
|
impl WindowBuilderExtStdweb for WindowBuilder {
|
|
|
|
|
fn with_canvas(mut self, canvas: Option<CanvasElement>) -> Self {
|
|
|
|
|
self.platform_specific.canvas = canvas;
|
|
|
|
|
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "web-sys")]
|
|
|
|
|
pub trait WindowBuilderExtWebSys {
|
|
|
|
|
fn with_canvas(self, canvas: Option<HtmlCanvasElement>) -> Self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "web-sys")]
|
|
|
|
|
impl WindowBuilderExtWebSys for WindowBuilder {
|
|
|
|
|
fn with_canvas(mut self, canvas: Option<HtmlCanvasElement>) -> Self {
|
|
|
|
|
self.platform_specific.canvas = canvas;
|
|
|
|
|
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
}
|