UI: Window > Ease Presets panel draws, edits and applies ease curves (#254)

A dockable panel (our own design) for the keys.easePreset commands. A
value graph shows the working curve with its two handles, which drag
to edit it; Apply eases the selected keyframes with it and From Keys
loads the curve between the first selected pair. Every preset is a
thumbnail drawn in code; a click loads it and applies it to the
selected keys. Save Current keeps the working curve under the name in
the field, and Rename and Delete act on the selected user preset.
Wide panels put the presets beside the graph; narrow ones below it,
the graph shrinking to leave a row of presets, scrolled with the wheel.

The panel state (working curve, selection, name) is serde in the UI
state, and every control registers an automation id (easePresets.*).
widgets::text_field is the search field without its magnifier.

Test: clicking_an_ease_preset_eases_the_selected_keys_and_handles_edit_the_curve
(ui_keyframes); every_panel_registers_automation_ids_for_its_widgets
covers the new panel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bflatastic
2026-10-08 17:25:00 +07:00
co-authored by Claude Opus 5.5
parent 0717f12246
commit 1c22615553
9 changed files with 319 additions and 6 deletions
+42 -2
View File
@@ -1,6 +1,7 @@
//! Headless checks for Timeline keyframes as a person uses them: dragging keys over many frames
//! in one gesture (the drag used to end after the first frame), Shift-snapping, and Ctrl+C /
//! Ctrl+V, which the windowing layer delivers as clipboard events rather than key presses.
//! in one gesture (the drag used to end after the first frame), Shift-snapping, Ctrl+C /
//! Ctrl+V, which the windowing layer delivers as clipboard events rather than key presses, and
//! easing selected keys from the Ease Presets panel.
use effectcraft_engine::Session;
use effectcraft_engine::project::LayerId;
@@ -253,3 +254,42 @@ fn k_follows_the_revealed_properties_and_auto_select_picks_the_speed_graph_for_p
h.run_steps(3);
assert!(h.state().auto.find(&format!("timeline.graph.key.{pos}.1.0")).is_some(), "value graph: X and Y");
}
fn center(h: &Harness<'_, EffectcraftApp>, id: &str) -> Pos2 {
let e = h.state().auto.find(id).unwrap_or_else(|| panic!("no {id}"));
pos2(e.rect[0] + e.rect[2] / 2.0, e.rect[1] + e.rect[3] / 2.0)
}
#[test]
fn clicking_an_ease_preset_eases_the_selected_keys_and_handles_edit_the_curve() {
use effectcraft_engine::keyframe::{Ease, Interp};
use effectcraft_ui_egui::dock::PanelKind;
let (mut h, id, _) = harness();
h.state_mut().session.execute("prop.select", json!({"layer": id.0, "path": "transform/opacity"})).unwrap();
h.state_mut().show_panel(PanelKind::EasePresets);
h.state_mut().ui.maximized = Some(PanelKind::EasePresets);
h.run_steps(4);
let opacity =
|h: &Harness<'_, EffectcraftApp>| h.state().session.active_comp().unwrap().layer(id).unwrap().props.prop("transform/opacity").unwrap().clone();
let tile = h.state().auto.query("easePresets.preset.").into_iter().find(|e| e.label == "Ease In-Out").expect("the Ease In-Out thumbnail").id.clone();
let steps = h.state().session.history.undo.len();
let at = center(&h, &tile);
click_with(&mut h, at, Default::default());
let op = opacity(&h);
let eased = Ease { speed: 0.0, influence: 0.5 };
assert_eq!((op.keys[0].out_interp, op.keys[0].out_ease.clone()), (Interp::Bezier, vec![eased]));
assert_eq!((op.keys[1].in_interp, op.keys[1].in_ease.clone()), (Interp::Bezier, vec![eased]));
assert_eq!(h.state().session.history.undo.len(), steps + 1);
assert_eq!(h.state().ui.ease_presets.selected.as_deref(), Some("Ease In-Out"));
// Dragging the out handle to the right lengthens its influence; Apply uses the edited curve.
let graph = h.state().auto.find("easePresets.graph").unwrap().rect;
let from = center(&h, "easePresets.handle.out");
drag(&mut h, from, from + egui::vec2(graph[2] * 0.2, 0.0), Default::default());
let out = h.state().ui.ease_presets.curve.out_influence;
assert!(out > 60.0 && out < 75.0, "{out}");
let apply = center(&h, "easePresets.apply");
click_with(&mut h, apply, Default::default());
let applied = opacity(&h).keys[0].out_ease[0].influence;
assert!((applied * 100.0 - out).abs() < 1e-9, "{applied} vs {out}");
assert_eq!(h.state().session.history.undo.len(), steps + 2);
}