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
stops: Vec<GradientStop>stops defines the colors along the gradient.
spread: SpreadModespread controls colors outside the zero-to-one span.
local: Matrixlocal 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
stops: Vec<GradientStop>stops defines the colors along the gradient.
spread: SpreadModespread 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.
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
end_angle: f32end_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: SpreadModespread controls colors at angles outside the two.
Image
Image samples an image across the drawn geometry.
Fields
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
impl Shader
Sourcepub fn stops(&self) -> &[GradientStop]
pub fn stops(&self) -> &[GradientStop]
stops returns this gradient’s stops or an empty slice for image shaders.
Sourcepub fn spread(&self) -> Option<SpreadMode>
pub fn spread(&self) -> Option<SpreadMode>
spread returns how this gradient spreads past its span, or None
for image and runtime shaders.
Sourcepub fn fold_color_filter(&mut self, filter: &ColorFilter) -> bool
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.
Sourcepub fn runtime(shader: RuntimeShader) -> Result<Shader, EffectError>
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.
Trait Implementations§
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.
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.