Implemented Alpha for f32. (#18653)

# Objective

`f32` can be used to represent alpha, this streamlines generic code
related to colors.

## Solution

- Implemented `Alpha` for `f32`.
This commit is contained in:
Mincong Lu 2025-05-06 08:00:17 +08:00 committed by GitHub
parent 818459113e
commit 023b502153
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -77,6 +77,20 @@ pub trait Alpha: Sized {
}
}
impl Alpha for f32 {
fn with_alpha(&self, alpha: f32) -> Self {
alpha
}
fn alpha(&self) -> f32 {
*self
}
fn set_alpha(&mut self, alpha: f32) {
*self = alpha;
}
}
/// Trait for manipulating the hue of a color.
pub trait Hue: Sized {
/// Return a new version of this color with the hue channel set to the given value.