diff options
author | 2019-11-29 21:44:39 +0100 | |
---|---|---|
committer | 2019-11-29 21:44:39 +0100 | |
commit | 505588d5851fed8a3bb334edacfa6d96c545d562 (patch) | |
tree | 1fb107d7c5f9bae0b6fe0c9ff106d7b9bd483b52 /wgpu/src/renderer | |
parent | 811d8b90d71c26100f0933217f5474e090fbf17c (diff) | |
download | iced-505588d5851fed8a3bb334edacfa6d96c545d562.tar.gz iced-505588d5851fed8a3bb334edacfa6d96c545d562.tar.bz2 iced-505588d5851fed8a3bb334edacfa6d96c545d562.zip |
Allow to load an image from memory
New `image::Handle` opaque type uniquely identifying some `image::Data`,
allowing reliable caching.
Diffstat (limited to '')
-rw-r--r-- | wgpu/src/renderer.rs | 4 | ||||
-rw-r--r-- | wgpu/src/renderer/widget/image.rs | 12 |
2 files changed, 10 insertions, 6 deletions
diff --git a/wgpu/src/renderer.rs b/wgpu/src/renderer.rs index f27a4b8a..ad081383 100644 --- a/wgpu/src/renderer.rs +++ b/wgpu/src/renderer.rs @@ -229,9 +229,9 @@ impl Renderer { border_radius: *border_radius as f32, }); } - Primitive::Image { path, bounds } => { + Primitive::Image { handle, bounds } => { layer.images.push(Image { - path: path.clone(), + handle: handle.clone(), position: [bounds.x, bounds.y], scale: [bounds.width, bounds.height], }); diff --git a/wgpu/src/renderer/widget/image.rs b/wgpu/src/renderer/widget/image.rs index 0006dde1..70dc5d97 100644 --- a/wgpu/src/renderer/widget/image.rs +++ b/wgpu/src/renderer/widget/image.rs @@ -2,14 +2,18 @@ use crate::{Primitive, Renderer}; use iced_native::{image, Layout, MouseCursor}; impl image::Renderer for Renderer { - fn dimensions(&self, path: &str) -> (u32, u32) { - self.image_pipeline.dimensions(path) + fn dimensions(&self, handle: &image::Handle) -> (u32, u32) { + self.image_pipeline.dimensions(handle) } - fn draw(&mut self, path: &str, layout: Layout<'_>) -> Self::Output { + fn draw( + &mut self, + handle: image::Handle, + layout: Layout<'_>, + ) -> Self::Output { ( Primitive::Image { - path: String::from(path), + handle, bounds: layout.bounds(), }, MouseCursor::OutOfBounds, |