From 9c7bf417ac9c1ac72bcc55aa3cd5e8eb962243a2 Mon Sep 17 00:00:00 2001 From: shan Date: Thu, 6 Oct 2022 16:57:38 -0700 Subject: Added support for gradients to respect current frame transform. --- graphics/src/gradient.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'graphics/src/gradient.rs') diff --git a/graphics/src/gradient.rs b/graphics/src/gradient.rs index 13600fb9..683a7413 100644 --- a/graphics/src/gradient.rs +++ b/graphics/src/gradient.rs @@ -1,9 +1,10 @@ //! For creating a Gradient. mod linear; -use iced_native::Color; pub use crate::gradient::linear::Linear; +use crate::widget::canvas::frame::Transform; use crate::Point; +use iced_native::Color; #[derive(Debug, Clone, PartialEq)] /// A fill which transitions colors progressively along a direction, either linearly, radially (TBD), @@ -28,4 +29,15 @@ impl Gradient { pub fn linear(start: Point, end: Point) -> linear::Builder { linear::Builder::new(start, end) } + + /// Modifies the start & end stops of the gradient to have a proper transform value. + pub(crate) fn transform(mut self, transform: &Transform) -> Self { + match &mut self { + Gradient::Linear(linear) => { + linear.start = transform.apply_to(linear.start); + linear.end = transform.apply_to(linear.end); + } + } + self + } } -- cgit