Platform is called Web not Wasm (#3393)
This commit is contained in:
parent
2ee44246ae
commit
16d860736b
19 changed files with 57 additions and 57 deletions
|
|
@ -37,7 +37,7 @@ targets = [
|
|||
"x86_64-apple-ios",
|
||||
# Android
|
||||
"aarch64-linux-android",
|
||||
# WebAssembly
|
||||
# Web
|
||||
"wasm32-unknown-unknown",
|
||||
]
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ same MSRV policy.
|
|||
|
||||
Note that windows don't appear on Wayland until you draw/present to them.
|
||||
|
||||
#### WebAssembly
|
||||
#### Web
|
||||
|
||||
To run the web example: `cargo run-wasm --example web`
|
||||
|
||||
|
|
@ -87,7 +87,7 @@ either [provide Winit with a `<canvas>` element][web with_canvas], or [let Winit
|
|||
create a `<canvas>` element which you can then retrieve][web canvas getter] and
|
||||
insert it into the DOM yourself.
|
||||
|
||||
For the example code using Winit with WebAssembly, check out the [web example]. For
|
||||
For the example code using Winit on Web, check out the [web example]. For
|
||||
information on using Rust on WebAssembly, check out the [Rust and WebAssembly
|
||||
book].
|
||||
|
||||
|
|
|
|||
6
build.rs
6
build.rs
|
|
@ -8,7 +8,7 @@ fn main() {
|
|||
cfg_aliases! {
|
||||
// Systems.
|
||||
android_platform: { target_os = "android" },
|
||||
wasm_platform: { all(target_family = "wasm", not(target_os = "emscripten")) },
|
||||
web_platform: { all(target_family = "wasm", target_os = "unknown") },
|
||||
macos_platform: { target_os = "macos" },
|
||||
ios_platform: { target_os = "ios" },
|
||||
windows_platform: { target_os = "windows" },
|
||||
|
|
@ -17,8 +17,8 @@ fn main() {
|
|||
redox: { target_os = "redox" },
|
||||
|
||||
// Native displays.
|
||||
x11_platform: { all(feature = "x11", free_unix, not(wasm), not(redox)) },
|
||||
wayland_platform: { all(feature = "wayland", free_unix, not(wasm), not(redox)) },
|
||||
x11_platform: { all(feature = "x11", free_unix, not(redox)) },
|
||||
wayland_platform: { all(feature = "wayland", free_unix, not(redox)) },
|
||||
orbital_platform: { redox },
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
#![allow(clippy::single_match)]
|
||||
|
||||
use std::thread;
|
||||
#[cfg(not(wasm_platform))]
|
||||
#[cfg(not(web_platform))]
|
||||
use std::time;
|
||||
#[cfg(wasm_platform)]
|
||||
#[cfg(web_platform)]
|
||||
use web_time as time;
|
||||
|
||||
use simple_logger::SimpleLogger;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#![allow(clippy::single_match, clippy::disallowed_methods)]
|
||||
|
||||
#[cfg(not(wasm_platform))]
|
||||
#[cfg(not(web_platform))]
|
||||
use simple_logger::SimpleLogger;
|
||||
use winit::{
|
||||
event::{ElementState, Event, KeyEvent, WindowEvent},
|
||||
|
|
@ -8,14 +8,14 @@ use winit::{
|
|||
keyboard::Key,
|
||||
window::{CursorIcon, CustomCursor, WindowBuilder},
|
||||
};
|
||||
#[cfg(wasm_platform)]
|
||||
#[cfg(web_platform)]
|
||||
use {
|
||||
std::sync::atomic::{AtomicU64, Ordering},
|
||||
std::time::Duration,
|
||||
winit::platform::web::CustomCursorExtWebSys,
|
||||
};
|
||||
|
||||
#[cfg(wasm_platform)]
|
||||
#[cfg(web_platform)]
|
||||
static COUNTER: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
fn decode_cursor(bytes: &[u8], window_target: &EventLoopWindowTarget) -> CustomCursor {
|
||||
|
|
@ -28,22 +28,22 @@ fn decode_cursor(bytes: &[u8], window_target: &EventLoopWindowTarget) -> CustomC
|
|||
builder.build(window_target)
|
||||
}
|
||||
|
||||
#[cfg(not(wasm_platform))]
|
||||
#[cfg(not(web_platform))]
|
||||
#[path = "util/fill.rs"]
|
||||
mod fill;
|
||||
|
||||
fn main() -> Result<(), impl std::error::Error> {
|
||||
#[cfg(not(wasm_platform))]
|
||||
#[cfg(not(web_platform))]
|
||||
SimpleLogger::new()
|
||||
.with_level(log::LevelFilter::Info)
|
||||
.init()
|
||||
.unwrap();
|
||||
#[cfg(wasm_platform)]
|
||||
#[cfg(web_platform)]
|
||||
console_log::init_with_level(log::Level::Debug).unwrap();
|
||||
|
||||
let event_loop = EventLoop::new().unwrap();
|
||||
let builder = WindowBuilder::new().with_title("A fantastic window!");
|
||||
#[cfg(wasm_platform)]
|
||||
#[cfg(web_platform)]
|
||||
let builder = {
|
||||
use winit::platform::web::WindowBuilderExtWebSys;
|
||||
builder.with_append(true)
|
||||
|
|
@ -83,7 +83,7 @@ fn main() -> Result<(), impl std::error::Error> {
|
|||
log::debug!("Setting cursor visibility to {:?}", cursor_visible);
|
||||
window.set_cursor_visible(cursor_visible);
|
||||
}
|
||||
#[cfg(wasm_platform)]
|
||||
#[cfg(web_platform)]
|
||||
Key::Character("4") => {
|
||||
log::debug!("Setting cursor to a random image from an URL");
|
||||
window.set_cursor(
|
||||
|
|
@ -98,7 +98,7 @@ fn main() -> Result<(), impl std::error::Error> {
|
|||
.build(_elwt),
|
||||
);
|
||||
}
|
||||
#[cfg(wasm_platform)]
|
||||
#[cfg(web_platform)]
|
||||
Key::Character("5") => {
|
||||
log::debug!("Setting cursor to an animation");
|
||||
window.set_cursor(
|
||||
|
|
@ -125,11 +125,11 @@ fn main() -> Result<(), impl std::error::Error> {
|
|||
_ => {}
|
||||
},
|
||||
WindowEvent::RedrawRequested => {
|
||||
#[cfg(not(wasm_platform))]
|
||||
#[cfg(not(web_platform))]
|
||||
fill::fill_window(&window);
|
||||
}
|
||||
WindowEvent::CloseRequested => {
|
||||
#[cfg(not(wasm_platform))]
|
||||
#[cfg(not(web_platform))]
|
||||
_elwt.exit();
|
||||
}
|
||||
_ => (),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#![allow(clippy::single_match)]
|
||||
|
||||
#[cfg(not(wasm_platform))]
|
||||
#[cfg(not(web_platform))]
|
||||
fn main() -> Result<(), impl std::error::Error> {
|
||||
use simple_logger::SimpleLogger;
|
||||
use winit::{
|
||||
|
|
@ -56,7 +56,7 @@ fn main() -> Result<(), impl std::error::Error> {
|
|||
})
|
||||
}
|
||||
|
||||
#[cfg(wasm_platform)]
|
||||
#[cfg(web_platform)]
|
||||
fn main() {
|
||||
panic!("This example is not supported on web.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@
|
|||
//! Example for focusing a window.
|
||||
|
||||
use simple_logger::SimpleLogger;
|
||||
#[cfg(not(wasm_platform))]
|
||||
#[cfg(not(web_platform))]
|
||||
use std::time;
|
||||
#[cfg(wasm_platform)]
|
||||
#[cfg(web_platform)]
|
||||
use web_time as time;
|
||||
use winit::{
|
||||
event::{Event, StartCause, WindowEvent},
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#![allow(clippy::single_match)]
|
||||
|
||||
#[cfg(not(wasm_platform))]
|
||||
#[cfg(not(web_platform))]
|
||||
fn main() -> Result<(), impl std::error::Error> {
|
||||
use std::{collections::HashMap, sync::mpsc, thread, time::Duration};
|
||||
|
||||
|
|
@ -205,7 +205,7 @@ fn main() -> Result<(), impl std::error::Error> {
|
|||
})
|
||||
}
|
||||
|
||||
#[cfg(wasm_platform)]
|
||||
#[cfg(web_platform)]
|
||||
fn main() {
|
||||
panic!("Example not supported on Wasm");
|
||||
panic!("Example not supported on Web");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#![allow(clippy::single_match)]
|
||||
|
||||
#[cfg(not(wasm_platform))]
|
||||
#[cfg(not(web_platform))]
|
||||
fn main() -> Result<(), impl std::error::Error> {
|
||||
use std::{sync::Arc, thread, time};
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ fn main() -> Result<(), impl std::error::Error> {
|
|||
})
|
||||
}
|
||||
|
||||
#[cfg(wasm_platform)]
|
||||
#[cfg(web_platform)]
|
||||
fn main() {
|
||||
unimplemented!() // `Window` can't be sent between threads
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
#![allow(clippy::single_match)]
|
||||
|
||||
use std::time::Duration;
|
||||
#[cfg(not(wasm_platform))]
|
||||
#[cfg(not(web_platform))]
|
||||
use std::time::Instant;
|
||||
#[cfg(wasm_platform)]
|
||||
#[cfg(web_platform)]
|
||||
use web_time::Instant;
|
||||
|
||||
use simple_logger::SimpleLogger;
|
||||
|
|
|
|||
|
|
@ -11,18 +11,18 @@ pub fn main() -> Result<(), impl std::error::Error> {
|
|||
let event_loop = EventLoop::new().unwrap();
|
||||
|
||||
let builder = WindowBuilder::new().with_title("A fantastic window!");
|
||||
#[cfg(wasm_platform)]
|
||||
#[cfg(web_platform)]
|
||||
let builder = {
|
||||
use winit::platform::web::WindowBuilderExtWebSys;
|
||||
builder.with_append(true)
|
||||
};
|
||||
let window = builder.build(&event_loop).unwrap();
|
||||
|
||||
#[cfg(wasm_platform)]
|
||||
#[cfg(web_platform)]
|
||||
let log_list = wasm::insert_canvas_and_create_log_list(&window);
|
||||
|
||||
event_loop.run(move |event, elwt| {
|
||||
#[cfg(wasm_platform)]
|
||||
#[cfg(web_platform)]
|
||||
wasm::log_event(&log_list, &event);
|
||||
|
||||
match event {
|
||||
|
|
@ -57,7 +57,7 @@ pub fn main() -> Result<(), impl std::error::Error> {
|
|||
})
|
||||
}
|
||||
|
||||
#[cfg(wasm_platform)]
|
||||
#[cfg(web_platform)]
|
||||
mod wasm {
|
||||
use std::num::NonZeroU32;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ pub fn main() {
|
|||
println!("This example must be run with cargo run-wasm --example web_aspect_ratio")
|
||||
}
|
||||
|
||||
#[cfg(wasm_platform)]
|
||||
#[cfg(web_platform)]
|
||||
mod wasm {
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::JsCast;
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ fn main() -> std::process::ExitCode {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(any(ios_platform, wasm_platform, orbital_platform))]
|
||||
#[cfg(any(ios_platform, web_platform, orbital_platform))]
|
||||
fn main() {
|
||||
println!("This platform doesn't support pump_events.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,13 +34,13 @@
|
|||
//! [`ControlFlow::WaitUntil`]: crate::event_loop::ControlFlow::WaitUntil
|
||||
use std::path::PathBuf;
|
||||
use std::sync::{Mutex, Weak};
|
||||
#[cfg(not(wasm_platform))]
|
||||
#[cfg(not(web_platform))]
|
||||
use std::time::Instant;
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
use smol_str::SmolStr;
|
||||
#[cfg(wasm_platform)]
|
||||
#[cfg(web_platform)]
|
||||
use web_time::Instant;
|
||||
|
||||
use crate::error::ExternalError;
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, RawFd};
|
|||
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
|
||||
use std::{error, fmt};
|
||||
|
||||
#[cfg(not(wasm_platform))]
|
||||
#[cfg(not(web_platform))]
|
||||
use std::time::{Duration, Instant};
|
||||
#[cfg(wasm_platform)]
|
||||
#[cfg(web_platform)]
|
||||
use web_time::{Duration, Instant};
|
||||
|
||||
use crate::error::EventLoopError;
|
||||
|
|
@ -130,7 +130,7 @@ impl<T> EventLoopBuilder<T> {
|
|||
})
|
||||
}
|
||||
|
||||
#[cfg(wasm_platform)]
|
||||
#[cfg(web_platform)]
|
||||
pub(crate) fn allow_event_loop_recreation() {
|
||||
EVENT_LOOP_CREATED.store(false, Ordering::Relaxed);
|
||||
}
|
||||
|
|
@ -223,10 +223,10 @@ impl<T> EventLoop<T> {
|
|||
///
|
||||
/// Web applications are recommended to use
|
||||
#[cfg_attr(
|
||||
wasm_platform,
|
||||
web_platform,
|
||||
doc = "[`EventLoopExtWebSys::spawn()`][crate::platform::web::EventLoopExtWebSys::spawn()]"
|
||||
)]
|
||||
#[cfg_attr(not(wasm_platform), doc = "`EventLoopExtWebSys::spawn()`")]
|
||||
#[cfg_attr(not(web_platform), doc = "`EventLoopExtWebSys::spawn()`")]
|
||||
/// [^1] instead of [`run()`] to avoid the need
|
||||
/// for the Javascript exception trick, and to make it clearer that the event loop runs
|
||||
/// asynchronously (via the browser's own, internal, event loop) and doesn't block the
|
||||
|
|
@ -236,9 +236,9 @@ impl<T> EventLoop<T> {
|
|||
///
|
||||
/// [`set_control_flow()`]: EventLoopWindowTarget::set_control_flow()
|
||||
/// [`run()`]: Self::run()
|
||||
/// [^1]: `EventLoopExtWebSys::spawn()` is only available on WASM.
|
||||
/// [^1]: `EventLoopExtWebSys::spawn()` is only available on Web.
|
||||
#[inline]
|
||||
#[cfg(not(all(wasm_platform, target_feature = "exception-handling")))]
|
||||
#[cfg(not(all(web_platform, target_feature = "exception-handling")))]
|
||||
pub fn run<F>(self, event_handler: F) -> Result<(), EventLoopError>
|
||||
where
|
||||
F: FnMut(Event<T>, &EventLoopWindowTarget),
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ pub mod orbital;
|
|||
pub mod startup_notify;
|
||||
#[cfg(any(wayland_platform, docsrs))]
|
||||
pub mod wayland;
|
||||
#[cfg(any(wasm_platform, docsrs))]
|
||||
#[cfg(any(web_platform, docsrs))]
|
||||
pub mod web;
|
||||
#[cfg(any(windows_platform, docsrs))]
|
||||
pub mod windows;
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ pub trait EventLoopExtRunOnDemand {
|
|||
/// - **iOS:** It's not possible to stop and start an `NSApplication` repeatedly on iOS.
|
||||
///
|
||||
#[cfg_attr(
|
||||
not(wasm_platform),
|
||||
not(web_platform),
|
||||
doc = "[^1]: `spawn()` is only available on `wasm` platforms."
|
||||
)]
|
||||
///
|
||||
|
|
|
|||
|
|
@ -34,18 +34,18 @@ use std::pin::Pin;
|
|||
use std::task::{Context, Poll};
|
||||
use std::time::Duration;
|
||||
|
||||
#[cfg(wasm_platform)]
|
||||
#[cfg(web_platform)]
|
||||
use web_sys::HtmlCanvasElement;
|
||||
|
||||
use crate::cursor::CustomCursorBuilder;
|
||||
use crate::event::Event;
|
||||
use crate::event_loop::{EventLoop, EventLoopWindowTarget};
|
||||
#[cfg(wasm_platform)]
|
||||
#[cfg(web_platform)]
|
||||
use crate::platform_impl::CustomCursorFuture as PlatformCustomCursorFuture;
|
||||
use crate::platform_impl::{PlatformCustomCursor, PlatformCustomCursorBuilder};
|
||||
use crate::window::{CustomCursor, Window, WindowBuilder};
|
||||
|
||||
#[cfg(not(wasm_platform))]
|
||||
#[cfg(not(web_platform))]
|
||||
#[doc(hidden)]
|
||||
pub struct HtmlCanvasElement;
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ pub trait WindowBuilderExtWebSys {
|
|||
///
|
||||
/// [`None`] by default.
|
||||
#[cfg_attr(
|
||||
not(wasm_platform),
|
||||
not(web_platform),
|
||||
doc = "",
|
||||
doc = "[`HtmlCanvasElement`]: #only-available-on-wasm"
|
||||
)]
|
||||
|
|
@ -150,11 +150,11 @@ pub trait EventLoopExtWebSys {
|
|||
///
|
||||
/// Unlike
|
||||
#[cfg_attr(
|
||||
all(wasm_platform, target_feature = "exception-handling"),
|
||||
all(web_platform, target_feature = "exception-handling"),
|
||||
doc = "`run()`"
|
||||
)]
|
||||
#[cfg_attr(
|
||||
not(all(wasm_platform, target_feature = "exception-handling")),
|
||||
not(all(web_platform, target_feature = "exception-handling")),
|
||||
doc = "[`run()`]"
|
||||
)]
|
||||
/// [^1], this returns immediately, and doesn't throw an exception in order to
|
||||
|
|
@ -166,7 +166,7 @@ pub trait EventLoopExtWebSys {
|
|||
/// event loop when switching between tabs on a single page application.
|
||||
///
|
||||
#[cfg_attr(
|
||||
not(all(wasm_platform, target_feature = "exception-handling")),
|
||||
not(all(web_platform, target_feature = "exception-handling")),
|
||||
doc = "[`run()`]: EventLoop::run()"
|
||||
)]
|
||||
/// [^1]: `run()` is _not_ available on WASM when the target supports `exception-handling`.
|
||||
|
|
@ -327,7 +327,7 @@ impl CustomCursorBuilderExtWebSys for CustomCursorBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(not(wasm_platform))]
|
||||
#[cfg(not(web_platform))]
|
||||
struct PlatformCustomCursorFuture;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ mod platform;
|
|||
#[cfg(ios_platform)]
|
||||
#[path = "ios/mod.rs"]
|
||||
mod platform;
|
||||
#[cfg(wasm_platform)]
|
||||
#[cfg(web_platform)]
|
||||
#[path = "web/mod.rs"]
|
||||
mod platform;
|
||||
#[cfg(orbital_platform)]
|
||||
|
|
@ -63,7 +63,7 @@ impl From<Fullscreen> for RootFullscreen {
|
|||
not(android_platform),
|
||||
not(x11_platform),
|
||||
not(wayland_platform),
|
||||
not(wasm_platform),
|
||||
not(web_platform),
|
||||
not(orbital_platform),
|
||||
))]
|
||||
compile_error!("The platform you're compiling for is not supported by winit");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue