Enum tiny_skia::Shader

source ·
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>

source

pub fn is_opaque(&self) -> bool

Checks if the shader is guaranteed to produce only opaque colors.

source

pub fn transform(&mut self, ts: Transform)

Transforms the shader.

source

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 multiply color.alpha by opacity.
  • For gradients this function will multiply all colors by opacity.
  • For Pattern this function will multiply Patter::opacity by opacity.

Trait Implementations§

source§

impl<'a> Clone for Shader<'a>

source§

fn clone(&self) -> Shader<'a>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for Shader<'a>

source§

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

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

impl<'a> PartialEq for Shader<'a>

source§

fn eq(&self, other: &Shader<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

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> 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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> 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.