Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

#227: Lumetri presets can be dragged onto a Timeline clip

vangel7678a3fea2229a
diff --git a/crates/ui-egui/src/panels/effects.rs b/crates/ui-egui/src/panels/effects.rs
index 76f4f8c28..df3e7d939 100644
--- a/crates/ui-egui/src/panels/effects.rs
+++ b/crates/ui-egui/src/panels/effects.rs
@@ -3,7 +3,8 @@
//!
//! Lumetri Presets: each preset row has a thumbnail (our Lumetri on the procedural preview
//! picture, `filmcraft_render::lumetri_presets`); double-click (or right-click ▸ Apply to Selected
-//! Clips, `effects.presetMenu.apply`) applies it (`lumetri.applyPreset`).
+//! Clips, `effects.presetMenu.apply`) applies it (`lumetri.applyPreset`), and dragging it onto a
+//! Timeline clip applies it to that clip (rows and grid cells alike).
//! When the panel is wide (maximized), clicking a Lumetri Presets folder shows its presets as a
//! thumbnail grid to the right of the tree. Automation ids: `effects.lumetriPreset.<name>`,
//! `effects.presetGrid` (the grid area), `effects.presetGrid.<name>`.
@@ -232,7 +233,7 @@ fn lumetri_rows(app: &mut FilmcraftApp, ui: &mut egui::Ui, filter: &str) -> Opti
continue;
}
for p in items {
- let (r, resp) = ui.allocate_exact_size(vec2(ui.available_width(), 24.0), Sense::click());
+ let (r, resp) = ui.allocate_exact_size(vec2(ui.available_width(), 24.0), Sense::click_and_drag());
if resp.hovered() {
ui.painter().rect_filled(r, 0.0, t.hover);
}
@@ -242,6 +243,9 @@ fn lumetri_rows(app: &mut FilmcraftApp, ui: &mut egui::Ui, filter: &str) -> Opti
ui.painter().text(pos2(tr.max.x + 8.0, r.center().y), Align2::LEFT_CENTER, crate::i18n::t(p.name), Tokens::ui(12.0), t.text);
app.auto.add(&format!("effects.lumetriPreset.{}", p.name), r, p.name);
let resp = resp.on_hover_text(crate::i18n::t(p.description));
+ if resp.drag_started() {
+ crate::panels::start_drag_lumetri_preset(ui, p.name);
+ }
if apply_menu(app, &resp) {
apply = Some(p.name.to_string());
}
@@ -273,12 +277,15 @@ fn preset_grid(app: &mut FilmcraftApp, ui: &mut egui::Ui, area: Rect) -> Option<
}
let pic = Rect::from_min_size(cell.min, vec2(cw, ch));
let tex = preset_texture(app, ui.ctx(), p, 160);
- let resp = ui.interact(cell, egui::Id::new(("lumetri-grid", p.name)), Sense::click()).on_hover_text(crate::i18n::t(p.description));
+ let resp = ui.interact(cell, egui::Id::new(("lumetri-grid", p.name)), Sense::click_and_drag()).on_hover_text(crate::i18n::t(p.description));
ui.painter().rect_filled(cell, 3.0, if resp.hovered() { t.hover } else { t.field_bg });
ui.painter().image(tex, pic.shrink(2.0), Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0)), Color32::WHITE);
let label = ui.painter().layout(crate::i18n::t(p.name).to_string(), Tokens::ui(11.0), t.text, cw - 6.0);
ui.painter().galley(pos2(cell.min.x + 4.0, pic.max.y + 2.0), label, t.text);
app.auto.add(&format!("effects.presetGrid.{}", p.name), cell, p.name);
+ if resp.drag_started() {
+ crate::panels::start_drag_lumetri_preset(ui, p.name);
+ }
if apply_menu(app, &resp) {
apply = Some(p.name.to_string());
}
diff --git a/crates/ui-egui/src/panels/mod.rs b/crates/ui-egui/src/panels/mod.rs
index bcb386fbb..95c9442e2 100644
--- a/crates/ui-egui/src/panels/mod.rs
+++ b/crates/ui-egui/src/panels/mod.rs
@@ -145,6 +145,13 @@ pub fn dragged_template(ui: &egui::Ui) -> Option<String> {
pub fn start_drag_effect(ui: &egui::Ui, id: &str) {
ui.ctx().data_mut(|d| d.insert_temp(payload_id(), Some(DragPayloadBox(DragPayload::Effect(id.to_string())))));
}
+/// Prefix of a dragged effect payload that names a Lumetri preset rather than an effect id.
+pub const LUMETRI_PRESET_PREFIX: &str = "lumetri:";
+/// A Lumetri preset (Effects ▸ Lumetri Presets) dragged onto a clip: an effect payload
+/// `lumetri:<name>` the Timeline applies with `lumetri.applyPreset`.
+pub fn start_drag_lumetri_preset(ui: &egui::Ui, name: &str) {
+ start_drag_effect(ui, &format!("{LUMETRI_PRESET_PREFIX}{name}"));
+}
#[derive(Clone, Debug)]
struct DragPayloadBox(DragPayload);
@@ -185,9 +192,10 @@ pub fn drag_ghost(app: &FilmcraftApp, ui: &egui::Ui) {
format!("{name} · {mode} · {:.2} s", s.range.duration.seconds())
}
DragPayload::Template(_, name) => name.clone(),
- DragPayload::Effect(e) => match e.strip_prefix("preset:") {
- Some(name) => name.to_string(),
- None => filmcraft_project::find_effect(e).map(|d| d.name.to_string()).unwrap_or_default(),
+ DragPayload::Effect(e) => match (e.strip_prefix("preset:"), e.strip_prefix(LUMETRI_PRESET_PREFIX)) {
+ (Some(name), _) => name.to_string(),
+ (_, Some(name)) => crate::i18n::t(name).to_string(),
+ _ => filmcraft_project::find_effect(e).map(|d| d.name.to_string()).unwrap_or_default(),
},
};
let painter = ctx.layer_painter(egui::LayerId::new(egui::Order::Tooltip, egui::Id::new("drag-ghost")));
diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rs
index 17a5eef96..84b863973 100644
--- a/crates/ui-egui/src/panels/timeline.rs
+++ b/crates/ui-egui/src/panels/timeline.rs
@@ -2471,6 +2471,8 @@ fn interact(app: &mut FilmcraftApp, ui: &mut egui::Ui, seq: &Sequence, layout: &
if ctx.input(|i| i.pointer.any_released()) {
let r = if let Some(name) = effect.strip_prefix("preset:") {
app.session.execute("presets.apply", json!({"preset": name, "clips": [clip.0]}))
+ } else if let Some(name) = effect.strip_prefix(crate::panels::LUMETRI_PRESET_PREFIX) {
+ app.session.execute("lumetri.applyPreset", json!({"name": name, "clips": [clip.0]}))
} else if transition_kind.is_some() {
app.session.execute("effects.apply", params)
} else {
diff --git a/crates/ui-egui/tests/color_ui.rs b/crates/ui-egui/tests/color_ui.rs
index 956e7f211..1ea047c84 100644
--- a/crates/ui-egui/tests/color_ui.rs
+++ b/crates/ui-egui/tests/color_ui.rs
@@ -324,3 +324,26 @@ fn lumetri_presets_in_the_effects_panel() {
let e = lumetri(&mut d, clip);
assert_eq!(e["params"]["temperature"]["value"], json!("Float(35.0)"), "{e}");
}
+
+#[test]
+fn lumetri_presets_drag_onto_a_timeline_clip() {
+ let mut d = Driver::demo();
+ d.ok("ui.panel.show", json!({"panel": "Effects"}));
+ d.frames(3);
+ // the first clip is selected; the preset is dropped on the second, which gets it alone
+ let selected = select_first_clip(&mut d);
+ let seq = d.exec("sequence.inspect", json!({}));
+ let target = seq["video"][0]["items"][1]["clip"].as_u64().unwrap_or_else(|| panic!("no second clip: {seq}"));
+ d.click("effects.folder.Lumetri Presets");
+ d.click("effects.folder.Lumetri Presets/Monochrome");
+ d.frames(2);
+ assert!(d.element(&format!("timeline.clip.{target}")).is_some(), "target clip not on screen");
+ d.ok("ui.drag", json!({"from": {"id": "effects.lumetriPreset.Neutral Mono"}, "to": {"id": format!("timeline.clip.{target}")}, "steps": 8}));
+ d.frames(3);
+ let e = lumetri(&mut d, target);
+ assert_eq!(e["params"]["saturation"]["value"], json!("Float(0.0)"), "dropped preset on the target clip: {e}");
+ assert_eq!(lumetri(&mut d, selected), Value::Null, "the selected clip it was not dropped on is untouched");
+ // one undo step removes it again
+ d.exec("edit.undo", json!({}));
+ assert_eq!(lumetri(&mut d, target), Value::Null);
+}