pub struct Gradient { /* private fields */ }Expand description
A multi-stop color gradient for smooth transitions.
Gradients interpolate between two or more color stops. Use at(t) to sample
a color at any point along the gradient, or generate(n) to produce a
sequence of evenly-spaced colors.
Implementations§
Source§impl Gradient
impl Gradient
Sourcepub fn new(stops: Vec<OpalineColor>) -> Self
pub fn new(stops: Vec<OpalineColor>) -> Self
Sourcepub fn try_new(stops: Vec<OpalineColor>) -> Result<Self, OpalineError>
pub fn try_new(stops: Vec<OpalineColor>) -> Result<Self, OpalineError>
Create a gradient from a list of color stops, returning an error if empty.
Sourcepub fn at(&self, t: f32) -> OpalineColor
pub fn at(&self, t: f32) -> OpalineColor
Sample the gradient at position t (clamped to [0.0, 1.0]).
With a single stop, always returns that stop. With multiple stops, linearly interpolates between the appropriate segment.
Sourcepub fn generate(&self, n: usize) -> Vec<OpalineColor>
pub fn generate(&self, n: usize) -> Vec<OpalineColor>
Generate n evenly-spaced colors across the gradient.
Returns a single color for n == 1, or empty vec for n == 0.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether this gradient has no stops (always false after construction).
Sourcepub fn stops(&self) -> &[OpalineColor]
pub fn stops(&self) -> &[OpalineColor]
Access the underlying color stops.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Gradient
impl<'de> Deserialize<'de> for Gradient
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Gradient
Auto Trait Implementations§
impl Freeze for Gradient
impl RefUnwindSafe for Gradient
impl Send for Gradient
impl Sync for Gradient
impl Unpin for Gradient
impl UnsafeUnpin for Gradient
impl UnwindSafe for Gradient
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
Mutably borrows from an owned value. Read more
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>
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 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>
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