summaryrefslogtreecommitdiffstats
path: root/tiny_skia/src/backend.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2023-05-19 04:37:58 +0200
committerLibravatar GitHub <noreply@github.com>2023-05-19 04:37:58 +0200
commitcc5d11f1a6fca90ea57e3fb3a69587c65281b6b9 (patch)
tree349d98171b467b7738874a5ef99ce536512c10eb /tiny_skia/src/backend.rs
parent8e8b1e1eacc4e2c19c9878625f423c8e09e2d3b9 (diff)
parentf7ed645eddd96f7964268367e24abcb5bb78a979 (diff)
downloadiced-cc5d11f1a6fca90ea57e3fb3a69587c65281b6b9.tar.gz
iced-cc5d11f1a6fca90ea57e3fb3a69587c65281b6b9.tar.bz2
iced-cc5d11f1a6fca90ea57e3fb3a69587c65281b6b9.zip
Merge pull request #1846 from bungoboingo/feat/background-gradients
[Feature] Gradients for Backgrounds
Diffstat (limited to 'tiny_skia/src/backend.rs')
-rw-r--r--tiny_skia/src/backend.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/tiny_skia/src/backend.rs b/tiny_skia/src/backend.rs
index 39bed555..9d0fc527 100644
--- a/tiny_skia/src/backend.rs
+++ b/tiny_skia/src/backend.rs
@@ -1,4 +1,5 @@
use crate::core::text;
+use crate::core::Gradient;
use crate::core::{Background, Color, Font, Point, Rectangle, Size, Vector};
use crate::graphics::backend;
use crate::graphics::{Primitive, Viewport};
@@ -184,6 +185,48 @@ impl Backend {
*color,
))
}
+ Background::Gradient(Gradient::Linear(linear)) => {
+ let (start, end) =
+ linear.angle.to_distance(bounds);
+
+ let stops: Vec<tiny_skia::GradientStop> =
+ linear
+ .stops
+ .into_iter()
+ .flatten()
+ .map(|stop| {
+ tiny_skia::GradientStop::new(
+ stop.offset,
+ tiny_skia::Color::from_rgba(
+ stop.color.b,
+ stop.color.g,
+ stop.color.r,
+ stop.color.a,
+ )
+ .expect("Create color"),
+ )
+ })
+ .collect();
+
+ tiny_skia::LinearGradient::new(
+ tiny_skia::Point {
+ x: start.x,
+ y: start.y,
+ },
+ tiny_skia::Point { x: end.x, y: end.y },
+ if stops.is_empty() {
+ vec![tiny_skia::GradientStop::new(
+ 0.0,
+ tiny_skia::Color::BLACK,
+ )]
+ } else {
+ stops
+ },
+ tiny_skia::SpreadMode::Pad,
+ tiny_skia::Transform::identity(),
+ )
+ .expect("Create linear gradient")
+ }
},
anti_alias: true,
..tiny_skia::Paint::default()