♻️ Refactor adding gradient stops

This commit is contained in:
Belén Albeza 2024-12-02 17:04:44 +01:00
parent 5e9f533624
commit 7105e49ac2
3 changed files with 32 additions and 26 deletions

View file

@ -92,14 +92,16 @@ impl Shape {
self.fills.clear();
}
pub fn add_gradient_stop(&mut self, color: skia::Color, offset: f32) -> Result<(), String> {
pub fn add_gradient_stops(&mut self, buffer: Vec<RawStopData>) -> Result<(), String> {
let fill = self.fills.last_mut().ok_or("Shape has no fills")?;
let gradient = match fill {
Fill::LinearGradient(g) => Ok(g),
_ => Err("Active fill is not a gradient"),
}?;
gradient.add_stop(color, offset);
for stop in buffer.into_iter() {
gradient.add_stop(stop.color(), stop.offset());
}
Ok(())
}