Skip to main content

Shader

Enum Shader 

Source
pub enum Shader {
    Linear {
        start: Point,
        end: Point,
        stops: Vec<GradientStop>,
        spread: SpreadMode,
        local: Matrix,
    },
    Radial {
        center: Point,
        radius: f32,
        stops: Vec<GradientStop>,
        spread: SpreadMode,
        focus: Option<FocalCircle>,
        local: Matrix,
    },
    Sweep {
        center: Point,
        start_angle: f32,
        stops: Vec<GradientStop>,
        local: Matrix,
    },
    Image {
        image: Image,
        sampling: Sampling,
        local: Matrix,
    },
}
Expand description

Shader determines the color painted at each point of a drawing operation.

Shader coordinates begin in the draw’s local coordinate space, so shaders follow the same transforms as their geometry.

Variants§

§

Linear

Linear interpolates colors along the line from start to end.

Fields

§start: Point

start is the zero-offset point in local coordinates.

§end: Point

end is the one-offset point in local coordinates.

§stops: Vec<GradientStop>

stops defines the colors along the gradient.

§spread: SpreadMode

spread controls colors outside the zero-to-one span.

§local: Matrix

local transforms the shader independently of the drawn geometry.

Use Matrix::IDENTITY when no additional transform is needed.

§

Radial

Radial interpolates between a start circle and an end circle.

Fields

§center: Point

center is the end circle’s center in local coordinates.

§radius: f32

radius is the end circle’s radius in local coordinates.

§stops: Vec<GradientStop>

stops defines the colors along the gradient.

§spread: SpreadMode

spread controls colors outside the zero-to-one span.

§focus: Option<FocalCircle>

focus is the optional start circle.

None starts at a zero-radius circle centered on center.

§local: Matrix

local transforms the shader independently of the drawn geometry.

§

Sweep

Sweep interpolates colors around one full clockwise turn.

Fields

§center: Point

center is the sweep origin in local coordinates.

§start_angle: f32

start_angle is the zero-offset angle in radians clockwise from +x.

§stops: Vec<GradientStop>

stops defines the colors around the sweep.

§local: Matrix

local transforms the shader independently of the drawn geometry.

§

Image

Image samples an image across the drawn geometry.

Fields

§image: Image

image supplies the sampled pixels.

§sampling: Sampling

sampling controls filtering, mipmaps, and tiling.

§local: Matrix

local transforms the image pattern independently of the geometry.

Implementations§

Source§

impl Shader

Source

pub fn stops(&self) -> &[GradientStop]

stops returns this gradient’s stops or an empty slice for image shaders.

Source

pub fn fold_color_filter(&mut self, filter: &ColorFilter) -> bool

fold_color_filter applies a color filter directly to gradient stops.

It returns false for image shaders, whose colors must be filtered during sampling.

Source

pub fn linear(start: Point, end: Point, from: Color, to: Color) -> Self

linear creates a two-color padded linear gradient.

Trait Implementations§

Source§

impl Clone for Shader

Source§

fn clone(&self) -> Shader

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 Shader

Source§

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

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

impl PartialEq for Shader

Source§

fn eq(&self, other: &Shader) -> 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 Shader

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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

Source§

fn downcast(&self) -> &T

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = 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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,