cosmic::cosmic_theme::palette::blend

Trait BlendWith

source
pub trait BlendWith {
    type Color: Premultiply;

    // Required method
    fn blend_with<F>(self, destination: Self, blend_function: F) -> Self
       where F: BlendFunction<Self::Color>;
}
Expand description

Blending with a custom blend function.

This is a convenience trait that makes it possible to use BlendFunction via a method on the source color. This makes custom blending more similar to how the Compose and Blend are used, including automatic pre-multiplication.

Required Associated Types§

source

type Color: Premultiply

The base color type of Self.

Required Methods§

source

fn blend_with<F>(self, destination: Self, blend_function: F) -> Self
where F: BlendFunction<Self::Color>,

Blend self, as the source color, with destination, using blend_function. Anything that implements BlendFunction is acceptable, including functions and closures.

use palette::{LinSrgb, LinSrgba};
use palette::blend::{BlendWith, PreAlpha};

type PreRgba = PreAlpha<LinSrgb<f32>>;

fn blend_mode(a: PreRgba, b: PreRgba) -> PreRgba {
   PreAlpha {
       color: LinSrgb::new(a.red * b.green, a.green * b.blue, a.blue * b.red),
       alpha: a.alpha * b.alpha,
   }
}

let a = LinSrgba::new(0.2, 0.5, 0.1, 0.8);
let b = LinSrgba::new(0.6, 0.3, 0.5, 0.1);
let c = a.blend_with(b, blend_mode);

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<C> BlendWith for Alpha<C, <C as Premultiply>::Scalar>
where C: Premultiply,

source§

type Color = C

source§

impl<C> BlendWith for PreAlpha<C>
where C: Premultiply,

source§

type Color = C

source§

impl<C> BlendWith for C

source§

type Color = C