summaryrefslogtreecommitdiffstats
path: root/graphics/src/geometry/path.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2023-03-09 19:05:38 +0100
committerLibravatar GitHub <noreply@github.com>2023-03-09 19:05:38 +0100
commitcaf2836b1b15bff6e8a2ea72441d67f297eb8707 (patch)
tree0ffa0d1d604780999892b88de85ee93e3ed7d539 /graphics/src/geometry/path.rs
parent11b2c3bbe31a43e73a61b9bd9f022233f302ae27 (diff)
parent424ac8177309440bbd8efe0dd9f7622cb10807ce (diff)
downloadiced-caf2836b1b15bff6e8a2ea72441d67f297eb8707.tar.gz
iced-caf2836b1b15bff6e8a2ea72441d67f297eb8707.tar.bz2
iced-caf2836b1b15bff6e8a2ea72441d67f297eb8707.zip
Merge pull request #1748 from iced-rs/feature/software-renderer
Software renderer, runtime renderer fallback, and core consolidation
Diffstat (limited to '')
-rw-r--r--graphics/src/geometry/path.rs (renamed from graphics/src/widget/canvas/path.rs)52
1 files changed, 5 insertions, 47 deletions
diff --git a/graphics/src/widget/canvas/path.rs b/graphics/src/geometry/path.rs
index aeb2589e..c3127bdf 100644
--- a/graphics/src/widget/canvas/path.rs
+++ b/graphics/src/geometry/path.rs
@@ -7,18 +7,16 @@ mod builder;
pub use arc::Arc;
pub use builder::Builder;
-use crate::widget::canvas::LineDash;
+pub use lyon_path;
-use iced_native::{Point, Size};
-use lyon::algorithms::walk::{walk_along_path, RepeatedPattern, WalkerEvent};
-use lyon::path::iterator::PathIterator;
+use iced_core::{Point, Size};
/// An immutable set of points that may or may not be connected.
///
/// A single [`Path`] can represent different kinds of 2D shapes!
#[derive(Debug, Clone)]
pub struct Path {
- raw: lyon::path::Path,
+ raw: lyon_path::Path,
}
impl Path {
@@ -56,54 +54,14 @@ impl Path {
}
#[inline]
- pub(crate) fn raw(&self) -> &lyon::path::Path {
+ pub fn raw(&self) -> &lyon_path::Path {
&self.raw
}
#[inline]
- pub(crate) fn transformed(
- &self,
- transform: &lyon::math::Transform,
- ) -> Path {
+ pub fn transform(&self, transform: &lyon_path::math::Transform) -> Path {
Path {
raw: self.raw.clone().transformed(transform),
}
}
}
-
-pub(super) fn dashed(path: &Path, line_dash: LineDash<'_>) -> Path {
- Path::new(|builder| {
- let segments_odd = (line_dash.segments.len() % 2 == 1)
- .then(|| [line_dash.segments, line_dash.segments].concat());
-
- let mut draw_line = false;
-
- walk_along_path(
- path.raw().iter().flattened(0.01),
- 0.0,
- lyon::tessellation::StrokeOptions::DEFAULT_TOLERANCE,
- &mut RepeatedPattern {
- callback: |event: WalkerEvent<'_>| {
- let point = Point {
- x: event.position.x,
- y: event.position.y,
- };
-
- if draw_line {
- builder.line_to(point);
- } else {
- builder.move_to(point);
- }
-
- draw_line = !draw_line;
-
- true
- },
- index: line_dash.offset,
- intervals: segments_odd
- .as_deref()
- .unwrap_or(line_dash.segments),
- },
- );
- })
-}