summaryrefslogtreecommitdiffstats
path: root/winit
diff options
context:
space:
mode:
Diffstat (limited to 'winit')
-rw-r--r--winit/Cargo.toml6
-rw-r--r--winit/README.md4
-rw-r--r--winit/src/application.rs64
-rw-r--r--winit/src/clipboard.rs8
-rw-r--r--winit/src/settings.rs6
5 files changed, 79 insertions, 9 deletions
diff --git a/winit/Cargo.toml b/winit/Cargo.toml
index bfcfacbc..f7232248 100644
--- a/winit/Cargo.toml
+++ b/winit/Cargo.toml
@@ -2,7 +2,7 @@
name = "iced_winit"
version = "0.3.0"
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
-edition = "2018"
+edition = "2021"
description = "A winit runtime for Iced"
license = "MIT"
repository = "https://github.com/hecrj/iced"
@@ -37,3 +37,7 @@ path = "../futures"
[target.'cfg(target_os = "windows")'.dependencies.winapi]
version = "0.3.6"
+
+[target.'cfg(target_arch = "wasm32")'.dependencies.web-sys]
+version = "0.3"
+features = ["Document", "Window"]
diff --git a/winit/README.md b/winit/README.md
index 58c782c6..5a94cd92 100644
--- a/winit/README.md
+++ b/winit/README.md
@@ -2,7 +2,7 @@
[![Documentation](https://docs.rs/iced_winit/badge.svg)][documentation]
[![Crates.io](https://img.shields.io/crates/v/iced_winit.svg)](https://crates.io/crates/iced_winit)
[![License](https://img.shields.io/crates/l/iced_winit.svg)](https://github.com/hecrj/iced/blob/master/LICENSE)
-[![project chat](https://img.shields.io/badge/chat-on_zulip-brightgreen.svg)](https://iced.zulipchat.com)
+[![Discord Server](https://img.shields.io/discord/628993209984614400?label=&labelColor=6A7EC2&logo=discord&logoColor=ffffff&color=7389D8)](https://discord.gg/3xZJ65GAhd)
`iced_winit` offers some convenient abstractions on top of [`iced_native`] to quickstart development when using [`winit`].
@@ -26,4 +26,4 @@ iced_winit = "0.3"
__Iced moves fast and the `master` branch can contain breaking changes!__ If
you want to learn about a specific release, check out [the release list].
-[the release list]: https://github.com/hecrj/iced/releases
+[the release list]: https://github.com/iced-rs/iced/releases
diff --git a/winit/src/application.rs b/winit/src/application.rs
index e9212b5e..ed077507 100644
--- a/winit/src/application.rs
+++ b/winit/src/application.rs
@@ -115,12 +115,11 @@ where
use futures::task;
use futures::Future;
use winit::event_loop::EventLoop;
- use winit::platform::run_return::EventLoopExtRunReturn;
let mut debug = Debug::new();
debug.startup_started();
- let mut event_loop = EventLoop::with_user_event();
+ let event_loop = EventLoop::with_user_event();
let mut proxy = event_loop.create_proxy();
let mut runtime = {
@@ -149,6 +148,21 @@ where
.build(&event_loop)
.map_err(Error::WindowCreationFailed)?;
+ #[cfg(target_arch = "wasm32")]
+ {
+ use winit::platform::web::WindowExtWebSys;
+
+ let canvas = window.canvas();
+
+ let window = web_sys::window().unwrap();
+ let document = window.document().unwrap();
+ let body = document.body().unwrap();
+
+ let _ = body
+ .append_child(&canvas)
+ .expect("Append canvas to HTML body");
+ }
+
let mut clipboard = Clipboard::connect(&window);
run_command(
@@ -179,7 +193,7 @@ where
let mut context = task::Context::from_waker(task::noop_waker_ref());
- event_loop.run_return(move |event, _, control_flow| {
+ platform::run(event_loop, move |event, _, control_flow| {
use winit::event_loop::ControlFlow;
if let ControlFlow::Exit = control_flow {
@@ -211,9 +225,7 @@ where
task::Poll::Ready(_) => ControlFlow::Exit,
};
}
- });
-
- Ok(())
+ })
}
async fn run_instance<A, E, C>(
@@ -562,3 +574,43 @@ pub fn run_command<Message: 'static + std::fmt::Debug + Send, E: Executor>(
}
}
}
+
+#[cfg(not(target_arch = "wasm32"))]
+mod platform {
+ pub fn run<T, F>(
+ mut event_loop: winit::event_loop::EventLoop<T>,
+ event_handler: F,
+ ) -> Result<(), super::Error>
+ where
+ F: 'static
+ + FnMut(
+ winit::event::Event<'_, T>,
+ &winit::event_loop::EventLoopWindowTarget<T>,
+ &mut winit::event_loop::ControlFlow,
+ ),
+ {
+ use winit::platform::run_return::EventLoopExtRunReturn;
+
+ let _ = event_loop.run_return(event_handler);
+
+ Ok(())
+ }
+}
+
+#[cfg(target_arch = "wasm32")]
+mod platform {
+ pub fn run<T, F>(
+ event_loop: winit::event_loop::EventLoop<T>,
+ event_handler: F,
+ ) -> !
+ where
+ F: 'static
+ + FnMut(
+ winit::event::Event<'_, T>,
+ &winit::event_loop::EventLoopWindowTarget<T>,
+ &mut winit::event_loop::ControlFlow,
+ ),
+ {
+ event_loop.run(event_handler)
+ }
+}
diff --git a/winit/src/clipboard.rs b/winit/src/clipboard.rs
index 1b92b28d..c1fd8813 100644
--- a/winit/src/clipboard.rs
+++ b/winit/src/clipboard.rs
@@ -26,6 +26,14 @@ impl Clipboard {
Clipboard { state }
}
+ /// Creates a new [`Clipboard`] that isn't associated with a window.
+ /// This clipboard will never contain a copied value.
+ pub fn unconnected() -> Clipboard {
+ Clipboard {
+ state: State::Unavailable,
+ }
+ }
+
/// Reads the current content of the [`Clipboard`] as text.
pub fn read(&self) -> Option<String> {
match &self.state {
diff --git a/winit/src/settings.rs b/winit/src/settings.rs
index 045cb156..9a93824a 100644
--- a/winit/src/settings.rs
+++ b/winit/src/settings.rs
@@ -38,6 +38,12 @@ pub struct Settings<Flags> {
/// Whether the [`Application`] should exit when the user requests the
/// window to close (e.g. the user presses the close button).
pub exit_on_close_request: bool,
+
+ /// Whether the [`Application`] should try to build the context
+ /// using OpenGL ES first then OpenGL.
+ ///
+ /// NOTE: Only works for the `glow` backend.
+ pub try_opengles_first: bool,
}
/// The window settings of an application.