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,
        end_angle: f32,
        stops: Vec<GradientStop>,
        spread: SpreadMode,
        local: Matrix,
    },
    Image {
        image: Image,
        sampling: Sampling,
        local: Matrix,
    },
    Runtime(RuntimeShader),
}
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 center, from start_angle to end_angle: Skia’s SkGradientShader::MakeSweep and Flutter’s Gradient.sweep.

The angle of a point is measured from +x, clockwise in Valo’s y-down coordinates, from 0 up to one full turn; it is not wrapped round to the start angle. So the offset at a point is how far its angle lies from start_angle toward end_angle, and points whose angle lies outside the two take their colour from spread. A full turn from zero (0.0 to std::f32::consts::TAU) is the whole circle; a full turn from any other start with SpreadMode::Repeat is the whole circle rotated to begin at it, which is Canvas2D’s createConicGradient.

Fields

§center: Point

center is the sweep origin in local coordinates.

§start_angle: f32

start_angle is the angle of offset zero, in radians.

§end_angle: f32

end_angle is the angle of offset one, in radians; it must be greater than start_angle, as Skia and dart:ui require.

§stops: Vec<GradientStop>

stops defines the colors around the sweep.

§spread: SpreadMode

spread controls colors at angles outside the two.

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

§

Runtime(RuntimeShader)

Runtime colours each pixel with a runtime effect’s shade function. The effect is made by RuntimeEffect::shader; see Shader::runtime.

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 spread(&self) -> Option<SpreadMode>

spread returns how this gradient spreads past its span, or None for image and runtime 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 runtime(shader: RuntimeShader) -> Result<Shader, EffectError>

runtime creates a shader from a runtime paint shader effect with one draw’s inputs; a filter’s effect, or an image left unset, is refused.

Source

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

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<(), Error>

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

impl From<&FragmentShader> for Shader

The shader as a paint draws it, its floats and images copied now: ReusableFragmentShader::shader, as Paint.shader takes a FragmentShader.

§Panics

Where an image is not set, as Dart’s Paint.shader setter throws in a debug build.

Source§

fn from(shader: &FragmentShader) -> Shader

Converts to this type from the input type.
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 = !

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.
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,