color macro
This commit is contained in:
parent
40084591ff
commit
a99e19de4b
|
@ -12,6 +12,16 @@ use windows::Win32::Graphics::Direct2D::Common::D2D1_COLOR_F;
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub struct Color(pub f32, pub f32, pub f32, pub f32);
|
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)]
|
#[cfg(windows)]
|
||||||
impl From<Color> for D2D1_COLOR_F {
|
impl From<Color> for D2D1_COLOR_F {
|
||||||
fn from(color: Color) -> Self {
|
fn from(color: Color) -> Self {
|
||||||
|
@ -23,3 +33,18 @@ impl From<Color> 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)
|
||||||
|
// };
|
||||||
|
}
|
||||||
|
|
|
@ -26,5 +26,6 @@ pub mod prelude {
|
||||||
pub use crate::widget::Label;
|
pub use crate::widget::Label;
|
||||||
pub use crate::widget::Widget;
|
pub use crate::widget::Widget;
|
||||||
pub use crate::window::*;
|
pub use crate::window::*;
|
||||||
|
pub use crate::color;
|
||||||
pub use crate::launch;
|
pub use crate::launch;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,5 @@ fn launch() -> _ {
|
||||||
.apply_plugin(QuitPlugin)
|
.apply_plugin(QuitPlugin)
|
||||||
.add_window(Window::builder(
|
.add_window(Window::builder(
|
||||||
Label::new("Hello, AbleTK!")
|
Label::new("Hello, AbleTK!")
|
||||||
.color(Color(1.0, 0.0, 1.0, 1.0))
|
.color(color!(0xFF00FFFF))))
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue