diff --git a/src/builder.rs b/src/builder.rs index 46ff739..33f48b7 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -176,6 +176,16 @@ impl GradientBuilder { self } + pub fn reset(&mut self) -> &mut Self { + self.colors.clear(); + self.positions.clear(); + self.mode = BlendMode::Rgb; + self.invalid_html_colors.clear(); + self.invalid_css_gradient = false; + self.clean = false; + self + } + #[doc(hidden)] pub fn get_colors(&self) -> &[Color] { &self.colors diff --git a/tests/builder.rs b/tests/builder.rs index e8627d6..6839165 100644 --- a/tests/builder.rs +++ b/tests/builder.rs @@ -115,6 +115,16 @@ fn builder() { assert_eq!(g.at(0.0).to_rgba8(), [255, 0, 0, 255]); assert_eq!(g.at(35.0).to_rgba8(), [0, 0, 255, 255]); assert_eq!(g.at(100.0).to_rgba8(), [0, 255, 0, 255]); + + // Reset + gb.reset(); + gb.colors(&[ + Color::from_rgba8(127, 0, 100, 255), + Color::from_rgba8(50, 255, 0, 255), + ]); + gb.build::().unwrap(); + assert_eq!(gb.get_positions(), &[0.0, 1.0]); + assert_eq!(&colors2hex(gb.get_colors()), &["#7f0064", "#32ff00"]); } #[test]