pub struct PathBuilder { /* private fields */ }
Expand description

A path builder.

Implementations§

source§

impl PathBuilder

source

pub fn new() -> Self

Creates a new builder.

source

pub fn with_capacity(verbs_capacity: usize, points_capacity: usize) -> Self

Creates a new builder with a specified capacity.

Number of points depends on a verb type:

  • Move - 1
  • Line - 1
  • Quad - 2
  • Cubic - 3
  • Close - 0
source

pub fn from_rect(rect: Rect) -> Path

Creates a new Path from Rect.

Never fails since Rect is always valid.

Segments are created clockwise: TopLeft -> TopRight -> BottomRight -> BottomLeft

The contour is closed.

source

pub fn from_circle(cx: f32, cy: f32, radius: f32) -> Option<Path>

Creates a new Path from a circle.

See PathBuilder::push_circle for details.

source

pub fn from_oval(oval: Rect) -> Option<Path>

Creates a new Path from an oval.

See PathBuilder::push_oval for details.

source

pub fn len(&self) -> usize

Returns the current number of segments in the builder.

source

pub fn is_empty(&self) -> bool

Checks if the builder has any segments added.

source

pub fn move_to(&mut self, x: f32, y: f32)

Adds beginning of a contour.

Multiple continuous MoveTo segments are not allowed. If the previous segment was also MoveTo, it will be overwritten with the current one.

source

pub fn line_to(&mut self, x: f32, y: f32)

Adds a line from the last point.

  • If Path is empty - adds Move(0, 0) first.
  • If Path ends with Close - adds Move(last_x, last_y) first.
source

pub fn quad_to(&mut self, x1: f32, y1: f32, x: f32, y: f32)

Adds a quad curve from the last point to x, y.

  • If Path is empty - adds Move(0, 0) first.
  • If Path ends with Close - adds Move(last_x, last_y) first.
source

pub fn cubic_to(&mut self, x1: f32, y1: f32, x2: f32, y2: f32, x: f32, y: f32)

Adds a cubic curve from the last point to x, y.

  • If Path is empty - adds Move(0, 0) first.
  • If Path ends with Close - adds Move(last_x, last_y) first.
source

pub fn close(&mut self)

Closes the current contour.

A closed contour connects the first and the last Point with a line, forming a continuous loop.

Does nothing when Path is empty or already closed.

Open and closed contour will be filled the same way. Stroking an open contour will add LineCap at contour’s start and end. Stroking an closed contour will add LineJoin at contour’s start and end.

source

pub fn last_point(&self) -> Option<Point>

Returns the last point if any.

source

pub fn push_rect(&mut self, rect: Rect)

Adds a rectangle contour.

The contour is closed and has a clock-wise direction.

source

pub fn push_oval(&mut self, oval: Rect)

Adds an oval contour bounded by the provided rectangle.

The contour is closed and has a clock-wise direction.

source

pub fn push_circle(&mut self, x: f32, y: f32, r: f32)

Adds a circle contour.

The contour is closed and has a clock-wise direction.

Does nothing when:

  • radius <= 0
  • any value is not finite or really large
source

pub fn push_path(&mut self, other: &Path)

Adds a path.

source

pub fn clear(&mut self)

Reset the builder.

Memory is not deallocated.

source

pub fn finish(self) -> Option<Path>

Finishes the builder and returns a Path.

Returns None when Path is empty or has invalid bounds.

Trait Implementations§

source§

impl Clone for PathBuilder

source§

fn clone(&self) -> PathBuilder

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for PathBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for PathBuilder

source§

fn default() -> PathBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.