mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 13:02:50 -05:00
Gradient: reversed stops unlink the gradient swatch
A stops write with reverse compares the final, reversed stops with the paint's current stops, so writing the same stops reversed clears the gradient swatch link while an unchanged write still keeps it.
This commit is contained in:
1 parent
db3ace4b0d
commit
7cf9fa9c47
1 file changed
+17
-6
@@ -527,16 +527,20 @@ fn apply_gradient_edit_in_model(
|
||||
switched = true;
|
||||
}
|
||||
}
|
||||
let recolor = p.get("stops").is_some() || bool_or(p, "reverse", false);
|
||||
let reverse = bool_or(p, "reverse", false);
|
||||
let recolor = p.get("stops").is_some() || reverse;
|
||||
if let Some(stops) = p.get("stops") {
|
||||
let stops = parse_stops(stops)?;
|
||||
// A paint whose stops stay as they are keeps its gradient swatch.
|
||||
if stops != gp.gradient.stops {
|
||||
gp.gradient.stops = stops;
|
||||
let before = std::mem::replace(&mut gp.gradient.stops, stops);
|
||||
if reverse {
|
||||
// Midpoints mirrored with their segments.
|
||||
gp.gradient.reverse();
|
||||
}
|
||||
// A paint whose final stops stay as they are keeps its gradient swatch.
|
||||
if gp.gradient.stops != before {
|
||||
gp.swatch = None;
|
||||
}
|
||||
}
|
||||
if bool_or(p, "reverse", false) {
|
||||
} else if reverse {
|
||||
// Midpoints mirrored with their segments.
|
||||
gp.gradient.reverse();
|
||||
}
|
||||
@@ -933,4 +937,11 @@ mod tests {
|
||||
let other = json!({"stops": [{"offset": 0, "color": "#ff0000"}, {"offset": 1, "color": "#000000"}]});
|
||||
assert_eq!(swatch(&apply_gradient_edit(&paint, &other, None).unwrap()), None, "new stops unlink the swatch");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn writing_the_same_stops_reversed_unlinks_the_gradient_swatch() {
|
||||
let paint = linked(&[(0.0, "#ffffff"), (1.0, "#000000")]);
|
||||
let reversed = json!({"stops": [{"offset": 0, "color": "#ffffff"}, {"offset": 1, "color": "#000000"}], "reverse": true});
|
||||
assert_eq!(swatch(&apply_gradient_edit(&paint, &reversed, None).unwrap()), None, "reversed stops unlink the swatch");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user