Merge pull request #683 from hecrj/lyon-0.17
Update `lyon` to `0.17` in `iced_graphics`
This commit is contained in:
commit
b7b7741578
4 changed files with 54 additions and 51 deletions
|
|
@ -36,7 +36,7 @@ version = "0.3"
|
||||||
path = "../style"
|
path = "../style"
|
||||||
|
|
||||||
[dependencies.lyon]
|
[dependencies.lyon]
|
||||||
version = "0.16"
|
version = "0.17"
|
||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
[dependencies.qrcode]
|
[dependencies.qrcode]
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,19 @@ use crate::{
|
||||||
triangle, Primitive,
|
triangle, Primitive,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use lyon::tessellation;
|
||||||
|
|
||||||
/// The frame of a [`Canvas`].
|
/// The frame of a [`Canvas`].
|
||||||
///
|
///
|
||||||
/// [`Canvas`]: crate::widget::Canvas
|
/// [`Canvas`]: crate::widget::Canvas
|
||||||
#[derive(Debug)]
|
#[allow(missing_debug_implementations)]
|
||||||
pub struct Frame {
|
pub struct Frame {
|
||||||
size: Size,
|
size: Size,
|
||||||
buffers: lyon::tessellation::VertexBuffers<triangle::Vertex2D, u32>,
|
buffers: lyon::tessellation::VertexBuffers<triangle::Vertex2D, u32>,
|
||||||
primitives: Vec<Primitive>,
|
primitives: Vec<Primitive>,
|
||||||
transforms: Transforms,
|
transforms: Transforms,
|
||||||
|
fill_tessellator: tessellation::FillTessellator,
|
||||||
|
stroke_tessellator: tessellation::StrokeTessellator,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -45,6 +49,8 @@ impl Frame {
|
||||||
is_identity: true,
|
is_identity: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
fill_tessellator: tessellation::FillTessellator::new(),
|
||||||
|
stroke_tessellator: tessellation::StrokeTessellator::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -75,26 +81,30 @@ impl Frame {
|
||||||
/// Draws the given [`Path`] on the [`Frame`] by filling it with the
|
/// Draws the given [`Path`] on the [`Frame`] by filling it with the
|
||||||
/// provided style.
|
/// provided style.
|
||||||
pub fn fill(&mut self, path: &Path, fill: impl Into<Fill>) {
|
pub fn fill(&mut self, path: &Path, fill: impl Into<Fill>) {
|
||||||
use lyon::tessellation::{
|
|
||||||
BuffersBuilder, FillOptions, FillTessellator,
|
|
||||||
};
|
|
||||||
|
|
||||||
let Fill { color, rule } = fill.into();
|
let Fill { color, rule } = fill.into();
|
||||||
|
|
||||||
let mut buffers = BuffersBuilder::new(
|
let mut buffers = tessellation::BuffersBuilder::new(
|
||||||
&mut self.buffers,
|
&mut self.buffers,
|
||||||
FillVertex(color.into_linear()),
|
FillVertex(color.into_linear()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut tessellator = FillTessellator::new();
|
let options =
|
||||||
let options = FillOptions::default().with_fill_rule(rule.into());
|
tessellation::FillOptions::default().with_fill_rule(rule.into());
|
||||||
|
|
||||||
let result = if self.transforms.current.is_identity {
|
let result = if self.transforms.current.is_identity {
|
||||||
tessellator.tessellate_path(path.raw(), &options, &mut buffers)
|
self.fill_tessellator.tessellate_path(
|
||||||
|
path.raw(),
|
||||||
|
&options,
|
||||||
|
&mut buffers,
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
let path = path.transformed(&self.transforms.current.raw);
|
let path = path.transformed(&self.transforms.current.raw);
|
||||||
|
|
||||||
tessellator.tessellate_path(path.raw(), &options, &mut buffers)
|
self.fill_tessellator.tessellate_path(
|
||||||
|
path.raw(),
|
||||||
|
&options,
|
||||||
|
&mut buffers,
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
let _ = result.expect("Tessellate path");
|
let _ = result.expect("Tessellate path");
|
||||||
|
|
@ -108,11 +118,9 @@ impl Frame {
|
||||||
size: Size,
|
size: Size,
|
||||||
fill: impl Into<Fill>,
|
fill: impl Into<Fill>,
|
||||||
) {
|
) {
|
||||||
use lyon::tessellation::{BuffersBuilder, FillOptions};
|
|
||||||
|
|
||||||
let Fill { color, rule } = fill.into();
|
let Fill { color, rule } = fill.into();
|
||||||
|
|
||||||
let mut buffers = BuffersBuilder::new(
|
let mut buffers = tessellation::BuffersBuilder::new(
|
||||||
&mut self.buffers,
|
&mut self.buffers,
|
||||||
FillVertex(color.into_linear()),
|
FillVertex(color.into_linear()),
|
||||||
);
|
);
|
||||||
|
|
@ -127,42 +135,49 @@ impl Frame {
|
||||||
lyon::math::Vector::new(size.width, size.height),
|
lyon::math::Vector::new(size.width, size.height),
|
||||||
);
|
);
|
||||||
|
|
||||||
let _ = lyon::tessellation::basic_shapes::fill_rectangle(
|
let options =
|
||||||
&lyon::math::Rect::new(top_left, size.into()),
|
tessellation::FillOptions::default().with_fill_rule(rule.into());
|
||||||
&FillOptions::default().with_fill_rule(rule.into()),
|
|
||||||
&mut buffers,
|
let _ = self
|
||||||
)
|
.fill_tessellator
|
||||||
.expect("Fill rectangle");
|
.tessellate_rectangle(
|
||||||
|
&lyon::math::Rect::new(top_left, size.into()),
|
||||||
|
&options,
|
||||||
|
&mut buffers,
|
||||||
|
)
|
||||||
|
.expect("Fill rectangle");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draws the stroke of the given [`Path`] on the [`Frame`] with the
|
/// Draws the stroke of the given [`Path`] on the [`Frame`] with the
|
||||||
/// provided style.
|
/// provided style.
|
||||||
pub fn stroke(&mut self, path: &Path, stroke: impl Into<Stroke>) {
|
pub fn stroke(&mut self, path: &Path, stroke: impl Into<Stroke>) {
|
||||||
use lyon::tessellation::{
|
|
||||||
BuffersBuilder, StrokeOptions, StrokeTessellator,
|
|
||||||
};
|
|
||||||
|
|
||||||
let stroke = stroke.into();
|
let stroke = stroke.into();
|
||||||
|
|
||||||
let mut buffers = BuffersBuilder::new(
|
let mut buffers = tessellation::BuffersBuilder::new(
|
||||||
&mut self.buffers,
|
&mut self.buffers,
|
||||||
StrokeVertex(stroke.color.into_linear()),
|
StrokeVertex(stroke.color.into_linear()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut tessellator = StrokeTessellator::new();
|
let mut options = tessellation::StrokeOptions::default();
|
||||||
|
|
||||||
let mut options = StrokeOptions::default();
|
|
||||||
options.line_width = stroke.width;
|
options.line_width = stroke.width;
|
||||||
options.start_cap = stroke.line_cap.into();
|
options.start_cap = stroke.line_cap.into();
|
||||||
options.end_cap = stroke.line_cap.into();
|
options.end_cap = stroke.line_cap.into();
|
||||||
options.line_join = stroke.line_join.into();
|
options.line_join = stroke.line_join.into();
|
||||||
|
|
||||||
let result = if self.transforms.current.is_identity {
|
let result = if self.transforms.current.is_identity {
|
||||||
tessellator.tessellate_path(path.raw(), &options, &mut buffers)
|
self.stroke_tessellator.tessellate_path(
|
||||||
|
path.raw(),
|
||||||
|
&options,
|
||||||
|
&mut buffers,
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
let path = path.transformed(&self.transforms.current.raw);
|
let path = path.transformed(&self.transforms.current.raw);
|
||||||
|
|
||||||
tessellator.tessellate_path(path.raw(), &options, &mut buffers)
|
self.stroke_tessellator.tessellate_path(
|
||||||
|
path.raw(),
|
||||||
|
&options,
|
||||||
|
&mut buffers,
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
let _ = result.expect("Stroke path");
|
let _ = result.expect("Stroke path");
|
||||||
|
|
@ -282,28 +297,15 @@ impl Frame {
|
||||||
|
|
||||||
struct FillVertex([f32; 4]);
|
struct FillVertex([f32; 4]);
|
||||||
|
|
||||||
impl lyon::tessellation::BasicVertexConstructor<triangle::Vertex2D>
|
|
||||||
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<triangle::Vertex2D>
|
impl lyon::tessellation::FillVertexConstructor<triangle::Vertex2D>
|
||||||
for FillVertex
|
for FillVertex
|
||||||
{
|
{
|
||||||
fn new_vertex(
|
fn new_vertex(
|
||||||
&mut self,
|
&mut self,
|
||||||
position: lyon::math::Point,
|
vertex: lyon::tessellation::FillVertex<'_>,
|
||||||
_attributes: lyon::tessellation::FillAttributes<'_>,
|
|
||||||
) -> triangle::Vertex2D {
|
) -> triangle::Vertex2D {
|
||||||
|
let position = vertex.position();
|
||||||
|
|
||||||
triangle::Vertex2D {
|
triangle::Vertex2D {
|
||||||
position: [position.x, position.y],
|
position: [position.x, position.y],
|
||||||
color: self.0,
|
color: self.0,
|
||||||
|
|
@ -318,9 +320,10 @@ impl lyon::tessellation::StrokeVertexConstructor<triangle::Vertex2D>
|
||||||
{
|
{
|
||||||
fn new_vertex(
|
fn new_vertex(
|
||||||
&mut self,
|
&mut self,
|
||||||
position: lyon::math::Point,
|
vertex: lyon::tessellation::StrokeVertex<'_, '_>,
|
||||||
_attributes: lyon::tessellation::StrokeAttributes<'_, '_>,
|
|
||||||
) -> triangle::Vertex2D {
|
) -> triangle::Vertex2D {
|
||||||
|
let position = vertex.position();
|
||||||
|
|
||||||
triangle::Vertex2D {
|
triangle::Vertex2D {
|
||||||
position: [position.x, position.y],
|
position: [position.x, position.y],
|
||||||
color: self.0,
|
color: self.0,
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ impl Path {
|
||||||
transform: &lyon::math::Transform,
|
transform: &lyon::math::Transform,
|
||||||
) -> Path {
|
) -> Path {
|
||||||
Path {
|
Path {
|
||||||
raw: self.raw.transformed(transform),
|
raw: self.raw.clone().transformed(transform),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
use crate::canvas::path::{arc, Arc, Path};
|
use crate::canvas::path::{arc, Arc, Path};
|
||||||
|
|
||||||
use iced_native::{Point, Size};
|
use iced_native::{Point, Size};
|
||||||
use lyon::path::builder::{Build, FlatPathBuilder, PathBuilder, SvgBuilder};
|
use lyon::path::builder::SvgPathBuilder;
|
||||||
|
|
||||||
/// A [`Path`] builder.
|
/// A [`Path`] builder.
|
||||||
///
|
///
|
||||||
/// Once a [`Path`] is built, it can no longer be mutated.
|
/// Once a [`Path`] is built, it can no longer be mutated.
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
pub struct Builder {
|
pub struct Builder {
|
||||||
raw: lyon::path::builder::SvgPathBuilder<lyon::path::Builder>,
|
raw: lyon::path::builder::WithSvg<lyon::path::path::Builder>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Builder {
|
impl Builder {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue