Trait colorsys::ColorAlpha

source ·
pub trait ColorAlpha {
    fn alpha(&self) -> f64;
    fn get_alpha(&self) -> f64;
    fn set_alpha(&mut self, val: f64);
    fn opacify(&mut self, val: f64);
}
Expand description

Methods to work with alpha channel in color.

Required Methods§

Returns alpha channel. If it not set will returns 1.0

👎Deprecated since 0.7.0: Please use alpha instead

Returns alpha channel. If it not set will returns 1.0

Sets alpha channel

use colorsys::{Hsl,ColorAlpha};
let mut hsl = Hsl::default(); // Hsl { a: None, .. }
hsl.set_alpha(0.45); // Hsl { a: 0.45, .. }
hsl.set_alpha(123.015); // Hsl { a: 1.0, .. }
hsl.set_alpha(-123.3); // Hsl { a: 0.0, .. }

Increase/decrease color alpha channel with specified value. Value can be negative.

Example
use colorsys::{Hsl,ColorAlpha};
let mut hsl = Hsl::default(); // Hsl { a: None, .. }
hsl.opacify(-0.3); // Hsl { a: 0.7, .. }
hsl.opacify(0.015); // Hsl { a: 0.715, .. }

Implementors§