From 2303111e09d806ef2a652bddc2b73be6dccf6ae2 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 10 Nov 2019 01:55:32 +0100 Subject: Draft new layout API --- wgpu/src/renderer/widget/image.rs | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) (limited to 'wgpu/src/renderer/widget/image.rs') diff --git a/wgpu/src/renderer/widget/image.rs b/wgpu/src/renderer/widget/image.rs index 0e312706..ea9d19c7 100644 --- a/wgpu/src/renderer/widget/image.rs +++ b/wgpu/src/renderer/widget/image.rs @@ -1,28 +1,18 @@ use crate::{Primitive, Renderer}; -use iced_native::{image, Image, Layout, Length, MouseCursor, Node, Style}; +use iced_native::{image, layout, Image, Layout, MouseCursor, Rectangle}; 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 layout(&self, image: &Image, limits: &layout::Limits) -> Layout { + // TODO + Layout::new(Rectangle { + x: 0.0, + y: 0.0, + width: 0.0, + height: 0.0, + }) } - fn draw(&mut self, image: &Image, layout: Layout<'_>) -> Self::Output { + fn draw(&mut self, image: &Image, layout: &Layout) -> Self::Output { ( Primitive::Image { path: image.path.clone(), -- cgit From 0240c3981b716c82ecb3364945815335b420a63e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 10 Nov 2019 06:05:20 +0100 Subject: Draft custom layout engine based on `druid` --- wgpu/src/renderer/widget/image.rs | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'wgpu/src/renderer/widget/image.rs') diff --git a/wgpu/src/renderer/widget/image.rs b/wgpu/src/renderer/widget/image.rs index ea9d19c7..0afb11e3 100644 --- a/wgpu/src/renderer/widget/image.rs +++ b/wgpu/src/renderer/widget/image.rs @@ -1,18 +1,31 @@ use crate::{Primitive, Renderer}; -use iced_native::{image, layout, Image, Layout, MouseCursor, Rectangle}; +use iced_native::{image, layout, Image, Layout, Length, MouseCursor, Size}; impl image::Renderer for Renderer { - fn layout(&self, image: &Image, limits: &layout::Limits) -> Layout { - // TODO - Layout::new(Rectangle { - x: 0.0, - y: 0.0, - width: 0.0, - height: 0.0, - }) + 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; + + // TODO: Deal with additional cases + let (width, height) = match (image.width, image.height) { + (Length::Units(width), _) => ( + image.width, + Length::Units((width as f32 / aspect_ratio).round() as u16), + ), + (_, _) => { + (Length::Units(width as u16), Length::Units(height as u16)) + } + }; + + 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 { + fn draw(&mut self, image: &Image, layout: Layout<'_>) -> Self::Output { ( Primitive::Image { path: image.path.clone(), -- cgit