Skip to content
This repository was archived by the owner on Jul 10, 2023. It is now read-only.

Commit e0064ac

Browse files
committed
Add color macro_rule
1 parent 3399d2f commit e0064ac

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

color.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@
44

55
use std::libc::types::os::arch::c95::c_double;
66
use std::cmp::Eq;
7+
use std::ascii::AsciiStr;
8+
9+
macro_rules! define_color(
10+
($color:ident, $r:expr, $g:expr, $b:expr) => {
11+
static $color: Color = Color { red: $r as u8, green: $g as u8, blue: $b as u8, alpha: 1.0 };
12+
}
13+
)
14+
15+
macro_rules! parse_static_color(
16+
($name:expr, $($color:ident),+) => {
17+
{
18+
let name = $name.trim().to_owned().into_ascii().to_upper().into_str();
19+
let mut color = None;
20+
$(
21+
if (stringify!($color) == name) {
22+
color = Some($color);
23+
}
24+
)+
25+
color
26+
}
27+
}
28+
)
729

830
#[deriving(Eq)]
931
pub struct Color {

0 commit comments

Comments
 (0)