From 40f45d7b7e35dd4937abe6b5ce16b6256b4f1eeb Mon Sep 17 00:00:00 2001 From: shan Date: Thu, 29 Sep 2022 10:52:58 -0700 Subject: Adds linear gradient support to 2D meshes in the canvas widget. --- graphics/src/triangle.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'graphics/src/triangle.rs') diff --git a/graphics/src/triangle.rs b/graphics/src/triangle.rs index 05028f51..92709fe2 100644 --- a/graphics/src/triangle.rs +++ b/graphics/src/triangle.rs @@ -6,20 +6,22 @@ use bytemuck::{Pod, Zeroable}; pub struct Mesh2D { /// The vertices of the mesh pub vertices: Vec, - /// The list of vertex indices that defines the triangles of the mesh. - /// - /// Therefore, this list should always have a length that is a multiple of - /// 3. pub indices: Vec, } -/// A two-dimensional vertex with some color in __linear__ RGBA. +/// A two-dimensional vertex. #[derive(Copy, Clone, Debug, Zeroable, Pod)] #[repr(C)] pub struct Vertex2D { - /// The vertex position + /// The vertex position in 2D space. pub position: [f32; 2], - /// The vertex color in __linear__ RGBA. - pub color: [f32; 4], +} + +/// Convert from lyon's position data to Iced's Vertex2D type. +impl Vertex2D { + /// Converts from [`lyon::math::Point`] to [`Vertex2D`]. Used for generating primitives. + pub fn from(points: Vec) -> Vec { + points.iter().map(|p| Vertex2D { position: [p.x, p.y]}).collect() + } } -- cgit From 5d0fffc626928177239336757507b986b081b878 Mon Sep 17 00:00:00 2001 From: shan Date: Fri, 30 Sep 2022 10:27:00 -0700 Subject: Fixed some importing issues since you can use a Shader::Gradient outside a Canvas widget, where it was previously only accessible. --- graphics/src/triangle.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'graphics/src/triangle.rs') diff --git a/graphics/src/triangle.rs b/graphics/src/triangle.rs index 92709fe2..8f82c5df 100644 --- a/graphics/src/triangle.rs +++ b/graphics/src/triangle.rs @@ -16,12 +16,4 @@ pub struct Mesh2D { pub struct Vertex2D { /// The vertex position in 2D space. pub position: [f32; 2], -} - -/// Convert from lyon's position data to Iced's Vertex2D type. -impl Vertex2D { - /// Converts from [`lyon::math::Point`] to [`Vertex2D`]. Used for generating primitives. - pub fn from(points: Vec) -> Vec { - points.iter().map(|p| Vertex2D { position: [p.x, p.y]}).collect() - } -} +} \ No newline at end of file -- cgit From cb7c4676543cd508dfae8d4dcbd9cc8b61b1a94e Mon Sep 17 00:00:00 2001 From: shan Date: Thu, 6 Oct 2022 07:28:05 -0700 Subject: Fixed lint issues & cleaned up some documentation. --- graphics/src/triangle.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'graphics/src/triangle.rs') diff --git a/graphics/src/triangle.rs b/graphics/src/triangle.rs index 8f82c5df..f019d55d 100644 --- a/graphics/src/triangle.rs +++ b/graphics/src/triangle.rs @@ -16,4 +16,4 @@ pub struct Mesh2D { pub struct Vertex2D { /// The vertex position in 2D space. pub position: [f32; 2], -} \ No newline at end of file +} -- cgit From c4565759e4294540f54a81e4d91ddea7a769d3d4 Mon Sep 17 00:00:00 2001 From: bungoboingo Date: Tue, 18 Oct 2022 15:18:37 -0700 Subject: Cleaned up namespaces re: PR comments. --- graphics/src/triangle.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'graphics/src/triangle.rs') diff --git a/graphics/src/triangle.rs b/graphics/src/triangle.rs index f019d55d..39359cfb 100644 --- a/graphics/src/triangle.rs +++ b/graphics/src/triangle.rs @@ -7,6 +7,8 @@ pub struct Mesh2D { /// The vertices of the mesh pub vertices: Vec, /// The list of vertex indices that defines the triangles of the mesh. + /// + /// Therefore, this list should always have a length that is a multiple of 3. pub indices: Vec, } -- cgit From 84d1b79fefc88534835fdfbe79bc0eb3b43627cf Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 3 Nov 2022 05:50:53 +0100 Subject: Move `mesh::Style` to `triangle` and reuse it in `fill` and `stroke` --- graphics/src/triangle.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'graphics/src/triangle.rs') diff --git a/graphics/src/triangle.rs b/graphics/src/triangle.rs index 39359cfb..04ff6d21 100644 --- a/graphics/src/triangle.rs +++ b/graphics/src/triangle.rs @@ -1,4 +1,6 @@ //! Draw geometry using meshes of triangles. +use crate::{Color, Gradient}; + use bytemuck::{Pod, Zeroable}; /// A set of [`Vertex2D`] and indices representing a list of triangles. @@ -19,3 +21,24 @@ pub struct Vertex2D { /// The vertex position in 2D space. pub position: [f32; 2], } + +#[derive(Debug, Clone, PartialEq)] +/// Supported shaders for triangle primitives. +pub enum Style { + /// Fill a primitive with a solid color. + Solid(Color), + /// Fill a primitive with an interpolated color. + Gradient(Gradient), +} + +impl From for Style { + fn from(color: Color) -> Self { + Self::Solid(color) + } +} + +impl From for Style { + fn from(gradient: Gradient) -> Self { + Self::Gradient(gradient) + } +} -- cgit