diff --git a/canvas/src/lib.rs b/canvas/src/lib.rs index 167da7b1..f75946f0 100644 --- a/canvas/src/lib.rs +++ b/canvas/src/lib.rs @@ -155,13 +155,13 @@ impl CanvasRenderingContext2D { // Fill and stroke styles #[inline] - pub fn set_fill_style(&mut self, new_fill_style: FillStyle) { - self.current_state.fill_paint = new_fill_style.into_paint(); + pub fn set_fill_style(&mut self, new_fill_style: FS) where FS: Into { + self.current_state.fill_paint = new_fill_style.into().into_paint(); } #[inline] - pub fn set_stroke_style(&mut self, new_stroke_style: FillStyle) { - self.current_state.stroke_paint = new_stroke_style.into_paint(); + pub fn set_stroke_style(&mut self, new_stroke_style: FS) where FS: Into { + self.current_state.stroke_paint = new_stroke_style.into().into_paint(); } // Shadows @@ -710,3 +710,24 @@ impl Debug for Path2D { self.clone().into_outline().fmt(formatter) } } + +impl From for FillStyle { + #[inline] + fn from(color: ColorU) -> FillStyle { + FillStyle::Color(color) + } +} + +impl From for FillStyle { + #[inline] + fn from(gradient: Gradient) -> FillStyle { + FillStyle::Gradient(gradient) + } +} + +impl From for FillStyle { + #[inline] + fn from(pattern: Pattern) -> FillStyle { + FillStyle::Pattern(pattern) + } +}