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 From 365f37a3ae10e7aff407b84050f77da10820866e Mon Sep 17 00:00:00 2001 From: bungoboingo Date: Thu, 10 Nov 2022 14:43:38 -0800 Subject: Added conditional configurations for WASM target for gradients & storage buffers, since storage buffers are not supported on wgpu WASM target at the moment. --- graphics/src/triangle.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'graphics/src/triangle.rs') diff --git a/graphics/src/triangle.rs b/graphics/src/triangle.rs index 04ff6d21..8b41bfc4 100644 --- a/graphics/src/triangle.rs +++ b/graphics/src/triangle.rs @@ -1,5 +1,7 @@ //! Draw geometry using meshes of triangles. -use crate::{Color, Gradient}; +use crate::Color; +#[cfg(not(target_arch = "wasm32"))] +use crate::Gradient; use bytemuck::{Pod, Zeroable}; @@ -27,6 +29,7 @@ pub struct Vertex2D { pub enum Style { /// Fill a primitive with a solid color. Solid(Color), + #[cfg(not(target_arch = "wasm32"))] /// Fill a primitive with an interpolated color. Gradient(Gradient), } @@ -37,6 +40,7 @@ impl From for Style { } } +#[cfg(not(target_arch = "wasm32"))] impl From for Style { fn from(gradient: Gradient) -> Self { Self::Gradient(gradient) -- cgit From 33c3c0c0aa774bb7462e3c42aa04c591a66376a7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 14 Nov 2022 00:02:42 +0100 Subject: Group all solid triangles independently of color --- graphics/src/triangle.rs | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) (limited to 'graphics/src/triangle.rs') diff --git a/graphics/src/triangle.rs b/graphics/src/triangle.rs index 8b41bfc4..f52b2339 100644 --- a/graphics/src/triangle.rs +++ b/graphics/src/triangle.rs @@ -1,15 +1,12 @@ //! Draw geometry using meshes of triangles. -use crate::Color; -#[cfg(not(target_arch = "wasm32"))] -use crate::Gradient; - use bytemuck::{Pod, Zeroable}; /// A set of [`Vertex2D`] and indices representing a list of triangles. #[derive(Clone, Debug)] -pub struct Mesh2D { +pub struct Mesh2D { /// The vertices of the mesh - pub vertices: Vec, + 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. @@ -24,25 +21,13 @@ pub struct Vertex2D { 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), - #[cfg(not(target_arch = "wasm32"))] - /// Fill a primitive with an interpolated color. - Gradient(Gradient), -} - -impl From for Style { - fn from(color: Color) -> Self { - Self::Solid(color) - } -} +/// A two-dimensional vertex with a color. +#[derive(Copy, Clone, Debug, Zeroable, Pod)] +#[repr(C)] +pub struct ColoredVertex2D { + /// The vertex position in 2D space. + pub position: [f32; 2], -#[cfg(not(target_arch = "wasm32"))] -impl From for Style { - fn from(gradient: Gradient) -> Self { - Self::Gradient(gradient) - } + /// The color of the vertex in __linear__ RGBA. + pub color: [f32; 4], } -- cgit