From 023b502153c7060fcfe66ce65e60089930e8ba82 Mon Sep 17 00:00:00 2001 From: Mincong Lu <139340600+mintlu8@users.noreply.github.com> Date: Tue, 6 May 2025 08:00:17 +0800 Subject: [PATCH] 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`. --- crates/bevy_color/src/color_ops.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/bevy_color/src/color_ops.rs b/crates/bevy_color/src/color_ops.rs index 776ee906f9..a3266ba2d6 100644 --- a/crates/bevy_color/src/color_ops.rs +++ b/crates/bevy_color/src/color_ops.rs @@ -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.