Struct Gradient

Source
pub struct Gradient {
    pub stops: Vec<(f32, Hsva)>,
    pub interpolation_method: InterpolationMethod,
}
Expand description

A color gradient, that will be interpolated between a number of fixed points, a.k.a. stops.

Fields§

§stops: Vec<(f32, Hsva)>§interpolation_method: InterpolationMethod

Implementations§

Source§

impl Gradient

Source

pub fn new( interpolation_method: InterpolationMethod, stops: impl IntoIterator<Item = (f32, impl Into<Hsva>)>, ) -> Self

Create a new gradient from an iterator over key colors.

Source

pub fn interpolator(&self) -> ColorInterpolator

Create a ColorInterpolator to evaluate the gradient at any point.

Source

pub fn interpolator_opaque(&self) -> ColorInterpolator

Create a ColorInterpolator that discards the alpha component of the color gradient and always produces an opaque color.

Source

pub fn argsort(&self) -> Vec<usize>

Produce a list of the indices of the gradient’s stops that would place them in order.

Use this to prepare for the upcoming reordering of the stops by sort().

Source

pub fn sort(&mut self)

Sort the gradient’s stops by ascending position.

Source

pub fn linear_eval(&self, n: usize, opaque: bool) -> Vec<Color32>

Return a vector of the gradient’s color sampled on linearly spaced points between 0 and 1.

The first and last samples correspond to the gradient’s value at 0.0 and 1.0, respectively.

This is useful for generating a texture.

§Panics

Will panic if the provided size n is smaller or equal to 1, or if the gradient is empty.

Trait Implementations§

Source§

impl Default for Gradient

Source§

fn default() -> Self

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

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

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

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.