feat(ext): ColorExt trait to add ::blend_alpha method

This commit is contained in:
Michael Aaron Murphy 2023-09-13 16:06:05 +02:00 committed by Michael Murphy
parent 55095abfce
commit 4c6c678f88

View file

@ -83,3 +83,20 @@ impl<'a, Message: 'a> CollectionWidget<'a, Message> for crate::widget::Row<'a, M
self.push(element)
}
}
pub trait ColorExt {
/// Combines color with background to create appearance of transparency.
#[must_use]
fn blend_alpha(self, background: Self, alpha: f32) -> Self;
}
impl ColorExt for iced::Color {
fn blend_alpha(self, background: Self, alpha: f32) -> Self {
Color {
a: 1.0,
r: background.r + (self.r - background.r) * alpha,
g: background.g + (self.g - background.g) * alpha,
b: background.b + (self.b - background.b) * alpha,
}
}
}