summaryrefslogtreecommitdiffstats
path: root/graphics/src/widget/canvas/fill.rs
diff options
context:
space:
mode:
authorLibravatar shan <shankern@protonmail.com>2022-09-29 10:52:58 -0700
committerLibravatar shan <shankern@protonmail.com>2022-09-29 11:15:35 -0700
commit40f45d7b7e35dd4937abe6b5ce16b6256b4f1eeb (patch)
tree38ffc5dd6bae5da4da3b93664dfe27e024dfa261 /graphics/src/widget/canvas/fill.rs
parent97f385e093711c269df315b28f76e66e0220e22a (diff)
downloadiced-40f45d7b7e35dd4937abe6b5ce16b6256b4f1eeb.tar.gz
iced-40f45d7b7e35dd4937abe6b5ce16b6256b4f1eeb.tar.bz2
iced-40f45d7b7e35dd4937abe6b5ce16b6256b4f1eeb.zip
Adds linear gradient support to 2D meshes in the canvas widget.
Diffstat (limited to 'graphics/src/widget/canvas/fill.rs')
-rw-r--r--graphics/src/widget/canvas/fill.rs33
1 files changed, 22 insertions, 11 deletions
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<Color> for Fill {
- fn from(color: Color) -> Fill {
+impl<'a> From<Color> 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.
///