Skip to content

Commit

Permalink
Reflect default in colorspaces in bevy_color (#12528)
Browse files Browse the repository at this point in the history
# Objective

- For some reason, we don't reflect the Default trait in colorspaces

## Solution

- Reflect it.

---
  • Loading branch information
pablo-lua authored Mar 17, 2024
1 parent e9dc270 commit 7002b24
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions crates/bevy_color/src/color.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
Alpha, Hsla, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklaba, Oklcha, Srgba, StandardColor, Xyza,
};
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
use bevy_reflect::prelude::*;
use serde::{Deserialize, Serialize};

/// An enumerated type that can represent any of the color types in this crate.
Expand All @@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize};
#[doc = include_str!("../docs/diagrams/model_graph.svg")]
/// </div>
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)]
#[reflect(PartialEq, Serialize, Deserialize)]
#[reflect(PartialEq, Serialize, Deserialize, Default)]
pub enum Color {
/// A color in the sRGB color space with alpha.
Srgba(Srgba),
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_color/src/hsla.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{Alpha, Hsva, Hwba, Lcha, LinearRgba, Luminance, Mix, Srgba, StandardColor, Xyza};
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
use bevy_reflect::prelude::*;
use serde::{Deserialize, Serialize};

/// Color in Hue-Saturation-Lightness (HSL) color space with alpha.
Expand All @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
#[doc = include_str!("../docs/diagrams/model_graph.svg")]
/// </div>
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)]
#[reflect(PartialEq, Serialize, Deserialize)]
#[reflect(PartialEq, Serialize, Deserialize, Default)]
pub struct Hsla {
/// The hue channel. [0.0, 360.0]
pub hue: f32,
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_color/src/hsva.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{Alpha, Hwba, Lcha, LinearRgba, Srgba, StandardColor, Xyza};
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
use bevy_reflect::prelude::*;
use serde::{Deserialize, Serialize};

/// Color in Hue-Saturation-Value (HSV) color space with alpha.
Expand All @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
#[doc = include_str!("../docs/diagrams/model_graph.svg")]
/// </div>
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)]
#[reflect(PartialEq, Serialize, Deserialize)]
#[reflect(PartialEq, Serialize, Deserialize, Default)]
pub struct Hsva {
/// The hue channel. [0.0, 360.0]
pub hue: f32,
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_color/src/hwba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//!
//! [_HWB - A More Intuitive Hue-Based Color Model_]: https://web.archive.org/web/20240226005220/http://alvyray.com/Papers/CG/HWB_JGTv208.pdf
use crate::{Alpha, Lcha, LinearRgba, Srgba, StandardColor, Xyza};
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
use bevy_reflect::prelude::*;
use serde::{Deserialize, Serialize};

/// Color in Hue-Whiteness-Blackness (HWB) color space with alpha.
Expand All @@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize};
#[doc = include_str!("../docs/diagrams/model_graph.svg")]
/// </div>
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)]
#[reflect(PartialEq, Serialize, Deserialize)]
#[reflect(PartialEq, Serialize, Deserialize, Default)]
pub struct Hwba {
/// The hue channel. [0.0, 360.0]
pub hue: f32,
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_color/src/laba.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
Alpha, Hsla, Hsva, Hwba, LinearRgba, Luminance, Mix, Oklaba, Srgba, StandardColor, Xyza,
};
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
use bevy_reflect::prelude::*;
use serde::{Deserialize, Serialize};

/// Color in LAB color space, with alpha
Expand All @@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize};
#[doc = include_str!("../docs/diagrams/model_graph.svg")]
/// </div>
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)]
#[reflect(PartialEq, Serialize, Deserialize)]
#[reflect(PartialEq, Serialize, Deserialize, Default)]
pub struct Laba {
/// The lightness channel. [0.0, 1.5]
pub lightness: f32,
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_color/src/lcha.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{Alpha, Laba, LinearRgba, Luminance, Mix, Srgba, StandardColor, Xyza};
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
use bevy_reflect::prelude::*;
use serde::{Deserialize, Serialize};

/// Color in LCH color space, with alpha
Expand All @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
#[doc = include_str!("../docs/diagrams/model_graph.svg")]
/// </div>
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)]
#[reflect(PartialEq, Serialize, Deserialize)]
#[reflect(PartialEq, Serialize, Deserialize, Default)]
pub struct Lcha {
/// The lightness channel. [0.0, 1.5]
pub lightness: f32,
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_color/src/linear_rgba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::ops::{Div, Mul};

use crate::{color_difference::EuclideanDistance, Alpha, Luminance, Mix, StandardColor};
use bevy_math::Vec4;
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
use bevy_reflect::prelude::*;
use bytemuck::{Pod, Zeroable};
use serde::{Deserialize, Serialize};

Expand All @@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize};
#[doc = include_str!("../docs/diagrams/model_graph.svg")]
/// </div>
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)]
#[reflect(PartialEq, Serialize, Deserialize)]
#[reflect(PartialEq, Serialize, Deserialize, Default)]
#[repr(C)]
pub struct LinearRgba {
/// The red channel. [0.0, 1.0]
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_color/src/oklaba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
color_difference::EuclideanDistance, Alpha, Hsla, Hsva, Hwba, Lcha, LinearRgba, Luminance, Mix,
Srgba, StandardColor, Xyza,
};
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
use bevy_reflect::prelude::*;
use serde::{Deserialize, Serialize};

/// Color in Oklab color space, with alpha
Expand All @@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
#[doc = include_str!("../docs/diagrams/model_graph.svg")]
/// </div>
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)]
#[reflect(PartialEq, Serialize, Deserialize)]
#[reflect(PartialEq, Serialize, Deserialize, Default)]
pub struct Oklaba {
/// The 'l' channel. [0.0, 1.0]
pub l: f32,
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_color/src/oklcha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
color_difference::EuclideanDistance, Alpha, Hsla, Hsva, Hwba, Laba, Lcha, LinearRgba,
Luminance, Mix, Oklaba, Srgba, StandardColor, Xyza,
};
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
use bevy_reflect::prelude::*;
use serde::{Deserialize, Serialize};

/// Color in Oklch color space, with alpha
Expand All @@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
#[doc = include_str!("../docs/diagrams/model_graph.svg")]
/// </div>
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)]
#[reflect(PartialEq, Serialize, Deserialize)]
#[reflect(PartialEq, Serialize, Deserialize, Default)]
pub struct Oklcha {
/// The 'lightness' channel. [0.0, 1.0]
pub lightness: f32,
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_color/src/srgba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::ops::{Div, Mul};
use crate::color_difference::EuclideanDistance;
use crate::{Alpha, LinearRgba, Luminance, Mix, StandardColor, Xyza};
use bevy_math::Vec4;
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
use bevy_reflect::prelude::*;
use serde::{Deserialize, Serialize};
use thiserror::Error;

Expand All @@ -13,7 +13,7 @@ use thiserror::Error;
#[doc = include_str!("../docs/diagrams/model_graph.svg")]
/// </div>
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)]
#[reflect(PartialEq, Serialize, Deserialize)]
#[reflect(PartialEq, Serialize, Deserialize, Default)]
pub struct Srgba {
/// The red channel. [0.0, 1.0]
pub red: f32,
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_color/src/xyza.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{Alpha, LinearRgba, Luminance, Mix, StandardColor};
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
use bevy_reflect::prelude::*;
use serde::{Deserialize, Serialize};

/// [CIE 1931](https://en.wikipedia.org/wiki/CIE_1931_color_space) color space, also known as XYZ, with an alpha channel.
Expand All @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
#[doc = include_str!("../docs/diagrams/model_graph.svg")]
/// </div>
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)]
#[reflect(PartialEq, Serialize, Deserialize)]
#[reflect(PartialEq, Serialize, Deserialize, Default)]
pub struct Xyza {
/// The x-axis. [0.0, 1.0]
pub x: f32,
Expand Down

0 comments on commit 7002b24

Please sign in to comment.