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: f32How 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
impl Dash
Sourcepub fn of(lengths: &[f32]) -> Option<Self>
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.
Sourcepub fn offset(self, offset: f32) -> Self
pub fn offset(self, offset: f32) -> Self
Self::offset set.
Sourcepub fn is_solid(&self) -> bool
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.
Sourcepub fn cut(&self, width: f32) -> Option<Cut>
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.