Add draggable diamond midpoint gizmos to the Gradient tool (#3826)

This commit is contained in:
Keavon Chambers
2026-02-24 20:25:15 -08:00
committed by GitHub
parent 7250b091d5
commit 4a6cdffd84
6 changed files with 401 additions and 75 deletions

View File

@@ -232,7 +232,7 @@ impl GradientStops {
pub fn sort(&mut self) {
let mut indices: Vec<usize> = (0..self.position.len()).collect();
indices.sort_unstable_by(|&a, &b| self.position[a].partial_cmp(&self.position[b]).unwrap());
indices.sort_unstable_by(|&a, &b| self.position[a].total_cmp(&self.position[b]));
self.position = indices.iter().map(|&i| self.position[i]).collect();
self.midpoint = indices.iter().map(|&i| self.midpoint[i]).collect();
self.color = indices.iter().map(|&i| self.color[i]).collect();
@@ -437,9 +437,10 @@ impl Gradient {
index += 1;
}
// Insert the new stop
// Insert the new stop, duplicating the midpoint ratio of the interval being split
let inherited_midpoint = if index > 0 { self.stops.midpoint[index - 1] } else { 0.5 };
self.stops.position.insert(index, new_position);
self.stops.midpoint.insert(index, 0.5);
self.stops.midpoint.insert(index, inherited_midpoint);
self.stops.color.insert(index, new_color);
Some(index)