FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
#259: the timeline shows the edge a press will grab
Bloxy42cc47e7db09
diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rsindex da8254666..2b8dd294b 100644--- a/crates/ui-egui/src/panels/timeline.rs+++ b/crates/ui-egui/src/panels/timeline.rs@@ -1737,6 +1737,10 @@ fn interact(app: &mut FilmcraftApp, ui: &mut egui::Ui, seq: &Sequence, layout: &_ => CursorIcon::Default,};ctx.set_cursor_icon(cur);+ // the edge a press here would grab, and the trim it starts (#259)+ if let Grab::Edge { track, clip, edge, kind } = g {+ super::trim_monitor::paint_hover_bracket(ui.painter(), seq, layout, track, clip, edge, kind);+ }// razor preview lineif tool == Tool::Razor&& let Grab::Other(Hit::Clip { track, .. }) = gdiff --git a/crates/ui-egui/src/panels/trim_monitor.rs b/crates/ui-egui/src/panels/trim_monitor.rsindex 4347bf6ff..cee0b505c 100644--- a/crates/ui-egui/src/panels/trim_monitor.rs+++ b/crates/ui-egui/src/panels/trim_monitor.rs@@ -14,7 +14,8 @@//! `trimMonitor.playAround`, `trimMonitor.exit`.use egui::{Align2, Color32, Rect, Sense, Stroke, StrokeKind, pos2, vec2};-use filmcraft_project::{ItemKind, Sequence, Track};+use filmcraft_edit::Edge;+use filmcraft_project::{ClipId, ItemKind, Sequence, Track, TrackId};use filmcraft_time::{Tick, TimeDisplay, format_time};use serde_json::{Value, json};@@ -22,6 +23,7 @@ use crate::FilmcraftApp;use crate::frames::{FrameKey, Target};use crate::icons::{self, Icon};use crate::panels::timeline::{Layout, Row};+use crate::panels::timeline_hit::EdgeKind;use crate::theme::Tokens;/// Ripple edit points are red, roll / regular trims yellow (as in Premiere's timeline).@@ -79,19 +81,40 @@ pub fn paint_edit_points(app: &FilmcraftApp, p: &egui::Painter, seq: &Sequence,let col = if ep.kind == TrimKind::Ripple { RIPPLE_RED } else { ROLL_YELLOW };for (clip, out) in marks {let Some(it) = tr.item(clip) else { continue };- let x = layout.x_of(if out { it.end() } else { it.start });- let (y0, y1) = (row.rect.min.y + 2.0, row.rect.max.y - 2.0);- let dir = if out { -1.0 } else { 1.0 };- let xi = x + dir * 1.5;- let w = 6.0 * dir;- let s = Stroke::new(3.0, col);- p.line_segment([pos2(xi, y0), pos2(xi, y1)], s);- p.line_segment([pos2(xi, y0 + 1.0), pos2(xi + w, y0 + 1.0)], s);- p.line_segment([pos2(xi, y1 - 1.0), pos2(xi + w, y1 - 1.0)], s);+ paint_bracket(p, layout.x_of(if out { it.end() } else { it.start }), row, out, col);}}}+/// A trim bracket at `x` on `row`, its arms pointing into the clip (left for an Out edge).+pub fn paint_bracket(p: &egui::Painter, x: f32, row: &Row, out: bool, col: Color32) {+ let (y0, y1) = (row.rect.min.y + 2.0, row.rect.max.y - 2.0);+ let dir = if out { -1.0 } else { 1.0 };+ let xi = x + dir * 1.5;+ let w = 6.0 * dir;+ let s = Stroke::new(3.0, col);+ p.line_segment([pos2(xi, y0), pos2(xi, y1)], s);+ p.line_segment([pos2(xi, y0 + 1.0), pos2(xi + w, y0 + 1.0)], s);+ p.line_segment([pos2(xi, y1 - 1.0), pos2(xi + w, y1 - 1.0)], s);+}++/// The bracket on the edge a press would grab (#259): an edit point's bracket at half strength,+/// red for a ripple and yellow otherwise; a roll marks both sides of the cut.+pub fn paint_hover_bracket(p: &egui::Painter, seq: &Sequence, layout: &Layout, track: TrackId, clip: ClipId, edge: Edge, kind: EdgeKind) {+ let Some(row) = layout.rows.iter().find(|r| r.track == track) else { return };+ let Some(tr) = seq.track(track) else { return };+ let full = if kind == EdgeKind::Ripple { RIPPLE_RED } else { ROLL_YELLOW };+ let col = full.gamma_multiply(0.5);+ let marks = match kind {+ EdgeKind::Roll { left, right } => vec![(left, true), (right, false)],+ _ => vec![(clip, edge == Edge::Out)],+ };+ for (c, out) in marks {+ let Some(it) = tr.item(c) else { continue };+ paint_bracket(p, layout.x_of(if out { it.end() } else { it.start }), row, out, col);+ }+}+/// Fit a w×h picture into `area`.fn fit(area: Rect, w: f32, h: f32) -> Rect {let s = (area.width() / w.max(1.0)).min(area.height() / h.max(1.0));diff --git a/crates/ui-egui/tests/timeline_trim_ui.rs b/crates/ui-egui/tests/timeline_trim_ui.rsindex 6e8c0e9f0..2412961b4 100644--- a/crates/ui-egui/tests/timeline_trim_ui.rs+++ b/crates/ui-egui/tests/timeline_trim_ui.rs@@ -98,6 +98,19 @@ impl Driver {self.harness.output().platform_output.cursor_icon}+ /// Render the window to `<target tmp>/ui-screenshots/<name>.png` (needs a GPU).+ fn screenshot(&mut self, name: &str) -> std::path::PathBuf {+ self.frames(2);+ let img = self.harness.render().expect("render");+ let png = filmcraft_ui_egui::control::encode_png(img.as_raw(), img.width(), img.height()).expect("png");+ let dir = std::path::PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("ui-screenshots");+ std::fs::create_dir_all(&dir).unwrap();+ let path = dir.join(format!("{name}.png"));+ std::fs::write(&path, png).unwrap();+ eprintln!("screenshot: {}", path.display());+ path+ }+/// The clip named `name` on V1.fn v1_clip(&self, name: &str) -> u64 {let seq = self.app().session.active_sequence().expect("sequence");@@ -237,3 +250,22 @@ fn cursor_hit_test_and_press_agree_at_a_cut() {let h = hit(&mut d, mid, json!({}));assert_eq!((h["clip"].as_u64(), h["kind"].clone()), (Some(city), Value::Null), "mid-clip: {h}");}++/// Renders the hover bracket at the City_Night_Drive / Desert_Dunes cut to PNGs for visual+/// review (needs a GPU): `cargo test -p filmcraft-ui-egui --test timeline_trim_ui -- --ignored+/// hover_bracket_screenshots`. Yellow on City_Night_Drive's Out edge just left of the cut and on+/// Desert_Dunes' In edge just right of it, red for the Ripple tool, both sides for the Rolling tool.+#[test]+#[ignore]+fn hover_bracket_screenshots() {+ let mut d = Driver::demo();+ let dunes = d.v1_clip(DUNES);+ let (cut, _, y) = d.edges(dunes);+ for (tool, name, x) in+ [("selection", "trim-out", cut - 3.0), ("selection", "trim-in", cut + 3.0), ("ripple", "ripple-in", cut + 3.0), ("rolling", "roll", cut + 3.0)]+ {+ d.ok("ui.set", json!({"tool": tool}));+ d.hover(pos2(x, y));+ d.screenshot(&format!("hover-{name}"));+ }+}