Skip to main content

Gradient

Struct Gradient 

Source
pub struct Gradient {
    pub kind: GradientKind,
    pub stops: Vec<ColorStop>,
    pub repeating: bool,
}
Expand description

A gradient image (backgroundImage, maskImage).

Fields§

§kind: GradientKind

Geometry.

§stops: Vec<ColorStop>

At least two stops.

§repeating: bool

Repeats past the last stop.

Implementations§

Source§

impl Gradient

Source

pub fn lerp(&self, to: &Self, t: f32) -> Option<Self>

The gradient t of the way to to (t beyond 0..1 overshoots): each stop’s color (in premultiplied RGBA, as CSS mixes them) and position, and the geometry’s angle and center. None when the two do not interpolate and to applies at once, as CSS’s discrete interpolation does: different kinds, sizes or repeating, a different number of stops, a linear gradient toward a different corner, or a stop placed in one and not the other, or as a fraction in one and a length in the other.

Source

pub fn has_lengths(&self) -> bool

Whether a stop is placed in points, so the stops depend on the size of the box (Gradient::resolved_stops).

Source

pub fn line_length(&self, size: Size<Points>) -> Points

The length of the gradient line over a box of size, what lengths of stops are fractions of (CSS Images 3): a linear gradient’s line through the center, long enough that the corners get the end colors; a radial gradient’s ray to the right, from the center to the ending shape; 0 for a conic gradient, whose stops are angles.

Source

pub fn resolved_stops(&self, size: Size<Points>) -> Vec<(Color, Percentage)>

Stop positions over a box of size as fractions of the gradient line, resolved as CSS does: lengths against the line’s length, missing ones spread evenly, each at least the one before it.

Source

pub fn resolve_stops( &self, size: Size<Points>, out: &mut Vec<(Color, Percentage)>, )

Gradient::resolved_stops into a reused buffer.

Source

pub fn unrolled_stops( &self, size: Size<Points>, reach: Percentage, ) -> Vec<(Color, Percentage)>

The stops over a box of size as a toolkit gradient that repeats nothing and takes stops within 0..=1 (Core Animation’s, Android’s shaders) draws them over 0..reach of the gradient line (1: the whole line of a linear or conic gradient; a radial gradient’s rings go on past its ending shape, to the box’s farthest corner): the positions as fractions of reach. A repeating gradient’s stops are repeated over all of it, with period last − first, both ways (CSS Images 3), and cut at both ends with the colors there. A non-repeating gradient’s, or one whose period is too short to repeat, are Gradient::resolved_stops.

Trait Implementations§

Source§

impl Clone for Gradient

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Gradient

Source§

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

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

impl PartialEq for Gradient

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Gradient

Auto Trait Implementations§

§

impl Forget for Gradient

§

impl Freeze for Gradient

§

impl Move for Gradient

§

impl RefUnwindSafe for Gradient

§

impl Send for Gradient
where RawVecInner: Send,

§

impl Sync for Gradient
where RawVecInner: Sync,

§

impl Unpin for Gradient
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for Gradient

§

impl UnwindSafe for Gradient
where RawVecInner: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

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

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

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

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

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.