pub enum Shader<'a> {
SolidColor(Color),
LinearGradient(LinearGradient),
RadialGradient(RadialGradient),
Pattern(Pattern<'a>),
}
Expand description
A shader specifies the source color(s) for what is being drawn.
If a paint has no shader, then the paint’s color is used. If the paint has a shader, then the shader’s color(s) are use instead, but they are modulated by the paint’s alpha. This makes it easy to create a shader once (e.g. bitmap tiling or gradient) and then change its transparency without having to modify the original shader. Only the paint’s alpha needs to be modified.
Variants§
SolidColor(Color)
A solid color shader.
LinearGradient(LinearGradient)
A linear gradient shader.
RadialGradient(RadialGradient)
A radial gradient shader.
Pattern(Pattern<'a>)
A pattern shader.
Implementations§
source§impl<'a> Shader<'a>
impl<'a> Shader<'a>
sourcepub fn is_opaque(&self) -> bool
pub fn is_opaque(&self) -> bool
Checks if the shader is guaranteed to produce only opaque colors.
sourcepub(crate) fn push_stages(&self, p: &mut RasterPipelineBuilder) -> bool
pub(crate) fn push_stages(&self, p: &mut RasterPipelineBuilder) -> bool
If this returns false, then we draw nothing (do not fall back to shader context)
sourcepub fn apply_opacity(&mut self, opacity: f32)
pub fn apply_opacity(&mut self, opacity: f32)
Shifts shader’s opacity.
opacity
will be clamped to the 0..=1 range.
This is roughly the same as Skia’s SkPaint::setAlpha
.
Unlike Skia, we do not support global alpha/opacity, which is in Skia
is set via the alpha channel of the SkPaint::fColor4f
.
Instead, you can shift the opacity of the shader to whatever value you need.
- For
SolidColor
this function will multiplycolor.alpha
byopacity
. - For gradients this function will multiply all colors by
opacity
. - For
Pattern
this function will multiplyPatter::opacity
byopacity
.
Trait Implementations§
impl<'a> StructuralPartialEq for Shader<'a>
Auto Trait Implementations§
impl<'a> Freeze for Shader<'a>
impl<'a> RefUnwindSafe for Shader<'a>
impl<'a> Send for Shader<'a>
impl<'a> Sync for Shader<'a>
impl<'a> Unpin for Shader<'a>
impl<'a> UnwindSafe for Shader<'a>
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)