summaryrefslogtreecommitdiffstats
path: root/graphics/src/primitive.rs
diff options
context:
space:
mode:
authorLibravatar Bingus <shankern@protonmail.com>2023-05-11 09:12:06 -0700
committerLibravatar Bingus <shankern@protonmail.com>2023-05-11 11:13:44 -0700
commit6551a0b2ab6c831dd1d3646ecf55180339275e22 (patch)
treede1e4a85b3176f94fd006fed190ef035d3202e49 /graphics/src/primitive.rs
parent669f7cc74b2e7918e86a8197916f503f2d3d9b93 (diff)
downloadiced-6551a0b2ab6c831dd1d3646ecf55180339275e22.tar.gz
iced-6551a0b2ab6c831dd1d3646ecf55180339275e22.tar.bz2
iced-6551a0b2ab6c831dd1d3646ecf55180339275e22.zip
Added support for gradients as background variants + other optimizations.
Diffstat (limited to 'graphics/src/primitive.rs')
-rw-r--r--graphics/src/primitive.rs32
1 files changed, 19 insertions, 13 deletions
diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs
index d4446c87..9728db39 100644
--- a/graphics/src/primitive.rs
+++ b/graphics/src/primitive.rs
@@ -3,7 +3,7 @@ use crate::core::alignment;
use crate::core::image;
use crate::core::svg;
use crate::core::text;
-use crate::core::{Background, Color, Font, Gradient, Rectangle, Size, Vector};
+use crate::core::{Background, Color, Font, Rectangle, Size, Vector};
use bytemuck::{Pod, Zeroable};
use std::sync::Arc;
@@ -39,7 +39,7 @@ pub enum Primitive {
bounds: Rectangle,
/// The background of the quad
background: Background,
- /// The border radius of the quad
+ /// The border radii of the quad
border_radius: [f32; 4],
/// The border width of the quad
border_width: f32,
@@ -81,15 +81,12 @@ pub enum Primitive {
/// It can be used to render many kinds of geometry freely.
GradientMesh {
/// The vertices and indices of the mesh.
- buffers: Mesh2D<Vertex2D>,
+ buffers: Mesh2D<GradientVertex2D>,
/// The size of the drawable region of the mesh.
///
/// Any geometry that falls out of this region will be clipped.
size: Size,
-
- /// The [`Gradient`] to apply to the mesh.
- gradient: Gradient,
},
/// A [`tiny_skia`] path filled with some paint.
#[cfg(feature = "tiny-skia")]
@@ -242,25 +239,34 @@ pub struct Mesh2D<T> {
pub indices: Vec<u32>,
}
-/// A two-dimensional vertex.
+/// A two-dimensional vertex with a color.
#[derive(Copy, Clone, Debug, PartialEq, Zeroable, Pod)]
#[repr(C)]
-pub struct Vertex2D {
+pub struct ColoredVertex2D {
/// The vertex position in 2D space.
pub position: [f32; 2],
+
+ /// The color of the vertex in __linear__ RGBA.
+ pub color: [f32; 4],
}
-/// A two-dimensional vertex with a color.
-#[derive(Copy, Clone, Debug, PartialEq, Zeroable, Pod)]
+/// A vertex which contains 2D position & packed gradient data.
+#[derive(Copy, Clone, Debug, PartialEq)]
#[repr(C)]
-pub struct ColoredVertex2D {
+pub struct GradientVertex2D {
/// The vertex position in 2D space.
pub position: [f32; 2],
- /// The color of the vertex in __linear__ RGBA.
- pub color: [f32; 4],
+ /// The packed vertex data of the gradient.
+ pub gradient: [f32; 44],
}
+#[allow(unsafe_code)]
+unsafe impl Zeroable for GradientVertex2D {}
+
+#[allow(unsafe_code)]
+unsafe impl Pod for GradientVertex2D {}
+
impl From<()> for Primitive {
fn from(_: ()) -> Self {
Self::Group { primitives: vec![] }