Skip to main content

Dash

Struct Dash 

Source
pub struct Dash {
    pub pattern: [f32; 4],
    pub offset: f32,
}
Expand description

A stroke’s dash pattern (backlog V2): a mark, a gap, a second mark and a second gap, repeated along the stroke’s length from its first point.

The lengths are the ones seen, in logical px. Every mark is round-capped, as the stroke itself is, so a mark on long is drawn as a capsule whose centre line is on − width long, and a mark no longer than the stroke is wide is a dot. (SVG’s stroke-dasharray measures the centre line instead, which with a round cap makes 4 4 at a width of 4 a solid line; this pattern at any width is SVG’s on − width, off + width.) The first mark’s cap sits where a solid stroke’s would, half the width before the first point.

A dot is as wide as the stroke whatever its mark says, so where a mark and its gap together come to no more than the width the dots meet or overlap and the gap is not seen. Such a gap closes: the marks either side of it are one mark, and a pattern with no gap left draws solid (backlog RG118) — where {2, 2} at a width of 8 was 8 px dots every 4 px, a lumpy solid line at a quad a dot. Every gap that is seen is the length given.

The pattern runs along the arc length of the whole stroke, so it keeps its phase across the corners of a polyline and the pieces of a curve; on a path it restarts at every subpath, as SVG’s does.

Fields§

§pattern: [f32; 4]

Mark, gap, mark, gap. A two-length pattern is the same pair twice.

§offset: f32

How far into the pattern the stroke starts, in logical px: growing it moves the marks towards the stroke’s first point, which is what a marquee’s marching ants are. Any number; it wraps.

Implementations§

Source§

impl Dash

Source

pub const SOLID: Dash

No dashes: the stroke unbroken.

Source

pub fn new(on: f32, off: f32) -> Self

Marks on long with gaps off long between them.

Source

pub fn of(lengths: &[f32]) -> Option<Self>

The pattern as the bindings spell it: one length (marks and gaps alike), two (a mark and a gap) or four (a mark, a gap, a second mark, a second gap — a dash-dot). None for any other count.

Source

pub fn offset(self, offset: f32) -> Self

Source

pub fn is_solid(&self) -> bool

Whether the pattern leaves the stroke unbroken: no gap in it, or a length that is not a number.

Source

pub fn cut(&self, width: f32) -> Option<Cut>

The pattern as centre-line lengths for a stroke width wide, or None for one that draws solid: a length that is not finite, or no gap anywhere that the width leaves seen. Negative lengths are zero, a pair that is zero altogether is the other pair, and a gap the width closes joins the marks either side of it.

Trait Implementations§

Source§

impl Clone for Dash

Source§

fn clone(&self) -> Self

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 Copy for Dash

Source§

impl Debug for Dash

Source§

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

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

impl Default for Dash

Source§

fn default() -> Self

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

impl PartialEq for Dash

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Dash

Auto Trait Implementations§

§

impl Freeze for Dash

§

impl RefUnwindSafe for Dash

§

impl Send for Dash

§

impl Sync for Dash

§

impl Unpin for Dash

§

impl UnsafeUnpin for Dash

§

impl UnwindSafe for Dash

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.