From 40f45d7b7e35dd4937abe6b5ce16b6256b4f1eeb Mon Sep 17 00:00:00 2001 From: shan Date: Thu, 29 Sep 2022 10:52:58 -0700 Subject: Adds linear gradient support to 2D meshes in the canvas widget. --- graphics/src/widget/canvas/fill.rs | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'graphics/src/widget/canvas/fill.rs') diff --git a/graphics/src/widget/canvas/fill.rs b/graphics/src/widget/canvas/fill.rs index 56495435..02d2311f 100644 --- a/graphics/src/widget/canvas/fill.rs +++ b/graphics/src/widget/canvas/fill.rs @@ -1,12 +1,14 @@ use iced_native::Color; +use crate::widget::canvas::Gradient; + /// The style used to fill geometry. -#[derive(Debug, Clone, Copy)] -pub struct Fill { - /// The color used to fill geometry. +#[derive(Debug, Clone)] +pub struct Fill<'a> { + /// The color or gradient of the fill. /// - /// By default, it is set to `BLACK`. - pub color: Color, + /// By default, it is set to [`FillStyle::Solid`] `BLACK`. + pub style: FillStyle<'a>, /// The fill rule defines how to determine what is inside and what is /// outside of a shape. @@ -19,24 +21,33 @@ pub struct Fill { pub rule: FillRule, } -impl Default for Fill { - fn default() -> Fill { +impl <'a> Default for Fill<'a> { + fn default() -> Fill<'a> { Fill { - color: Color::BLACK, + style: FillStyle::Solid(Color::BLACK), rule: FillRule::NonZero, } } } -impl From for Fill { - fn from(color: Color) -> Fill { +impl<'a> From for Fill<'a> { + fn from(color: Color) -> Fill<'a> { Fill { - color, + style: FillStyle::Solid(color), ..Fill::default() } } } +/// The color or gradient of a [`Fill`]. +#[derive(Debug, Clone)] +pub enum FillStyle<'a> { + /// A solid color + Solid(Color), + /// A color gradient + Gradient(&'a Gradient), +} + /// The fill rule defines how to determine what is inside and what is outside of /// a shape. /// -- cgit