From e835cea03c5d6eeba2d76b52206516dcc2a6b628 Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Thu, 27 Jan 2022 09:40:52 -0800 Subject: Add line dash API --- graphics/src/widget/canvas/stroke.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'graphics/src/widget/canvas/stroke.rs') diff --git a/graphics/src/widget/canvas/stroke.rs b/graphics/src/widget/canvas/stroke.rs index 9f0449d0..5c20405e 100644 --- a/graphics/src/widget/canvas/stroke.rs +++ b/graphics/src/widget/canvas/stroke.rs @@ -1,7 +1,7 @@ use iced_native::Color; /// The style of a stroke. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone)] pub struct Stroke { /// The color of the stroke. pub color: Color, @@ -12,6 +12,8 @@ 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, } impl Stroke { @@ -43,6 +45,7 @@ impl Default for Stroke { width: 1.0, line_cap: LineCap::default(), line_join: LineJoin::default(), + line_dash: LineDash::default(), } } } @@ -103,3 +106,12 @@ impl From for lyon::tessellation::LineJoin { } } } + +/// The dash pattern used when stroking the line. +#[derive(Debug, Clone, Default)] +pub struct LineDash { + /// The alternating lengths of lines and gaps which describe the pattern. + pub segments: Vec, + /// The offset of [`LineDash::segments`] to start the pattern. + pub offset: usize, +} -- cgit From f56c8a7361ceb215bce68e88bd6ce402e2694693 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 3 Feb 2022 17:18:05 +0700 Subject: Ask for a slice of segments instead of ownership in `LineDash` --- graphics/src/widget/canvas/stroke.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'graphics/src/widget/canvas/stroke.rs') diff --git a/graphics/src/widget/canvas/stroke.rs b/graphics/src/widget/canvas/stroke.rs index 5c20405e..6accc2fb 100644 --- a/graphics/src/widget/canvas/stroke.rs +++ b/graphics/src/widget/canvas/stroke.rs @@ -1,8 +1,8 @@ use iced_native::Color; /// The style of a stroke. -#[derive(Debug, Clone)] -pub struct Stroke { +#[derive(Debug, Clone, Copy)] +pub struct Stroke<'a> { /// The color of the stroke. pub color: Color, /// The distance between the two edges of the stroke. @@ -13,33 +13,33 @@ pub struct Stroke { /// are stroked. pub line_join: LineJoin, /// The dash pattern used when stroking the line. - pub line_dash: LineDash, + 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, @@ -108,10 +108,11 @@ impl From for lyon::tessellation::LineJoin { } /// The dash pattern used when stroking the line. -#[derive(Debug, Clone, Default)] -pub struct LineDash { +#[derive(Debug, Clone, Copy, Default)] +pub struct LineDash<'a> { /// The alternating lengths of lines and gaps which describe the pattern. - pub segments: Vec, + pub segments: &'a [f32], + /// The offset of [`LineDash::segments`] to start the pattern. pub offset: usize, } -- cgit