Add a `From` implementation to `FillStyle` and use it in `canvas` for brevity
This commit is contained in:
parent
f1d5906c9e
commit
e864536b31
|
@ -155,13 +155,13 @@ impl CanvasRenderingContext2D {
|
||||||
// Fill and stroke styles
|
// Fill and stroke styles
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_fill_style(&mut self, new_fill_style: FillStyle) {
|
pub fn set_fill_style<FS>(&mut self, new_fill_style: FS) where FS: Into<FillStyle> {
|
||||||
self.current_state.fill_paint = new_fill_style.into_paint();
|
self.current_state.fill_paint = new_fill_style.into().into_paint();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_stroke_style(&mut self, new_stroke_style: FillStyle) {
|
pub fn set_stroke_style<FS>(&mut self, new_stroke_style: FS) where FS: Into<FillStyle> {
|
||||||
self.current_state.stroke_paint = new_stroke_style.into_paint();
|
self.current_state.stroke_paint = new_stroke_style.into().into_paint();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shadows
|
// Shadows
|
||||||
|
@ -710,3 +710,24 @@ impl Debug for Path2D {
|
||||||
self.clone().into_outline().fmt(formatter)
|
self.clone().into_outline().fmt(formatter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<ColorU> for FillStyle {
|
||||||
|
#[inline]
|
||||||
|
fn from(color: ColorU) -> FillStyle {
|
||||||
|
FillStyle::Color(color)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Gradient> for FillStyle {
|
||||||
|
#[inline]
|
||||||
|
fn from(gradient: Gradient) -> FillStyle {
|
||||||
|
FillStyle::Gradient(gradient)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Pattern> for FillStyle {
|
||||||
|
#[inline]
|
||||||
|
fn from(pattern: Pattern) -> FillStyle {
|
||||||
|
FillStyle::Pattern(pattern)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue