diff options
author | 2019-11-05 21:46:37 +0100 | |
---|---|---|
committer | 2019-11-05 21:46:37 +0100 | |
commit | ae6156f779c24beaabf43ea6110d3ce38e34a998 (patch) | |
tree | 9545408530437eb780ac73c600f7d40968803786 /wgpu/src/renderer/widget/image.rs | |
parent | da2717c74dbe3e1123ff41de345a409c1afc2f18 (diff) | |
parent | 0157121038987feb6c2ea3066a21ce25e689888e (diff) | |
download | iced-ae6156f779c24beaabf43ea6110d3ce38e34a998.tar.gz iced-ae6156f779c24beaabf43ea6110d3ce38e34a998.tar.bz2 iced-ae6156f779c24beaabf43ea6110d3ce38e34a998.zip |
Merge pull request #38 from hecrj/feature/performance-metrics
Debug view
Diffstat (limited to 'wgpu/src/renderer/widget/image.rs')
-rw-r--r-- | wgpu/src/renderer/widget/image.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/wgpu/src/renderer/widget/image.rs b/wgpu/src/renderer/widget/image.rs new file mode 100644 index 00000000..0e312706 --- /dev/null +++ b/wgpu/src/renderer/widget/image.rs @@ -0,0 +1,34 @@ +use crate::{Primitive, Renderer}; +use iced_native::{image, Image, Layout, Length, MouseCursor, Node, Style}; + +impl image::Renderer for Renderer { + fn node(&self, image: &Image) -> Node { + let (width, height) = self.image_pipeline.dimensions(&image.path); + + let aspect_ratio = width as f32 / height as f32; + + let mut style = Style::default().align_self(image.align_self); + + // TODO: Deal with additional cases + style = match (image.width, image.height) { + (Length::Units(width), _) => style.width(image.width).height( + Length::Units((width as f32 / aspect_ratio).round() as u16), + ), + (_, _) => style + .width(Length::Units(width as u16)) + .height(Length::Units(height as u16)), + }; + + Node::new(style) + } + + fn draw(&mut self, image: &Image, layout: Layout<'_>) -> Self::Output { + ( + Primitive::Image { + path: image.path.clone(), + bounds: layout.bounds(), + }, + MouseCursor::OutOfBounds, + ) + } +} |