pub trait PathBuilder {
Show 20 methods
// Required methods
fn num_attributes(&self) -> usize;
fn begin(
&mut self,
at: Point,
custom_attributes: Attributes<'_>,
) -> EndpointId;
fn end(&mut self, close: bool);
fn line_to(
&mut self,
to: Point,
custom_attributes: Attributes<'_>,
) -> EndpointId;
fn quadratic_bezier_to(
&mut self,
ctrl: Point,
to: Point,
custom_attributes: Attributes<'_>,
) -> EndpointId;
fn cubic_bezier_to(
&mut self,
ctrl1: Point,
ctrl2: Point,
to: Point,
custom_attributes: Attributes<'_>,
) -> EndpointId;
// Provided methods
fn close(&mut self) { ... }
fn reserve(&mut self, _endpoints: usize, _ctrl_points: usize) { ... }
fn path_event(&mut self, event: PathEvent, attributes: Attributes<'_>) { ... }
fn event(&mut self, event: Event<(Point, Attributes<'_>), Point>) { ... }
fn add_polygon(
&mut self,
polygon: Polygon<'_, Point>,
attributes: Attributes<'_>,
) { ... }
fn add_point(&mut self, at: Point, attributes: Attributes<'_>) -> EndpointId { ... }
fn add_line_segment(
&mut self,
line: &LineSegment<f32>,
attributes: Attributes<'_>,
) -> (EndpointId, EndpointId) { ... }
fn add_ellipse(
&mut self,
center: Point,
radii: Vector,
x_rotation: Angle,
winding: Winding,
attributes: Attributes<'_>,
) { ... }
fn add_circle(
&mut self,
center: Point,
radius: f32,
winding: Winding,
attributes: Attributes<'_>,
)
where Self: Sized { ... }
fn add_rectangle(
&mut self,
rect: &Box2D,
winding: Winding,
attributes: Attributes<'_>,
) { ... }
fn add_rounded_rectangle(
&mut self,
rect: &Box2D,
radii: &BorderRadii,
winding: Winding,
custom_attributes: Attributes<'_>,
)
where Self: Sized { ... }
fn flattened(self, tolerance: f32) -> Flattened<Self>
where Self: Sized { ... }
fn transformed<Transform>(
self,
transform: Transform,
) -> Transformed<Self, Transform>
where Self: Sized,
Transform: Transformation<f32> { ... }
fn with_svg(self) -> WithSvg<Self>
where Self: Sized { ... }
}
Expand description
The base path building interface.
Unlike SvgPathBuilder
, this interface strictly requires sub-paths to be manually
started and ended (See the begin
and end
methods).
All positions are provided in absolute coordinates.
The goal of this interface is to abstract over simple and fast implementations that do not deal with corner cases such as adding segments without starting a sub-path.
More elaborate interfaces are built on top of the provided primitives. In particular,
the SvgPathBuilder
trait providing more permissive and richer interface is
automatically implemented via the WithSvg
adapter (See the with_svg
method).
Required Methods§
fn num_attributes(&self) -> usize
sourcefn begin(&mut self, at: Point, custom_attributes: Attributes<'_>) -> EndpointId
fn begin(&mut self, at: Point, custom_attributes: Attributes<'_>) -> EndpointId
Starts a new sub-path at a given position.
There must be no sub-path in progress when this method is called.
at
becomes the current position of the sub-path.
sourcefn end(&mut self, close: bool)
fn end(&mut self, close: bool)
Ends the current sub path.
A sub-path must be in progress when this method is called.
After this method is called, there is no sub-path in progress until
begin
is called again.
sourcefn line_to(
&mut self,
to: Point,
custom_attributes: Attributes<'_>,
) -> EndpointId
fn line_to( &mut self, to: Point, custom_attributes: Attributes<'_>, ) -> EndpointId
Adds a line segment to the current sub-path.
A sub-path must be in progress when this method is called.
sourcefn quadratic_bezier_to(
&mut self,
ctrl: Point,
to: Point,
custom_attributes: Attributes<'_>,
) -> EndpointId
fn quadratic_bezier_to( &mut self, ctrl: Point, to: Point, custom_attributes: Attributes<'_>, ) -> EndpointId
Adds a quadratic bézier curve to the current sub-path.
A sub-path must be in progress when this method is called.
sourcefn cubic_bezier_to(
&mut self,
ctrl1: Point,
ctrl2: Point,
to: Point,
custom_attributes: Attributes<'_>,
) -> EndpointId
fn cubic_bezier_to( &mut self, ctrl1: Point, ctrl2: Point, to: Point, custom_attributes: Attributes<'_>, ) -> EndpointId
Adds a cubic bézier curve to the current sub-path.
A sub-path must be in progress when this method is called.
Provided Methods§
sourcefn reserve(&mut self, _endpoints: usize, _ctrl_points: usize)
fn reserve(&mut self, _endpoints: usize, _ctrl_points: usize)
Hints at the builder that a certain number of endpoints and control points will be added.
The Builder implementation may use this information to pre-allocate memory as an optimization.
sourcefn path_event(&mut self, event: PathEvent, attributes: Attributes<'_>)
fn path_event(&mut self, event: PathEvent, attributes: Attributes<'_>)
Applies the provided path event.
By default this calls one of begin
, end
, line
, quadratic_bezier_segment
,
or cubic_bezier_segment
according to the path event.
The requirements for each method apply to the corresponding event.
fn event(&mut self, event: Event<(Point, Attributes<'_>), Point>)
sourcefn add_polygon(
&mut self,
polygon: Polygon<'_, Point>,
attributes: Attributes<'_>,
)
fn add_polygon( &mut self, polygon: Polygon<'_, Point>, attributes: Attributes<'_>, )
Adds a sub-path from a polygon.
There must be no sub-path in progress when this method is called. No sub-path is in progress after the method is called.
sourcefn add_point(&mut self, at: Point, attributes: Attributes<'_>) -> EndpointId
fn add_point(&mut self, at: Point, attributes: Attributes<'_>) -> EndpointId
Adds a sub-path containing a single point.
There must be no sub-path in progress when this method is called. No sub-path is in progress after the method is called.
sourcefn add_line_segment(
&mut self,
line: &LineSegment<f32>,
attributes: Attributes<'_>,
) -> (EndpointId, EndpointId)
fn add_line_segment( &mut self, line: &LineSegment<f32>, attributes: Attributes<'_>, ) -> (EndpointId, EndpointId)
Adds a sub-path containing a single line segment.
There must be no sub-path in progress when this method is called. No sub-path is in progress after the method is called.
sourcefn add_ellipse(
&mut self,
center: Point,
radii: Vector,
x_rotation: Angle,
winding: Winding,
attributes: Attributes<'_>,
)
fn add_ellipse( &mut self, center: Point, radii: Vector, x_rotation: Angle, winding: Winding, attributes: Attributes<'_>, )
Adds a sub-path containing an ellipse.
There must be no sub-path in progress when this method is called. No sub-path is in progress after the method is called.
sourcefn add_circle(
&mut self,
center: Point,
radius: f32,
winding: Winding,
attributes: Attributes<'_>,
)where
Self: Sized,
fn add_circle(
&mut self,
center: Point,
radius: f32,
winding: Winding,
attributes: Attributes<'_>,
)where
Self: Sized,
Adds a sub-path containing a circle.
There must be no sub-path in progress when this method is called. No sub-path is in progress after the method is called.
sourcefn add_rectangle(
&mut self,
rect: &Box2D,
winding: Winding,
attributes: Attributes<'_>,
)
fn add_rectangle( &mut self, rect: &Box2D, winding: Winding, attributes: Attributes<'_>, )
Adds a sub-path containing a rectangle.
There must be no sub-path in progress when this method is called. No sub-path is in progress after the method is called.
sourcefn add_rounded_rectangle(
&mut self,
rect: &Box2D,
radii: &BorderRadii,
winding: Winding,
custom_attributes: Attributes<'_>,
)where
Self: Sized,
fn add_rounded_rectangle(
&mut self,
rect: &Box2D,
radii: &BorderRadii,
winding: Winding,
custom_attributes: Attributes<'_>,
)where
Self: Sized,
Adds a sub-path containing a rectangle.
There must be no sub-path in progress when this method is called. No sub-path is in progress after the method is called.
sourcefn flattened(self, tolerance: f32) -> Flattened<Self>where
Self: Sized,
fn flattened(self, tolerance: f32) -> Flattened<Self>where
Self: Sized,
Returns a builder that approximates all curves with sequences of line segments.
sourcefn transformed<Transform>(
self,
transform: Transform,
) -> Transformed<Self, Transform>
fn transformed<Transform>( self, transform: Transform, ) -> Transformed<Self, Transform>
Returns a builder that applies the given transformation to all positions.