summaryrefslogtreecommitdiffstats
path: root/wgpu/src/layer.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2023-05-29 21:09:17 +0200
committerLibravatar GitHub <noreply@github.com>2023-05-29 21:09:17 +0200
commit75110b9c0e82f37f3c75ce276216db5dbcb4ff1b (patch)
treed559afb3868aa12132e5047d18cb95c1fb135595 /wgpu/src/layer.rs
parentfcb1b454368638209862aeb5db41bc5f7d6d51a7 (diff)
parent8ca7b884c0695e4e7a031ea1359ee733bdcaa8a4 (diff)
downloadiced-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 '')
-rw-r--r--wgpu/src/layer.rs32
1 files changed, 2 insertions, 30 deletions
diff --git a/wgpu/src/layer.rs b/wgpu/src/layer.rs
index 980d807b..bf5c4c0a 100644
--- a/wgpu/src/layer.rs
+++ b/wgpu/src/layer.rs
@@ -13,6 +13,7 @@ pub use text::Text;
use crate::core;
use crate::core::alignment;
use crate::core::{Background, Color, Font, Point, Rectangle, Size, Vector};
+use crate::graphics::gradient;
use crate::graphics::{Primitive, Viewport};
/// A group of primitives that should be clipped together.
@@ -182,7 +183,7 @@ impl<'a> Layer<'a> {
}
Background::Gradient(gradient) => {
let quad = quad::Gradient {
- gradient: pack_gradient(
+ gradient: gradient::pack(
gradient,
Rectangle::new(
quad.position.into(),
@@ -310,32 +311,3 @@ impl<'a> Layer<'a> {
}
}
}
-
-/// Packs the [`Gradient`] for use in shader code.
-fn pack_gradient(gradient: &core::Gradient, bounds: Rectangle) -> [f32; 44] {
- match gradient {
- core::Gradient::Linear(linear) => {
- let mut pack: [f32; 44] = [0.0; 44];
-
- for (index, stop) in linear.stops.iter().enumerate() {
- let [r, g, b, a] =
- stop.map_or(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;
- pack[32 + index] = stop.map_or(2.0, |s| s.offset);
- }
-
- let (start, end) = linear.angle.to_distance(&bounds);
-
- pack[40] = start.x;
- pack[41] = start.y;
- pack[42] = end.x;
- pack[43] = end.y;
-
- pack
- }
- }
-}