mirror of
https://github.com/encounter/rust-sdl2.git
synced 2026-07-10 21:18:41 -07:00
Add tuple conversions with From for Color #699
This commit is contained in:
@@ -157,6 +157,19 @@ impl From<sys::SDL_Color> for Color {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl From<(u8, u8, u8)> for Color {
|
||||
fn from((r, g, b): (u8, u8, u8)) -> Color {
|
||||
Color::RGB(r, g, b)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(u8, u8, u8, u8)> for Color {
|
||||
fn from((r, g, b, a): (u8, u8, u8, u8)) -> Color {
|
||||
Color::RGBA(r, g, b, a)
|
||||
}
|
||||
}
|
||||
|
||||
impl rand::Rand for Color {
|
||||
fn rand<R: rand::Rng>(rng: &mut R) -> Color {
|
||||
if rng.gen() { Color::RGBA(rng.gen(), rng.gen(), rng.gen(), rng.gen()) }
|
||||
|
||||
+2
-2
@@ -902,8 +902,8 @@ impl<T: RenderTarget> Canvas<T> {
|
||||
}
|
||||
|
||||
/// Sets the color used for drawing operations (Rect, Line and Clear).
|
||||
pub fn set_draw_color(&mut self, color: pixels::Color) {
|
||||
let (r, g, b, a) = color.rgba();
|
||||
pub fn set_draw_color<C: Into<pixels::Color>>(&mut self, color: C) {
|
||||
let (r, g, b, a) = color.into().rgba();
|
||||
let ret = unsafe { sys::SDL_SetRenderDrawColor(self.raw, r, g, b, a) };
|
||||
// Should only fail on an invalid renderer
|
||||
if ret != 0 {
|
||||
|
||||
Reference in New Issue
Block a user