summaryrefslogtreecommitdiffstats
path: root/graphics/src/widget
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/src/widget')
-rw-r--r--graphics/src/widget/canvas.rs8
-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
4 files changed, 42 insertions, 24 deletions
diff --git a/graphics/src/widget/canvas.rs b/graphics/src/widget/canvas.rs
index f6929e97..6ed3a12f 100644
--- a/graphics/src/widget/canvas.rs
+++ b/graphics/src/widget/canvas.rs
@@ -9,17 +9,17 @@ pub mod path;
mod cache;
mod cursor;
-mod fill;
mod frame;
mod geometry;
mod program;
-mod stroke;
mod text;
+pub mod fill;
+pub mod stroke;
pub use cache::Cache;
pub use cursor::Cursor;
pub use event::Event;
-pub use fill::{Fill, FillRule, Style};
+pub use fill::{Fill, FillRule};
pub use frame::Frame;
pub use geometry::Geometry;
pub use path::Path;
@@ -37,6 +37,8 @@ use iced_native::{
Clipboard, Element, Length, Point, Rectangle, Shell, Size, Vector, Widget,
};
+pub use crate::gradient::Gradient;
+
use std::marker::PhantomData;
/// A widget capable of drawing 2D graphics.
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()
}
}