summaryrefslogtreecommitdiffstats
path: root/graphics/src/widget/canvas/stroke.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/stroke.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/stroke.rs')
-rw-r--r--graphics/src/widget/canvas/stroke.rs26
1 files changed, 21 insertions, 5 deletions
diff --git a/graphics/src/widget/canvas/stroke.rs b/graphics/src/widget/canvas/stroke.rs
index 6accc2fb..c319b398 100644
--- a/graphics/src/widget/canvas/stroke.rs
+++ b/graphics/src/widget/canvas/stroke.rs
@@ -1,10 +1,14 @@
use iced_native::Color;
+use crate::widget::canvas::Gradient;
+
/// The style of a stroke.
-#[derive(Debug, Clone, Copy)]
+#[derive(Debug, Clone)]
pub struct Stroke<'a> {
- /// The color of the stroke.
- pub color: Color,
+ /// The color or gradient of the stroke.
+ ///
+ /// By default, it is set to [`StrokeStyle::Solid`] `BLACK`.
+ pub style: StrokeStyle<'a>,
/// The distance between the two edges of the stroke.
pub width: f32,
/// The shape to be used at the end of open subpaths when they are stroked.
@@ -19,7 +23,10 @@ pub struct Stroke<'a> {
impl<'a> Stroke<'a> {
/// Sets the color of the [`Stroke`].
pub fn with_color(self, color: Color) -> Self {
- Stroke { color, ..self }
+ Stroke {
+ style: StrokeStyle::Solid(color),
+ ..self
+ }
}
/// Sets the width of the [`Stroke`].
@@ -41,7 +48,7 @@ impl<'a> Stroke<'a> {
impl<'a> Default for Stroke<'a> {
fn default() -> Self {
Stroke {
- color: Color::BLACK,
+ style: StrokeStyle::Solid(Color::BLACK),
width: 1.0,
line_cap: LineCap::default(),
line_join: LineJoin::default(),
@@ -50,6 +57,15 @@ impl<'a> Default for Stroke<'a> {
}
}
+/// The color or gradient of a [`Stroke`].
+#[derive(Debug, Clone, Copy)]
+pub enum StrokeStyle<'a> {
+ /// A solid color
+ Solid(Color),
+ /// A color gradient
+ Gradient(&'a Gradient),
+}
+
/// The shape used at the end of open subpaths when they are stroked.
#[derive(Debug, Clone, Copy)]
pub enum LineCap {