Created
January 24, 2020 14:39
-
-
Save Nachasic/10d3a3db863751c4ec4c3d6f3ec5e71e to your computer and use it in GitHub Desktop.
Color macro for raylib in Rust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use raylib::prelude::*; | |
#[allow(unused_macros)] | |
macro_rules! color { | |
(# $color_hex:expr) => {{ | |
let color = i32::from_str_radix(stringify!($color_hex), 16).unwrap(); | |
let b = color % 0x100; | |
let g = (color - b) / 0x100 % 0x100; | |
let r = (color - g) / 0x10000; | |
Color { | |
r: r as u8, | |
g: g as u8, | |
b: b as u8, | |
a: 255 | |
} | |
}}; | |
} | |
#[test] | |
fn get_color () { | |
let color_white = color!(#FFFFFF); | |
let color_black = color!(#000000); | |
assert_eq!(color_black, Color::BLACK); | |
assert_eq!(color_white, Color::WHITE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment