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/frame.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'graphics/src/widget/canvas/frame.rs') diff --git a/graphics/src/widget/canvas/frame.rs b/graphics/src/widget/canvas/frame.rs index 4873e7fb..b98c3002 100644 --- a/graphics/src/widget/canvas/frame.rs +++ b/graphics/src/widget/canvas/frame.rs @@ -1,6 +1,9 @@ +use std::borrow::Cow; + use iced_native::{Point, Rectangle, Size, Vector}; use crate::{ + canvas::path, canvas::{Fill, Geometry, Path, Stroke, Text}, triangle, Primitive, }; @@ -164,6 +167,12 @@ impl Frame { options.end_cap = stroke.line_cap.into(); options.line_join = stroke.line_join.into(); + let path = if stroke.line_dash.segments.is_empty() { + Cow::Borrowed(path) + } else { + Cow::Owned(path::dashed(path, stroke.line_dash)) + }; + let result = if self.transforms.current.is_identity { self.stroke_tessellator.tessellate_path( path.raw(), -- 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/frame.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'graphics/src/widget/canvas/frame.rs') diff --git a/graphics/src/widget/canvas/frame.rs b/graphics/src/widget/canvas/frame.rs index b98c3002..357dfa62 100644 --- a/graphics/src/widget/canvas/frame.rs +++ b/graphics/src/widget/canvas/frame.rs @@ -153,7 +153,7 @@ impl Frame { /// Draws the stroke of the given [`Path`] on the [`Frame`] with the /// provided style. - pub fn stroke(&mut self, path: &Path, stroke: impl Into) { + pub fn stroke<'a>(&mut self, path: &Path, stroke: impl Into>) { let stroke = stroke.into(); let mut buffers = tessellation::BuffersBuilder::new( -- cgit