diff options
author | 2023-05-29 21:09:17 +0200 | |
---|---|---|
committer | 2023-05-29 21:09:17 +0200 | |
commit | 75110b9c0e82f37f3c75ce276216db5dbcb4ff1b (patch) | |
tree | d559afb3868aa12132e5047d18cb95c1fb135595 /wgpu/src/geometry.rs | |
parent | fcb1b454368638209862aeb5db41bc5f7d6d51a7 (diff) | |
parent | 8ca7b884c0695e4e7a031ea1359ee733bdcaa8a4 (diff) | |
download | iced-75110b9c0e82f37f3c75ce276216db5dbcb4ff1b.tar.gz iced-75110b9c0e82f37f3c75ce276216db5dbcb4ff1b.tar.bz2 iced-75110b9c0e82f37f3c75ce276216db5dbcb4ff1b.zip |
Merge pull request #1871 from bungoboingo/fix/bg-gradient
[Fix] Make gradient pack fn public for iced_graphics::Gradient
Diffstat (limited to 'wgpu/src/geometry.rs')
-rw-r--r-- | wgpu/src/geometry.rs | 46 |
1 files changed, 4 insertions, 42 deletions
diff --git a/wgpu/src/geometry.rs b/wgpu/src/geometry.rs index d1d4fd3c..740ec20c 100644 --- a/wgpu/src/geometry.rs +++ b/wgpu/src/geometry.rs @@ -7,6 +7,7 @@ use crate::graphics::geometry::{ use crate::graphics::primitive::{self, Primitive}; use crate::graphics::Gradient; +use iced_graphics::gradient; use lyon::geom::euclid; use lyon::tessellation; use std::borrow::Cow; @@ -74,7 +75,7 @@ impl BufferStack { Box::new(tessellation::BuffersBuilder::new( buffer, GradientVertex2DBuilder { - gradient: pack_gradient(gradient), + gradient: gradient.pack(), }, )) } @@ -97,7 +98,7 @@ impl BufferStack { Box::new(tessellation::BuffersBuilder::new( buffer, GradientVertex2DBuilder { - gradient: pack_gradient(gradient), + gradient: gradient.pack(), }, )) } @@ -490,7 +491,7 @@ impl Frame { } struct GradientVertex2DBuilder { - gradient: [f32; 44], + gradient: gradient::Packed, } impl tessellation::FillVertexConstructor<primitive::GradientVertex2D> @@ -623,42 +624,3 @@ pub(super) fn dashed(path: &Path, line_dash: LineDash<'_>) -> Path { ); }) } - -/// Packs the [`Gradient`] for use in shader code. -fn pack_gradient(gradient: &Gradient) -> [f32; 44] { - match gradient { - Gradient::Linear(linear) => { - let mut pack: [f32; 44] = [0.0; 44]; - let mut offsets: [f32; 8] = [2.0; 8]; - - for (index, stop) in linear.stops.iter().enumerate() { - let [r, g, b, a] = stop - .map_or(crate::core::Color::default(), |s| s.color) - .into_linear(); - - pack[index * 4] = r; - pack[(index * 4) + 1] = g; - pack[(index * 4) + 2] = b; - pack[(index * 4) + 3] = a; - - offsets[index] = stop.map_or(2.0, |s| s.offset); - } - - pack[32] = offsets[0]; - pack[33] = offsets[1]; - pack[34] = offsets[2]; - pack[35] = offsets[3]; - pack[36] = offsets[4]; - pack[37] = offsets[5]; - pack[38] = offsets[6]; - pack[39] = offsets[7]; - - pack[40] = linear.start.x; - pack[41] = linear.start.y; - pack[42] = linear.end.x; - pack[43] = linear.end.y; - - pack - } - } -} |