Implement Color integer constructors
@@ -26,6 +26,25 @@ impl Color {
pub fn rgba(r: f32, g: f32, b: f32, a: f32) -> Color {
Color { r, g, b, a }
}
+
+ /// Creates a new `Color`, with the specified RGB integer values and the alpha set to 1.0.
+ pub fn rgb8(r: u8, g: u8, b: u8) -> Color {
+ let r = f32::from(r) / 255.0;
+ let g = f32::from(g) / 255.0;
+ let b = f32::from(b) / 255.0;
+
+ Color { r, g, b, a: 1.0 }
+ }
+
+ /// Creates a new `Color`, with the specified RGBA integer values.
+ pub fn rgba8(r: u8, g: u8, b: u8, a: u8) -> Color {
+ let r = f32::from(r) / 255.0;
+ let g = f32::from(g) / 255.0;
+ let b = f32::from(b) / 255.0;
+ let a = f32::from(a) / 255.0;
+
+ Color { r, g, b, a }
+ }
}
/// Shortcut for Color::rgb(0.0, 0.0, 0.0).
