forge
Explore
Log in

Don't you dare go Hollow

The words get a track of their own, dragged and trimmed like everything else

Browse files at this commit

eef3d5d644c1eeccb15c810ef846ec75129dca07Ahmet Kaan GümüşParent: 6f06fea
  • feat
    • the words get a track of their own, dragged and trimmed like everything else
Show full message
✨ feat(app): the words get a track of their own, dragged and trimmed like everything else

The subtitle strip under the lanes is gone and the subtitle lanes the engine
model landed are drawn as lanes: the same row, the same header, the same bed.
A palette row is dragged out of the Subtitles list onto one, a placement is
dragged along it or onto another subtitle track, either end is trimmed, and the
box's own × lifts it off -- a caption is not in the clip selection's index
space, so no stroke reaches it and a lane holding one may not be removed.

The row is `lane_row`, unbranched: a subtitle lane holds no `Clip` and every
other lane holds no `SubClip`, so the two lists are never both full and there is
no second kind of row to keep in step. Headers reorder and remove through the
machinery every lane already had.

An `Ok` is never a toast: `move_sub` and `trim_sub` answer a pick-up-put-back
and an edge stopped at a wall with `Ok` and no undo step, so only the refusals
are shown, in the engine's own words after the head. A subtitle lane refuses
media in `lane_refuses`, so the shadow is red on the way down.

