diff options
author | 2022-02-04 14:44:08 +0700 | |
---|---|---|
committer | 2022-02-04 14:44:08 +0700 | |
commit | c15701581e52ae838f8e7153ae7e639dd86b1ef6 (patch) | |
tree | 27be3d4b7fa56b3b72b9265c07907b1349d07c37 /graphics/src/widget/canvas/stroke.rs | |
parent | 74a64d88e1b5b4173fa15c30506aece19ea368d0 (diff) | |
parent | bace264bfe5e3cb5046867bd411e54969a637c79 (diff) | |
download | iced-c15701581e52ae838f8e7153ae7e639dd86b1ef6.tar.gz iced-c15701581e52ae838f8e7153ae7e639dd86b1ef6.tar.bz2 iced-c15701581e52ae838f8e7153ae7e639dd86b1ef6.zip |
Merge pull request #1225 from tarkah/feat/canvas-line-dash
Add line dash API
Diffstat (limited to 'graphics/src/widget/canvas/stroke.rs')
-rw-r--r-- | graphics/src/widget/canvas/stroke.rs | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/graphics/src/widget/canvas/stroke.rs b/graphics/src/widget/canvas/stroke.rs index 9f0449d0..6accc2fb 100644 --- a/graphics/src/widget/canvas/stroke.rs +++ b/graphics/src/widget/canvas/stroke.rs @@ -2,7 +2,7 @@ use iced_native::Color; /// The style of a stroke. #[derive(Debug, Clone, Copy)] -pub struct Stroke { +pub struct Stroke<'a> { /// The color of the stroke. pub color: Color, /// The distance between the two edges of the stroke. @@ -12,37 +12,40 @@ pub struct Stroke { /// The shape to be used at the corners of paths or basic shapes when they /// are stroked. pub line_join: LineJoin, + /// The dash pattern used when stroking the line. + pub line_dash: LineDash<'a>, } -impl Stroke { +impl<'a> Stroke<'a> { /// Sets the color of the [`Stroke`]. - pub fn with_color(self, color: Color) -> Stroke { + pub fn with_color(self, color: Color) -> Self { Stroke { color, ..self } } /// Sets the width of the [`Stroke`]. - pub fn with_width(self, width: f32) -> Stroke { + pub fn with_width(self, width: f32) -> Self { Stroke { width, ..self } } /// Sets the [`LineCap`] of the [`Stroke`]. - pub fn with_line_cap(self, line_cap: LineCap) -> Stroke { + pub fn with_line_cap(self, line_cap: LineCap) -> Self { Stroke { line_cap, ..self } } /// Sets the [`LineJoin`] of the [`Stroke`]. - pub fn with_line_join(self, line_join: LineJoin) -> Stroke { + pub fn with_line_join(self, line_join: LineJoin) -> Self { Stroke { line_join, ..self } } } -impl Default for Stroke { - fn default() -> Stroke { +impl<'a> Default for Stroke<'a> { + fn default() -> Self { Stroke { color: Color::BLACK, width: 1.0, line_cap: LineCap::default(), line_join: LineJoin::default(), + line_dash: LineDash::default(), } } } @@ -103,3 +106,13 @@ impl From<LineJoin> for lyon::tessellation::LineJoin { } } } + +/// The dash pattern used when stroking the line. +#[derive(Debug, Clone, Copy, Default)] +pub struct LineDash<'a> { + /// The alternating lengths of lines and gaps which describe the pattern. + pub segments: &'a [f32], + + /// The offset of [`LineDash::segments`] to start the pattern. + pub offset: usize, +} |