From 8cb733469204e5d24c130d108143a3f7657285b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 20 Aug 2026 02:14:26 +0300 Subject: [PATCH] draw fades and their drag handles on the timeline Translucent wedge overlay per clip end (fade_wedge, widgets.rs, canvas+PathBuilder idiom) and a small top-corner hit zone beside each trim strip (FADE_HANDLE_W/H) that drives start_fade_drag/fade_drag_to/ commit_fade. Pixel-delta-to-frames goes through the pure fade_delta_frames helper in timeline_math.rs. --- crates/app/src/ui/timeline.rs | 85 +++++++++++++++++++++++++++++++++++ crates/app/src/ui/widgets.rs | 41 +++++++++++++++++ 2 files changed, 126 insertions(+) diff --git a/crates/app/src/ui/timeline.rs b/crates/app/src/ui/timeline.rs index a8dd011..9c2c881 100644 --- a/crates/app/src/ui/timeline.rs +++ b/crates/app/src/ui/timeline.rs @@ -1492,6 +1492,91 @@ impl Player { .child(inner), ) })) + // The fades: a translucent wedge at each end an + // audio clip ramps, drawn over the waveform the way + // every editor shades a fade. Width comes straight + // off the clip's own frames, never off the visible + // slice -- unlike the waveform a wedge that starts + // off the left edge of the bed still shades the + // clip's own corner once scrolled back into view, + // because `overflow_hidden` on the box already + // clips it, and clamped to the box's own width so a + // fade longer than a zoomed-in clip never draws + // past its neighbour. + .when(audio, |d| { + let fade_in = self.shown_fade_in(lane, i, clip); + let fade_out = self.shown_fade_out(lane, i, clip); + d.children( + [ + (fade_in > 0).then(|| { + div() + .absolute() + .left_0() + .top_0() + .h_full() + .w(px(scale + .width_px(f64::from(fade_in) / self.fps) + .min(width))) + .child(fade_wedge(true)) + }), + (fade_out > 0).then(|| { + div() + .absolute() + .right_0() + .top_0() + .h_full() + .w(px(scale + .width_px(f64::from(fade_out) / self.fps) + .min(width))) + .child(fade_wedge(false)) + }), + ] + .into_iter() + .flatten(), + ) + }) + // The fade handles: a small grab corner at each + // *top* of an audio clip's box, sitting just + // inside the [`EDGE_W`] trim strip rather than on + // top of it -- [`FADE_HANDLE_H`] never reaches + // past the label row, so a trim's own strip (the + // box's *full* height) is still the whole of what + // a press below the label starts. Gated on + // [`trims`] like the trim strips themselves: a box + // too small for an edge to trim by is too small + // for a fade handle either. + .when(audio && trims(span), |d| { + d.children([Edge::Start, Edge::End].into_iter().map(|edge| { + let is_in = edge == Edge::Start; + let mut handle = div() + .absolute() + .top_0() + .w(px(FADE_HANDLE_W)) + .h(px(FADE_HANDLE_H)) + .occlude() + .cursor(CursorStyle::ResizeLeftRight) + .hover(|s| s.bg(rgb(ACCENT_PRIMARY()))) + .on_mouse_down( + MouseButton::Left, + cx.listener( + move |this, event: &MouseDownEvent, _, cx| { + this.start_fade_drag( + lane, + i, + is_in, + event.position.x, + cx, + ); + }, + ), + ); + handle = match edge { + Edge::Start => handle.left(px(EDGE_W)), + Edge::End => handle.right(px(EDGE_W)), + }; + handle + })) + }) // A speeded clip says so on the box, in the corner // the label does not reach: the box's width alone // cannot say whether a short clip is a trim or a diff --git a/crates/app/src/ui/widgets.rs b/crates/app/src/ui/widgets.rs index 82d2200..4223c48 100644 --- a/crates/app/src/ui/widgets.rs +++ b/crates/app/src/ui/widgets.rs @@ -35,6 +35,47 @@ pub(crate) fn waveform(peaks: Arc>, from: f64, to: f64) -> impl .size_full() } +/// An audio clip's fade, drawn as a translucent wedge over its box: silent +/// (full shade) at the clip's own edge, clear by the fade's far side -- +/// [`is_in`] mirrors it for the tail's ramp-down. The same `canvas` + +/// `PathBuilder` idiom [`waveform`] draws its envelope with, filled with the +/// same wash the in/out range already paints the bed with +/// (`ACCENT_WASH`, timeline.rs), so a fade reads as one more overlay on this +/// bed rather than a shape borrowed from somewhere else. +pub(crate) fn fade_wedge(is_in: bool) -> impl IntoElement { + canvas( + |_, _, _| (), + move |bounds, _, window, _| { + let (o, s) = (bounds.origin, bounds.size); + let (w, h) = (f32::from(s.width), f32::from(s.height)); + if w <= 0. || h <= 0. { + return; + } + // A right triangle: the clip's silent corner (top of the clip's + // own edge) down to the bed and across to the fade's far side -- + // the wedge shape every editor draws for a ramp. + let points = match is_in { + true => vec![ + point(o.x, o.y), + point(o.x, o.y + px(h)), + point(o.x + px(w), o.y + px(h)), + ], + false => vec![ + point(o.x + px(w), o.y), + point(o.x + px(w), o.y + px(h)), + point(o.x, o.y + px(h)), + ], + }; + let mut path = PathBuilder::fill(); + path.add_polygon(&points, true); + if let Ok(path) = path.build() { + window.paint_path(path, rgba(ACCENT_WASH())); + } + }, + ) + .size_full() +} + /// A toolbar button: its glyph, its name, and its key on hover. `id` only buys /// `on_click` and the tooltip -- it is still not focusable, so the root's own /// key listener keeps working after a press, and the click lands on mouse-up