summaryrefslogtreecommitdiffstats
path: root/graphics/src/geometry/path
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
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
-rw-r--r--graphics/src/geometry/path/arc.rs (renamed from graphics/src/widget/canvas/path/arc.rs)2
-rw-r--r--graphics/src/geometry/path/builder.rs (renamed from graphics/src/widget/canvas/path/builder.rs)27
3 files changed, 17 insertions, 64 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),
- },
- );
- })
-}
diff --git a/graphics/src/widget/canvas/path/arc.rs b/graphics/src/geometry/path/arc.rs
index b8e72daf..2cdebb66 100644
--- a/graphics/src/widget/canvas/path/arc.rs
+++ b/graphics/src/geometry/path/arc.rs
@@ -1,5 +1,5 @@
//! Build and draw curves.
-use iced_native::{Point, Vector};
+use iced_core::{Point, Vector};
/// A segment of a differentiable curve.
#[derive(Debug, Clone, Copy)]
diff --git a/graphics/src/widget/canvas/path/builder.rs b/graphics/src/geometry/path/builder.rs
index 5121aa68..794dd3bc 100644
--- a/graphics/src/widget/canvas/path/builder.rs
+++ b/graphics/src/geometry/path/builder.rs
@@ -1,35 +1,38 @@
-use crate::widget::canvas::path::{arc, Arc, Path};
+use crate::geometry::path::{arc, Arc, Path};
-use iced_native::{Point, Size};
-use lyon::path::builder::SvgPathBuilder;
+use iced_core::{Point, Size};
+
+use lyon_path::builder::{self, SvgPathBuilder};
+use lyon_path::geom;
+use lyon_path::math;
/// A [`Path`] builder.
///
/// Once a [`Path`] is built, it can no longer be mutated.
#[allow(missing_debug_implementations)]
pub struct Builder {
- raw: lyon::path::builder::WithSvg<lyon::path::path::BuilderImpl>,
+ raw: builder::WithSvg<lyon_path::path::BuilderImpl>,
}
impl Builder {
/// Creates a new [`Builder`].
pub fn new() -> Builder {
Builder {
- raw: lyon::path::Path::builder().with_svg(),
+ raw: lyon_path::Path::builder().with_svg(),
}
}
/// Moves the starting point of a new sub-path to the given `Point`.
#[inline]
pub fn move_to(&mut self, point: Point) {
- let _ = self.raw.move_to(lyon::math::Point::new(point.x, point.y));
+ let _ = self.raw.move_to(math::Point::new(point.x, point.y));
}
/// Connects the last point in the [`Path`] to the given `Point` with a
/// straight line.
#[inline]
pub fn line_to(&mut self, point: Point) {
- let _ = self.raw.line_to(lyon::math::Point::new(point.x, point.y));
+ let _ = self.raw.line_to(math::Point::new(point.x, point.y));
}
/// Adds an [`Arc`] to the [`Path`] from `start_angle` to `end_angle` in
@@ -53,8 +56,6 @@ impl Builder {
/// See [the HTML5 specification of `arcTo`](https://html.spec.whatwg.org/multipage/canvas.html#building-paths:dom-context-2d-arcto)
/// for more details and examples.
pub fn arc_to(&mut self, a: Point, b: Point, radius: f32) {
- use lyon::{math, path};
-
let start = self.raw.current_position();
let mid = math::Point::new(a.x, a.y);
let end = math::Point::new(b.x, b.y);
@@ -92,7 +93,7 @@ impl Builder {
self.raw.arc_to(
math::Vector::new(radius, radius),
math::Angle::radians(0.0),
- path::ArcFlags {
+ lyon_path::ArcFlags {
large_arc: false,
sweep,
},
@@ -102,8 +103,6 @@ impl Builder {
/// Adds an ellipse to the [`Path`] using a clockwise direction.
pub fn ellipse(&mut self, arc: arc::Elliptical) {
- use lyon::{geom, math};
-
let arc = geom::Arc {
center: math::Point::new(arc.center.x, arc.center.y),
radii: math::Vector::new(arc.radii.x, arc.radii.y),
@@ -128,8 +127,6 @@ impl Builder {
control_b: Point,
to: Point,
) {
- use lyon::math;
-
let _ = self.raw.cubic_bezier_to(
math::Point::new(control_a.x, control_a.y),
math::Point::new(control_b.x, control_b.y),
@@ -141,8 +138,6 @@ impl Builder {
/// and its end point.
#[inline]
pub fn quadratic_curve_to(&mut self, control: Point, to: Point) {
- use lyon::math;
-
let _ = self.raw.quadratic_bezier_to(
math::Point::new(control.x, control.y),
math::Point::new(to.x, to.y),