diff --git a/abletk-common/src/color.rs b/abletk-common/src/color.rs index 3028975..ad9b81d 100755 --- a/abletk-common/src/color.rs +++ b/abletk-common/src/color.rs @@ -12,6 +12,16 @@ use windows::Win32::Graphics::Direct2D::Common::D2D1_COLOR_F; #[derive(Copy, Clone, Debug)] pub struct Color(pub f32, pub f32, pub f32, pub f32); +impl Color { + pub fn from_rgba(rgba: u32) -> Self { + let r = ((rgba >> 24) & 0xFF) as f32 / 255.0; + let g = ((rgba >> 16) & 0xFF) as f32 / 255.0; + let b = ((rgba >> 8) & 0xFF) as f32 / 255.0; + let a = (rgba & 0xFF) as f32 / 255.0; + Self(r, g, b, a) + } +} + #[cfg(windows)] impl From for D2D1_COLOR_F { fn from(color: Color) -> Self { @@ -23,3 +33,18 @@ impl From for D2D1_COLOR_F { } } } + +// fixme: figure out how to tell RGB, RGBA, HSL, HSLA, any of those in +// hexadecimal numbers, etc. apart. +#[macro_export] +macro_rules! color { + ($r:expr, $g:expr, $b:expr, $a:expr) => { + $crate::color::Color($r, $g, $b, $a) + }; + ($r:expr, $g:expr, $b:expr) => { + $crate::color::Color($r, $g, $b, 1.0) + }; + // ($rgba:expr) => { + // $crate::color::Color::from_rgba($rgba) + // }; +} diff --git a/src/lib.rs b/src/lib.rs index 6647afd..d6be9c9 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,5 +26,6 @@ pub mod prelude { pub use crate::widget::Label; pub use crate::widget::Widget; pub use crate::window::*; + pub use crate::color; pub use crate::launch; } diff --git a/src/main.rs b/src/main.rs index 567991b..0758303 100755 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,5 @@ fn launch() -> _ { .apply_plugin(QuitPlugin) .add_window(Window::builder( Label::new("Hello, AbleTK!") - .color(Color(1.0, 0.0, 1.0, 1.0)) - )) + .color(color!(0xFF00FFFF)))) }