pub struct ConicGradient<P: Pixel> {
pub angle: f64,
pub position: GradientPosition,
pub colors: Vec<(P, f64)>,
pub interpolation: Interpolation,
pub blend_mode: BlendMode,
}Expand description
A conic gradient.
Fields§
§angle: f64The angle of the conic gradient, in radians. Defaults to 0.0, where the start and end
values will meet vertically at the top.
position: GradientPositionThe position of the center of the conic gradient. Defaults to the center of the bounding box.
colors: Vec<(P, f64)>A Vec of colors and their positions in the gradient, represented as (color, position)
where position is a value in the range [0.0, 1.0].
§Normalization of positions
During building of this struct, there might be some positions that are nan which represent
positions that will be normalized later. For example, [0.0, nan, 1.0] is normalized to
[0.0, 0.5, 1.0] because 0.5 is the midpoint between 0.0 and 1.0.
Similarly, [0.0, nan, nan, nan, 1.0] is normalized to [0.0, 0.25, 0.5, 0.75, 1.0]
because they evenly distribute between 0.0 and 1.0.
§Normalization of endpoints
If the first position is nan, it will be normalized to 0.0. If the last position is
nan, it will be normalized to 1.0.
interpolation: InterpolationThe interpolation mode to use when rendering the gradient. Defaults to
Interpolation::Linear.
blend_mode: BlendModeThe blending mode to use when rendering the gradient. Defaults to
BlendMode::LinearRgb. If the gradient looks off or some colors are weirdly balanced,
trying different blend modes here could help.
Implementations§
Source§impl<P: Pixel> ConicGradient<P>
impl<P: Pixel> ConicGradient<P>
Sourcepub const fn with_angle(self, angle: f64) -> Self
pub const fn with_angle(self, angle: f64) -> Self
Sets the angle of the gradient in radians. Angles outside of the range [0.0, 2 * PI)
will be normalized.
If your angle is in degrees, the f64::to_radians method can be used to convert into
degrees, or the convenience method Self::with_angle_degrees can be used.
Sourcepub fn with_angle_degrees(self, angle: f64) -> Self
pub fn with_angle_degrees(self, angle: f64) -> Self
A shortcut method to set the angle of the gradient in degrees. Angles outside of the
range [0.0, 360.0) will be normalized.
See Self::with_angle for more information.
Sourcepub const fn with_position(self, position: GradientPosition) -> Self
pub const fn with_position(self, position: GradientPosition) -> Self
Sets the position of the center of the gradient.
Sourcepub const fn with_interpolation(self, interpolation: Interpolation) -> Self
pub const fn with_interpolation(self, interpolation: Interpolation) -> Self
Sets the interpolation mode to use when rendering the gradient.
Sourcepub const fn with_blend_mode(self, blend_mode: BlendMode) -> Self
pub const fn with_blend_mode(self, blend_mode: BlendMode) -> Self
Sets the blending mode to use when rendering the gradient.
Sourcepub fn with_start_color(self, color: P) -> Self
pub fn with_start_color(self, color: P) -> Self
Sets the start color of the gradient. This will be rendered at the position 0.0.
§Note
This uses insert instead of push to ensure that the start color is always at the
beginning of the gradient. This means other colors will be shifted to the right.
Sourcepub fn with_end_color(self, color: P) -> Self
pub fn with_end_color(self, color: P) -> Self
Sets the end color of the gradient. This will be rendered at the position 1.0.
Sourcepub fn push_color_at(&mut self, position: f64, color: P)
pub fn push_color_at(&mut self, position: f64, color: P)
Adds a color to the gradient at the specified position in place.
§Panics
- If the position is outside of the range
[0.0, 1.0]. For auto-normalized positions, seeSelf::push_color.
Sourcepub fn with_color_at(self, position: f64, color: P) -> Self
pub fn with_color_at(self, position: f64, color: P) -> Self
Takes this gradient and adds a color to the gradient at the specified position.
§Panics
- If the position is outside of the range
[0.0, 1.0]. For auto-normalized positions, seeSelf::with_color.
Sourcepub fn push_color(&mut self, color: P)
pub fn push_color(&mut self, color: P)
Adds a color to the gradient, automatically calculating its position. See the documentation
for [Self.colors] for more information of how colors are normalized.
§See Also
Self::push_color_atfor adding a color at a specific position.
Sourcepub fn with_color(self, color: P) -> Self
pub fn with_color(self, color: P) -> Self
Takes this gradient and adds a color to the gradient, automatically calculating its position.
See the documentation for [Self.colors] for more information of how colors are normalized.
§See Also
Self::with_color_atfor adding a color at a specific position.
Sourcepub fn extend_with_positions<I: IntoIterator<Item = (P, f64)>>(
&mut self,
iter: I,
)
pub fn extend_with_positions<I: IntoIterator<Item = (P, f64)>>( &mut self, iter: I, )
Extends the colors and positions of this gradient with those specified in the given
iterator of tuples represented as (color, position).
§Panics
- If any of the positions are outside of the range
[0.0, 1.0]. For auto-normalized positions, seeSelf::extend.
Sourcepub fn extend<I: IntoIterator<Item = P>>(&mut self, iter: I)
pub fn extend<I: IntoIterator<Item = P>>(&mut self, iter: I)
Extends the colors of this gradient with those specified in the given iterator.
The positions of the colors will be automatically calculated. See the documentation for
[Self.colors] for more information of how colors are normalized.
§See Also
Self::extend_with_positionsfor adding colors at specific positions.
Trait Implementations§
Source§impl<P: Clone + Pixel> Clone for ConicGradient<P>
impl<P: Clone + Pixel> Clone for ConicGradient<P>
Source§fn clone(&self) -> ConicGradient<P>
fn clone(&self) -> ConicGradient<P>
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<P: Pixel> Default for ConicGradient<P>
impl<P: Pixel> Default for ConicGradient<P>
Auto Trait Implementations§
impl<P> Freeze for ConicGradient<P>
impl<P> RefUnwindSafe for ConicGradient<P>where
P: RefUnwindSafe,
impl<P> Send for ConicGradient<P>where
P: Send,
impl<P> Sync for ConicGradient<P>where
P: Sync,
impl<P> Unpin for ConicGradient<P>where
P: Unpin,
impl<P> UnwindSafe for ConicGradient<P>where
P: UnwindSafe,
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)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