diff options
-rw-r--r-- | .github/workflows/test.yml | 2 | ||||
-rw-r--r-- | futures/Cargo.toml | 2 | ||||
-rw-r--r-- | futures/src/command.rs | 52 | ||||
-rw-r--r-- | native/Cargo.toml | 2 | ||||
-rw-r--r-- | native/src/widget/image.rs | 4 | ||||
-rw-r--r-- | wgpu/Cargo.toml | 2 | ||||
-rw-r--r-- | wgpu/src/renderer.rs | 24 |
7 files changed, 73 insertions, 15 deletions
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 520d8da9..9e73d3d3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,3 +29,5 @@ jobs: run: cargo check --package iced --target wasm32-unknown-unknown - name: Check compilation of `tour` example run: cargo build --package tour --target wasm32-unknown-unknown + - name: Check compilation of `pokedex` example + run: cargo build --package pokedex --target wasm32-unknown-unknown diff --git a/futures/Cargo.toml b/futures/Cargo.toml index e0815d9d..f0e2a104 100644 --- a/futures/Cargo.toml +++ b/futures/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iced_futures" -version = "0.1.1" +version = "0.1.2" authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"] edition = "2018" description = "Commands, subscriptions, and runtimes for Iced" diff --git a/futures/src/command.rs b/futures/src/command.rs index d4f99b82..063e9b68 100644 --- a/futures/src/command.rs +++ b/futures/src/command.rs @@ -27,6 +27,7 @@ impl<T> Command<T> { /// Creates a [`Command`] that performs the action of the given future. /// /// [`Command`]: struct.Command.html + #[cfg(not(target_arch = "wasm32"))] pub fn perform<A>( future: impl Future<Output = T> + 'static + Send, f: impl Fn(T) -> A + 'static + Send, @@ -36,9 +37,23 @@ impl<T> Command<T> { } } + /// Creates a [`Command`] that performs the action of the given future. + /// + /// [`Command`]: struct.Command.html + #[cfg(target_arch = "wasm32")] + pub fn perform<A>( + future: impl Future<Output = T> + 'static, + f: impl Fn(T) -> A + 'static + Send, + ) -> Command<A> { + Command { + futures: vec![Box::pin(future.map(f))], + } + } + /// Applies a transformation to the result of a [`Command`]. /// /// [`Command`]: struct.Command.html + #[cfg(not(target_arch = "wasm32"))] pub fn map<A>( mut self, f: impl Fn(T) -> A + 'static + Send + Sync, @@ -62,6 +77,30 @@ impl<T> Command<T> { } } + /// Applies a transformation to the result of a [`Command`]. + /// + /// [`Command`]: struct.Command.html + #[cfg(target_arch = "wasm32")] + pub fn map<A>(mut self, f: impl Fn(T) -> A + 'static) -> Command<A> + where + T: 'static, + { + let f = std::rc::Rc::new(f); + + Command { + futures: self + .futures + .drain(..) + .map(|future| { + let f = f.clone(); + + Box::pin(future.map(move |result| f(result))) + as BoxFuture<A> + }) + .collect(), + } + } + /// Creates a [`Command`] that performs the actions of all the given /// commands. /// @@ -85,6 +124,7 @@ impl<T> Command<T> { } } +#[cfg(not(target_arch = "wasm32"))] impl<T, A> From<A> for Command<T> where A: Future<Output = T> + 'static + Send, @@ -96,6 +136,18 @@ where } } +#[cfg(target_arch = "wasm32")] +impl<T, A> From<A> for Command<T> +where + A: Future<Output = T> + 'static, +{ + fn from(future: A) -> Self { + Self { + futures: vec![future.boxed_local()], + } + } +} + impl<T> std::fmt::Debug for Command<T> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("Command").finish() diff --git a/native/Cargo.toml b/native/Cargo.toml index ca58d75c..7e9c2a5a 100644 --- a/native/Cargo.toml +++ b/native/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iced_native" -version = "0.2.1" +version = "0.2.2" authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"] edition = "2018" description = "A renderer-agnostic library for native GUIs" diff --git a/native/src/widget/image.rs b/native/src/widget/image.rs index 6bd0fd68..132f249d 100644 --- a/native/src/widget/image.rs +++ b/native/src/widget/image.rs @@ -123,6 +123,8 @@ pub struct Handle { impl Handle { /// Creates an image [`Handle`] pointing to the image of the given path. /// + /// Makes an educated guess about the image format by examining the data in the file. + /// /// [`Handle`]: struct.Handle.html pub fn from_path<T: Into<PathBuf>>(path: T) -> Handle { Self::from_data(Data::Path(path.into())) @@ -145,6 +147,8 @@ impl Handle { /// Creates an image [`Handle`] containing the image data directly. /// + /// Makes an educated guess about the image format by examining the given data. + /// /// This is useful if you already have your image loaded in-memory, maybe /// because you downloaded or generated it procedurally. /// diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 0794b970..00f18472 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iced_wgpu" -version = "0.2.1" +version = "0.2.2" authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"] edition = "2018" description = "A wgpu renderer for Iced" diff --git a/wgpu/src/renderer.rs b/wgpu/src/renderer.rs index 481b310c..ca9364c1 100644 --- a/wgpu/src/renderer.rs +++ b/wgpu/src/renderer.rs @@ -339,6 +339,18 @@ impl Renderer { ) { let bounds = layer.bounds * scale_factor; + if !layer.quads.is_empty() { + self.quad_pipeline.draw( + device, + encoder, + &layer.quads, + transformation, + scale_factor, + bounds, + target, + ); + } + if !layer.meshes.is_empty() { let scaled = transformation * Transformation::scale(scale_factor, scale_factor); @@ -355,18 +367,6 @@ impl Renderer { ); } - if !layer.quads.is_empty() { - self.quad_pipeline.draw( - device, - encoder, - &layer.quads, - transformation, - scale_factor, - bounds, - target, - ); - } - #[cfg(any(feature = "image", feature = "svg"))] { if !layer.images.is_empty() { |