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: f32Full width of the stroke, not the half-width offset.
cap: LineCap§join: LineJoin§miter_limit: f32Maximum 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
impl StrokeStyle
pub fn new(width: f32) -> Self
Sourcepub fn with_width(self, width: f32) -> Self
pub fn with_width(self, width: f32) -> Self
The same style at another width.
pub fn with_cap(self, cap: LineCap) -> Self
pub fn with_join(self, join: LineJoin) -> Self
pub fn with_miter_limit(self, limit: f32) -> Self
Sourcepub fn is_visible(&self) -> bool
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.
Sourcepub fn can_draw(&self) -> bool
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.
Sourcepub fn max_extent(&self) -> f32
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
impl Clone for StrokeStyle
impl Copy for StrokeStyle
Source§impl Debug for StrokeStyle
impl Debug for StrokeStyle
Source§impl Default for StrokeStyle
impl Default for StrokeStyle
Source§impl PartialEq for StrokeStyle
impl PartialEq for StrokeStyle
impl StructuralPartialEq for StrokeStyle
Auto Trait Implementations§
impl Freeze for StrokeStyle
impl RefUnwindSafe for StrokeStyle
impl Send for StrokeStyle
impl Sync for StrokeStyle
impl Unpin for StrokeStyle
impl UnsafeUnpin for StrokeStyle
impl UnwindSafe for StrokeStyle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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