Skip to content

Commit

Permalink
GradientBuilder: new method reset()
Browse files Browse the repository at this point in the history
  • Loading branch information
mazznoer committed Nov 28, 2024
1 parent 970c15b commit 3d9161d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<LinearGradient>().unwrap();
assert_eq!(gb.get_positions(), &[0.0, 1.0]);
assert_eq!(&colors2hex(gb.get_colors()), &["#7f0064", "#32ff00"]);
}

#[test]
Expand Down

0 comments on commit 3d9161d

Please sign in to comment.