summaryrefslogtreecommitdiffstats
path: root/graphics/src/widget/canvas
diff options
context:
space:
mode:
authorLibravatar shan <shankern@protonmail.com>2022-10-05 10:49:58 -0700
committerLibravatar shan <shankern@protonmail.com>2022-10-05 10:49:58 -0700
commit30432cbade3d9b25c4df62656a7494db3f4ea82a (patch)
tree186ca59e50caede84ede2e2381dc01dd0483806b /graphics/src/widget/canvas
parent6e7b3ced0b1daf368e44e181ecdb4ae529877eb6 (diff)
downloadiced-30432cbade3d9b25c4df62656a7494db3f4ea82a.tar.gz
iced-30432cbade3d9b25c4df62656a7494db3f4ea82a.tar.bz2
iced-30432cbade3d9b25c4df62656a7494db3f4ea82a.zip
Readjusted namespaces, removed Geometry example as it's no longer relevant.
Diffstat (limited to 'graphics/src/widget/canvas')
-rw-r--r--graphics/src/widget/canvas/fill.rs16
-rw-r--r--graphics/src/widget/canvas/frame.rs32
-rw-r--r--graphics/src/widget/canvas/stroke.rs10
3 files changed, 37 insertions, 21 deletions
diff --git a/graphics/src/widget/canvas/fill.rs b/graphics/src/widget/canvas/fill.rs
index 6f10505c..55cb3966 100644
--- a/graphics/src/widget/canvas/fill.rs
+++ b/graphics/src/widget/canvas/fill.rs
@@ -1,6 +1,8 @@
-use iced_native::Color;
+//! Fill [crate::widget::canvas::Geometry] with a certain style.
+
use crate::gradient::Gradient;
-use crate::shader::Shader;
+use crate::layer::mesh;
+use iced_native::Color;
/// The style used to fill geometry.
#[derive(Debug, Clone)]
@@ -21,7 +23,7 @@ pub struct Fill<'a> {
pub rule: FillRule,
}
-impl <'a> Default for Fill<'a> {
+impl<'a> Default for Fill<'a> {
fn default() -> Fill<'a> {
Fill {
style: Style::Solid(Color::BLACK),
@@ -48,11 +50,11 @@ pub enum Style<'a> {
Gradient(&'a Gradient),
}
-impl <'a> Into<Shader> for Style<'a> {
- fn into(self) -> Shader {
+impl<'a> Into<mesh::Style> for Style<'a> {
+ fn into(self) -> mesh::Style {
match self {
- Style::Solid(color) => Shader::Solid(color),
- Style::Gradient(gradient) => gradient.clone().into()
+ Style::Solid(color) => mesh::Style::Solid(color),
+ Style::Gradient(gradient) => gradient.clone().into(),
}
}
}
diff --git a/graphics/src/widget/canvas/frame.rs b/graphics/src/widget/canvas/frame.rs
index 30239b2a..6517d62a 100644
--- a/graphics/src/widget/canvas/frame.rs
+++ b/graphics/src/widget/canvas/frame.rs
@@ -6,7 +6,7 @@ use crate::triangle;
use crate::widget::canvas::{path, Fill, Geometry, Path, Stroke, Text};
use crate::Primitive;
-use crate::shader::Shader;
+use crate::layer::mesh;
use crate::triangle::Vertex2D;
use lyon::tessellation;
use lyon::tessellation::geometry_builder::Positions;
@@ -17,7 +17,10 @@ use lyon::tessellation::geometry_builder::Positions;
#[allow(missing_debug_implementations)]
pub struct Frame {
size: Size,
- buffers: Vec<(tessellation::VertexBuffers<lyon::math::Point, u32>, Shader)>,
+ buffers: Vec<(
+ tessellation::VertexBuffers<lyon::math::Point, u32>,
+ mesh::Style,
+ )>,
primitives: Vec<Primitive>,
transforms: Transforms,
fill_tessellator: tessellation::FillTessellator,
@@ -109,7 +112,8 @@ impl Frame {
&options,
&mut buffers,
)
- }.expect("Tessellate path.");
+ }
+ .expect("Tessellate path.");
self.buffers.push((buf, style.into()))
}
@@ -126,7 +130,8 @@ impl Frame {
let mut buf = tessellation::VertexBuffers::new();
- let mut buffers = tessellation::BuffersBuilder::new(&mut buf, Positions);
+ let mut buffers =
+ tessellation::BuffersBuilder::new(&mut buf, Positions);
let top_left =
self.transforms.current.raw.transform_point(
@@ -159,7 +164,8 @@ impl Frame {
let mut buf = tessellation::VertexBuffers::new();
- let mut buffers = tessellation::BuffersBuilder::new(&mut buf, Positions);
+ let mut buffers =
+ tessellation::BuffersBuilder::new(&mut buf, Positions);
let mut options = tessellation::StrokeOptions::default();
options.line_width = stroke.width;
@@ -187,7 +193,8 @@ impl Frame {
&options,
&mut buffers,
)
- }.expect("Stroke path");
+ }
+ .expect("Stroke path");
self.buffers.push((buf, stroke.style.into()))
}
@@ -331,7 +338,7 @@ impl Frame {
}
fn into_primitives(mut self) -> Vec<Primitive> {
- for (buffer, shader) in self.buffers {
+ for (buffer, style) in self.buffers {
if !buffer.indices.is_empty() {
self.primitives.push(Primitive::Mesh2D {
buffers: triangle::Mesh2D {
@@ -339,7 +346,7 @@ impl Frame {
indices: buffer.indices,
},
size: self.size,
- shader,
+ style,
})
}
}
@@ -350,5 +357,10 @@ 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()
-} \ No newline at end of file
+ points
+ .iter()
+ .map(|p| Vertex2D {
+ position: [p.x, p.y],
+ })
+ .collect()
+}
diff --git a/graphics/src/widget/canvas/stroke.rs b/graphics/src/widget/canvas/stroke.rs
index 7ce5ff1d..a19937ea 100644
--- a/graphics/src/widget/canvas/stroke.rs
+++ b/graphics/src/widget/canvas/stroke.rs
@@ -1,6 +1,8 @@
+//! Create lines from a [crate::widget::canvas::Path] and render with various attributes/styles.
+
use iced_native::Color;
use crate::gradient::Gradient;
-use crate::shader::Shader;
+use crate::layer::mesh;
/// The style of a stroke.
#[derive(Debug, Clone)]
@@ -66,10 +68,10 @@ pub enum Style<'a> {
Gradient(&'a Gradient),
}
-impl <'a> Into<Shader> for Style<'a> {
- fn into(self) -> Shader {
+impl <'a> Into<mesh::Style> for Style<'a> {
+ fn into(self) -> mesh::Style {
match self {
- Style::Solid(color) => Shader::Solid(color),
+ Style::Solid(color) => mesh::Style::Solid(color),
Style::Gradient(gradient) => gradient.clone().into()
}
}