mirror of
https://github.com/bevyengine/bevy
synced 2024-11-14 00:47:32 +00:00
Add with_a
and friends to Color
(#6899)
# Objective ```rust // makes clippy complain about 'taking a mutable reference to a `const` item' let color = *Color::RED.set_a(0.5); // Now you can do let color = Color::RED.with_a(0.5); ``` ## Changelog Added `with_r`, `with_g`, `with_b`, and `with_a` to `Color`. Co-authored-by: devil-ira <justthecooldude@gmail.com>
This commit is contained in:
parent
75880a0b17
commit
ea8f74692f
1 changed files with 28 additions and 0 deletions
|
@ -358,6 +358,13 @@ impl Color {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns this color with red set to a new value in sRGB colorspace.
|
||||||
|
#[must_use]
|
||||||
|
pub fn with_r(mut self, r: f32) -> Self {
|
||||||
|
self.set_r(r);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Set green in sRGB colorspace.
|
/// Set green in sRGB colorspace.
|
||||||
pub fn set_g(&mut self, g: f32) -> &mut Self {
|
pub fn set_g(&mut self, g: f32) -> &mut Self {
|
||||||
*self = self.as_rgba();
|
*self = self.as_rgba();
|
||||||
|
@ -368,6 +375,13 @@ impl Color {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns this color with green set to a new value in sRGB colorspace.
|
||||||
|
#[must_use]
|
||||||
|
pub fn with_g(mut self, g: f32) -> Self {
|
||||||
|
self.set_g(g);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Set blue in sRGB colorspace.
|
/// Set blue in sRGB colorspace.
|
||||||
pub fn set_b(&mut self, b: f32) -> &mut Self {
|
pub fn set_b(&mut self, b: f32) -> &mut Self {
|
||||||
*self = self.as_rgba();
|
*self = self.as_rgba();
|
||||||
|
@ -378,6 +392,13 @@ impl Color {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns this color with blue set to a new value in sRGB colorspace.
|
||||||
|
#[must_use]
|
||||||
|
pub fn with_b(mut self, b: f32) -> Self {
|
||||||
|
self.set_b(b);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Get alpha.
|
/// Get alpha.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn a(&self) -> f32 {
|
pub fn a(&self) -> f32 {
|
||||||
|
@ -400,6 +421,13 @@ impl Color {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns this color with a new alpha value.
|
||||||
|
#[must_use]
|
||||||
|
pub fn with_a(mut self, a: f32) -> Self {
|
||||||
|
self.set_a(a);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Converts a `Color` to variant `Color::Rgba`
|
/// Converts a `Color` to variant `Color::Rgba`
|
||||||
pub fn as_rgba(self: &Color) -> Color {
|
pub fn as_rgba(self: &Color) -> Color {
|
||||||
match self {
|
match self {
|
||||||
|
|
Loading…
Reference in a new issue