live-preview: Do not stop the first gradient stop from moving

This commit is contained in:
Tobias Hunger 2025-04-16 10:51:05 +00:00 committed by Tobias Hunger
parent 7ae6212b0b
commit cd48bbd251

View file

@ -37,7 +37,7 @@ pub fn move_gradient_stop(
new_position: f32,
) -> i32 {
let mut row_usize = row as usize;
if row <= 0 || row_usize >= model.row_count() {
if row < 0 || row_usize >= model.row_count() {
return row;
}
@ -571,6 +571,55 @@ mod tests {
let model = make_model();
assert_eq!(super::move_gradient_stop(model.clone(), 0, 0.05), 1);
let mut it = model.iter();
assert_eq!(
it.next(),
Some(ui::GradientStop {
position: 0.0,
color: slint::Color::from_argb_encoded(0xff040404)
})
);
assert_eq!(
it.next(),
Some(ui::GradientStop {
position: 0.05,
color: slint::Color::from_argb_encoded(0xff030303)
})
);
assert_eq!(
it.next(),
Some(ui::GradientStop {
position: 0.1445,
color: slint::Color::from_argb_encoded(0xff060606),
}),
);
assert_eq!(
it.next(),
Some(ui::GradientStop {
position: 0.5,
color: slint::Color::from_argb_encoded(0xff050505)
})
);
assert_eq!(
it.next(),
Some(ui::GradientStop {
position: 1.0,
color: slint::Color::from_argb_encoded(0xff010101)
})
);
assert_eq!(
it.next(),
Some(ui::GradientStop {
position: 1.0,
color: slint::Color::from_argb_encoded(0xff020202)
})
);
assert_eq!(it.next(), None);
let model = make_model();
assert_eq!(super::move_gradient_stop(model.clone(), 3, 0.0), 2);
let mut it = model.iter();