summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/clock/src/main.rs4
-rw-r--r--examples/solar_system/src/main.rs2
-rw-r--r--graphics/src/widget/canvas/frame.rs2
-rw-r--r--graphics/src/widget/canvas/path.rs17
-rw-r--r--graphics/src/widget/canvas/stroke.rs27
5 files changed, 26 insertions, 26 deletions
diff --git a/examples/clock/src/main.rs b/examples/clock/src/main.rs
index fce57cc0..325ccc1a 100644
--- a/examples/clock/src/main.rs
+++ b/examples/clock/src/main.rs
@@ -100,14 +100,14 @@ impl canvas::Program<Message> for Clock {
let wide_stroke = Stroke {
width: thin_stroke.width * 3.0,
- ..thin_stroke.clone()
+ ..thin_stroke
};
frame.translate(Vector::new(center.x, center.y));
frame.with_save(|frame| {
frame.rotate(hand_rotation(self.now.hour(), 12));
- frame.stroke(&short_hand, wide_stroke.clone());
+ frame.stroke(&short_hand, wide_stroke);
});
frame.with_save(|frame| {
diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs
index fb782d9c..12184dd1 100644
--- a/examples/solar_system/src/main.rs
+++ b/examples/solar_system/src/main.rs
@@ -165,7 +165,7 @@ impl<Message> canvas::Program<Message> for State {
color: Color::from_rgba8(0, 153, 255, 0.1),
line_dash: canvas::LineDash {
offset: 0,
- segments: vec![3.0, 6.0],
+ segments: &[3.0, 6.0],
},
..Stroke::default()
},
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<Stroke>) {
+ pub fn stroke<'a>(&mut self, path: &Path, stroke: impl Into<Stroke<'a>>) {
let stroke = stroke.into();
let mut buffers = tessellation::BuffersBuilder::new(
diff --git a/graphics/src/widget/canvas/path.rs b/graphics/src/widget/canvas/path.rs
index bc258b67..cb7e5035 100644
--- a/graphics/src/widget/canvas/path.rs
+++ b/graphics/src/widget/canvas/path.rs
@@ -71,15 +71,11 @@ impl Path {
}
}
-pub(super) fn dashed(path: &Path, line_dash: LineDash) -> Path {
+pub(super) fn dashed(path: &Path, line_dash: LineDash<'_>) -> Path {
Path::new(|builder| {
- let segments_odd = line_dash.segments.len() % 2 == 1;
-
- let segments = segments_odd
- .then(|| {
- [&line_dash.segments[..], &line_dash.segments[..]].concat()
- })
- .unwrap_or(line_dash.segments);
+ let segments_odd = (line_dash.segments.len() % 2 == 1).then(|| {
+ [&line_dash.segments[..], &line_dash.segments[..]].concat()
+ });
let mut draw_line = false;
@@ -106,7 +102,10 @@ pub(super) fn dashed(path: &Path, line_dash: LineDash) -> Path {
true
},
index: line_dash.offset,
- intervals: &segments,
+ intervals: segments_odd
+ .as_ref()
+ .map(Vec::as_slice)
+ .unwrap_or(line_dash.segments),
},
);
})
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<LineJoin> 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<f32>,
+ pub segments: &'a [f32],
+
/// The offset of [`LineDash::segments`] to start the pattern.
pub offset: usize,
}