forge
Explore
Log in

Don't you dare go Hollow

draw fades and their drag handles on the timeline

Browse files at this commit

8cb733469204e5d24c130d108143a3f7657285b5Ahmet Kaan GümüşParent: 55dd056
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.rsmodified+85 -0
@@ -1492,6 +1492,91 @@ impl Player {
1492 .child(inner),1492 .child(inner),
1493 )1493 )
1494 }))1494 }))
1495+ // The fades: a translucent wedge at each end an
1496+ // audio clip ramps, drawn over the waveform the way
1497+ // every editor shades a fade. Width comes straight
1498+ // off the clip's own frames, never off the visible
1499+ // slice -- unlike the waveform a wedge that starts
1500+ // off the left edge of the bed still shades the
1501+ // clip's own corner once scrolled back into view,
1502+ // because `overflow_hidden` on the box already
1503+ // clips it, and clamped to the box's own width so a
1504+ // fade longer than a zoomed-in clip never draws
1505+ // past its neighbour.
1506+ .when(audio, |d| {
1507+ let fade_in = self.shown_fade_in(lane, i, clip);
1508+ let fade_out = self.shown_fade_out(lane, i, clip);
1509+ d.children(
1510+ [
1511+ (fade_in > 0).then(|| {
1512+ div()
1513+ .absolute()
1514+ .left_0()
1515+ .top_0()
1516+ .h_full()
1517+ .w(px(scale
1518+ .width_px(f64::from(fade_in) / self.fps)
1519+ .min(width)))
1520+ .child(fade_wedge(true))
1521+ }),
1522+ (fade_out > 0).then(|| {
1523+ div()
1524+ .absolute()
1525+ .right_0()
1526+ .top_0()
1527+ .h_full()
1528+ .w(px(scale
1529+ .width_px(f64::from(fade_out) / self.fps)
1530+ .min(width)))
1531+ .child(fade_wedge(false))
1532+ }),
1533+ ]
1534+ .into_iter()
1535+ .flatten(),
1536+ )
1537+ })
1538+ // The fade handles: a small grab corner at each
1539+ // *top* of an audio clip's box, sitting just
1540+ // inside the [`EDGE_W`] trim strip rather than on
1541+ // top of it -- [`FADE_HANDLE_H`] never reaches
1542+ // past the label row, so a trim's own strip (the
1543+ // box's *full* height) is still the whole of what
1544+ // a press below the label starts. Gated on
1545+ // [`trims`] like the trim strips themselves: a box
1546+ // too small for an edge to trim by is too small
1547+ // for a fade handle either.
1548+ .when(audio && trims(span), |d| {
1549+ d.children([Edge::Start, Edge::End].into_iter().map(|edge| {
1550+ let is_in = edge == Edge::Start;
1551+ let mut handle = div()
1552+ .absolute()
1553+ .top_0()
1554+ .w(px(FADE_HANDLE_W))
1555+ .h(px(FADE_HANDLE_H))
1556+ .occlude()
1557+ .cursor(CursorStyle::ResizeLeftRight)
1558+ .hover(|s| s.bg(rgb(ACCENT_PRIMARY())))
1559+ .on_mouse_down(
1560+ MouseButton::Left,
1561+ cx.listener(
1562+ move |this, event: &MouseDownEvent, _, cx| {
1563+ this.start_fade_drag(
1564+ lane,
1565+ i,
1566+ is_in,
1567+ event.position.x,
1568+ cx,
1569+ );
1570+ },
1571+ ),
1572+ );
1573+ handle = match edge {
1574+ Edge::Start => handle.left(px(EDGE_W)),
1575+ Edge::End => handle.right(px(EDGE_W)),
1576+ };
1577+ handle
1578+ }))
1579+ })
1495 // A speeded clip says so on the box, in the corner1580 // A speeded clip says so on the box, in the corner
1496 // the label does not reach: the box's width alone1581 // the label does not reach: the box's width alone
1497 // cannot say whether a short clip is a trim or a1582 // cannot say whether a short clip is a trim or a
crates/app/src/ui/widgets.rsmodified+41 -0
@@ -35,6 +35,47 @@ pub(crate) fn waveform(peaks: Arc<Vec<(f32, f32)>>, from: f64, to: f64) -> impl
35 .size_full()35 .size_full()
36 }36 }
37 37
38+/// An audio clip's fade, drawn as a translucent wedge over its box: silent
39+/// (full shade) at the clip's own edge, clear by the fade's far side --
40+/// [`is_in`] mirrors it for the tail's ramp-down. The same `canvas` +
41+/// `PathBuilder` idiom [`waveform`] draws its envelope with, filled with the
42+/// same wash the in/out range already paints the bed with
43+/// (`ACCENT_WASH`, timeline.rs), so a fade reads as one more overlay on this
44+/// bed rather than a shape borrowed from somewhere else.
45+pub(crate) fn fade_wedge(is_in: bool) -> impl IntoElement {
46+ canvas(
47+ |_, _, _| (),
48+ move |bounds, _, window, _| {
49+ let (o, s) = (bounds.origin, bounds.size);
50+ let (w, h) = (f32::from(s.width), f32::from(s.height));
51+ if w <= 0. || h <= 0. {
52+ return;
53+ }
54+ // A right triangle: the clip's silent corner (top of the clip's
55+ // own edge) down to the bed and across to the fade's far side --
56+ // the wedge shape every editor draws for a ramp.
57+ let points = match is_in {
58+ true => vec![
59+ point(o.x, o.y),
60+ point(o.x, o.y + px(h)),
61+ point(o.x + px(w), o.y + px(h)),
62+ ],
63+ false => vec![
64+ point(o.x + px(w), o.y),
65+ point(o.x + px(w), o.y + px(h)),
66+ point(o.x, o.y + px(h)),
67+ ],
68+ };
69+ let mut path = PathBuilder::fill();
70+ path.add_polygon(&points, true);
71+ if let Ok(path) = path.build() {
72+ window.paint_path(path, rgba(ACCENT_WASH()));
73+ }
74+ },
75+ )
76+ .size_full()
77+}
78+
38 /// A toolbar button: its glyph, its name, and its key on hover. `id` only buys79 /// A toolbar button: its glyph, its name, and its key on hover. `id` only buys
39 /// `on_click` and the tooltip -- it is still not focusable, so the root's own80 /// `on_click` and the tooltip -- it is still not focusable, so the root's own
40 /// key listener keeps working after a press, and the click lands on mouse-up81 /// key listener keeps working after a press, and the click lands on mouse-up