Skip to main content

Shape

Struct Shape 

Source
pub struct Shape<'a> { /* private fields */ }
Expand description

The shape builder

Implementations§

Source§

impl<'a> Shape<'a>

Source

pub fn new() -> Self

Create an empty shape to start building.

Source

pub fn fill_color(self, color: Color) -> Self

Set the fill color of the shape.

Source

pub fn fill_paint(self, texture: &'a Paint<'_>) -> Self

Set the fill paint of the shape. This allows for more complex fills such as gradients and patterns.

Source

pub fn no_fill(self) -> Self

Don’t fill the shape. If this is not called the shape will not be closed.

Source

pub fn no_stroke(self) -> Self

Don’t stroke the shape.

Source

pub fn stroke_color(self, color: Color) -> Self

Set the stroke color of the shape.

Source

pub fn stroke_paint(self, paint: &'a Paint<'_>) -> Self

Set the stroke paint of the shape. This allows for more complex fills such as gradients and patterns.

Source

pub fn stroke_weight(self, weight: f32) -> Self

Set the stroke width of the shape.

Source

pub fn line_cap(self, cap: LineCap) -> Self

Set the line cap of the shape.

Source

pub fn line_join(self, join: LineJoin) -> Self

Set the line join of the shape.

Source

pub fn miter_limit(self, limit: f32) -> Self

Source

pub fn stroke_dash(self, dash: StrokeDash) -> Self

Set the stroke dash of the shape.

Source

pub fn points(self, pts: &[Point]) -> Self

Set the points that determine the shape.

Source

pub fn get_points(&self) -> &[Point]

Get points.

Source

pub fn rect_ltrb(self, lt: Point, rb: Point) -> Self

Interpret the points as a rectangle. The first point is the top left corner and the second point is the bottom right corner.

Source

pub fn rect_xywh(self, xy: Point, wh: Point) -> Self

Inerpret the points as a rectangle. The first point is the top left corner and the second point is the size of the rectangle.

Source

pub fn rect_cwh(self, c: Point, wh: Point) -> Self

Inerpret the points as a rectangle. The first point is the center of the rectangle and the second point is the size of the rectangle.

Source

pub fn circle(self, center: Point, radius: f32) -> Self

Create circle from it’s center and radius.

Source

pub fn ellipse(self, center: Point, width: f32, height: f32) -> Self

Create ellispse from it’s center, width and heighr.

Source

pub fn polygon(self, center: Point, radius: f32, sides: u32) -> Self

Create a polygon from it’s center, radius and number of sides.

Source

pub fn star( self, center: Point, inner_radius: f32, outer_radius: f32, sides: u32, ) -> Self

Create a star from it’s center, inner radius, outer radius, number of sides and smoothness parameter.

Source

pub fn pearl<R: RngCore>( self, center: Point, a: f32, b: f32, sides: u32, smoothness: u32, rng: &mut R, ) -> Self

A pearl is a deformed polygon using the normal distribution to alter the location of each point. The a and b parameters control the width and height of the pearl. The sides parameter controls the number of sides of the polygon. The smoothness parameter controls the smoothnes of the polygon. using the Chaiken algorithm.

Source

pub fn quad(self) -> Self

Interpret the points as a quadratic bezier curve. The first point is the start point, the second point is the control point and the third point is the end point and so on.

Source

pub fn cubic(self) -> Self

Interpret the points as a cubic bezier curve. The first point is the start point, the second point is the first control point, the third point is the second control point and the fourth point is the end point and so on.

Source

pub fn line(self, from: Point, to: Point) -> Self

Create a line from it’s start and end points.

Source

pub fn fill_rule(self, fillrule: FillRule) -> Self

Set the fill rule for the shape.

Source

pub fn transform(self, transform: &Transform) -> Self

Set the transform for the shape.

Source

pub fn cartesian<T: AsPrimitive<f32>>(self, width: T, height: T) -> Self

Interpret points as cartiesian coordinates with center at (0, 0).

Source

pub fn draw(self, canvas: &mut Canvas)

Draw the shape to the canvas.

Trait Implementations§

Source§

impl<'a> Clone for Shape<'a>

Source§

fn clone(&self) -> Shape<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Shape<'a>

Source§

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

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

impl Default for Shape<'_>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<'a> Freeze for Shape<'a>

§

impl<'a> RefUnwindSafe for Shape<'a>

§

impl<'a> Send for Shape<'a>

§

impl<'a> Sync for Shape<'a>

§

impl<'a> Unpin for Shape<'a>

§

impl<'a> UnsafeUnpin for Shape<'a>

§

impl<'a> UnwindSafe for Shape<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

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

Source§

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>,

Source§

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>,

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V