Support to pass no color space to Paint::set_color4f.
@@ -61,7 +61,11 @@ impl Default for Handle<SkPaint> {
}
impl Handle<SkPaint> {
- pub fn new(color: impl AsRef<Color4f>, color_space: Option<&ColorSpace>) -> Paint {
+ pub fn new<'a>(
+ color: impl AsRef<Color4f>,
+ color_space: impl Into<Option<&'a ColorSpace>>,
+ ) -> Paint {
+ let color_space = color_space.into();
Paint::from_native_c(unsafe {
SkPaint::new1(
color.as_ref().native(),
@@ -140,14 +144,17 @@ impl Handle<SkPaint> {
self
}
- pub fn set_color4f(
+ pub fn set_color4f<'a>(
&mut self,
color: impl AsRef<Color4f>,
- color_space: &ColorSpace,
+ color_space: impl Into<Option<&'a ColorSpace>>,
) -> &mut Self {
+ let color_space: Option<&'a ColorSpace> = color_space.into();
unsafe {
- self.native_mut()
- .setColor1(color.as_ref().native(), color_space.native_mut_force())
+ self.native_mut().setColor1(
+ color.as_ref().native(),
+ color_space.native_ptr_or_null_mut_force(),
+ )
}
self
}
@@ -365,3 +372,14 @@ fn union_flags() {
paint.set_style(Style::Fill);
}
}
+
+#[test]
+fn set_color4f_color_space() {
+ let mut paint = Paint::default();
+ let color = Color4f::from(Color::DARK_GRAY);
+ let color_space = ColorSpace::new_srgb();
+ paint.set_color4f(&color, None);
+ paint.set_color4f(&color, &color_space);
+ let color2 = Color4f::from(Color::DARK_GRAY);
+ paint.set_color4f(color2, Some(&color_space));
+}
