use elicitation::{elicit_newtype, elicit_newtype_traits};
use elicitation_derive::reflect_methods;
use std::sync::Arc;
macro_rules! color_space_newtype {
($name:ident, $upstream:path) => {
elicit_newtype!($upstream, as $name);
elicit_newtype_traits!($name, $upstream, [eq]);
impl serde::Serialize for $name {
fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
(*self.0).serialize(s)
}
}
impl<'de> serde::Deserialize<'de> for $name {
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
<$upstream>::deserialize(d).map(|v| $name(Arc::new(v)))
}
}
impl From<$name> for $upstream {
fn from(v: $name) -> Self {
*v.0
}
}
impl elicitation::ElicitComplete for $name {}
};
}
color_space_newtype!(Srgba, bevy::color::Srgba);
#[reflect_methods]
impl Srgba {
#[tracing::instrument(skip(self))]
pub fn srgba_red(&self) -> f32 {
self.0.red
}
#[tracing::instrument(skip(self))]
pub fn srgba_green(&self) -> f32 {
self.0.green
}
#[tracing::instrument(skip(self))]
pub fn srgba_blue(&self) -> f32 {
self.0.blue
}
#[tracing::instrument(skip(self))]
pub fn srgba_alpha(&self) -> f32 {
self.0.alpha
}
#[tracing::instrument(skip(self))]
pub fn srgba_with_red(&self, red: f32) -> Srgba {
Srgba::from((*self.0).with_red(red))
}
#[tracing::instrument(skip(self))]
pub fn srgba_with_green(&self, green: f32) -> Srgba {
Srgba::from((*self.0).with_green(green))
}
#[tracing::instrument(skip(self))]
pub fn srgba_with_blue(&self, blue: f32) -> Srgba {
Srgba::from((*self.0).with_blue(blue))
}
#[tracing::instrument(skip(self))]
pub fn srgba_with_alpha(&self, alpha: f32) -> Srgba {
use bevy::color::Alpha;
Srgba::from(self.0.with_alpha(alpha))
}
#[tracing::instrument(skip(self))]
pub fn to_u8_array(&self) -> Vec<u8> {
use bevy::color::ColorToPacked;
(*self.0).to_u8_array().to_vec()
}
#[tracing::instrument(skip(self))]
pub fn to_f32_array(&self) -> Vec<f32> {
use bevy::color::ColorToComponents;
(*self.0).to_f32_array().to_vec()
}
#[tracing::instrument(skip(self))]
pub fn to_hex(&self) -> String {
self.0.to_hex()
}
#[tracing::instrument(skip(self))]
pub fn from_hex(&self, hex: &str) -> Option<Srgba> {
bevy::color::Srgba::hex(hex).ok().map(Srgba::from)
}
#[tracing::instrument(skip(self))]
pub fn srgba_new(&self, r: f32, g: f32, b: f32, a: f32) -> Srgba {
Srgba::from(bevy::color::Srgba {
red: r,
green: g,
blue: b,
alpha: a,
})
}
#[tracing::instrument(skip(self))]
pub fn srgba_is_fully_transparent(&self) -> bool {
use bevy::color::Alpha;
self.0.is_fully_transparent()
}
#[tracing::instrument(skip(self))]
pub fn srgba_is_fully_opaque(&self) -> bool {
use bevy::color::Alpha;
self.0.is_fully_opaque()
}
#[tracing::instrument(skip(self))]
pub fn srgba_lerp(&self, other: Srgba, factor: f32) -> Srgba {
use bevy::color::Mix;
Srgba::from((*self.0).mix(&*other.0, factor))
}
}
mod emit_srgba {
use super::Srgba;
use elicitation::emit_code::ToCodeLiteral;
use proc_macro2::TokenStream;
impl ToCodeLiteral for Srgba {
fn to_code_literal(&self) -> TokenStream {
let (r, g, b, a) = (self.0.red, self.0.green, self.0.blue, self.0.alpha);
quote::quote! {
::elicit_bevy::Srgba::from(::bevy::color::Srgba {
red: #r, green: #g, blue: #b, alpha: #a,
})
}
}
}
}
color_space_newtype!(LinearRgba, bevy::color::LinearRgba);
#[reflect_methods]
impl LinearRgba {
#[tracing::instrument(skip(self))]
pub fn linear_rgba_red(&self) -> f32 {
self.0.red
}
#[tracing::instrument(skip(self))]
pub fn linear_rgba_green(&self) -> f32 {
self.0.green
}
#[tracing::instrument(skip(self))]
pub fn linear_rgba_blue(&self) -> f32 {
self.0.blue
}
#[tracing::instrument(skip(self))]
pub fn linear_rgba_alpha(&self) -> f32 {
self.0.alpha
}
#[tracing::instrument(skip(self))]
pub fn linear_rgba_with_red(&self, red: f32) -> LinearRgba {
LinearRgba::from((*self.0).with_red(red))
}
#[tracing::instrument(skip(self))]
pub fn linear_rgba_with_green(&self, green: f32) -> LinearRgba {
LinearRgba::from((*self.0).with_green(green))
}
#[tracing::instrument(skip(self))]
pub fn linear_rgba_with_blue(&self, blue: f32) -> LinearRgba {
LinearRgba::from((*self.0).with_blue(blue))
}
#[tracing::instrument(skip(self))]
pub fn linear_rgba_with_alpha(&self, alpha: f32) -> LinearRgba {
use bevy::color::Alpha;
LinearRgba::from(self.0.with_alpha(alpha))
}
#[tracing::instrument(skip(self))]
pub fn luminance(&self) -> f32 {
use bevy::color::Luminance;
self.0.luminance()
}
#[tracing::instrument(skip(self))]
pub fn linear_rgba_new(&self, r: f32, g: f32, b: f32, a: f32) -> LinearRgba {
LinearRgba::from(bevy::color::LinearRgba {
red: r,
green: g,
blue: b,
alpha: a,
})
}
#[tracing::instrument(skip(self))]
pub fn linear_rgba_is_fully_transparent(&self) -> bool {
use bevy::color::Alpha;
self.0.is_fully_transparent()
}
#[tracing::instrument(skip(self))]
pub fn linear_rgba_is_fully_opaque(&self) -> bool {
use bevy::color::Alpha;
self.0.is_fully_opaque()
}
#[tracing::instrument(skip(self))]
pub fn linear_rgba_lerp(&self, other: LinearRgba, factor: f32) -> LinearRgba {
use bevy::color::Mix;
LinearRgba::from((*self.0).mix(&*other.0, factor))
}
}
mod emit_lrgba {
use super::LinearRgba;
use elicitation::emit_code::ToCodeLiteral;
use proc_macro2::TokenStream;
impl ToCodeLiteral for LinearRgba {
fn to_code_literal(&self) -> TokenStream {
let (r, g, b, a) = (self.0.red, self.0.green, self.0.blue, self.0.alpha);
quote::quote! {
::elicit_bevy::LinearRgba::from(::bevy::color::LinearRgba {
red: #r, green: #g, blue: #b, alpha: #a,
})
}
}
}
}
color_space_newtype!(Hsla, bevy::color::Hsla);
#[reflect_methods]
impl Hsla {
#[tracing::instrument(skip(self))]
pub fn hsla_hue(&self) -> f32 {
self.0.hue
}
#[tracing::instrument(skip(self))]
pub fn hsla_saturation(&self) -> f32 {
self.0.saturation
}
#[tracing::instrument(skip(self))]
pub fn hsla_lightness(&self) -> f32 {
self.0.lightness
}
#[tracing::instrument(skip(self))]
pub fn hsla_alpha(&self) -> f32 {
self.0.alpha
}
#[tracing::instrument(skip(self))]
pub fn hsla_with_hue(&self, hue: f32) -> Hsla {
use bevy::color::Hue;
Hsla::from(self.0.with_hue(hue))
}
#[tracing::instrument(skip(self))]
pub fn hsla_with_saturation(&self, saturation: f32) -> Hsla {
Hsla::from((*self.0).with_saturation(saturation))
}
#[tracing::instrument(skip(self))]
pub fn hsla_with_lightness(&self, lightness: f32) -> Hsla {
Hsla::from((*self.0).with_lightness(lightness))
}
#[tracing::instrument(skip(self))]
pub fn hsla_with_alpha(&self, alpha: f32) -> Hsla {
use bevy::color::Alpha;
Hsla::from(self.0.with_alpha(alpha))
}
#[tracing::instrument(skip(self))]
pub fn hsla_rotate_hue(&self, degrees: f32) -> Hsla {
use bevy::color::Hue;
Hsla::from((*self.0).rotate_hue(degrees))
}
#[tracing::instrument(skip(self))]
pub fn hsla_is_fully_transparent(&self) -> bool {
use bevy::color::Alpha;
self.0.is_fully_transparent()
}
#[tracing::instrument(skip(self))]
pub fn hsla_is_fully_opaque(&self) -> bool {
use bevy::color::Alpha;
self.0.is_fully_opaque()
}
#[tracing::instrument(skip(self))]
pub fn hsla_lerp(&self, other: Hsla, factor: f32) -> Hsla {
use bevy::color::Mix;
Hsla::from((*self.0).mix(&*other.0, factor))
}
}
mod emit_hsla {
use super::Hsla;
use elicitation::emit_code::ToCodeLiteral;
use proc_macro2::TokenStream;
impl ToCodeLiteral for Hsla {
fn to_code_literal(&self) -> TokenStream {
let (h, s, l, a) = (
self.0.hue,
self.0.saturation,
self.0.lightness,
self.0.alpha,
);
quote::quote! {
::elicit_bevy::Hsla::from(::bevy::color::Hsla {
hue: #h, saturation: #s, lightness: #l, alpha: #a,
})
}
}
}
}
color_space_newtype!(Hsva, bevy::color::Hsva);
#[reflect_methods]
impl Hsva {
#[tracing::instrument(skip(self))]
pub fn hsva_hue(&self) -> f32 {
self.0.hue
}
#[tracing::instrument(skip(self))]
pub fn hsva_saturation(&self) -> f32 {
self.0.saturation
}
#[tracing::instrument(skip(self))]
pub fn value(&self) -> f32 {
self.0.value
}
#[tracing::instrument(skip(self))]
pub fn hsva_alpha(&self) -> f32 {
self.0.alpha
}
#[tracing::instrument(skip(self))]
pub fn hsva_with_hue(&self, hue: f32) -> Hsva {
use bevy::color::Hue;
Hsva::from(self.0.with_hue(hue))
}
#[tracing::instrument(skip(self))]
pub fn hsva_with_saturation(&self, saturation: f32) -> Hsva {
Hsva::from((*self.0).with_saturation(saturation))
}
#[tracing::instrument(skip(self))]
pub fn with_value(&self, value: f32) -> Hsva {
Hsva::from((*self.0).with_value(value))
}
#[tracing::instrument(skip(self))]
pub fn hsva_with_alpha(&self, alpha: f32) -> Hsva {
use bevy::color::Alpha;
Hsva::from(self.0.with_alpha(alpha))
}
#[tracing::instrument(skip(self))]
pub fn hsva_rotate_hue(&self, degrees: f32) -> Hsva {
use bevy::color::Hue;
Hsva::from((*self.0).rotate_hue(degrees))
}
#[tracing::instrument(skip(self))]
pub fn hsva_is_fully_transparent(&self) -> bool {
use bevy::color::Alpha;
self.0.is_fully_transparent()
}
#[tracing::instrument(skip(self))]
pub fn hsva_is_fully_opaque(&self) -> bool {
use bevy::color::Alpha;
self.0.is_fully_opaque()
}
#[tracing::instrument(skip(self))]
pub fn hsva_lerp(&self, other: Hsva, factor: f32) -> Hsva {
use bevy::color::Mix;
Hsva::from((*self.0).mix(&*other.0, factor))
}
}
mod emit_hsva {
use super::Hsva;
use elicitation::emit_code::ToCodeLiteral;
use proc_macro2::TokenStream;
impl ToCodeLiteral for Hsva {
fn to_code_literal(&self) -> TokenStream {
let (h, s, v, a) = (self.0.hue, self.0.saturation, self.0.value, self.0.alpha);
quote::quote! {
::elicit_bevy::Hsva::from(::bevy::color::Hsva {
hue: #h, saturation: #s, value: #v, alpha: #a,
})
}
}
}
}
color_space_newtype!(Hwba, bevy::color::Hwba);
#[reflect_methods]
impl Hwba {
#[tracing::instrument(skip(self))]
pub fn hwba_hue(&self) -> f32 {
self.0.hue
}
#[tracing::instrument(skip(self))]
pub fn whiteness(&self) -> f32 {
self.0.whiteness
}
#[tracing::instrument(skip(self))]
pub fn blackness(&self) -> f32 {
self.0.blackness
}
#[tracing::instrument(skip(self))]
pub fn hwba_alpha(&self) -> f32 {
self.0.alpha
}
#[tracing::instrument(skip(self))]
pub fn hwba_with_hue(&self, hue: f32) -> Hwba {
use bevy::color::Hue;
Hwba::from(self.0.with_hue(hue))
}
#[tracing::instrument(skip(self))]
pub fn with_whiteness(&self, whiteness: f32) -> Hwba {
Hwba::from((*self.0).with_whiteness(whiteness))
}
#[tracing::instrument(skip(self))]
pub fn with_blackness(&self, blackness: f32) -> Hwba {
Hwba::from((*self.0).with_blackness(blackness))
}
#[tracing::instrument(skip(self))]
pub fn hwba_with_alpha(&self, alpha: f32) -> Hwba {
use bevy::color::Alpha;
Hwba::from(self.0.with_alpha(alpha))
}
#[tracing::instrument(skip(self))]
pub fn hwba_rotate_hue(&self, degrees: f32) -> Hwba {
use bevy::color::Hue;
Hwba::from((*self.0).rotate_hue(degrees))
}
#[tracing::instrument(skip(self))]
pub fn hwba_is_fully_transparent(&self) -> bool {
use bevy::color::Alpha;
self.0.is_fully_transparent()
}
#[tracing::instrument(skip(self))]
pub fn hwba_is_fully_opaque(&self) -> bool {
use bevy::color::Alpha;
self.0.is_fully_opaque()
}
#[tracing::instrument(skip(self))]
pub fn hwba_lerp(&self, other: Hwba, factor: f32) -> Hwba {
use bevy::color::Mix;
Hwba::from((*self.0).mix(&*other.0, factor))
}
}
mod emit_hwba {
use super::Hwba;
use elicitation::emit_code::ToCodeLiteral;
use proc_macro2::TokenStream;
impl ToCodeLiteral for Hwba {
fn to_code_literal(&self) -> TokenStream {
let (h, w, b, a) = (self.0.hue, self.0.whiteness, self.0.blackness, self.0.alpha);
quote::quote! {
::elicit_bevy::Hwba::from(::bevy::color::Hwba {
hue: #h, whiteness: #w, blackness: #b, alpha: #a,
})
}
}
}
}
color_space_newtype!(Laba, bevy::color::Laba);
#[reflect_methods]
impl Laba {
#[tracing::instrument(skip(self))]
pub fn laba_lightness(&self) -> f32 {
self.0.lightness
}
#[tracing::instrument(skip(self))]
pub fn laba_a(&self) -> f32 {
self.0.a
}
#[tracing::instrument(skip(self))]
pub fn laba_b(&self) -> f32 {
self.0.b
}
#[tracing::instrument(skip(self))]
pub fn laba_alpha(&self) -> f32 {
self.0.alpha
}
#[tracing::instrument(skip(self))]
pub fn laba_with_lightness(&self, lightness: f32) -> Laba {
Laba::from((*self.0).with_lightness(lightness))
}
#[tracing::instrument(skip(self))]
pub fn laba_with_alpha(&self, alpha: f32) -> Laba {
use bevy::color::Alpha;
Laba::from(self.0.with_alpha(alpha))
}
#[tracing::instrument(skip(self))]
pub fn laba_is_fully_transparent(&self) -> bool {
use bevy::color::Alpha;
self.0.is_fully_transparent()
}
#[tracing::instrument(skip(self))]
pub fn laba_is_fully_opaque(&self) -> bool {
use bevy::color::Alpha;
self.0.is_fully_opaque()
}
#[tracing::instrument(skip(self))]
pub fn laba_lerp(&self, other: Laba, factor: f32) -> Laba {
use bevy::color::Mix;
Laba::from((*self.0).mix(&*other.0, factor))
}
}
mod emit_laba {
use super::Laba;
use elicitation::emit_code::ToCodeLiteral;
use proc_macro2::TokenStream;
impl ToCodeLiteral for Laba {
fn to_code_literal(&self) -> TokenStream {
let (l, a, b, al) = (self.0.lightness, self.0.a, self.0.b, self.0.alpha);
quote::quote! {
::elicit_bevy::Laba::from(::bevy::color::Laba {
lightness: #l, a: #a, b: #b, alpha: #al,
})
}
}
}
}
color_space_newtype!(Lcha, bevy::color::Lcha);
#[reflect_methods]
impl Lcha {
#[tracing::instrument(skip(self))]
pub fn lcha_lightness(&self) -> f32 {
self.0.lightness
}
#[tracing::instrument(skip(self))]
pub fn lcha_chroma(&self) -> f32 {
self.0.chroma
}
#[tracing::instrument(skip(self))]
pub fn lcha_hue(&self) -> f32 {
self.0.hue
}
#[tracing::instrument(skip(self))]
pub fn lcha_alpha(&self) -> f32 {
self.0.alpha
}
#[tracing::instrument(skip(self))]
pub fn lcha_with_lightness(&self, lightness: f32) -> Lcha {
Lcha::from((*self.0).with_lightness(lightness))
}
#[tracing::instrument(skip(self))]
pub fn lcha_with_chroma(&self, chroma: f32) -> Lcha {
Lcha::from((*self.0).with_chroma(chroma))
}
#[tracing::instrument(skip(self))]
pub fn lcha_with_hue(&self, hue: f32) -> Lcha {
use bevy::color::Hue;
Lcha::from(self.0.with_hue(hue))
}
#[tracing::instrument(skip(self))]
pub fn lcha_with_alpha(&self, alpha: f32) -> Lcha {
use bevy::color::Alpha;
Lcha::from(self.0.with_alpha(alpha))
}
#[tracing::instrument(skip(self))]
pub fn lcha_rotate_hue(&self, degrees: f32) -> Lcha {
use bevy::color::Hue;
Lcha::from((*self.0).rotate_hue(degrees))
}
#[tracing::instrument(skip(self))]
pub fn lcha_is_fully_transparent(&self) -> bool {
use bevy::color::Alpha;
self.0.is_fully_transparent()
}
#[tracing::instrument(skip(self))]
pub fn lcha_is_fully_opaque(&self) -> bool {
use bevy::color::Alpha;
self.0.is_fully_opaque()
}
#[tracing::instrument(skip(self))]
pub fn lcha_lerp(&self, other: Lcha, factor: f32) -> Lcha {
use bevy::color::Mix;
Lcha::from((*self.0).mix(&*other.0, factor))
}
}
mod emit_lcha {
use super::Lcha;
use elicitation::emit_code::ToCodeLiteral;
use proc_macro2::TokenStream;
impl ToCodeLiteral for Lcha {
fn to_code_literal(&self) -> TokenStream {
let (l, c, h, a) = (self.0.lightness, self.0.chroma, self.0.hue, self.0.alpha);
quote::quote! {
::elicit_bevy::Lcha::from(::bevy::color::Lcha {
lightness: #l, chroma: #c, hue: #h, alpha: #a,
})
}
}
}
}
color_space_newtype!(Oklaba, bevy::color::Oklaba);
#[reflect_methods]
impl Oklaba {
#[tracing::instrument(skip(self))]
pub fn oklaba_lightness(&self) -> f32 {
self.0.lightness
}
#[tracing::instrument(skip(self))]
pub fn oklaba_a(&self) -> f32 {
self.0.a
}
#[tracing::instrument(skip(self))]
pub fn oklaba_b(&self) -> f32 {
self.0.b
}
#[tracing::instrument(skip(self))]
pub fn oklaba_alpha(&self) -> f32 {
self.0.alpha
}
#[tracing::instrument(skip(self))]
pub fn oklaba_with_lightness(&self, lightness: f32) -> Oklaba {
Oklaba::from((*self.0).with_lightness(lightness))
}
#[tracing::instrument(skip(self))]
pub fn with_a(&self, a: f32) -> Oklaba {
Oklaba::from((*self.0).with_a(a))
}
#[tracing::instrument(skip(self))]
pub fn with_b(&self, b: f32) -> Oklaba {
Oklaba::from((*self.0).with_b(b))
}
#[tracing::instrument(skip(self))]
pub fn oklaba_with_alpha(&self, alpha: f32) -> Oklaba {
use bevy::color::Alpha;
Oklaba::from(self.0.with_alpha(alpha))
}
#[tracing::instrument(skip(self))]
pub fn oklaba_is_fully_transparent(&self) -> bool {
use bevy::color::Alpha;
self.0.is_fully_transparent()
}
#[tracing::instrument(skip(self))]
pub fn oklaba_is_fully_opaque(&self) -> bool {
use bevy::color::Alpha;
self.0.is_fully_opaque()
}
#[tracing::instrument(skip(self))]
pub fn oklaba_lerp(&self, other: Oklaba, factor: f32) -> Oklaba {
use bevy::color::Mix;
Oklaba::from((*self.0).mix(&*other.0, factor))
}
}
mod emit_oklaba {
use super::Oklaba;
use elicitation::emit_code::ToCodeLiteral;
use proc_macro2::TokenStream;
impl ToCodeLiteral for Oklaba {
fn to_code_literal(&self) -> TokenStream {
let (l, a, b, al) = (self.0.lightness, self.0.a, self.0.b, self.0.alpha);
quote::quote! {
::elicit_bevy::Oklaba::from(::bevy::color::Oklaba {
lightness: #l, a: #a, b: #b, alpha: #al,
})
}
}
}
}
color_space_newtype!(Oklcha, bevy::color::Oklcha);
#[reflect_methods]
impl Oklcha {
#[tracing::instrument(skip(self))]
pub fn oklcha_lightness(&self) -> f32 {
self.0.lightness
}
#[tracing::instrument(skip(self))]
pub fn oklcha_chroma(&self) -> f32 {
self.0.chroma
}
#[tracing::instrument(skip(self))]
pub fn oklcha_hue(&self) -> f32 {
self.0.hue
}
#[tracing::instrument(skip(self))]
pub fn oklcha_alpha(&self) -> f32 {
self.0.alpha
}
#[tracing::instrument(skip(self))]
pub fn oklcha_with_lightness(&self, lightness: f32) -> Oklcha {
Oklcha::from((*self.0).with_lightness(lightness))
}
#[tracing::instrument(skip(self))]
pub fn oklcha_with_chroma(&self, chroma: f32) -> Oklcha {
Oklcha::from((*self.0).with_chroma(chroma))
}
#[tracing::instrument(skip(self))]
pub fn oklcha_with_hue(&self, hue: f32) -> Oklcha {
use bevy::color::Hue;
Oklcha::from(self.0.with_hue(hue))
}
#[tracing::instrument(skip(self))]
pub fn oklcha_with_alpha(&self, alpha: f32) -> Oklcha {
use bevy::color::Alpha;
Oklcha::from(self.0.with_alpha(alpha))
}
#[tracing::instrument(skip(self))]
pub fn oklcha_rotate_hue(&self, degrees: f32) -> Oklcha {
use bevy::color::Hue;
Oklcha::from((*self.0).rotate_hue(degrees))
}
#[tracing::instrument(skip(self))]
pub fn oklcha_is_fully_transparent(&self) -> bool {
use bevy::color::Alpha;
self.0.is_fully_transparent()
}
#[tracing::instrument(skip(self))]
pub fn oklcha_is_fully_opaque(&self) -> bool {
use bevy::color::Alpha;
self.0.is_fully_opaque()
}
#[tracing::instrument(skip(self))]
pub fn oklcha_lerp(&self, other: Oklcha, factor: f32) -> Oklcha {
use bevy::color::Mix;
Oklcha::from((*self.0).mix(&*other.0, factor))
}
}
mod emit_oklcha {
use super::Oklcha;
use elicitation::emit_code::ToCodeLiteral;
use proc_macro2::TokenStream;
impl ToCodeLiteral for Oklcha {
fn to_code_literal(&self) -> TokenStream {
let (l, c, h, a) = (self.0.lightness, self.0.chroma, self.0.hue, self.0.alpha);
quote::quote! {
::elicit_bevy::Oklcha::from(::bevy::color::Oklcha {
lightness: #l, chroma: #c, hue: #h, alpha: #a,
})
}
}
}
}
color_space_newtype!(Xyza, bevy::color::Xyza);
#[reflect_methods]
impl Xyza {
#[tracing::instrument(skip(self))]
pub fn x(&self) -> f32 {
self.0.x
}
#[tracing::instrument(skip(self))]
pub fn y(&self) -> f32 {
self.0.y
}
#[tracing::instrument(skip(self))]
pub fn z(&self) -> f32 {
self.0.z
}
#[tracing::instrument(skip(self))]
pub fn xyza_alpha(&self) -> f32 {
self.0.alpha
}
#[tracing::instrument(skip(self))]
pub fn with_x(&self, x: f32) -> Xyza {
Xyza::from((*self.0).with_x(x))
}
#[tracing::instrument(skip(self))]
pub fn with_y(&self, y: f32) -> Xyza {
Xyza::from((*self.0).with_y(y))
}
#[tracing::instrument(skip(self))]
pub fn with_z(&self, z: f32) -> Xyza {
Xyza::from((*self.0).with_z(z))
}
#[tracing::instrument(skip(self))]
pub fn xyza_with_alpha(&self, alpha: f32) -> Xyza {
use bevy::color::Alpha;
Xyza::from(self.0.with_alpha(alpha))
}
#[tracing::instrument(skip(self))]
pub fn xyza_is_fully_transparent(&self) -> bool {
use bevy::color::Alpha;
self.0.is_fully_transparent()
}
#[tracing::instrument(skip(self))]
pub fn xyza_is_fully_opaque(&self) -> bool {
use bevy::color::Alpha;
self.0.is_fully_opaque()
}
#[tracing::instrument(skip(self))]
pub fn xyza_lerp(&self, other: Xyza, factor: f32) -> Xyza {
use bevy::color::Mix;
Xyza::from((*self.0).mix(&*other.0, factor))
}
}
mod emit_xyza {
use super::Xyza;
use elicitation::emit_code::ToCodeLiteral;
use proc_macro2::TokenStream;
impl ToCodeLiteral for Xyza {
fn to_code_literal(&self) -> TokenStream {
let (x, y, z, a) = (self.0.x, self.0.y, self.0.z, self.0.alpha);
quote::quote! {
::elicit_bevy::Xyza::from(::bevy::color::Xyza {
x: #x, y: #y, z: #z, alpha: #a,
})
}
}
}
}
elicit_newtype!(bevy::color::Color, as Color);
elicit_newtype_traits!(Color, bevy::color::Color, [eq]);
impl serde::Serialize for Color {
fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
(*self.0).serialize(s)
}
}
impl<'de> serde::Deserialize<'de> for Color {
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
bevy::color::Color::deserialize(d).map(|v| Color(Arc::new(v)))
}
}
impl From<Color> for bevy::color::Color {
fn from(v: Color) -> Self {
*v.0
}
}
#[reflect_methods]
impl Color {
#[tracing::instrument(skip(self))]
pub fn to_srgba(&self) -> Srgba {
Srgba::from(self.0.to_srgba())
}
#[tracing::instrument(skip(self))]
pub fn to_linear(&self) -> LinearRgba {
LinearRgba::from(self.0.to_linear())
}
#[tracing::instrument(skip(self))]
pub fn to_hsla(&self) -> Hsla {
Hsla::from(bevy::color::Hsla::from(*self.0))
}
#[tracing::instrument(skip(self))]
pub fn to_oklaba(&self) -> Oklaba {
Oklaba::from(bevy::color::Oklaba::from(*self.0))
}
#[tracing::instrument(skip(self))]
pub fn color_alpha(&self) -> f32 {
use bevy::color::Alpha;
self.0.alpha()
}
#[tracing::instrument(skip(self))]
pub fn color_with_alpha(&self, alpha: f32) -> Color {
use bevy::color::Alpha;
Color::from(self.0.with_alpha(alpha))
}
#[tracing::instrument(skip(self))]
pub fn color_is_fully_transparent(&self) -> bool {
use bevy::color::Alpha;
self.0.is_fully_transparent()
}
#[tracing::instrument(skip(self))]
pub fn color_is_fully_opaque(&self) -> bool {
use bevy::color::Alpha;
self.0.is_fully_opaque()
}
#[tracing::instrument(skip(self))]
pub fn linear_slow_transition(&self, end: Color, f: f32) -> Color {
use bevy::color::Mix;
Color::from((*self.0).mix(&*end.0, f))
}
#[tracing::instrument(skip(self))]
pub fn variant_name(&self) -> &'static str {
match *self.0 {
bevy::color::Color::Srgba(_) => "Srgba",
bevy::color::Color::LinearRgba(_) => "LinearRgba",
bevy::color::Color::Hsla(_) => "Hsla",
bevy::color::Color::Hsva(_) => "Hsva",
bevy::color::Color::Hwba(_) => "Hwba",
bevy::color::Color::Laba(_) => "Laba",
bevy::color::Color::Lcha(_) => "Lcha",
bevy::color::Color::Oklaba(_) => "Oklaba",
bevy::color::Color::Oklcha(_) => "Oklcha",
bevy::color::Color::Xyza(_) => "Xyza",
}
}
#[tracing::instrument(skip(self))]
pub fn is_srgba(&self) -> bool {
matches!(*self.0, bevy::color::Color::Srgba(_))
}
#[tracing::instrument(skip(self))]
pub fn is_linear_rgba(&self) -> bool {
matches!(*self.0, bevy::color::Color::LinearRgba(_))
}
#[tracing::instrument(skip(self))]
pub fn is_hsla(&self) -> bool {
matches!(*self.0, bevy::color::Color::Hsla(_))
}
#[tracing::instrument(skip(self))]
pub fn white(&self) -> Color {
Color::from(bevy::color::Color::WHITE)
}
#[tracing::instrument(skip(self))]
pub fn black(&self) -> Color {
Color::from(bevy::color::Color::BLACK)
}
#[tracing::instrument(skip(self))]
pub fn none(&self) -> Color {
Color::from(bevy::color::Color::NONE)
}
#[tracing::instrument(skip(self))]
pub fn srgb(&self, r: f32, g: f32, b: f32) -> Color {
Color::from(bevy::color::Color::srgb(r, g, b))
}
#[tracing::instrument(skip(self))]
pub fn srgb_from_hex(&self, hex: &str) -> Option<Color> {
bevy::color::Srgba::hex(hex)
.ok()
.map(|c| Color::from(bevy::color::Color::Srgba(c)))
}
}
mod emit_color {
use super::Color;
use elicitation::emit_code::ToCodeLiteral;
use proc_macro2::TokenStream;
impl ToCodeLiteral for Color {
fn to_code_literal(&self) -> TokenStream {
let json = serde_json::to_string(&**self).unwrap_or_default();
quote::quote! {
::elicit_bevy::Color::from(
::serde_json::from_str::<::bevy::color::Color>(#json).unwrap()
)
}
}
}
}
impl elicitation::ElicitComplete for Color {}