diff options
author | 2019-11-14 06:46:50 +0100 | |
---|---|---|
committer | 2019-11-14 06:46:50 +0100 | |
commit | bc8d347736ec997ec0e0c401289e2bc09e212b8a (patch) | |
tree | b98798c09a3aa914b7d0869fba0cfd3efff7754f /wgpu/src/renderer/widget/image.rs | |
parent | 839e039dbf2fb89dcb8c141503740777d2af2eb3 (diff) | |
parent | 73f3c900071f950ea914652ca3f0002c1e173f61 (diff) | |
download | iced-bc8d347736ec997ec0e0c401289e2bc09e212b8a.tar.gz iced-bc8d347736ec997ec0e0c401289e2bc09e212b8a.tar.bz2 iced-bc8d347736ec997ec0e0c401289e2bc09e212b8a.zip |
Merge pull request #52 from hecrj/custom-layout-engine
Custom layout engine
Diffstat (limited to 'wgpu/src/renderer/widget/image.rs')
-rw-r--r-- | wgpu/src/renderer/widget/image.rs | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/wgpu/src/renderer/widget/image.rs b/wgpu/src/renderer/widget/image.rs index 0e312706..0afb11e3 100644 --- a/wgpu/src/renderer/widget/image.rs +++ b/wgpu/src/renderer/widget/image.rs @@ -1,25 +1,28 @@ use crate::{Primitive, Renderer}; -use iced_native::{image, Image, Layout, Length, MouseCursor, Node, Style}; +use iced_native::{image, layout, Image, Layout, Length, MouseCursor, Size}; impl image::Renderer for Renderer { - fn node(&self, image: &Image) -> Node { + fn layout(&self, image: &Image, limits: &layout::Limits) -> layout::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( + let (width, height) = match (image.width, image.height) { + (Length::Units(width), _) => ( + image.width, Length::Units((width as f32 / aspect_ratio).round() as u16), ), - (_, _) => style - .width(Length::Units(width as u16)) - .height(Length::Units(height as u16)), + (_, _) => { + (Length::Units(width as u16), Length::Units(height as u16)) + } }; - Node::new(style) + let mut size = limits.width(width).height(height).resolve(Size::ZERO); + + size.height = size.width / aspect_ratio; + + layout::Node::new(size) } fn draw(&mut self, image: &Image, layout: Layout<'_>) -> Self::Output { |