Skip to content

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

#259: caption edges trim from where they were pressed

Bloxyaf2b4601c88e
diff --git a/crates/ui-egui/src/panels/timeline_captions.rs b/crates/ui-egui/src/panels/timeline_captions.rs
index b154f5540..bbb73c21f 100644
--- a/crates/ui-egui/src/panels/timeline_captions.rs
+++ b/crates/ui-egui/src/panels/timeline_captions.rs
@@ -213,8 +213,10 @@ fn interact_block(
if tr.locked {
return;
}
+ // decide on what was under the pointer when the button went down, not where egui recognised
+ // the drag (6 pt later, past the 5 px edge zones) (#259)
if resp.drag_started()
- && let Some(p) = resp.interact_pointer_pos()
+ && let Some(p) = ctx.input(|i| i.pointer.press_origin()).or(resp.interact_pointer_pos())
{
let g = match gesture_at(p.x) {
Gesture::Move => 0u8,
diff --git a/crates/ui-egui/tests/timeline_trim_ui.rs b/crates/ui-egui/tests/timeline_trim_ui.rs
index 2412961b4..8ea07cd2b 100644
--- a/crates/ui-egui/tests/timeline_trim_ui.rs
+++ b/crates/ui-egui/tests/timeline_trim_ui.rs
@@ -68,6 +68,10 @@ impl Driver {
v["result"].clone()
}
+ fn exec(&mut self, command: &str, params: Value) -> Value {
+ self.ok("engine.execute", json!({"command": command, "params": params}))
+ }
+
fn app(&self) -> &FilmcraftApp {
self.harness.state()
}
@@ -269,3 +273,28 @@ fn hover_bracket_screenshots() {
d.screenshot(&format!("hover-{name}"));
}
}
+
+/// A caption's Out edge, grabbed 2 px inside and dragged inward, trims the caption. The gesture
+/// used to be decided where the drag was recognised, about 9 px inside (2 px plus egui's 6 pt drag
+/// threshold), past the 5 px edge zone, so the caption moved.
+#[test]
+fn dragging_a_caption_edge_inward_trims_it() {
+ let mut d = Driver::demo();
+ let id = d.exec("captions.add", json!({"seconds": 2.0, "durationSeconds": 2.0}))["caption"].as_u64().expect("caption id");
+ d.frames(4);
+ let name = format!("timeline.caption.{id}");
+ let els = d.ok("ui.elements", json!({"prefix": name}));
+ let el = els.as_array().expect("elements").iter().find(|e| e["id"] == name.as_str()).unwrap_or_else(|| panic!("no {name}: {els}")).clone();
+ let r: Vec<f32> = el["rect"].as_array().expect("rect").iter().map(|v| v.as_f64().expect("number") as f32).collect();
+ let (x1, y) = (r[0] + r[2], r[1] + r[3] / 2.0);
+ let span = |d: &Driver| {
+ let seq = d.app().session.active_sequence().expect("sequence");
+ let (_, c) = seq.find_caption(ClipId(id)).expect("caption");
+ (c.start.0, c.end().0)
+ };
+ let (s0, e0) = span(&d);
+ d.drag(pos2(x1 - 2.0, y), pos2(x1 - 32.0, y), 30);
+ let (s1, e1) = span(&d);
+ assert_eq!(s1, s0, "the caption's start stayed: trimmed, not moved");
+ assert!(e1 < e0, "the caption's end moved in: {e0} → {e1}");
+}