From b6b4e4a8d14a4fb91af5169a8d1957b23a387ada Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 16 Jul 2026 16:51:29 +0200 Subject: feat(engine): add Rgb, Rgba, Lumen & LumenA color structs --- engine/src/data_types/color.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'engine') diff --git a/engine/src/data_types/color.rs b/engine/src/data_types/color.rs index c5316e6..06df450 100644 --- a/engine/src/data_types/color.rs +++ b/engine/src/data_types/color.rs @@ -1,5 +1,32 @@ use std::ops::{Add, Div, Mul, Neg, Sub}; +pub trait Pixel: sealed::Sealed +{ + type Component; +} + +macro_rules! gen_color { + ($ident: ident, components=($($component: ident),+)) => { + #[derive(Debug, Clone)] + pub struct $ident + { + $(pub $component: Component),+ + } + + impl Pixel for $ident + { + type Component = Component; + } + + impl sealed::Sealed for $ident {} + }; +} + +gen_color!(Rgb, components = (r, g, b)); +gen_color!(Rgba, components = (r, g, b, a)); +gen_color!(Luma, components = (l)); +gen_color!(LumaA, components = (l, a)); + #[derive(Debug, Clone, Default)] pub struct Color { @@ -95,3 +122,8 @@ where } } } + +mod sealed +{ + pub trait Sealed {} +} -- cgit v1.2.3-18-g5258