mirror of
https://github.com/lisk77/comet.git
synced 2025-10-23 21:38:50 +00:00
feat: added Color trait to the comet_colors crate to make parameters simpler
This commit is contained in:
parent
b2578f7673
commit
7dc17fb435
13 changed files with 100 additions and 132 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{sRgba, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklaba, Oklcha, Xyza};
|
||||
use crate::{sRgba, Color, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklaba, Oklcha, Xyza};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Hsla {
|
||||
|
|
@ -98,4 +98,10 @@ impl Hsla {
|
|||
pub fn to_oklcha(&self) -> Oklcha {
|
||||
self.to_oklaba().to_oklcha()
|
||||
}
|
||||
}
|
||||
|
||||
impl Color for Hsla {
|
||||
fn to_wgpu(&self) -> wgpu::Color {
|
||||
self.to_linear().to_wgpu()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{sRgba, Hsla, Hwba, Laba, Lcha, LinearRgba, Oklaba, Oklcha, Xyza};
|
||||
use crate::{sRgba, Color, Hsla, Hwba, Laba, Lcha, LinearRgba, Oklaba, Oklcha, Xyza};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Hsva {
|
||||
|
|
@ -96,4 +96,10 @@ impl Hsva {
|
|||
pub fn to_oklcha(&self) -> Oklcha {
|
||||
self.to_oklaba().to_oklcha()
|
||||
}
|
||||
}
|
||||
|
||||
impl Color for Hsva {
|
||||
fn to_wgpu(&self) -> wgpu::Color {
|
||||
self.to_linear().to_wgpu()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{sRgba, Hsla, Hsva, Laba, Lcha, LinearRgba, Oklaba, Oklcha, Xyza};
|
||||
use crate::{sRgba, Color, Hsla, Hsva, Laba, Lcha, LinearRgba, Oklaba, Oklcha, Xyza};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Hwba {
|
||||
|
|
@ -159,4 +159,10 @@ impl Hwba {
|
|||
self.to_oklaba().to_oklcha()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Color for Hwba {
|
||||
fn to_wgpu(&self) -> wgpu::Color {
|
||||
self.to_linear().to_wgpu()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{sRgba, Hsla, Hsva, Hwba, Lcha, LinearRgba, Oklaba, Oklcha, Xyza};
|
||||
use crate::{sRgba, Color, Hsla, Hsva, Hwba, Lcha, LinearRgba, Oklaba, Oklcha, Xyza};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Laba {
|
||||
|
|
@ -140,4 +140,10 @@ impl Laba {
|
|||
pub fn to_hsla(&self) -> Hsla {
|
||||
self.to_hsva().to_hsla()
|
||||
}
|
||||
}
|
||||
|
||||
impl Color for Laba {
|
||||
fn to_wgpu(&self) -> wgpu::Color {
|
||||
self.to_linear().to_wgpu()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{sRgba, Hsla, Hsva, Hwba, Laba, LinearRgba, Oklaba, Oklcha, Xyza};
|
||||
use crate::{sRgba, Color, Hsla, Hsva, Hwba, Laba, LinearRgba, Oklaba, Oklcha, Xyza};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Lcha {
|
||||
|
|
@ -90,4 +90,10 @@ impl Lcha {
|
|||
self.to_hsva().to_hsla()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Color for Lcha {
|
||||
fn to_wgpu(&self) -> wgpu::Color {
|
||||
self.to_linear().to_wgpu()
|
||||
}
|
||||
}
|
||||
|
|
@ -19,4 +19,8 @@ mod xyza;
|
|||
mod laba;
|
||||
mod lcha;
|
||||
mod oklaba;
|
||||
mod oklcha;
|
||||
mod oklcha;
|
||||
|
||||
pub trait Color {
|
||||
fn to_wgpu(&self) -> wgpu::Color;
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
use wgpu::Color;
|
||||
use crate::{sRgba, Hsla, Hsva, Hwba, Laba, Lcha, Oklaba, Oklcha, Xyza};
|
||||
use wgpu;
|
||||
use crate::{sRgba, Color, Hsla, Hsva, Hwba, Laba, Lcha, Oklaba, Oklcha, Xyza};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct LinearRgba {
|
||||
|
|
@ -123,9 +123,11 @@ impl LinearRgba {
|
|||
pub fn to_hsla(&self) -> Hsla {
|
||||
self.to_hsva().to_hsla()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_wgpu(&self) -> Color {
|
||||
Color {
|
||||
impl Color for LinearRgba {
|
||||
fn to_wgpu(&self) -> wgpu::Color {
|
||||
wgpu::Color {
|
||||
r: self.red as f64,
|
||||
g: self.green as f64,
|
||||
b: self.blue as f64,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{sRgba, Hsla, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklcha, Xyza};
|
||||
use crate::{sRgba, Color, Hsla, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklcha, Xyza};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Oklaba {
|
||||
|
|
@ -110,4 +110,10 @@ impl Oklaba {
|
|||
pub fn to_hsla(&self) -> Hsla {
|
||||
self.to_hsva().to_hsla()
|
||||
}
|
||||
}
|
||||
|
||||
impl Color for Oklaba {
|
||||
fn to_wgpu(&self) -> wgpu::Color {
|
||||
self.to_linear().to_wgpu()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{sRgba, Hsla, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklaba, Xyza};
|
||||
use crate::{sRgba, Color, Hsla, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklaba, Xyza};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Oklcha {
|
||||
|
|
@ -89,4 +89,10 @@ impl Oklcha {
|
|||
pub fn to_hsla(&self) -> Hsla {
|
||||
self.to_hsva().to_hsla()
|
||||
}
|
||||
}
|
||||
|
||||
impl Color for Oklcha {
|
||||
fn to_wgpu(&self) -> wgpu::Color {
|
||||
self.to_linear().to_wgpu()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{math::Vec4, Hsla, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklaba, Oklcha, Xyza};
|
||||
use crate::{math::Vec4, Color, Hsla, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklaba, Oklcha, Xyza};
|
||||
|
||||
/// sRGB representation of color
|
||||
/// There are two variants: `sRgba<u8>` and `sRgba<f32>`
|
||||
|
|
@ -342,4 +342,16 @@ impl sRgba<f32> {
|
|||
self.alpha
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Color for sRgba<f32> {
|
||||
fn to_wgpu(&self) -> wgpu::Color {
|
||||
self.to_linear().to_wgpu()
|
||||
}
|
||||
}
|
||||
|
||||
impl Color for sRgba<u8> {
|
||||
fn to_wgpu(&self) -> wgpu::Color {
|
||||
self.to_linear().to_wgpu()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{sRgba, Hsla, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklaba, Oklcha};
|
||||
use crate::{sRgba, Color, Hsla, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklaba, Oklcha};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Xyza {
|
||||
|
|
@ -106,4 +106,10 @@ impl Xyza {
|
|||
pub fn to_hsla(&self) -> Hsla {
|
||||
self.to_hsva().to_hsla()
|
||||
}
|
||||
}
|
||||
|
||||
impl Color for Xyza {
|
||||
fn to_wgpu(&self) -> wgpu::Color {
|
||||
self.to_linear().to_wgpu()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue