From bfa08d6d69e689d6951d3bf36e00f9e5b7fe225d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Tue, 5 Jan 2021 00:00:36 +0100 Subject: [PATCH] Update `lyon` to `0.17` in `iced_graphics` --- graphics/Cargo.toml | 2 +- graphics/src/widget/canvas/frame.rs | 44 ++++++++++------------ graphics/src/widget/canvas/path.rs | 2 +- graphics/src/widget/canvas/path/builder.rs | 4 +- 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/graphics/Cargo.toml b/graphics/Cargo.toml index aac9ccf2..0e70c67e 100644 --- a/graphics/Cargo.toml +++ b/graphics/Cargo.toml @@ -36,7 +36,7 @@ version = "0.2" path = "../style" [dependencies.lyon] -version = "0.16" +version = "0.17" optional = true [dependencies.qrcode] diff --git a/graphics/src/widget/canvas/frame.rs b/graphics/src/widget/canvas/frame.rs index b86f9e04..c241ecb3 100644 --- a/graphics/src/widget/canvas/frame.rs +++ b/graphics/src/widget/canvas/frame.rs @@ -108,7 +108,10 @@ impl Frame { size: Size, fill: impl Into, ) { - use lyon::tessellation::{BuffersBuilder, FillOptions}; + use lyon::path::builder::PathBuilder; + use lyon::tessellation::{ + BuffersBuilder, FillOptions, FillTessellator, + }; let Fill { color, rule } = fill.into(); @@ -127,12 +130,17 @@ impl Frame { lyon::math::Vector::new(size.width, size.height), ); - let _ = lyon::tessellation::basic_shapes::fill_rectangle( + let mut tessellator = FillTessellator::new(); + let options = FillOptions::default().with_fill_rule(rule.into()); + + let mut builder = tessellator.builder(&options, &mut buffers); + + builder.add_rectangle( &lyon::math::Rect::new(top_left, size.into()), - &FillOptions::default().with_fill_rule(rule.into()), - &mut buffers, - ) - .expect("Fill rectangle"); + lyon::path::Winding::Positive, + ); + + let _ = builder.build().expect("Fill rectangle"); } /// Draws the stroke of the given [`Path`] on the [`Frame`] with the @@ -282,28 +290,15 @@ impl Frame { struct FillVertex([f32; 4]); -impl lyon::tessellation::BasicVertexConstructor - for FillVertex -{ - fn new_vertex( - &mut self, - position: lyon::math::Point, - ) -> triangle::Vertex2D { - triangle::Vertex2D { - position: [position.x, position.y], - color: self.0, - } - } -} - impl lyon::tessellation::FillVertexConstructor for FillVertex { fn new_vertex( &mut self, - position: lyon::math::Point, - _attributes: lyon::tessellation::FillAttributes<'_>, + vertex: lyon::tessellation::FillVertex<'_>, ) -> triangle::Vertex2D { + let position = vertex.position(); + triangle::Vertex2D { position: [position.x, position.y], color: self.0, @@ -318,9 +313,10 @@ impl lyon::tessellation::StrokeVertexConstructor { fn new_vertex( &mut self, - position: lyon::math::Point, - _attributes: lyon::tessellation::StrokeAttributes<'_, '_>, + vertex: lyon::tessellation::StrokeVertex<'_, '_>, ) -> triangle::Vertex2D { + let position = vertex.position(); + triangle::Vertex2D { position: [position.x, position.y], color: self.0, diff --git a/graphics/src/widget/canvas/path.rs b/graphics/src/widget/canvas/path.rs index 6de19321..4e4fd734 100644 --- a/graphics/src/widget/canvas/path.rs +++ b/graphics/src/widget/canvas/path.rs @@ -62,7 +62,7 @@ impl Path { transform: &lyon::math::Transform, ) -> Path { Path { - raw: self.raw.transformed(transform), + raw: self.raw.clone().transformed(transform), } } } diff --git a/graphics/src/widget/canvas/path/builder.rs b/graphics/src/widget/canvas/path/builder.rs index 5ce0e02c..d04dbdde 100644 --- a/graphics/src/widget/canvas/path/builder.rs +++ b/graphics/src/widget/canvas/path/builder.rs @@ -1,14 +1,14 @@ use crate::canvas::path::{arc, Arc, Path}; use iced_native::{Point, Size}; -use lyon::path::builder::{Build, FlatPathBuilder, PathBuilder, SvgBuilder}; +use lyon::path::builder::SvgPathBuilder; /// A [`Path`] builder. /// /// Once a [`Path`] is built, it can no longer be mutated. #[allow(missing_debug_implementations)] pub struct Builder { - raw: lyon::path::builder::SvgPathBuilder, + raw: lyon::path::builder::WithSvg, } impl Builder {