pub struct StrokeStyle {
    pub line_join: LineJoin,
    pub line_cap: LineCap,
    pub dash_pattern: StrokeDash,
    pub dash_offset: f64,
}
Expand description

Options for drawing stroked lines.

You may configure particular aspects of the style by using the methods described below.

Defaults

Currently, the style (and its various consituent parts) have Default impls that conform to the defaults described in the Postscript Language Manual, 3rd Edition; that document is the basis for the choice of these types, and can be consulted for detailed explanations and illustrations.

It is possible that in the future certain of these defaults may change; if you are particular about your style you can create the various types explicitly instead of relying on the default impls.

use piet::{LineJoin, StrokeStyle};

const CONST_STLYE: StrokeStyle = StrokeStyle::new()
    .dash_pattern(&[5.0, 1.0, 2.0])
    .line_join(LineJoin::Round);

let style = StrokeStyle::new()
    .dash_pattern(&[10.0, 5.0, 2.0])
    .dash_offset(5.0);

Fields§

§line_join: LineJoin

How to join segments of the path.

By default, this is LineJoin::Miter with a limit of 10.0.

§line_cap: LineCap

How to terminate open paths.

(closed paths do not have ends.)

by default, this is LineCap::Butt.

§dash_pattern: StrokeDash

The sequence of alternating dashes and gaps uses to draw the line.

If the sequence is not empty, all numbers should be finite and non-negative, and the sequence should not be all zeros.

On platforms that do not support an odd number of lengths in the array, the implementation may concatenate two copies of the array to reach an even count.

By default, this is empty (&[]), indicating a solid line.

§dash_offset: f64

The distance into the dash_pattern at which drawing begins.

By default, this is 0.0.

Implementations§

§

impl StrokeStyle

pub const fn new() -> StrokeStyle

Create a new StrokeStyle with the provided pattern.

For no pattern (a solid line) pass &[].

This is available in a const context and does not allocate; the other methods for setting the dash pattern do allocate, for annoying reasons.

Example
 use piet::{LineJoin, StrokeStyle};

 const STYLE: StrokeStyle = StrokeStyle::new()
    .dash_pattern(&[4.0, 2.0])
    .dash_offset(8.0)
    .line_join(LineJoin::Round);

pub const fn line_join(self, line_join: LineJoin) -> StrokeStyle

Builder-style method to set the LineJoin.

pub const fn line_cap(self, line_cap: LineCap) -> StrokeStyle

Builder-style method to set the LineCap.

pub const fn dash_offset(self, offset: f64) -> StrokeStyle

Builder-style method to set the dash_offset.

pub const fn dash_pattern(self, lengths: &'static [f64]) -> StrokeStyle

Builder-style method to set the dash_pattern.

This method takes a &'static [f64], and does not allocate. If you do not have a static slice, you may use set_dash_pattern instead, which does allocate.

pub fn set_line_join(&mut self, line_join: LineJoin)

Set the LineJoin.

pub fn set_line_cap(&mut self, line_cap: LineCap)

Set the LineCap.

pub fn set_dash_offset(&mut self, offset: f64)

Set the dash offset.

pub fn set_dash_pattern(&mut self, lengths: impl Into<Rc<[f64]>>)

Set the dash pattern.

This method always allocates. To construct without allocating, use the dash_pattern builder method.

pub fn miter_limit(&self) -> Option<f64>

If the current LineJoin is LineJoin::Miter return the miter limit.

Trait Implementations§

§

impl Clone for StrokeStyle

§

fn clone(&self) -> StrokeStyle

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
§

impl Debug for StrokeStyle

§

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

Formats the value using the given formatter. Read more
§

impl Default for StrokeStyle

§

fn default() -> StrokeStyle

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

impl PartialEq<StrokeStyle> for StrokeStyle

§

fn eq(&self, other: &StrokeStyle) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl StructuralPartialEq for StrokeStyle

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AnyEq for Twhere T: Any + PartialEq<T>,

§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

§

fn as_any(&self) -> &(dyn Any + 'static)

source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

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

const: unstable · 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> RoundFrom<T> for T

§

fn round_from(x: T) -> T

Performs the conversion.
§

impl<T, U> RoundInto<U> for Twhere U: RoundFrom<T>,

§

fn round_into(self) -> U

Performs the conversion.
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more