summaryrefslogtreecommitdiffstats
path: root/graphics/src
diff options
context:
space:
mode:
authorLibravatar shan <shankern@protonmail.com>2022-10-06 08:04:43 -0700
committerLibravatar shan <shankern@protonmail.com>2022-10-06 08:04:43 -0700
commitf4878a1a66a2e95e9430a8ccee8da823d2cb17ff (patch)
tree5e392ea5de10a636970cfc302704201bab0729d4 /graphics/src
parentcb7c4676543cd508dfae8d4dcbd9cc8b61b1a94e (diff)
downloadiced-f4878a1a66a2e95e9430a8ccee8da823d2cb17ff.tar.gz
iced-f4878a1a66a2e95e9430a8ccee8da823d2cb17ff.tar.bz2
iced-f4878a1a66a2e95e9430a8ccee8da823d2cb17ff.zip
Changed tesselation functions to take Vertex2D builder instead of using lyon's builtin Point type to avoid extra copies.
Diffstat (limited to 'graphics/src')
-rw-r--r--graphics/src/widget/canvas/frame.rs48
1 files changed, 31 insertions, 17 deletions
diff --git a/graphics/src/widget/canvas/frame.rs b/graphics/src/widget/canvas/frame.rs
index 6517d62a..427a2e2a 100644
--- a/graphics/src/widget/canvas/frame.rs
+++ b/graphics/src/widget/canvas/frame.rs
@@ -9,7 +9,6 @@ use crate::Primitive;
use crate::layer::mesh;
use crate::triangle::Vertex2D;
use lyon::tessellation;
-use lyon::tessellation::geometry_builder::Positions;
/// The frame of a [`Canvas`].
///
@@ -17,10 +16,7 @@ use lyon::tessellation::geometry_builder::Positions;
#[allow(missing_debug_implementations)]
pub struct Frame {
size: Size,
- buffers: Vec<(
- tessellation::VertexBuffers<lyon::math::Point, u32>,
- mesh::Style,
- )>,
+ buffers: Vec<(tessellation::VertexBuffers<Vertex2D, u32>, mesh::Style)>,
primitives: Vec<Primitive>,
transforms: Transforms,
fill_tessellator: tessellation::FillTessellator,
@@ -93,7 +89,7 @@ impl Frame {
let mut buf = tessellation::VertexBuffers::new();
let mut buffers =
- tessellation::BuffersBuilder::new(&mut buf, Positions);
+ tessellation::BuffersBuilder::new(&mut buf, Vertex2DBuilder);
let options =
tessellation::FillOptions::default().with_fill_rule(rule.into());
@@ -131,7 +127,7 @@ impl Frame {
let mut buf = tessellation::VertexBuffers::new();
let mut buffers =
- tessellation::BuffersBuilder::new(&mut buf, Positions);
+ tessellation::BuffersBuilder::new(&mut buf, Vertex2DBuilder);
let top_left =
self.transforms.current.raw.transform_point(
@@ -165,7 +161,7 @@ impl Frame {
let mut buf = tessellation::VertexBuffers::new();
let mut buffers =
- tessellation::BuffersBuilder::new(&mut buf, Positions);
+ tessellation::BuffersBuilder::new(&mut buf, Vertex2DBuilder);
let mut options = tessellation::StrokeOptions::default();
options.line_width = stroke.width;
@@ -342,7 +338,7 @@ impl Frame {
if !buffer.indices.is_empty() {
self.primitives.push(Primitive::Mesh2D {
buffers: triangle::Mesh2D {
- vertices: vertices_from(buffer.vertices),
+ vertices: buffer.vertices,
indices: buffer.indices,
},
size: self.size,
@@ -355,12 +351,30 @@ impl Frame {
}
}
-/// Converts from [`lyon::math::Point`] to [`Vertex2D`]. Used for generating primitives.
-fn vertices_from(points: Vec<lyon::math::Point>) -> Vec<Vertex2D> {
- points
- .iter()
- .map(|p| Vertex2D {
- position: [p.x, p.y],
- })
- .collect()
+struct Vertex2DBuilder;
+
+impl tessellation::FillVertexConstructor<Vertex2D> for Vertex2DBuilder {
+ fn new_vertex(
+ &mut self,
+ vertex: tessellation::FillVertex<'_>,
+ ) -> Vertex2D {
+ let position = vertex.position();
+
+ Vertex2D {
+ position: [position.x, position.y],
+ }
+ }
}
+
+impl tessellation::StrokeVertexConstructor<Vertex2D> for Vertex2DBuilder {
+ fn new_vertex(
+ &mut self,
+ vertex: tessellation::StrokeVertex<'_, '_>,
+ ) -> Vertex2D {
+ let position = vertex.position();
+
+ Vertex2D {
+ position: [position.x, position.y],
+ }
+ }
+} \ No newline at end of file