summaryrefslogtreecommitdiffstats
path: root/winit
diff options
context:
space:
mode:
authorLibravatar Vladyslav Nikonov <mail@pacmancoder.xyz>2021-10-21 22:42:14 +0300
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-01-28 21:37:14 +0700
commitbdca20fc4a3e8f6bd8ffb59de75e6ca0f8a94b6a (patch)
tree8ea0d2ff0a0d780ff763d7491fc67878f549a615 /winit
parentc75ed37148b019358b0297171cf31b2577eeb9ae (diff)
downloadiced-bdca20fc4a3e8f6bd8ffb59de75e6ca0f8a94b6a.tar.gz
iced-bdca20fc4a3e8f6bd8ffb59de75e6ca0f8a94b6a.tar.bz2
iced-bdca20fc4a3e8f6bd8ffb59de75e6ca0f8a94b6a.zip
Experimental wgpu WebGL backend support
- Added missing `draw_cache_align_4x4` call for `brush_glyph` on wasm32 target - Added WebGL support to `integratio_wgpu` example - Fixed test.yml CI workflow - Removed spir-v shader in `integration_wgpu`; Fixed formatting - Removed redundant `BoxStream` typedef
Diffstat (limited to 'winit')
-rw-r--r--winit/Cargo.toml4
-rw-r--r--winit/src/application.rs106
-rw-r--r--winit/src/clipboard.rs25
3 files changed, 103 insertions, 32 deletions
diff --git a/winit/Cargo.toml b/winit/Cargo.toml
index bfcfacbc..e0581b00 100644
--- a/winit/Cargo.toml
+++ b/winit/Cargo.toml
@@ -14,7 +14,6 @@ categories = ["gui"]
debug = ["iced_native/debug"]
[dependencies]
-window_clipboard = "0.2"
log = "0.4"
thiserror = "1.0"
@@ -37,3 +36,6 @@ path = "../futures"
[target.'cfg(target_os = "windows")'.dependencies.winapi]
version = "0.3.6"
+
+[target.'cfg(not(target_arch = "wasm32"))'.dependencies.window_clipboard]
+version = "0.2"
diff --git a/winit/src/application.rs b/winit/src/application.rs
index e9212b5e..a3715b04 100644
--- a/winit/src/application.rs
+++ b/winit/src/application.rs
@@ -115,12 +115,16 @@ where
use futures::task;
use futures::Future;
use winit::event_loop::EventLoop;
+ #[cfg(not(target_arch = "wasm32"))]
use winit::platform::run_return::EventLoopExtRunReturn;
let mut debug = Debug::new();
debug.startup_started();
+ #[cfg(not(target_arch = "wasm32"))]
let mut event_loop = EventLoop::with_user_event();
+ #[cfg(target_arch = "wasm32")]
+ let event_loop = EventLoop::with_user_event();
let mut proxy = event_loop.create_proxy();
let mut runtime = {
@@ -179,41 +183,81 @@ where
let mut context = task::Context::from_waker(task::noop_waker_ref());
- event_loop.run_return(move |event, _, control_flow| {
- use winit::event_loop::ControlFlow;
+ #[cfg(not(target_arch = "wasm32"))]
+ {
+ event_loop.run_return(move |event, _, control_flow| {
+ use winit::event_loop::ControlFlow;
- if let ControlFlow::Exit = control_flow {
- return;
- }
+ if let ControlFlow::Exit = control_flow {
+ return;
+ }
- let event = match event {
- winit::event::Event::WindowEvent {
- event:
- winit::event::WindowEvent::ScaleFactorChanged {
- new_inner_size,
- ..
- },
- window_id,
- } => Some(winit::event::Event::WindowEvent {
- event: winit::event::WindowEvent::Resized(*new_inner_size),
- window_id,
- }),
- _ => event.to_static(),
- };
-
- if let Some(event) = event {
- sender.start_send(event).expect("Send event");
-
- let poll = instance.as_mut().poll(&mut context);
-
- *control_flow = match poll {
- task::Poll::Pending => ControlFlow::Wait,
- task::Poll::Ready(_) => ControlFlow::Exit,
+ let event = match event {
+ winit::event::Event::WindowEvent {
+ event:
+ winit::event::WindowEvent::ScaleFactorChanged {
+ new_inner_size,
+ ..
+ },
+ window_id,
+ } => Some(winit::event::Event::WindowEvent {
+ event: winit::event::WindowEvent::Resized(*new_inner_size),
+ window_id,
+ }),
+ _ => event.to_static(),
};
- }
- });
- Ok(())
+ if let Some(event) = event {
+ sender.start_send(event).expect("Send event");
+
+ let poll = instance.as_mut().poll(&mut context);
+
+ *control_flow = match poll {
+ task::Poll::Pending => ControlFlow::Wait,
+ task::Poll::Ready(_) => ControlFlow::Exit,
+ };
+ }
+ });
+
+ Ok(())
+ }
+
+ #[cfg(target_arch = "wasm32")]
+ {
+ event_loop.run(move |event, _, control_flow| {
+ use winit::event_loop::ControlFlow;
+
+ if let ControlFlow::Exit = control_flow {
+ return;
+ }
+
+ let event = match event {
+ winit::event::Event::WindowEvent {
+ event:
+ winit::event::WindowEvent::ScaleFactorChanged {
+ new_inner_size,
+ ..
+ },
+ window_id,
+ } => Some(winit::event::Event::WindowEvent {
+ event: winit::event::WindowEvent::Resized(*new_inner_size),
+ window_id,
+ }),
+ _ => event.to_static(),
+ };
+
+ if let Some(event) = event {
+ sender.start_send(event).expect("Send event");
+
+ let poll = instance.as_mut().poll(&mut context);
+
+ *control_flow = match poll {
+ task::Poll::Pending => ControlFlow::Wait,
+ task::Poll::Ready(_) => ControlFlow::Exit,
+ };
+ }
+ });
+ }
}
async fn run_instance<A, E, C>(
diff --git a/winit/src/clipboard.rs b/winit/src/clipboard.rs
index 1b92b28d..197d32b3 100644
--- a/winit/src/clipboard.rs
+++ b/winit/src/clipboard.rs
@@ -6,15 +6,40 @@ use crate::command::{self, Command};
/// A buffer for short-term storage and transfer within and between
/// applications.
#[allow(missing_debug_implementations)]
+#[cfg(target_arch = "wasm32")]
+pub struct Clipboard;
+
+#[cfg(target_arch = "wasm32")]
+impl Clipboard {
+ /// Creates a new [`Clipboard`] for the given window.
+ pub fn connect(_window: &winit::window::Window) -> Clipboard {
+ Clipboard
+ }
+
+ /// Reads the current content of the [`Clipboard`] as text.
+ pub fn read(&self) -> Option<String> {
+ None
+ }
+
+ /// Writes the given text contents to the [`Clipboard`].
+ pub fn write(&mut self, _contents: String) {}
+}
+
+/// A buffer for short-term storage and transfer within and between
+/// applications.
+#[allow(missing_debug_implementations)]
+#[cfg(not(target_arch = "wasm32"))]
pub struct Clipboard {
state: State,
}
+#[cfg(not(target_arch = "wasm32"))]
enum State {
Connected(window_clipboard::Clipboard),
Unavailable,
}
+#[cfg(not(target_arch = "wasm32"))]
impl Clipboard {
/// Creates a new [`Clipboard`] for the given window.
pub fn connect(window: &winit::window::Window) -> Clipboard {