Skip to main content

StrokeStyle

Struct StrokeStyle 

Source
pub struct StrokeStyle {
    pub width: f32,
    pub cap: LineCap,
    pub join: LineJoin,
    pub miter_limit: f32,
}
Expand description

A stroke’s geometric parameters.

Fields§

§width: f32

Full width of the stroke, not the half-width offset.

§cap: LineCap§join: LineJoin§miter_limit: f32

Maximum ratio of miter length to line width before a miter join degrades to a bevel.

As the angle between two segments approaches zero the miter length grows without bound, so an unbounded miter would let a hairline path paint an arbitrarily long spike. The default of 4 is the SVG and PostScript convention; measured against this implementation, it degrades to a bevel just below 29 degrees.

Values below 2 all behave as 2, which bevels below 60 degrees. That floor comes from the tessellation backend rather than from the geometry, and such limits are rare enough in practice that matching them exactly is not worth carrying a second join implementation.

Implementations§

Source§

impl StrokeStyle

Source

pub fn new(width: f32) -> Self

Source

pub fn with_width(self, width: f32) -> Self

The same style at another width.

Source

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

Source

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

Source

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

Source

pub fn is_visible(&self) -> bool

Whether this style would produce any geometry at all.

A non-positive or non-finite width strokes nothing. Treating that as “draw nothing” rather than as an error matches how a caller animating a width down to zero expects it to behave.

Zero is excluded because the tessellator cannot build a stroke of no width: it offsets the path by half of it and normalizes the result, which for zero is a direction that does not exist. Asking it anyway put NaN in a vertex buffer, which a_stroked_path_of_any_shape_leaves_addressable_buffers caught. A caller’s zero is a hairline and is widened before it arrives – see Self::can_draw, which is the question asked before the widening.

Source

pub fn can_draw(&self) -> bool

Whether a stroke of this width can put ink on a frame at all.

Wider than Self::is_visible by exactly one value, and that value is the whole reason both exist: dart:ui documents Paint.strokeWidth as defaulting to zero and zero as “a hairline width”, so a zero-width stroke draws the thinnest line the device can. It cannot be tessellated at that width, so a canvas widens it to a device pixel first and dims nothing to pay for it, which is Impeller’s rule.

So this is the question to ask before the widening – may this draw at all – and is_visible is the question to ask after, with a width the tessellator can use.

Source

pub fn max_extent(&self) -> f32

How far the stroke can extend beyond the path itself.

Used to expand bounds for culling. A miter join reaches miter_limit * width / 2 at the limit, which is further than the half-width the stroke reaches along a straight run.

Trait Implementations§

Source§

impl Clone for StrokeStyle

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 StrokeStyle

Source§

impl Debug for StrokeStyle

Source§

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

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

impl Default for StrokeStyle

Source§

fn default() -> Self

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

impl PartialEq for StrokeStyle

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 StrokeStyle

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