ConicGradient

Struct ConicGradient 

Source
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: f64

The angle of the conic gradient, in radians. Defaults to 0.0, where the start and end values will meet vertically at the top.

§position: GradientPosition

The 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: Interpolation

The interpolation mode to use when rendering the gradient. Defaults to Interpolation::Linear.

§blend_mode: BlendMode

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

Source

pub fn new() -> Self

Creates a new conic gradient.

Source

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.

Source

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.

Source

pub const fn with_position(self, position: GradientPosition) -> Self

Sets the position of the center of the gradient.

Source

pub const fn with_interpolation(self, interpolation: Interpolation) -> Self

Sets the interpolation mode to use when rendering the gradient.

Source

pub const fn with_blend_mode(self, blend_mode: BlendMode) -> Self

Sets the blending mode to use when rendering the gradient.

Source

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.

Source

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.

Source

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, see Self::push_color.
Source

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, see Self::with_color.
Source

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
Source

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
Source

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, see Self::extend.
Source

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

Trait Implementations§

Source§

impl<P: Clone + Pixel> Clone for ConicGradient<P>

Source§

fn clone(&self) -> ConicGradient<P>

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<P: Debug + Pixel> Debug for ConicGradient<P>

Source§

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

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

impl<P: Pixel> Default for ConicGradient<P>

Source§

fn default() -> Self

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

impl<P: Pixel> IntoFill for ConicGradient<P>

Source§

type Pixel = P

The pixel type of the fill.
Source§

type Fill = ConicGradientFill<<ConicGradient<P> as IntoFill>::Pixel>

The fill type.
Source§

fn into_fill(self) -> Self::Fill

Converts the fill into a fill type.

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> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

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

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.