Each lane's header carries its eye, on by default and dropped wholesale when a
lane is removed or reordered -- what reads it over the picture is the next
slice; nothing is saved yet either.
crates/app/src/interact.rsmodified+19 -0
@@ -25,6 +25,25 @@ pub(crate) struct ClipDrag {
2525 pub(crate) clip: Clip,
2626 }
2727
28+/// A *palette* subtitle row being dragged onto a subtitle lane: which track of
29+/// [`PlaybackSession::subtitles`] it is, which is the whole of what a row names.
30+/// The window it lands with is the track's own, from its first microsecond to
31+/// its last cue -- a placement is trimmed after it is placed, like every clip
32+/// here.
33+pub(crate) struct SubPick(pub(crate) usize);
34+
35+/// A subtitle already placed on a lane being dragged: [`ClipDrag`]'s twin, and
36+/// carrying the placement itself for that struct's reason -- an edit made during
37+/// the gesture moves the indices gpui froze into the payload, so the drop finds
38+/// its placement by value ([`Player::dragged_sub`]) rather than by an index that
39+/// may since have become another caption's.
40+#[derive(Clone, Copy)]
41+pub(crate) struct SubDrag {
42+ pub(crate) lane: Lane,
43+ pub(crate) idx: usize,
44+ pub(crate) sub: SubClip,
45+}
46+
2847 /// A track *header* being dragged: which track the hand took hold of, to be
2948 /// let go over the header of the one whose place it is to take
3049 /// ([`Player::reorder_lane`]). The lane alone -- a track carries its own clips
crates/app/src/layout.rsmodified+0 -14
@@ -142,10 +142,6 @@ pub(crate) fn sub_bottom(bars_h: f32) -> f32 {
142142 // height -- either way there is nothing to clear.
143143 SUB_BOTTOM + bars_h.max(0.)
144144 }
145-/// The subtitle strip under the lanes: thin, because it is a picture of where
146-/// the cues are and nothing on it can be dragged -- `HIT_MIN` binds targets, and
147-/// this row has none.
148-pub(crate) const SUB_LANE_H: f32 = 16.;
149145 /// A mark narrower than this is still drawn this wide: a one-frame cue on a
150146 /// zoomed-out bed is worth a fraction of a pixel, and a mark nobody can see says
151147 /// the track is empty. The silence preview's marks are floored by it too -- they
@@ -229,16 +225,6 @@ pub(crate) fn px_below(max_offset_h: f32, offset_y: f32) -> f32 {
229225 (max_offset_h + offset_y).max(0.)
230226 }
231227
232-/// What the subtitle strip adds to the panel: its own row and the panel's gap
233-/// above it, and nothing at all for a timeline with no subtitles on it -- the
234-/// picture does not pay for a strip that is not drawn.
235-pub(crate) fn subtitle_strip_h(shown: bool) -> f32 {
236- match shown {
237- true => SUB_LANE_H + 8.,
238- false => 0.,
239- }
240-}
241-
242228 /// How tall the panel is with `lanes` tracks in it: [`PANEL_H`] is sized for the
243229 /// two a project starts with, and every further one adds its own row -- up to
244230 /// [`LANES_MAX`], past which the lane column scrolls instead and the panel stops
crates/app/src/main.rsmodified+20 -1
@@ -58,7 +58,7 @@ use engine::decode::Backend;
5858 use engine::eq::{Band, BandKind, EqParams};
5959 use engine::export::{AUDIO_KBPS, DEFAULT_AUDIO_KBPS, EncoderSeat, ExportSettings, Format};
6060 use engine::limiter::Limiter;
61-use engine::project::{Edge, Lane, LaneKind, Source, Speed};
61+use engine::project::{Edge, Lane, LaneKind, Source, Speed, SubClip};
6262 use engine::scale::FitPolicy;
6363 use engine::tonemap::Preset;
6464 use engine::{Clip, Codec, ExportHandle, Frame, MediaBitrate, PlaybackSession};
@@ -240,6 +240,24 @@ struct Player {
240240 /// one can be read at a time. Cleared with the timeline like every other
241241 /// index here -- track 2 of one project is not track 2 of the next.
242242 sub_track: usize,
243+ /// The subtitle lanes whose eye is shut: every lane shows its captions
244+ /// until this says otherwise, so a lane that was just added is a lane that
245+ /// draws. Held as the lanes that are *off* rather than a flag per lane, so
246+ /// adding one needs no bookkeeping at all.
247+ ///
248+ /// State only this slice: the preview reads the picked palette track still
249+ /// ([`Player::sub_picture`]), so shutting an eye marks the header and
250+ /// changes nothing over the picture until the slice that draws the lanes'
251+ /// cues there reads this field. Not saved either -- a `.edith` has no line
252+ /// for it yet.
253+ ///
254+ /// A [`Lane`] handle is a position among its kind, so a removal or a
255+ /// reorder leaves every shut eye naming another track: they are dropped
256+ /// wholesale there, exactly as the selection and the open cards are
257+ /// ([`Player::remove_lane`], [`Player::reorder_lane`]) -- which is why a
258+ /// lane added in a removed one's place opens with its eye open, as every
259+ /// new lane does.
260+ subs_off: Vec<Lane>,
243261 /// The frame the live gesture is about to land on, or `None` while it is
244262 /// over open bed: the line every lane draws so the snap is seen before it
245263 /// happens rather than discovered after the release. Stale between gestures,
@@ -629,6 +647,7 @@ fn main() {
629647 snap: true,
630648 subs_on: true,
631649 sub_track: 0,
650+ subs_off: Vec::new(),
632651 snap_cue: None,
633652 ghost: None,
634653 lane_drop: None,
crates/app/src/player/library.rsmodified+11 -1
@@ -147,8 +147,10 @@ impl Player {
147147 self.clipboard = None;
148148 self.selected = None;
149149 self.selected_asset = None;
150- // The subtitle rows go with the timeline they were on.
150+ // The subtitle rows go with the timeline they were on, and so do the
151+ // eyes: S1 of one project is not S1 of the next.
151152 self.sub_track = 0;
153+ self.subs_off.clear();
152154 self.context_menu = None;
153155 self.library_menu = None;
154156 self.eq_open = None;
@@ -991,6 +993,10 @@ impl Player {
991993 self.color_open = None;
992994 self.speed_open = None;
993995 self.close_silence();
996+ // The eyes with them: a `Lane` is a position among its
997+ // kind, so every shut one now names another track --
998+ // the same reason the selection and the cards go.
999+ self.subs_off.clear();
9941000 format!(
9951001 "{} REMOVED — {} brings it back",
9961002 lane.label(),
@@ -1043,6 +1049,10 @@ impl Player {
10431049 self.color_open = None;
10441050 self.speed_open = None;
10451051 self.close_silence();
1052+ // The eyes with them: a `Lane` is a position among its
1053+ // kind, so every shut one now names another track --
1054+ // the same reason the selection and the cards go.
1055+ self.subs_off.clear();
10461056 }
10471057 self.notify_user(
10481058 format!(
crates/app/src/player/timeline_edit.rsmodified+240 -5
@@ -264,6 +264,184 @@ impl Player {
264264 cx.notify();
265265 }
266266
267+ /// The whole of a palette track as a placement: from its own first
268+ /// microsecond to its last cue, and as many timeline frames as that is worth
269+ /// at this rate. What a row dragged out of the Subtitles list carries, and
270+ /// what the ghost is drawn from -- `start` is ignored by
271+ /// [`PlaybackSession::place_sub`], which takes the frame the hand let go on.
272+ ///
273+ /// `None` for a track with nothing to place: one that could not be read, and
274+ /// one that genuinely has no cues.
275+ pub(crate) fn sub_of_track(&self, track: usize) -> Option<SubClip> {
276+ let cues = &self.session.as_ref()?.subtitles().get(track)?.cues;
277+ let out_us = cues.iter().map(|c| c.end_us).max()?;
278+ Some(SubClip {
279+ start: 0,
280+ frames: frames_of_us(out_us, self.fps),
281+ track,
282+ in_us: 0,
283+ out_us,
284+ })
285+ }
286+
287+ /// A palette row let go at window `x` over subtitle lane `to`: the whole
288+ /// track goes down where the hand left it, one undo step
289+ /// ([`PlaybackSession::place_sub`]). Every refusal there is words -- an
290+ /// overlap, a lane that is not a subtitle lane, a track that is not there --
291+ /// and they are shown as the engine worded them.
292+ pub(crate) fn place_sub(&mut self, track: usize, to: Lane, x: Pixels, cx: &mut Context<Self>) {
293+ if self.exporting().is_some() {
294+ return;
295+ }
296+ self.snap_cue = None;
297+ self.ghost = None;
298+ let at = self.place_frame(x).0;
299+ let text = match (self.sub_of_track(track), &mut self.session) {
300+ (Some(sub), Some(session)) => match session.place_sub(to, at, sub) {
301+ Ok(()) => None,
302+ Err(e) => Some(format!("NOT PLACED — {e}")),
303+ },
304+ // The row is greyed and says why in the list; here it says why at
305+ // the moment somebody tried to use it anyway.
306+ (None, Some(_)) => Some(
307+ "NOT PLACED — that subtitle track has no cues to place; the list says why"
308+ .to_string(),
309+ ),
310+ (_, None) => Some("NOT PLACED — open a file first".to_string()),
311+ };
312+ if let Some(text) = text {
313+ self.notify_user(text.into());
314+ }
315+ cx.notify();
316+ }
317+
318+ /// Which index its lane holds the dragged placement at *now*
319+ /// ([`Player::dragged`]'s twin, through the same [`live_idx`]): a stroke
320+ /// during the gesture -- an undo, another drop -- moves the indices gpui
321+ /// froze into the payload.
322+ pub(crate) fn dragged_sub(&self, drag: &SubDrag) -> Option<usize> {
323+ live_idx(self.session.as_ref()?.sub_lane(drag.lane), drag.idx, drag.sub)
324+ }
325+
326+ /// A placed caption let go at window `x` over subtitle lane `to`: it lands
327+ /// with its head where the hand carried it, on the lane it was dropped on --
328+ /// one undo step, and none at all for a drop that changed nothing, which is
329+ /// why an `Ok` is never a toast ([`Project::move_sub`]). An overlap and a
330+ /// lane of the wrong kind are refused in the engine's own words.
331+ pub(crate) fn move_sub(&mut self, drag: &SubDrag, to: Lane, x: Pixels, cx: &mut Context<Self>) {
332+ if self.exporting().is_some() {
333+ return;
334+ }
335+ self.snap_cue = None;
336+ self.ghost = None;
337+ let Some(idx) = self.dragged_sub(drag) else {
338+ return;
339+ };
340+ let start = self.sub_drop_frame(drag.sub, x).0;
341+ if let Some(Err(e)) = self
342+ .session
343+ .as_mut()
344+ .map(|session| session.move_sub(drag.lane, idx, to, start))
345+ {
346+ self.notify_user(format!("NOT MOVED — {e}").into());
347+ }
348+ cx.notify();
349+ }
350+
351+ /// The × on a caption's own box: it comes off the lane and leaves the gap,
352+ /// one undo step ([`PlaybackSession::lift_sub`]). The palette row it played
353+ /// stays in the list, which is what makes this a lift and not a removal --
354+ /// and the way a subtitle lane is emptied so it can be taken off at all.
355+ pub(crate) fn lift_sub(&mut self, lane: Lane, idx: usize, cx: &mut Context<Self>) {
356+ if self.exporting().is_some() {
357+ return;
358+ }
359+ let lifted = self
360+ .session
361+ .as_mut()
362+ .is_some_and(|session| session.lift_sub(lane, idx));
363+ let text = match lifted {
364+ true => format!(
365+ "CAPTION LIFTED — {} puts it back",
366+ self.keymap.display(ActionId::Undo)
367+ ),
368+ false => "NOTHING LIFTED — that caption is not there any more".to_string(),
369+ };
370+ self.notify_user(text.into());
371+ cx.notify();
372+ }
373+
374+ /// A subtitle lane's eye: whether it draws its captions. State only for now
375+ /// -- what reads it is the slice that draws the lanes over the picture --
376+ /// and said out loud, because a toggle whose only effect is a header glyph
377+ /// has to say what it has and has not done yet.
378+ pub(crate) fn toggle_sub_lane(&mut self, lane: Lane, cx: &mut Context<Self>) {
379+ let text = match self.subs_off.iter().position(|&l| l == lane) {
380+ Some(i) => {
381+ self.subs_off.remove(i);
382+ format!("{} SHOWS ITS CAPTIONS", lane.label())
383+ }
384+ None => {
385+ self.subs_off.push(lane);
386+ format!("{} IS HIDDEN — its captions stay on the lane", lane.label())
387+ }
388+ };
389+ self.notify_user(text.into());
390+ cx.notify();
391+ }
392+
393+ /// Whether that subtitle lane's captions are drawn -- the eye, read by the
394+ /// header that offers it and by whatever draws cues from here on.
395+ pub(crate) fn sub_lane_on(&self, lane: Lane) -> bool {
396+ !self.subs_off.contains(&lane)
397+ }
398+
399+ /// Where a caption let go at window `x` wants its head: [`Player::drop_frame`]'s
400+ /// twin, and the same [`landing`] -- the grab offset the press noted, and the
401+ /// snap onto the edges the rest of the timeline offers, so a caption lands on
402+ /// the cut it is spoken over.
403+ pub(crate) fn sub_drop_frame(&self, sub: SubClip, x: Pixels) -> (u32, Option<u32>) {
404+ let marks = self.snap_targets(None);
405+ landing(
406+ self.frame_under(x),
407+ self.grab,
408+ sub.frames,
409+ self.snap,
410+ self.snap_frames(),
411+ &marks,
412+ )
413+ }
414+
415+ /// The shadow a caption in the hand would fill, on the lane the pointer is
416+ /// over: [`Player::preview_ghost`]'s twin, refused for any lane that is not a
417+ /// subtitle lane -- which is the answer [`Project::move_sub`] gives at the
418+ /// release.
419+ pub(crate) fn preview_ghost_sub(&mut self, drag: &SubDrag, to: Lane, x: Pixels, cx: &mut Context<Self>) {
420+ let (start, _) = self.sub_drop_frame(drag.sub, x);
421+ let ghost = Ghost {
422+ lane: to,
423+ start,
424+ frames: drag.sub.frames,
425+ tint: CLIP_TEXT(),
426+ refused: to.kind != LaneKind::Subtitle,
427+ };
428+ self.set_ghost(Some(ghost), cx);
429+ }
430+
431+ /// The same for a palette row on its way down: it lands at the frame it is
432+ /// let go on ([`Player::place_frame`]) and is as long as the whole track it
433+ /// names.
434+ pub(crate) fn preview_ghost_pick(&mut self, track: usize, to: Lane, x: Pixels, cx: &mut Context<Self>) {
435+ let ghost = Ghost {
436+ lane: to,
437+ start: self.place_frame(x).0,
438+ frames: self.sub_of_track(track).map_or(0, |sub| sub.frames),
439+ tint: CLIP_TEXT(),
440+ refused: to.kind != LaneKind::Subtitle,
441+ };
442+ self.set_ghost(Some(ghost), cx);
443+ }
444+
267445 /// Where a clip let go at window `x` over lane `to` wants its head: the
268446 /// frame under the pointer, less however far into the box the hand grabbed
269447 /// it (so the clip does not jump under the pointer), pulled onto a
@@ -624,6 +802,33 @@ impl Player {
624802 if self.modal() || self.exporting().is_some() {
625803 return;
626804 }
805+ // A caption's edge, on a lane that holds no `Clip` at all: the same
806+ // gesture, the same `Trim`, and the branch is the lane's kind wherever
807+ // the drag is asked about ([`Player::trim_to`],
808+ // [`Player::commit_trim`]). No selection -- a placement is not in the
809+ // clip selection's index space -- and no group: a caption has no half
810+ // on another lane.
811+ if lane.kind == LaneKind::Subtitle {
812+ let Some(sub) = self
813+ .session
814+ .as_ref()
815+ .and_then(|session| session.sub_lane(lane).get(idx).copied())
816+ else {
817+ return;
818+ };
819+ self.trim = Some(Trim {
820+ lane,
821+ idx,
822+ edge,
823+ to: match edge {
824+ Edge::Start => sub.start,
825+ Edge::End => sub.end(),
826+ },
827+ link: None,
828+ });
829+ cx.notify();
830+ return;
831+ }
627832 let Some(clip) = self
628833 .session
629834 .as_ref()
@@ -659,11 +864,16 @@ impl Player {
659864 // there is no other end travelling with it, so it snaps at length zero.
660865 let marks = self.snap_targets(Some((trim.lane, trim.idx)));
661866 let (at, cue) = self.snap_to(self.frame_under(x), 0, &marks);
662- let Some((lo, hi)) = self
663- .session
664- .as_ref()
665- .and_then(|session| session.trim_room(trim.lane, trim.idx, trim.edge))
666- else {
867+ let Some((lo, hi)) = self.session.as_ref().and_then(|session| {
868+ match trim.lane.kind == LaneKind::Subtitle {
869+ // The walls a caption's edge has -- its neighbour, its own
870+ // track's first microsecond and its last cue -- asked at this
871+ // timeline's rate, which is why the session is the door and not
872+ // the project.
873+ true => session.trim_sub_room(trim.lane, trim.idx, trim.edge),
874+ false => session.trim_room(trim.lane, trim.idx, trim.edge),
875+ }
876+ }) else {
667877 return;
668878 };
669879 let to = at.clamp(lo, hi);
@@ -693,6 +903,22 @@ impl Player {
693903 let Some(trim) = self.trim.take() else {
694904 return;
695905 };
906+ // A caption's edge reaches the engine through its own door, at this
907+ // timeline's rate. An `Ok` is *not* "something changed" -- an edge that
908+ // stopped at a wall it already stood against is `Ok` with no undo step
909+ // ([`Project::trim_sub`]) -- so only the refusal is ever said out loud,
910+ // and nothing reseeks: cues are drawn over whatever is decoded.
911+ if trim.lane.kind == LaneKind::Subtitle {
912+ if let Some(Err(e)) = self
913+ .session
914+ .as_mut()
915+ .map(|session| session.trim_sub(trim.lane, trim.idx, trim.edge, trim.to))
916+ {
917+ self.notify_user(format!("NOT TRIMMED — {e}").into());
918+ }
919+ cx.notify();
920+ return;
921+ }
696922 let trimmed = self
697923 .session
698924 .as_mut()
@@ -721,6 +947,15 @@ impl Player {
721947 trimmed_clip(clip, trim.edge, trim.to, still)
722948 }
723949
950+ /// The caption as the drag is showing it, [`Player::trimmed`]'s twin:
951+ /// display only, and the engine hears about it once, at the release.
952+ pub(crate) fn trimmed_sub(&self, lane: Lane, idx: usize, sub: SubClip) -> SubClip {
953+ match self.trim.filter(|t| (t.lane, t.idx) == (lane, idx)) {
954+ Some(trim) => trimmed_sub(sub, trim.edge, trim.to),
955+ None => sub,
956+ }
957+ }
958+
724959 /// How long the timeline is *drawn* as: its own length, and while a tail is
725960 /// being dragged the furthest that tail may reach. A bed that ends exactly
726961 /// at the last frame has nowhere to put a pointer that means "longer", so
crates/app/src/render.rsmodified+16 -0
@@ -515,6 +515,22 @@ impl Render for Player {
515515 this.set_ghost(None, cx);
516516 }),
517517 )
518+ // The same pair for the two subtitle gestures, for the same reason:
519+ // a palette row starts up in the library and a caption starts on a
520+ // lane, and both are let go somewhere else entirely.
521+ .on_drag_move(cx.listener(|this, event: &DragMoveEvent<SubPick>, _, cx| {
522+ this.preview_place(event.event.position.x, cx);
523+ this.set_ghost(None, cx);
524+ }))
525+ .on_drag_move(cx.listener(|this, event: &DragMoveEvent<SubDrag>, _, cx| {
526+ // The placement gpui froze into the payload, whose *length* is
527+ // all the line needs; which caption it is is the drop's
528+ // question ([`Player::dragged_sub`]).
529+ let (drag, x) = (*event.drag(cx), event.event.position.x);
530+ let cue = this.sub_drop_frame(drag.sub, x).1;
531+ this.set_cue(cue, x, cx);
532+ this.set_ghost(None, cx);
533+ }))
518534 // Scrubbing is tracked on the root because the pointer leaves the
519535 // 6 px ruler on the first drag and its own listeners then stop
520536 // firing; the root's hitbox is the whole window.
crates/app/src/tests/layout.rsmodified+76 -0
@@ -405,6 +405,82 @@ fn a_trim_preview_lands_where_the_release_commits() {
405405 }
406406 }
407407
408+/// The caption a drag is showing lands where the release commits -- the
409+/// subtitle twin of the trim preview above -- and the two contracts the boxes
410+/// on the lanes rest on: `place_sub`'s `at` wins over the placement's own
411+/// `start`, and a gesture that changed nothing is `Ok` and not a refusal, so a
412+/// front-end that toasted every `Ok` would toast a pick-up-put-back.
413+#[test]
414+fn a_caption_trim_preview_lands_where_the_release_commits() {
415+ let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture");
416+ session.set_gain(0.0);
417+ let fps = session.meta().frame_rate;
418+ let srt = Path::new(env!("CARGO_MANIFEST_DIR"))
419+ .join("../engine/tests/data/test_subs.srt")
420+ .canonicalize()
421+ .expect("the subtitle fixture");
422+ session.import_subtitles(&srt).expect("the .srt imports");
423+ let lane = session.add_lane(LaneKind::Subtitle);
424+ // The whole track as a placement, exactly as `Player::sub_of_track` builds
425+ // one from a palette row.
426+ let out_us = session.subtitles()[0]
427+ .cues
428+ .iter()
429+ .map(|c| c.end_us)
430+ .max()
431+ .expect("the fixture has cues");
432+ let whole = SubClip {
433+ start: 0,
434+ frames: frames_of_us(out_us, fps),
435+ track: 0,
436+ in_us: 0,
437+ out_us,
438+ };
439+ session
440+ .place_sub(lane, 30, whole)
441+ .expect("an empty subtitle lane takes it");
442+ assert_eq!(
443+ session.sub_lane(lane)[0].start,
444+ 30,
445+ "the frame the hand let go on wins over the placement's own start"
446+ );
447+ for edge in [Edge::Start, Edge::End] {
448+ let (lo, hi) = session
449+ .trim_sub_room(lane, 0, edge)
450+ .expect("placement 0 is there");
451+ for to in [lo, (lo + hi) / 2, hi] {
452+ let placed = session.sub_lane(lane)[0];
453+ let preview = trimmed_sub(placed, edge, to);
454+ session
455+ .trim_sub(lane, 0, edge, to)
456+ .expect("an edge inside its own room is never refused");
457+ let now = session.sub_lane(lane)[0];
458+ assert_eq!(
459+ (preview.start, preview.frames),
460+ (now.start, now.frames),
461+ "{edge:?} to {to}"
462+ );
463+ // One edit, one undo step -- and none at all where the edge was
464+ // already there, which is the `Ok` that must stay silent.
465+ if (now.start, now.frames) != (placed.start, placed.frames) {
466+ assert!(session.undo(), "the trim is one undo step");
467+ }
468+ }
469+ }
470+ // Picked up and put back down: `Ok`, nothing moved, nothing to say.
471+ let before = session.sub_lane(lane)[0];
472+ session
473+ .move_sub(lane, 0, lane, before.start)
474+ .expect("a drop that changes nothing is not a refusal");
475+ assert_eq!(session.sub_lane(lane)[0], before);
476+ // ...and two captions over one frame are refused in words, which is what
477+ // the notice shows verbatim.
478+ let over = session
479+ .place_sub(lane, before.start, whole)
480+ .expect_err("two captions may not cover one frame");
481+ assert!(over.to_string().contains("already covers"), "{over}");
482+}
483+
408484 /// A still trims the same way, and the preview knows it: its head grows
409485 /// forward from source frame 0 -- every frame of it is the same picture --
410486 /// so the box stretches instead of sliding left.
crates/app/src/tests/media.rsmodified+15 -13
@@ -796,18 +796,19 @@ fn a_cue_steps_over_whatever_bar_is_hanging_off_the_picture() {
796796 }
797797
798798 /// The two places a subtitle is drawn -- the plate over the picture and the
799-/// strip under the lanes -- inside the 640x360 floor the rest of this window
799+/// lanes under the tracks -- inside the 640x360 floor the rest of this window
800800 /// is sized for, and the plate readable on whatever the film is showing.
801801 #[test]
802-fn the_subtitle_plate_and_strip_fit_the_smallest_window() {
803- // The strip costs the panel its own row and the panel's gap, and costs
804- // nothing at all when there is no track to draw.
805- assert_eq!(subtitle_strip_h(false), 0.);
806- assert_eq!(subtitle_strip_h(true), SUB_LANE_H + 8.);
807- // What is left for the picture at the floor, with the panel a project
808- // starts with and the strip under it.
809- let picture = 360. - HEADER_H - panel_h(2) - subtitle_strip_h(true);
810- assert!(picture > 0., "the strip pushed the picture off the window");
802+fn the_subtitle_plate_and_lanes_fit_the_smallest_window() {
803+ // A subtitle lane is a lane: it costs the panel exactly what a third
804+ // track costs it, and a timeline with none costs nothing at all -- the
805+ // strip that used to hang under the lanes is gone, and with it the one
806+ // row nothing could be dropped on.
807+ assert_eq!(lanes_h(3) - lanes_h(2), LANE_H + 8.);
808+ // What is left for the picture at the floor, with a project's two tracks
809+ // and a subtitle lane under them.
810+ let picture = 360. - HEADER_H - panel_h(3);
811+ assert!(picture > 0., "a subtitle lane pushed the picture off the window");
811812 // A two-line cue and the gap under it fit inside that, which is the
812813 // whole claim: the plate sits *over* the picture and must not need more
813814 // of it than there is.
@@ -822,9 +823,10 @@ fn the_subtitle_plate_and_strip_fit_the_smallest_window() {
822823 for id in crate::ui::theme::PaletteId::ALL {
823824 assert!(contrast(id.palette().SUB_FG, 0x000000) >= 7., "{id:?}");
824825 }
825- // The strip is a picture and not a target -- nothing on it takes a
826- // click -- which is the only reason it may be under `HIT_MIN`.
827- assert!(SUB_LANE_H < HIT_MIN && SUB_LANE_H > 0.);
826+ // A subtitle lane is dragged onto, trimmed on and lifted from, so its row
827+ // is a target and binds `HIT_MIN` like every other lane's -- the whole
828+ // reason it is a lane and no longer a 16 px strip.
829+ assert!(LANE_H >= HIT_MIN);
828830 // The library's own list of tracks scrolls past three rather than
829831 // taking the media list's room.
830832 assert_eq!(SUB_ROWS_H / ROW_H, 3.);
crates/app/src/tests/mod.rsmodified+4 -4
@@ -39,7 +39,7 @@ use super::{
3939 };
4040
4141 use super::{
42- Choice, EDGE_W, ETA_SPAN, Edge, FITS, FRAME_RATES, LaneKind, PPS_DEFAULT, PPS_MIN, Preset, RESOLUTIONS, Repeat,
42+ Choice, EDGE_W, ETA_SPAN, Edge, FITS, FRAME_RATES, LaneKind, SubClip, PPS_DEFAULT, PPS_MIN, Preset, RESOLUTIONS, Repeat,
4343 Scale, View,
4444 ZOOM_MIN_FRAMES, ZOOM_OUT_MARGIN, ZOOM_STEP, audio_rate_choices, av1_hw_warning, clock,
4545 encoder_choices, encoder_label, eta_secs, file_name, file_uri,
@@ -49,16 +49,16 @@ use super::{
4949 Landing, arrival, launch_queue,
5050 read_ahead, scan_plan, seek_line, silence_line, source_secs, stash_or_write,
5151 repeats, resolution_choices, resolution_ladder, span_label, tone_choices, tone_label,
52- clip_width, trimmed_clip, trims, unscannable, unusable,
52+ clip_width, frames_of_us, trimmed_clip, trimmed_sub, trims, unscannable, unusable,
5353 visible_slice,
5454 };
5555
5656 use super::{
57- SUB_BOTTOM, SUB_CUE_MIN_W, SUB_HEAD_H, SUB_FG, SUB_LANE_H, SUB_LINE_H, SUB_ROWS_H,
57+ SUB_BOTTOM, SUB_CUE_MIN_W, SUB_HEAD_H, SUB_FG, SUB_LINE_H, SUB_ROWS_H,
5858 SUB_STEM_SHARE, SUB_TEXT, clip_middle, cue_box, sub_bottom,
5959 carries_subtitles, cues_at, file_tint, is_subtitle, lang_human, row_text_w, sub_headers_fit,
6060 Subs, subtitle_detail, subtitle_notice, subtitle_tail,
61- sub_pick_name, subtitle_rows, subtitle_strip_h, walk_subtitles,
61+ sub_pick_name, subtitle_rows, walk_subtitles,
6262 };
6363
6464 use engine::PlaybackSession;
crates/app/src/tests/view.rsmodified+14 -0
@@ -126,6 +126,20 @@ fn a_lane_refuses_the_files_it_cannot_hold_before_the_release_says_so() {
126126 // engine takes its sound onto one, and the words for a video-only file
127127 // are its own.
128128 assert_eq!(lane_refuses(movie, audio), None);
129+ // ...and a subtitle lane holds none of the three: a caption comes off the
130+ // Subtitles list, which is where the refusal points.
131+ for file in [sound, still, movie] {
132+ let why = lane_refuses(file, Lane::S1).expect("a subtitle lane takes no media");
133+ assert!(why.starts_with("NOT ON S1 — "), "{why}");
134+ assert!(why.contains("Subtitles list"), "{why}");
135+ }
136+ // How the two clocks a caption has meet, which is what a palette row's
137+ // length is worked out with: a second of words at 30 fps is 30 frames,
138+ // and a track shorter than one frame is still a caption to place.
139+ assert_eq!(frames_of_us(1_000_000, 30.), 30);
140+ assert_eq!(frames_of_us(500_000, 24.), 12);
141+ assert_eq!(frames_of_us(1_000, 30.), 1);
142+ assert_eq!(frames_of_us(1_000_000, 0.), 1);
129143 }
130144
131145 /// Where those edges come from: every lane, not the one being dropped on --
crates/app/src/timeline_math.rsmodified+49 -2
@@ -146,6 +146,45 @@ pub(crate) fn trimmed_clip(clip: Clip, edge: Edge, to: u32, still: bool) -> Clip
146146 }
147147 }
148148
149+/// How many timeline frames a stretch of a subtitle track is worth: the one
150+/// conversion between the two clocks a caption has -- microseconds for its
151+/// words, frames for where it sits -- and the app-side twin of the engine's own
152+/// (`Project::trim_sub_room`). Never zero: a placement of no frames is the one
153+/// [`Project::place_sub`] refuses as empty, and a track shorter than a frame is
154+/// still a caption somebody dragged.
155+pub(crate) fn frames_of_us(us: i64, fps: f64) -> u32 {
156+ match fps.is_finite() && fps > 0. {
157+ true => ((us as f64) * fps / 1e6)
158+ .round()
159+ .clamp(1., f64::from(u32::MAX)) as u32,
160+ false => 1,
161+ }
162+}
163+
164+/// The *placement* a trim is showing, the same way for a caption:
165+/// [`Project::trim_sub`] moves the head or the tail and the window follows it,
166+/// so the box on screen is the frames alone -- the words it will keep are the
167+/// engine's arithmetic at the release, and nothing here draws them.
168+///
169+/// An edge that has not moved draws the placement it pressed, and one dragged
170+/// past its other end keeps the one frame the engine's own walls always leave.
171+pub(crate) fn trimmed_sub(sub: SubClip, edge: Edge, to: u32) -> SubClip {
172+ match edge {
173+ Edge::Start => {
174+ let to = to.min(sub.end() - 1);
175+ SubClip {
176+ start: to,
177+ frames: sub.end() - to,
178+ ..sub
179+ }
180+ }
181+ Edge::End => SubClip {
182+ frames: to.max(sub.start + 1) - sub.start,
183+ ..sub
184+ },
185+ }
186+}
187+
149188 /// Which index on its own lane a dragged clip is at *now*: the one it was picked
150189 /// up at while nothing has moved, and wherever the clip itself has slid to when
151190 /// an edit during the drag rippled the lane's indices -- a delete, an undo or a
@@ -153,8 +192,9 @@ pub(crate) fn trimmed_clip(clip: Clip, edge: Edge, to: u32, still: bool) -> Clip
153192 /// `None` when the clip is gone altogether, and then the drop is not an edit at
154193 /// all: moving whatever slid into its place is the one thing the hand did not
155194 /// ask for. A lane's clips are disjoint and sorted, so at most one of them can
156-/// be the clip that was picked up.
157-pub(crate) fn live_idx(clips: &[Clip], idx: usize, clip: Clip) -> Option<usize> {
195+/// be the clip that was picked up. Generic over what a lane holds, because a
196+/// [`SubClip`] is dragged under exactly the same rule.
197+pub(crate) fn live_idx<T: Copy + PartialEq>(clips: &[T], idx: usize, clip: T) -> Option<usize> {
158198 match clips.get(idx) {
159199 Some(&at) if at == clip => Some(idx),
160200 _ => clips.iter().position(|&c| c == clip),
@@ -396,6 +436,13 @@ pub(crate) fn lane_refuses(path: &Path, lane: Lane) -> Option<String> {
396436 LaneKind::Audio if engine::is_image(path) => {
397437 Some(format!("NOT ON {label} — {name} is a still image; drop it on a video lane"))
398438 }
439+ // A subtitle lane holds words and no media at all: the refusal is here
440+ // rather than at the engine's door so the shadow is tinted red on the
441+ // way down, like every other lane a file cannot go on.
442+ LaneKind::Subtitle => Some(format!(
443+ "NOT ON {label} — {name} is a file; a subtitle track takes captions, dragged from the \
444+ Subtitles list"
445+ )),
399446 _ => None,
400447 }
401448 }
crates/app/src/ui/theme.rsmodified+4 -6
@@ -1095,12 +1095,10 @@ pub fn clip_kind(kind: LaneKind, image: bool) -> u32 {
10951095 LaneKind::Audio => CLIP_AUDIO(),
10961096 LaneKind::Video if image => CLIP_IMAGE(),
10971097 LaneKind::Video => CLIP_VIDEO(),
1098- // A caption borrows the still's shade until the slice that draws
1099- // subtitle lanes gives it one of its own in every family: nothing on
1100- // screen paints one yet (the engine model landed first), and inventing
1101- // a colour here for a box nobody draws is the one thing this call says
1102- // not to do.
1103- LaneKind::Subtitle => CLIP_IMAGE(),
1098+ // The purple every editor paints a title track, and the one clip colour
1099+ // this palette already carried and nothing drew: a caption's box is now
1100+ // that box.
1101+ LaneKind::Subtitle => CLIP_TEXT(),
11041102 }
11051103 }
11061104
crates/app/src/ui/timeline.rsmodified+287 -143
@@ -40,11 +40,6 @@ impl Player {
4040 for &lane in &lanes {
4141 rows.push(self.lane_row(lane, filled, cx));
4242 }
43- // Built from the same playhead pixel the lanes are, and before the
44- // export takes `filled` over below: the strip is a picture of the
45- // timeline, not of an export's progress.
46- let strip = self.subtitle_strip(filled, cx);
47- let strip_h = subtitle_strip_h(strip.is_some());
4843 let (hint, filled) = if let Some(export) = self.exporting() {
4944 let progress = export.progress();
5045 let elapsed = self
@@ -114,8 +109,8 @@ impl Player {
114109 // number a scroll is measured against, and the one the affordance below
115110 // counts with. The line it costs is taken off the box before the count,
116111 // or the row that says "1 more" would be the row hiding it.
117- let region_h = (timeline_h(lanes.len()) + strip_h).min(viewport_h * TIMELINE_SHARE);
118- let lanes_box = (region_h - TIMELINE_FIXED_H - strip_h).max(LANE_H);
112+ let region_h = timeline_h(lanes.len()).min(viewport_h * TIMELINE_SHARE);
113+ let lanes_box = (region_h - TIMELINE_FIXED_H).max(LANE_H);
119114 let overflows = lanes.len() > lanes_shown(lanes_box);
120115 let lanes_box = match overflows {
121116 true => (lanes_box - LABEL_H - 8.).max(LANE_H),
@@ -291,11 +286,6 @@ impl Player {
291286 }),
292287 )
293288 })
294- // Under the tracks and outside their scrolling column: a subtitle is
295- // not a track -- nothing can be dropped on it and nothing dragged
296- // along it -- and a strip that scrolled away with the sixth lane
297- // would be a strip nobody could see while editing.
298- .children(strip)
299289 }
300290
301291 /// The subtitle tracks this timeline holds, under the media list: one row
@@ -373,11 +363,15 @@ impl Player {
373363 let tip: SharedString = match &row.refused {
374364 Some(why) => format!("{} — {why}", path.display()),
375365 None => format!(
376- "{} — click to show this track over the picture",
366+ "{} — drag it onto a subtitle track to place it, click to show it \
367+ over the picture",
377368 path.display()
378369 ),
379370 }
380371 .into();
372+ // What the pointer carries onto a lane: the row's own
373+ // name, the ghost a library row makes.
374+ let carried: SharedString = title.clone().into();
381375 // Named, because a × is the same glyph on every row and
382376 // the tooltip is what says which track it takes off.
383377 let remove_tip: SharedString =
@@ -403,6 +397,15 @@ impl Player {
403397 .when(usable, |d| {
404398 d.cursor_pointer()
405399 .hover(|s| s.bg(rgb(BG_HOVER())))
400+ // Dragged, the whole track goes down on the
401+ // subtitle lane it is let go over -- the
402+ // gesture a media row already answers to,
403+ // on the list beside it. A track that could
404+ // not be read carries nothing: there is
405+ // nothing of it to place.
406+ .on_drag(SubPick(track), move |_, _, _, cx| {
407+ cx.new(|_| Tip(carried.clone()))
408+ })
406409 .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
407410 this.sub_track = track;
408411 // Picking a track is asking to see it: a
@@ -579,136 +582,6 @@ impl Player {
579582 /// is by its tint, and the tooltip is where every box says what clicking it
580583 /// does. Never focusable, so the root keeps focus and the play binding still
581584 /// works after a click (ledger:182).
582- /// The subtitle strip: where the picked track's cues are along the very same
583- /// bed the lanes are drawn on, through the very same [`Scale`], so a cue
584- /// lines up with the take it belongs to at every zoom.
585- ///
586- /// Display only -- no drag, no trim, no drop. What it is *for* is the
587- /// question "is there a subtitle here", which a timeline could not answer at
588- /// all before: the cues are the project's and are edited in the file they
589- /// came from.
590- ///
591- /// `None` with no track picked, so a timeline without subtitles is the panel
592- /// it has always been.
593- pub(crate) fn subtitle_strip(
594- &self,
595- filled: f32,
596- cx: &mut Context<Self>,
597- ) -> Option<impl IntoElement + use<>> {
598- let track = self.subtitle_track()?;
599- let scale = self.scale;
600- // The pick with its film on it, not the raw tag: two films' "eng"
601- // tracks read alike otherwise, and a header saying "und" names a
602- // language nobody speaks.
603- let label = sub_pick_name(self.session.as_ref()?.subtitles(), self.sub_track)?;
604- // The colour the file's own rows and clips wear, so the strip says
605- // whose subtitles these are before the tooltip is asked. `None` for a
606- // standalone `.srt` -- nobody's stream, and the first film's colour
607- // would be a lie about where it came from.
608- let tint = file_tint(self.sources(), &track.path).unwrap_or(BG_RAISED());
609- // The whole of what the row says in words, since a 40 px column can hold
610- // three characters of it: which track of which file, how many cues, the
611- // file itself in full -- one stem is two films when they are two cuts of
612- // it -- and, for a track that could not be read, the engine's own reason,
613- // where the library row's grey already says the same thing.
614- let tip: SharedString = match track.refused.is_some() {
615- true => format!(
616- "Subtitles: {label} — {} — {}",
617- subtitle_detail(track),
618- track.path.display()
619- ),
620- false => format!(
621- "Subtitles: {label} — {}, {} hides them — {}",
622- subtitle_detail(track),
623- self.keymap.display(ActionId::ToggleSubtitles),
624- track.path.display()
625- ),
626- }
627- .into();
628- // Where the cues are on *this* timeline and not in the file they came
629- // from ([`PlaybackSession::timeline_cues`]) -- the same map the plate
630- // over the picture and the export both go through, which is what keeps
631- // a mark under the take it is spoken over after a cut.
632- let cues: Vec<(f32, f32)> = self
633- .session
634- .as_ref()?
635- .timeline_cues(self.sub_track)
636- .iter()
637- .map(|cue| cue_box(scale, cue))
638- .collect();
639- Some(
640- div()
641- .flex_none()
642- .h(px(SUB_LANE_H))
643- .flex()
644- .gap(px(HEADER_GAP))
645- .child(
646- // Identified for the tooltip's sake and for nothing else:
647- // the whole of what a 40 px column can say is three
648- // characters, and the rest of it hangs off the hover.
649- div()
650- .id("subtitle-lane")
651- .flex_none()
652- .w(px(HEADER_W))
653- .h_full()
654- .flex()
655- .items_center()
656- // From the left rather than centred, unlike a lane's
657- // `V1`: a track label is a language or a file name, and
658- // a centred truncation eats both of its ends.
659- .px(px(2.))
660- .rounded(px(3.))
661- .bg(rgb(tint))
662- .text_size(px(9.))
663- .text_color(rgb(FG_SECONDARY()))
664- .truncate()
665- .tooltip(move |_, cx| cx.new(|_| Tip(tip.clone())).into())
666- .child(label),
667- )
668- .child(
669- div()
670- .relative()
671- .flex_1()
672- .min_w(px(0.))
673- .h_full()
674- .rounded(px(3.))
675- .bg(rgb(BG_TIMELINE()))
676- .overflow_hidden()
677- // The same bed under the same [`Scale`] answers the same
678- // wheel ([`Player::timeline_wheel`]): ctrl zooms about
679- // the pointer, bare scrolls the view along. A hand that
680- // wants a cue closer aims at the cue, and a timeline
681- // surface that ignores the wheel is a dead one.
682- .on_scroll_wheel(cx.listener(|this, event: &ScrollWheelEvent, _, cx| {
683- cx.stop_propagation();
684- this.timeline_wheel(event, cx);
685- }))
686- .children(cues.into_iter().map(|(left, width)| {
687- div()
688- .absolute()
689- .top_0()
690- .h_full()
691- .left(px(left))
692- .w(px(width))
693- .rounded(px(2.))
694- .bg(rgb(BG_SELECTED()))
695- }))
696- // The playhead again, last and in the lanes' own colour:
697- // the strip is only worth anything beside them if it
698- // reads as the same moment.
699- .child(
700- div()
701- .absolute()
702- .top_0()
703- .h_full()
704- .left(px(filled))
705- .w(px(2.))
706- .bg(rgb(ACCENT_PLAYHEAD())),
707- ),
708- ),
709- )
710- }
711-
712585 pub(crate) fn lane_row(
713586 &self,
714587 lane: Lane,
@@ -784,6 +657,39 @@ impl Player {
784657 .map_or(&[][..], PlaybackSession::sources);
785658 let (sel, sel_link) = (self.selected, self.selected_link());
786659 let audio = lane.kind == LaneKind::Audio;
660+ // A subtitle lane holds no `Clip` and every other lane holds no
661+ // `SubClip`, so the two lists below are never both full and the bed
662+ // draws whichever it was given -- one row, and no second kind of row to
663+ // keep in step with this one.
664+ let sub = lane.kind == LaneKind::Subtitle;
665+ let shown = self.sub_lane_on(lane);
666+ let subs: Vec<SubClip> = match (sub, &self.session) {
667+ (true, Some(session)) => session.sub_lane(lane).to_vec(),
668+ _ => Vec::new(),
669+ };
670+ // Where this lane's words actually are on this timeline
671+ // ([`PlaybackSession::sub_lane_cues`], the same map an export and the
672+ // plate over the picture go through): the marks inside the placements'
673+ // boxes, so a caption's box says where in it anybody speaks.
674+ let cues: Vec<(f32, f32)> = match (sub, &self.session) {
675+ (true, Some(session)) => session
676+ .sub_lane_cues(lane)
677+ .iter()
678+ .map(|cue| cue_box(scale, cue))
679+ .collect(),
680+ _ => Vec::new(),
681+ };
682+ let eye_tip: SharedString = match shown {
683+ true => format!("{name} shows its captions — click to hide this track"),
684+ false => format!("{name} is hidden — click to show its captions again"),
685+ }
686+ .into();
687+ // What a caption's box says clicking it does; the media boxes' tooltip
688+ // names edits a placement has none of (no group, no speed, no ripple).
689+ let sub_tip: SharedString =
690+ "Drag it along the lane or onto another subtitle track, an end to trim it, × takes it \
691+ off"
692+ .into();
787693 // What this track plays at, on the header it belongs to: shown only
788694 // when it is not unity, because a column 40 px wide has room for a
789695 // number or for a name, and the name is what a header is for. The
@@ -881,6 +787,37 @@ impl Player {
881787 false => format!("{name} {gain_db:+.0}"),
882788 })
883789 .into_any_element(),
790+ // A subtitle track's own one setting, in the same
791+ // place and for the same reason: whether this lane's
792+ // words are drawn over the picture. The eye every
793+ // player puts on a track, `HIT_MIN` tall like the mix
794+ // button it sits where.
795+ false if sub => div()
796+ .id(("eye-lane", lane.ord))
797+ .flex_1()
798+ .w_full()
799+ .flex()
800+ .flex_col()
801+ .items_center()
802+ .justify_center()
803+ .rounded(px(3.))
804+ .cursor_pointer()
805+ .hover(|s| s.bg(rgb(BG_HOVER())))
806+ .when(!shown, |d| d.text_color(rgb(FG_DISABLED())))
807+ .tooltip(move |_, cx| cx.new(|_| Tip(eye_tip.clone())).into())
808+ .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
809+ this.toggle_sub_lane(lane, cx)
810+ }))
811+ .child(name.clone())
812+ .child(
813+ div()
814+ .text_size(px(9.))
815+ .child(match shown {
816+ true => "◉",
817+ false => "○",
818+ }),
819+ )
820+ .into_any_element(),
884821 false => div()
885822 .flex_1()
886823 .flex()
@@ -993,6 +930,39 @@ impl Player {
993930 this.preview_ghost(&drag, lane, event.event.position.x, cx);
994931 },
995932 ))
933+ // A palette row let go over a lane places that whole
934+ // subtitle track where the hand left it -- and over a lane
935+ // that is not a subtitle one, `place_sub` refuses it in
936+ // words, which is why the listener is on every bed rather
937+ // than on the subtitle beds alone.
938+ .on_drop(cx.listener(move |this, drag: &SubPick, window, cx| {
939+ this.place_sub(drag.0, lane, window.mouse_position().x, cx);
940+ }))
941+ .drag_over::<SubPick>(|s, _, _, _| s.bg(rgb(BG_HOVER_DIM())))
942+ .on_drag_move(cx.listener(
943+ move |this, event: &DragMoveEvent<SubPick>, _, cx| {
944+ if !event.bounds.contains(&event.event.position) {
945+ return;
946+ }
947+ let track = event.drag(cx).0;
948+ this.preview_ghost_pick(track, lane, event.event.position.x, cx);
949+ },
950+ ))
951+ // ...and a caption already on a lane moves along it, or onto
952+ // another subtitle track, exactly as a clip does.
953+ .on_drop(cx.listener(move |this, drag: &SubDrag, window, cx| {
954+ this.move_sub(drag, lane, window.mouse_position().x, cx);
955+ }))
956+ .drag_over::<SubDrag>(|s, _, _, _| s.bg(rgb(BG_HOVER_DIM())))
957+ .on_drag_move(cx.listener(
958+ move |this, event: &DragMoveEvent<SubDrag>, _, cx| {
959+ if !event.bounds.contains(&event.event.position) {
960+ return;
961+ }
962+ let drag = *event.drag(cx);
963+ this.preview_ghost_sub(&drag, lane, event.event.position.x, cx);
964+ },
965+ ))
996966 .children(clips.iter().enumerate().map(|(i, clip)| {
997967 // The clip as the lane holds it, for the drag payload:
998968 // what a drop looks itself up by has to be the placed
@@ -1290,6 +1260,180 @@ impl Player {
12901260 )
12911261 })
12921262 }))
1263+ // The same bed's other kind of box: a stretch of a palette
1264+ // track placed on this lane, dragged along it, dragged onto
1265+ // another subtitle lane, trimmed at either end and lifted
1266+ // off by its own ×. Empty on every lane that is not a
1267+ // subtitle one, which is why there is one row and not two.
1268+ .children(subs.iter().enumerate().map(|(i, placed)| {
1269+ // What the drag payload names, and what an edge drag is
1270+ // *showing* -- the box moves under the pointer and the
1271+ // engine hears once, at the release.
1272+ let (placed, shown_sub) = (*placed, self.trimmed_sub(lane, i, *placed));
1273+ let (start, len) = (
1274+ f64::from(shown_sub.start) / self.fps,
1275+ f64::from(shown_sub.frames) / self.fps,
1276+ );
1277+ let span = scale.width_px(len);
1278+ let width = clip_width(span);
1279+ let left = scale.px_at(start);
1280+ let (vis_x, vis_w) = visible_slice(left, width, bed);
1281+ // Which track's words these are, film and all: two
1282+ // "eng" tracks off two files read alike otherwise.
1283+ let label = self
1284+ .session
1285+ .as_ref()
1286+ .and_then(|session| sub_pick_name(session.subtitles(), placed.track));
1287+ let ghost: SharedString =
1288+ label.clone().unwrap_or_else(|| lane.label()).into();
1289+ let tip = sub_tip.clone();
1290+ let head = shown_sub.start;
1291+ div()
1292+ .id((row_id.clone(), i))
1293+ .absolute()
1294+ .top_0()
1295+ .h_full()
1296+ .left(px(left))
1297+ .w(px(width))
1298+ .overflow_hidden()
1299+ .rounded(px(3.))
1300+ .border_1()
1301+ .border_color(rgb(FG_SECONDARY()))
1302+ // The captions' own colour, dimmed on a lane whose
1303+ // eye is shut: what is not being drawn over the
1304+ // picture is still on the lane, and says so.
1305+ .bg(rgb(CLIP_TEXT()))
1306+ .when(!shown, |d| d.opacity(0.55))
1307+ .cursor_pointer()
1308+ .hover(|s| s.border_color(rgb(ACCENT_PRIMARY())))
1309+ .tooltip(move |_, cx| cx.new(|_| Tip(tip.clone())).into())
1310+ .on_drag(
1311+ SubDrag {
1312+ lane,
1313+ idx: i,
1314+ sub: placed,
1315+ },
1316+ move |_, _, _, cx| cx.new(|_| Tip(ghost.clone())),
1317+ )
1318+ .on_mouse_down(
1319+ MouseButton::Left,
1320+ cx.listener(move |this, event: &MouseDownEvent, _, cx| {
1321+ // Where in the box the hand took hold, so
1322+ // the caption moves with the pointer rather
1323+ // than jumping its head under it.
1324+ this.grab =
1325+ this.frame_under(event.position.x).saturating_sub(head);
1326+ cx.notify();
1327+ }),
1328+ )
1329+ // The two strips a drag lengthens it by, on the same
1330+ // rule a clip's are drawn by ([`trims`]).
1331+ .children(
1332+ [Edge::Start, Edge::End]
1333+ .into_iter()
1334+ .filter(|_| trims(span))
1335+ .map(|edge| {
1336+ let mut zone = div()
1337+ .absolute()
1338+ .top_0()
1339+ .h_full()
1340+ .w(px(EDGE_W))
1341+ .occlude()
1342+ .cursor(CursorStyle::ResizeLeftRight)
1343+ .hover(|s| s.bg(rgb(ACCENT_PRIMARY())))
1344+ .on_mouse_down(
1345+ MouseButton::Left,
1346+ cx.listener(
1347+ move |this, _: &MouseDownEvent, _, cx| {
1348+ this.start_trim(lane, i, edge, cx);
1349+ },
1350+ ),
1351+ )
1352+ .on_scroll_wheel(cx.listener(
1353+ |this, event: &ScrollWheelEvent, _, cx| {
1354+ cx.stop_propagation();
1355+ this.timeline_wheel(event, cx);
1356+ },
1357+ ));
1358+ zone = match edge {
1359+ Edge::Start => zone.left_0(),
1360+ Edge::End => zone.right_0(),
1361+ };
1362+ zone
1363+ }),
1364+ )
1365+ .when_some(label.filter(|_| show_label(vis_w)), |d, label| {
1366+ d.child(
1367+ div()
1368+ .absolute()
1369+ .top_0()
1370+ .left(px(vis_x))
1371+ .w(px(vis_w))
1372+ .h(px(LABEL_H))
1373+ .px(px(4.))
1374+ .truncate()
1375+ .text_size(px(10.))
1376+ .child(label),
1377+ )
1378+ })
1379+ // The way back off the lane, on the box itself: a
1380+ // caption is not in the clip selection's index
1381+ // space, so no stroke reaches it -- and a lane
1382+ // holding one cannot be removed either
1383+ // ([`Project::remove_lane`] refuses it), which
1384+ // would leave a placement nobody could undo but by
1385+ // undoing. Only where the box is wide enough to
1386+ // hold a target beside its name; narrower than that
1387+ // it is lifted after zooming in, exactly as it is
1388+ // trimmed after zooming in.
1389+ //
1390+ // Clear of the tail's own trim strip by that
1391+ // strip's width: both occlude and this one is drawn
1392+ // last, so hard against the right edge it swallowed
1393+ // every press meant for the edge and the tail could
1394+ // not be dragged at all (caught driving it).
1395+ .when(vis_w >= 2. * HIT_MIN + EDGE_W, |d| {
1396+ d.child(
1397+ div()
1398+ .id(("sub-lift", i))
1399+ .absolute()
1400+ .top_0()
1401+ .left(px(vis_x + vis_w - HIT_MIN - EDGE_W))
1402+ .w(px(HIT_MIN))
1403+ .h(px(HIT_MIN))
1404+ .flex()
1405+ .items_center()
1406+ .justify_center()
1407+ .occlude()
1408+ .rounded(px(3.))
1409+ .cursor_pointer()
1410+ .hover(|s| s.bg(rgb(BG_HOVER())))
1411+ .on_click(cx.listener(
1412+ move |this, _: &ClickEvent, _, cx| {
1413+ cx.stop_propagation();
1414+ this.lift_sub(lane, i, cx);
1415+ },
1416+ ))
1417+ .child("×"),
1418+ )
1419+ })
1420+ }))
1421+ // ...and where the words actually are inside those boxes:
1422+ // the cues this lane shows on *this* timeline, in a band
1423+ // along the bottom of the row. A placement is a window of a
1424+ // track, so a box is not full of speech -- and a lane whose
1425+ // marks are all in its first half is a caption dragged too
1426+ // far, which is exactly what this band shows.
1427+ .children(cues.into_iter().map(|(left, width)| {
1428+ div()
1429+ .absolute()
1430+ .bottom_0()
1431+ .h(px(4.))
1432+ .left(px(left))
1433+ .w(px(width))
1434+ .rounded(px(2.))
1435+ .bg(rgb(BG_SELECTED()))
1436+ }))
12931437 // What the silence card found, over the clips it found them
12941438 // in and over the waveform band that shows why: on the lane
12951439 // the scan ran on and no other, because that is the only