pub trait ColorExt {
// Required methods
fn blend(&self, other: &Self) -> Self
where Self: Sized;
fn fade_out(&mut self, factor: f32);
fn opacity(&self, factor: f32) -> Self
where Self: Sized;
}Expand description
Required Methods§
Sourcefn blend(&self, other: &Self) -> Selfwhere
Self: Sized,
fn blend(&self, other: &Self) -> Selfwhere
Self: Sized,
Composites other over this color with Porter–Duff source-over.
Sourcefn fade_out(&mut self, factor: f32)
fn fade_out(&mut self, factor: f32)
Reduces the alpha of this color in place by factor.
A factor of 0.0 leaves the color unchanged, and 1.0 makes it fully transparent.
Values outside 0.0..=1.0 are clamped.
Sourcefn opacity(&self, factor: f32) -> Selfwhere
Self: Sized,
fn opacity(&self, factor: f32) -> Selfwhere
Self: Sized,
Returns a copy of this color with its alpha multiplied by factor.
If the color is opaque, the result has alpha factor. Use this for colors whose
opacity comes from data, such as a color chosen at runtime. Values outside
0.0..=1.0 are clamped.
§Examples
use gpui::ColorExt;
let faded = gpui::red().opacity(0.5);
assert_eq!(faded.alpha, 0.5);Multiplying a color that already has alpha gives a result that is less opaque:
use gpui::{ColorExt, hsla};
let color = hsla(0.7, 1.0, 0.5, 0.7);
let faded = color.opacity(0.16);
assert!((faded.alpha - 0.112).abs() < 1e-6);Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".