FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
fix(effect-controls): a dropped graph keyframe stays where it was dropped (fixes #1918)
Marco Arnulfo16b62adc2553
diff --git a/crates/ui-egui/src/panels/effect_controls.rs b/crates/ui-egui/src/panels/effect_controls.rsindex dafa06edc..b829a25fc 100644--- a/crates/ui-egui/src/panels/effect_controls.rs+++ b/crates/ui-egui/src/panels/effect_controls.rs@@ -1112,6 +1112,16 @@ pub(crate) fn graph_rows(lo = lo.max(min);hi = hi.min(max);}+ // While the graph stays open its range only widens: refitted to the keyframes, a keyframe+ // dragged off the top or bottom edge was drawn back on that edge, the curve unchanged (#1918)+ let range_id = egui::Id::new(("kfg-range", clip.0, idx, mask, pd.id));+ let frame = ui.ctx().cumulative_frame_nr();+ if let Some((a, b, seen)) = ui.data(|d| d.get_temp::<(f64, f64, u64)>(range_id))+ && frame.saturating_sub(seen) <= 1+ {+ (lo, hi) = (lo.min(a), hi.max(b));+ }+ ui.data_mut(|d| d.insert_temp(range_id, (lo, hi, frame)));let area = Rect::from_min_max(pos2(lane.min.x, vr.min.y + 4.0), pos2(lane.max.x, vr.max.y - 4.0));let y_of = |v: f64| area.max.y - ((v - lo) / (hi - lo)) as f32 * area.height();let v_of = |y: f32| lo + ((area.max.y - y) / area.height()) as f64 * (hi - lo);@@ -1536,6 +1546,31 @@ mod graph_drag_tests {egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }}+ /// #1918, #1921: a keyframe dragged to a new value stays where it was dropped. The graph+ /// used to fit itself to the new values, so with two keyframes the one at the bottom (or+ /// the top) went straight back there and the curve looked unchanged.+ #[test]+ fn a_dropped_graph_keyframe_stays_where_it_was_dropped() {+ for (key, offset) in [(0, vec2(0.0, -20.0)), (1, vec2(0.0, 20.0))] {+ let mut d = Driver::new();+ let before = d.param();+ d.frame(vec![]);+ let id = format!("effectControls.scale.graph.keyframe.{}", before.keyframes[key].time.0);+ let [x, y, w, h] = d.app.auto.find(&id).expect("the keyframe is drawn").rect;+ let start = pos2(x + w / 2.0, y + h / 2.0);+ d.frame(vec![egui::Event::PointerMoved(start), button(start, true)]);+ d.frame(vec![egui::Event::PointerMoved(start + offset)]);+ d.frame(vec![button(start + offset, false)]);+ d.frame(vec![]);+ d.frame(vec![]);+ let changed = d.param();+ assert_ne!(changed.keyframes[key].value, before.keyframes[key].value, "keyframe {key} takes the dropped value");+ let [x, y, w, h] = d.app.auto.find(&id).expect("the keyframe is drawn").rect;+ let now = pos2(x + w / 2.0, y + h / 2.0);+ assert!(now.distance(start + offset) < 0.5, "keyframe {key} stays where it was dropped: dropped at {:?}, drawn at {now:?}", start + offset);+ }+ }+#[test]fn scalar_graph_press_starts_at_the_pointer_origin_and_release_is_one_undo_step() {for influence in [false, true] {