From bdca20fc4a3e8f6bd8ffb59de75e6ca0f8a94b6a Mon Sep 17 00:00:00 2001 From: Vladyslav Nikonov Date: Thu, 21 Oct 2021 22:42:14 +0300 Subject: 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 --- native/src/subscription.rs | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'native/src') diff --git a/native/src/subscription.rs b/native/src/subscription.rs index 63834654..4fb7e760 100644 --- a/native/src/subscription.rs +++ b/native/src/subscription.rs @@ -7,6 +7,37 @@ use iced_futures::BoxStream; use std::hash::Hash; +#[cfg(not(target_arch = "wasm32"))] +mod trait_aliases { + use super::*; + + /// Wrapper type + pub trait RunnerStream: + Stream + Send + 'static + { + } + + impl RunnerStream for T where + T: Stream + Send + 'static + { + } +} + +#[cfg(target_arch = "wasm32")] +mod trait_aliases { + use super::*; + + /// Wrapper type + pub trait RunnerStream: Stream + 'static {} + + impl RunnerStream for T where + T: Stream + 'static + { + } +} + +pub use trait_aliases::RunnerStream; + /// A request to listen to external events. /// /// Besides performing async actions on demand with [`Command`], most @@ -191,7 +222,7 @@ impl Recipe where I: Hash + 'static, F: FnOnce(EventStream) -> S, - S: Stream + Send + 'static, + S: RunnerStream, { type Output = Message; @@ -203,6 +234,13 @@ where fn stream(self: Box, input: EventStream) -> BoxStream { use futures::stream::StreamExt; - (self.spawn)(input).boxed() + #[cfg(target_arch = "wasm32")] + { + (self.spawn)(input).boxed_local() + } + #[cfg(not(target_arch = "wasm32"))] + { + (self.spawn)(input).boxed() + } } } -- cgit From 9f47ac8d3158ba8a54730dddea5b58a9926b6e1b Mon Sep 17 00:00:00 2001 From: Kai Mast Date: Sat, 22 Jan 2022 18:39:59 -0600 Subject: Use instant instead of std::instant --- native/src/mouse/click.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'native/src') diff --git a/native/src/mouse/click.rs b/native/src/mouse/click.rs index 6c8b61a5..58cfda61 100644 --- a/native/src/mouse/click.rs +++ b/native/src/mouse/click.rs @@ -1,6 +1,6 @@ //! Track mouse clicks. use crate::Point; -use std::time::Instant; +use instant::Instant; /// A mouse click. #[derive(Debug, Clone, Copy)] -- cgit From 87b3e03d187237f665b376018ea5af0cc5f05814 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 28 Jan 2022 17:05:09 +0700 Subject: Enable `instant` only for `wasm32` targets ... and hide the dependency under a `time` module in `iced_native` --- native/src/debug/basic.rs | 4 +++- native/src/lib.rs | 1 + native/src/mouse/click.rs | 2 +- native/src/time.rs | 7 +++++++ 4 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 native/src/time.rs (limited to 'native/src') diff --git a/native/src/debug/basic.rs b/native/src/debug/basic.rs index a42f66ea..d706bb00 100644 --- a/native/src/debug/basic.rs +++ b/native/src/debug/basic.rs @@ -1,5 +1,7 @@ #![allow(missing_docs)] -use std::{collections::VecDeque, time}; +use crate::time; + +use std::collections::VecDeque; /// A bunch of time measurements for debugging purposes. #[derive(Debug)] diff --git a/native/src/lib.rs b/native/src/lib.rs index a5526e6d..bd50c6b2 100644 --- a/native/src/lib.rs +++ b/native/src/lib.rs @@ -49,6 +49,7 @@ pub mod renderer; pub mod subscription; pub mod svg; pub mod text; +pub mod time; pub mod touch; pub mod user_interface; pub mod widget; diff --git a/native/src/mouse/click.rs b/native/src/mouse/click.rs index 58cfda61..ec321387 100644 --- a/native/src/mouse/click.rs +++ b/native/src/mouse/click.rs @@ -1,6 +1,6 @@ //! Track mouse clicks. +use crate::time::Instant; use crate::Point; -use instant::Instant; /// A mouse click. #[derive(Debug, Clone, Copy)] diff --git a/native/src/time.rs b/native/src/time.rs new file mode 100644 index 00000000..5f95ee86 --- /dev/null +++ b/native/src/time.rs @@ -0,0 +1,7 @@ +//! Keep track of time, both in native and web platforms! + +#[cfg(target_arch = "wasm32")] +pub use instant::{Duration, Instant}; + +#[cfg(not(target_arch = "wasm32"))] +pub use std::time::{Duration, Instant}; -- cgit From 83c649b574d90667d23c8430baaebcd0ef933055 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 28 Jan 2022 17:20:40 +0700 Subject: Move `time` module from `iced_native` to `iced_core` --- native/src/lib.rs | 2 +- native/src/time.rs | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) delete mode 100644 native/src/time.rs (limited to 'native/src') diff --git a/native/src/lib.rs b/native/src/lib.rs index bd50c6b2..6d98f7d1 100644 --- a/native/src/lib.rs +++ b/native/src/lib.rs @@ -49,7 +49,6 @@ pub mod renderer; pub mod subscription; pub mod svg; pub mod text; -pub mod time; pub mod touch; pub mod user_interface; pub mod widget; @@ -70,6 +69,7 @@ mod debug; mod debug; pub use iced_core::alignment; +pub use iced_core::time; pub use iced_core::{ Alignment, Background, Color, Font, Length, Padding, Point, Rectangle, Size, Vector, diff --git a/native/src/time.rs b/native/src/time.rs deleted file mode 100644 index 5f95ee86..00000000 --- a/native/src/time.rs +++ /dev/null @@ -1,7 +0,0 @@ -//! Keep track of time, both in native and web platforms! - -#[cfg(target_arch = "wasm32")] -pub use instant::{Duration, Instant}; - -#[cfg(not(target_arch = "wasm32"))] -pub use std::time::{Duration, Instant}; -- cgit From 5dab5a327ef643ee38ac3e42ab35212fff445631 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 28 Jan 2022 17:35:47 +0700 Subject: Introduce `MaybeSend` trait in `iced_futures` It allows to clean up all the `trait_aliases` modules! --- native/src/subscription.rs | 58 +++++++--------------------------------------- 1 file changed, 9 insertions(+), 49 deletions(-) (limited to 'native/src') diff --git a/native/src/subscription.rs b/native/src/subscription.rs index 4fb7e760..9775c84b 100644 --- a/native/src/subscription.rs +++ b/native/src/subscription.rs @@ -3,41 +3,10 @@ use crate::event::{self, Event}; use crate::Hasher; use iced_futures::futures::{self, Future, Stream}; -use iced_futures::BoxStream; +use iced_futures::{BoxStream, MaybeSend}; use std::hash::Hash; -#[cfg(not(target_arch = "wasm32"))] -mod trait_aliases { - use super::*; - - /// Wrapper type - pub trait RunnerStream: - Stream + Send + 'static - { - } - - impl RunnerStream for T where - T: Stream + Send + 'static - { - } -} - -#[cfg(target_arch = "wasm32")] -mod trait_aliases { - use super::*; - - /// Wrapper type - pub trait RunnerStream: Stream + 'static {} - - impl RunnerStream for T where - T: Stream + 'static - { - } -} - -pub use trait_aliases::RunnerStream; - /// A request to listen to external events. /// /// Besides performing async actions on demand with [`Command`], most @@ -87,7 +56,7 @@ pub fn events_with( f: fn(Event, event::Status) -> Option, ) -> Subscription where - Message: 'static + Send, + Message: 'static + MaybeSend, { Subscription::from_recipe(Runner { id: f, @@ -109,7 +78,7 @@ where pub fn run(id: I, stream: S) -> Subscription where I: Hash + 'static, - S: Stream + Send + 'static, + S: Stream + MaybeSend + 'static, Message: 'static, { Subscription::from_recipe(Runner { @@ -190,13 +159,13 @@ where pub fn unfold( id: I, initial: T, - mut f: impl FnMut(T) -> Fut + Send + Sync + 'static, + mut f: impl FnMut(T) -> Fut + MaybeSend + Sync + 'static, ) -> Subscription where I: Hash + 'static, - T: Send + 'static, - Fut: Future, T)> + Send + 'static, - Message: 'static + Send, + T: MaybeSend + 'static, + Fut: Future, T)> + MaybeSend + 'static, + Message: 'static + MaybeSend, { use futures::future::{self, FutureExt}; use futures::stream::StreamExt; @@ -222,7 +191,7 @@ impl Recipe where I: Hash + 'static, F: FnOnce(EventStream) -> S, - S: RunnerStream, + S: Stream + MaybeSend + 'static, { type Output = Message; @@ -232,15 +201,6 @@ where } fn stream(self: Box, input: EventStream) -> BoxStream { - use futures::stream::StreamExt; - - #[cfg(target_arch = "wasm32")] - { - (self.spawn)(input).boxed_local() - } - #[cfg(not(target_arch = "wasm32"))] - { - (self.spawn)(input).boxed() - } + iced_futures::boxed_stream((self.spawn)(input)) } } -- cgit From e730d97f61bc2edc77d2f061b6a763c4d0a948df Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 28 Jan 2022 18:43:20 +0700 Subject: Implement `time` module for `wasm-bindgen` backend in `iced_futures` --- native/src/mouse/click.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'native/src') diff --git a/native/src/mouse/click.rs b/native/src/mouse/click.rs index ec321387..4a7d796c 100644 --- a/native/src/mouse/click.rs +++ b/native/src/mouse/click.rs @@ -62,9 +62,14 @@ impl Click { } fn is_consecutive(&self, new_position: Point, time: Instant) -> bool { + let duration = if time > self.time { + Some(time - self.time) + } else { + None + }; + self.position == new_position - && time - .checked_duration_since(self.time) + && duration .map(|duration| duration.as_millis() <= 300) .unwrap_or(false) } -- cgit From 90afd1db8df17a7afa06b521ccd52455eced9277 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 28 Jan 2022 21:45:30 +0700 Subject: Use `MaybeSend` in `perform` and `map` for `Command` --- native/src/clipboard.rs | 7 ++++++- native/src/command.rs | 8 +++++--- native/src/command/action.rs | 7 ++++++- 3 files changed, 17 insertions(+), 5 deletions(-) (limited to 'native/src') diff --git a/native/src/clipboard.rs b/native/src/clipboard.rs index 60703c31..c9105bc0 100644 --- a/native/src/clipboard.rs +++ b/native/src/clipboard.rs @@ -1,4 +1,6 @@ //! Access the clipboard. +use iced_futures::MaybeSend; + use std::fmt; /// A buffer for short-term storage and transfer within and between @@ -36,7 +38,10 @@ pub enum Action { impl Action { /// Maps the output of a clipboard [`Action`] using the provided closure. - pub fn map(self, f: impl Fn(T) -> A + 'static + Send + Sync) -> Action + pub fn map( + self, + f: impl Fn(T) -> A + 'static + MaybeSend + Sync, + ) -> Action where T: 'static, { diff --git a/native/src/command.rs b/native/src/command.rs index 6fe518d7..89d0f045 100644 --- a/native/src/command.rs +++ b/native/src/command.rs @@ -3,6 +3,8 @@ mod action; pub use action::Action; +use iced_futures::MaybeSend; + use std::fmt; use std::future::Future; @@ -24,8 +26,8 @@ impl Command { /// Creates a [`Command`] that performs the action of the given future. pub fn perform( - future: impl Future + 'static + Send, - f: impl Fn(T) -> A + 'static + Send, + future: impl Future + 'static + MaybeSend, + f: impl Fn(T) -> A + 'static + MaybeSend, ) -> Command { use iced_futures::futures::FutureExt; @@ -45,7 +47,7 @@ impl Command { /// Applies a transformation to the result of a [`Command`]. pub fn map( self, - f: impl Fn(T) -> A + 'static + Send + Sync + Clone, + f: impl Fn(T) -> A + 'static + MaybeSend + Sync + Clone, ) -> Command where T: 'static, diff --git a/native/src/command/action.rs b/native/src/command/action.rs index 77be1b59..5c7509c8 100644 --- a/native/src/command/action.rs +++ b/native/src/command/action.rs @@ -1,6 +1,8 @@ use crate::clipboard; use crate::window; +use iced_futures::MaybeSend; + use std::fmt; /// An action that a [`Command`] can perform. @@ -19,7 +21,10 @@ pub enum Action { impl Action { /// Applies a transformation to the result of a [`Command`]. - pub fn map(self, f: impl Fn(T) -> A + 'static + Send + Sync) -> Action + pub fn map( + self, + f: impl Fn(T) -> A + 'static + MaybeSend + Sync, + ) -> Action where T: 'static, { -- cgit