From 888f39d0a7ce97c761f2c6e5c5a652c023b1f77a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 15 Aug 2026 16:07:55 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(timeline):=20a=20caption=20is?= =?UTF-8?q?=20taken=20off=20the=20lane=20by=20the=20same=20stroke=20and=20?= =?UTF-8?q?row=20a=20clip=20is?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A placed caption could only be lifted by a ✕ that vanished on narrow boxes. Captions are now marked by a click, lifted by x/delete and the menu, and dragged — parity with every other thing on a lane. The mark is keyed by a caption's start frame, so a refused drop, a sorted insert or a removal cannot shift it onto the caption beside it. With a caption marked the playhead actions stay live while its menu carries only its own rows: the playhead's clip actions — split, rate, grade, fit — would read as the caption's. --- crates/app/src/oracle.rs | 53 +++++++ crates/app/src/player/actions.rs | 7 +- crates/app/src/player/timeline_edit.rs | 86 +++++++++-- crates/app/src/tests/editing.rs | 198 +++++++++++++++++++++++++ crates/app/src/timeline_math.rs | 14 ++ crates/app/src/ui/inspector.rs | 34 ++++- crates/app/src/ui/overlays.rs | 25 +++- crates/app/src/ui/timeline.rs | 108 +++++++------- 8 files changed, 451 insertions(+), 74 deletions(-) diff --git a/crates/app/src/oracle.rs b/crates/app/src/oracle.rs index e598d37..3723685 100644 --- a/crates/app/src/oracle.rs +++ b/crates/app/src/oracle.rs @@ -51,6 +51,12 @@ pub(crate) struct Ctx { /// and the clip-relative answers stand aside: those actions find their own /// clip under the playhead and word their own refusal. pub(crate) clip: Option<(Clip, Lane)>, + /// What was clicked is a placed caption and not a clip: a subtitle lane + /// holds no `Clip` at all, so [`Ctx::clip`] is `None` there and the + /// clip-relative answers would read it as "nothing marked". Its own flag, + /// so the one action a caption has -- coming off the lane again -- is a + /// live row while the rest are not rows at all. + pub(crate) caption: bool, /// The clip plays a still ([`engine::is_image`]), which has no sound to /// reach at all -- not the lane's business, because a still sits on a video /// lane exactly like a take whose sound is one lane down. @@ -127,6 +133,36 @@ pub(crate) fn enable(action: ActionId, ctx: Ctx) -> Enable { _ => Enable::No("an export is running"), }; } + // A caption is not a clip: the actions that act on *the marked clip and + // nothing else* have nothing to act on over a placed subtitle, so they are + // refusals of kind -- not rows at all, rather than rows saying "click a clip + // first" over a clicked caption. Delete is the one that means something: it + // routes to [`Player::lift_sub`] when what is marked is a caption. + // + // And it is *only* those. The playhead actions are about the timeline rather + // than about what is marked -- the split and the regroup act at the line + // ([`Player::cut`], [`Player::regroup`]), and the grade, the rate, the fit + // and the scan fall back to the clip under it -- so a caption in hand is no + // reason for them to stop. Hiding them here made them dead *and* silent + // ([`Player::act`] returns without a word on `Hidden`) from the moment a + // caption was clicked until something else was, which no click on the bed + // undoes: there is no handler there to clear the mark. + if ctx.caption + && matches!( + action, + ActionId::Copy + | ActionId::Delete + | ActionId::Lift + | ActionId::Detach + | ActionId::Group + | ActionId::Equalizer + ) + { + return match action { + ActionId::Delete => Enable::Yes, + _ => Enable::Hidden("this is a caption"), + }; + } match action { // -- class: what kind of thing the action is about. The equalizer // filters samples, and a video clip has none of its own here: the sound @@ -224,10 +260,27 @@ pub(crate) fn enable(action: ActionId, ctx: Ctx) -> Enable { /// a waveform, an equalizer on a picture -- is not a row at all, so a future /// action cannot appear where it does not apply by being added to /// [`MENU_ITEMS`] alone. +/// +/// Being *live* and *belonging in this menu* are two different questions, and +/// only this one is the menu's. The playhead actions stay live over a marked +/// caption -- [`enable`] says so, and the strokes and the toolbar read that -- +/// but a split, a rate, a grade or a fit listed under a right-clicked caption +/// reads as something the caption is about to get, when what they reach is the +/// video clip the playhead is standing in. So a caption's menu carries the one +/// row that is the caption's ([`Player::lift_sub`], reached through Delete) and +/// the rows the card already prints "(global)" beside, which say for themselves +/// that they are not about what was clicked. pub(crate) fn menu_items(ctx: Ctx) -> Vec { MENU_ITEMS .into_iter() .filter(|&action| enable(action, ctx).listed()) + .filter(|&action| { + !ctx.caption + || matches!( + action, + ActionId::Delete | ActionId::Paste | ActionId::ToggleMute + ) + }) .collect() } diff --git a/crates/app/src/player/actions.rs b/crates/app/src/player/actions.rs index aa893c8..b0a9062 100644 --- a/crates/app/src/player/actions.rs +++ b/crates/app/src/player/actions.rs @@ -213,11 +213,16 @@ impl Player { let Some(session) = &self.session else { return Ctx::default(); }; + let on = on.or(self.selected); let clip = on - .or(self.selected) .and_then(|(lane, idx)| session.lane_clips(lane).get(idx).map(|clip| (*clip, lane))); Ctx { clip, + // The same pair read in the other index space: a subtitle lane's + // own, where the box that was clicked is a caption. + caption: on.is_some_and(|(lane, idx)| { + lane.kind == LaneKind::Subtitle && idx < session.sub_lane(lane).len() + }), image: clip.is_some_and(|(clip, _)| { session .sources() diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index f07faed..17dda2f 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -121,6 +121,14 @@ impl Player { return; } let selected = self.selected.take(); + // A caption is marked in its own lane's index space -- that lane holds + // no `Clip` -- so the same key reaches it through the one removal a + // placed subtitle has ([`Player::lift_sub`], one undo step). Parity: the + // box on a subtitle lane goes by the stroke every other box goes by. + if let Some((lane, idx)) = selected.filter(|(lane, _)| lane.kind == LaneKind::Subtitle) { + self.lift_sub(lane, idx, cx); + return; + } // Whichever lane it was clicked in: the index is that lane's own, and // the ripple cuts the clip's span out of every lane -- a group covers // one span, so deleting a take by its audio half is the same edit as by @@ -296,6 +304,12 @@ impl Player { self.snap_cue = None; self.ghost = None; let at = self.place_frame(x).0; + // What the mark is on, before the lane is renumbered: a caption's start + // frame is its name on its lane ([`sub_mark`]). + let marked = self + .selected + .filter(|&(lane, _)| lane == to) + .and_then(|(lane, idx)| Some(self.session.as_ref()?.sub_lane(lane).get(idx)?.start)); let text = match (self.sub_of_track(track), &mut self.session) { (Some(sub), Some(session)) => match session.place_sub(to, at, sub) { Ok(()) => None, @@ -309,8 +323,21 @@ impl Player { ), (_, None) => Some("NOT PLACED — open a file first".to_string()), }; - if let Some(text) = text { - self.notify_user(text.into()); + match (text, marked) { + (Some(text), _) => self.notify_user(text.into()), + // It went down, and a lane holds its captions in start order + // ([`Project::place_sub`]'s sorted insert), so one placed *before* + // the marked caption slid it one along and the index left behind + // names its new neighbour -- the caption the next Delete would take. + // The mark goes back on the caption it was on. + (None, Some(start)) => { + self.selected = self + .session + .as_ref() + .and_then(|session| sub_mark(session.sub_lane(to), start)) + .map(|i| (to, i)); + } + (None, None) => {} } cx.notify(); } @@ -338,20 +365,46 @@ impl Player { return; }; let start = self.sub_drop_frame(drag.sub, x).0; - if let Some(Err(e)) = self + match self .session .as_mut() .map(|session| session.move_sub(drag.lane, idx, to, start)) { - self.notify_user(format!("NOT MOVED — {e}").into()); + Some(Err(e)) => { + // Nothing moved ([`Project::move_sub`] refuses before its + // snapshot), so nothing was renumbered and the mark is left + // exactly where it was. Re-reading it off the frame the drop + // *asked* for used to hand it to whatever caption already + // covered that frame -- the drop at the left edge saturates to + // 0 ([`landing`]), so a refused drag marked, and the next + // Delete lifted, a caption the hand never touched. + self.notify_user(format!("NOT MOVED — {e}").into()); + } + // A lane holds its captions in start order, so the drop moved the + // mark as well as the box: it is re-read off where the caption + // landed rather than left on the index it had, which after the move + // is a neighbour's. + Some(Ok(())) => { + self.selected = self + .session + .as_ref() + .and_then(|session| sub_mark(session.sub_lane(to), start)) + .map(|i| (to, i)); + } + None => {} } cx.notify(); } - /// The × on a caption's own box: it comes off the lane and leaves the gap, - /// one undo step ([`PlaybackSession::lift_sub`]). The palette row it played - /// stays in the list, which is what makes this a lift and not a removal -- - /// and the way a subtitle lane is emptied so it can be taken off at all. + /// A caption off its lane, leaving the gap, one undo step + /// ([`PlaybackSession::lift_sub`]). The palette row it played stays in the + /// list, which is what makes this a lift and not a removal -- and the way a + /// subtitle lane is emptied so it can be taken off at all. + /// + /// The one door out for a placed caption: the Delete key + /// ([`Player::delete_selected`]) and the Delete row of its own menu both + /// land here, so there is one removal and one undo step however it is asked + /// for. pub(crate) fn lift_sub(&mut self, lane: Lane, idx: usize, cx: &mut Context) { if self.exporting().is_some() { return; @@ -367,6 +420,16 @@ impl Player { ), false => "NOTHING LIFTED — that caption is not there any more".to_string(), }; + if lifted { + // Everything after it on that lane slid down one ([`Vec::remove`]), + // so a mark or an open menu left at or past it names a *different* + // caption now -- and the next Delete would take that one. Both go + // with the caption they were on. + if self.selected.is_some_and(|(l, i)| l == lane && i >= idx) { + self.selected = None; + } + self.context_menu = None; + } self.notify_user(text.into()); cx.notify(); } @@ -817,9 +880,10 @@ impl Player { // A caption's edge, on a lane that holds no `Clip` at all: the same // gesture, the same `Trim`, and the branch is the lane's kind wherever // the drag is asked about ([`Player::trim_to`], - // [`Player::commit_trim`]). No selection -- a placement is not in the - // clip selection's index space -- and no group: a caption has no half - // on another lane. + // [`Player::commit_trim`]). A caption *is* markable -- the mark is its + // lane and its index like a clip's ([`Player::select`]) -- but an edge + // drag is a trim and not a pick, so this leaves the mark where the hand + // left it. No group either: a caption has no half on another lane. if lane.kind == LaneKind::Subtitle { let Some(sub) = self .session diff --git a/crates/app/src/tests/editing.rs b/crates/app/src/tests/editing.rs index 57fc930..c71a2b5 100644 --- a/crates/app/src/tests/editing.rs +++ b/crates/app/src/tests/editing.rs @@ -263,6 +263,204 @@ fn every_audio_stream_of_a_file_is_a_row_usable_or_not() { /// the playhead rather than on the clicked clip are the ones that can be /// inapplicable, and a menu at the edge of the window has to come back /// inside it or its last item cannot be clicked at all. +/// A caption's own menu, opened on a box that is not a clip: one row that acts +/// on it -- Delete, which routes to `Player::lift_sub` -- the timeline's global +/// item beside it, and nothing else drawn at all. What a placed subtitle used to +/// have no menu, and no stroke, to do. +#[test] +fn a_caption_is_deleted_by_the_same_row_and_stroke_every_box_is() { + use keymap::ActionId; + // A subtitle lane holds no `Clip`, so this is what the player reads off a + // right-clicked caption: nothing in the clip index space, and `caption`. + let cap = Ctx { + caption: true, + timeline: true, + ..Ctx::default() + }; + assert!(cap.clip.is_none(), "a caption is never a clip"); + assert_eq!( + enable(ActionId::Delete, cap), + Enable::Yes, + "the one thing a placed caption can be asked to do", + ); + // The clip rows are refusals of *kind* on a caption, so the menu leaves them + // out rather than drawing "click a clip first" over a clicked box. + for clip_only in [ + ActionId::Copy, + ActionId::Lift, + ActionId::Detach, + ActionId::Group, + ActionId::Equalizer, + ] { + assert_eq!( + enable(clip_only, cap), + Enable::Hidden("this is a caption"), + "{clip_only:?} is not a row on a caption", + ); + } + // ...and the playhead's actions are *not* among them: the split and the + // regroup act at the line and the cards fall back to the clip under it, so a + // caption in hand is no reason for them to go dead -- which, hidden, is + // exactly what they went: `Player::act` returns without a word on `Hidden`, + // and no click on the bed clears the mark that put them there. + for playhead in [ + ActionId::Cut, + ActionId::Regroup, + ActionId::Color, + ActionId::Speed, + ActionId::Fit, + ActionId::Silence, + ] { + assert_eq!( + enable(playhead, cap), + Enable::Yes, + "{playhead:?} is about the playhead and not about the mark", + ); + } + // ...but live is not *listed*: every one of those rows reaches the clip + // under the playhead and not the caption, and a menu opened on a caption + // that offered a grade would read as the caption's. The caption's menu is + // its one row and the global pair the card already names as global. + assert_eq!( + menu_items(cap), + vec![ActionId::Paste, ActionId::Delete, ActionId::ToggleMute], + "the caption's menu is its removal and the global rows alone", + ); + // ...and the same reading with a clip under it is the clip menu, untouched: + // the flag is off wherever a `Clip` was clicked. + assert!(menu_items(Ctx { + timeline: true, + ..Ctx::default() + }) + .contains(&ActionId::Cut)); +} + +/// A timeline with a subtitle palette and an empty subtitle lane: what a +/// caption is placed on, at the fixture's own rate. +fn with_subtitle_lane() -> (PlaybackSession, Lane) { + let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); + session.set_gain(0.0); + subtitle_notice(&mut session, &asset("test_subs.mkv")).expect("the mkv carries subtitles"); + let lane = session.add_lane(LaneKind::Subtitle); + (session, lane) +} + +/// A second of palette track 0, to be placed wherever the test drops it. +fn one_second(start: u32) -> SubClip { + SubClip { + start, + frames: 30, + track: 0, + in_us: 0, + out_us: 1_000_000, + } +} + +/// A drop the engine *refuses* moves nothing -- so it must move no mark either. +/// A drag towards the left edge saturates to frame 0 (`landing`), and reading +/// the mark back off the frame the drop asked for handed it to whatever caption +/// already covered frame 0: the next Delete then lifted a caption the hand never +/// touched. The mark stays on the caption that did not move. +#[test] +fn a_refused_caption_drop_leaves_the_mark_where_it_was() { + use crate::sub_mark; + let (mut session, lane) = with_subtitle_lane(); + session.place_sub(lane, 0, one_second(0)).expect("A goes down"); + session + .place_sub(lane, 60, one_second(0)) + .expect("B goes down after it"); + let before = session.sub_lane(lane).to_vec(); + // The mark is on B, the caption in hand: index 1 of the lane. + assert_eq!(sub_mark(session.sub_lane(lane), 60), Some(1)); + + let err = session + .move_sub(lane, 1, lane, 0) + .expect_err("A already covers frame 0"); + assert!(err.to_string().contains("already covers"), "{err}"); + assert_eq!(session.sub_lane(lane), before, "a refusal moved nothing"); + // The trap this pins: the frame the drop *asked* for names A, so the old + // re-read marked A -- the caption nobody dragged -- and `x` lifted it. + assert_eq!( + sub_mark(session.sub_lane(lane), 0), + Some(0), + "frame 0 is A's, which is why a refused drop must not re-read the mark", + ); + // Nothing was renumbered, so B is still index 1 and still the marked one. + assert_eq!(sub_mark(session.sub_lane(lane), 60), Some(1)); +} + +/// A lane inserts its captions in start order (`Project::place_sub`), so one +/// placed *before* the marked caption slides it one along: the mark left on its +/// old index would name the caption that just arrived, and `x` would lift that +/// one instead. The mark is kept by the caption's start frame, which is its name +/// on its lane, so it follows the caption it was on. +#[test] +fn a_caption_placed_before_the_marked_one_leaves_the_mark_on_the_original() { + use crate::sub_mark; + let (mut session, lane) = with_subtitle_lane(); + session + .place_sub(lane, 100, one_second(0)) + .expect("A goes down"); + let marked = session.sub_lane(lane)[0].start; + assert_eq!(sub_mark(session.sub_lane(lane), marked), Some(0)); + + session + .place_sub(lane, 0, one_second(0)) + .expect("the new one goes down before it"); + assert_eq!( + session + .sub_lane(lane) + .iter() + .map(|s| s.start) + .collect::>(), + [0, 100], + "the lane holds them in start order", + ); + // What the player does with the mark across that placement. + let mark = sub_mark(session.sub_lane(lane), marked).expect("A is still there"); + assert_eq!(mark, 1, "A slid one along and the mark went with it"); + + // ...and the Delete that stroke reaches takes A, not the caption that + // arrived: `Player::delete_selected` routes a caption's mark to `lift_sub`. + assert!(session.lift_sub(lane, mark)); + assert_eq!( + session + .sub_lane(lane) + .iter() + .map(|s| s.start) + .collect::>(), + [0], + "the caption the user marked is the one that died", + ); +} + +/// The playhead's actions with a caption marked: live, and doing what they say. +/// Hidden, they were dead *and* silent -- `Player::act` says nothing on a class +/// refusal -- from the first click on a caption until something else was +/// clicked, and no click on the bed clears that mark. +#[test] +fn the_playhead_actions_still_work_with_a_caption_marked() { + use keymap::ActionId; + let cap = Ctx { + caption: true, + timeline: true, + ..Ctx::default() + }; + assert_eq!(enable(ActionId::Cut, cap), Enable::Yes); + assert_eq!(enable(ActionId::Regroup, cap), Enable::Yes); + + // And the edits themselves, on a timeline holding a placed caption: the + // split at the playhead and the rejoin at the seam it leaves. + let (mut session, lane) = with_subtitle_lane(); + session.place_sub(lane, 0, one_second(0)).expect("it goes down"); + let clips = session.lane_clips(Lane::V1).len(); + assert!(session.cut_at(2.0), "the playhead splits the clip under it"); + assert_eq!(session.lane_clips(Lane::V1).len(), clips + 1); + assert!(session.regroup_at(2.0), "and the seam rejoins"); + assert_eq!(session.lane_clips(Lane::V1).len(), clips); + assert_eq!(session.sub_lane(lane).len(), 1, "the caption is untouched"); +} + #[test] fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() { use keymap::{ActionId, Keymap}; diff --git a/crates/app/src/timeline_math.rs b/crates/app/src/timeline_math.rs index 0435d37..2730314 100644 --- a/crates/app/src/timeline_math.rs +++ b/crates/app/src/timeline_math.rs @@ -201,6 +201,20 @@ pub(crate) fn live_idx(clips: &[T], idx: usize, clip: T) -> } } +/// Which index a lane's mark is on after that lane was renumbered: the caption +/// that starts at `start`, and `None` when it is not there any more. +/// +/// The mark on a caption is an index like a clip's ([`Player::selected`]), and a +/// subtitle lane both *inserts in start order* ([`engine::Project::place_sub`]) +/// and removes, so any placement or lift renumbers every caption after it and an +/// index left as it was names a neighbour -- the caption the next Delete would +/// take. So the mark is read off the caption's start frame before such an edit +/// and found again by it after: captions on a lane are disjoint and in order, so +/// a start frame names exactly one of them and is the identity an index is not. +pub(crate) fn sub_mark(subs: &[SubClip], start: u32) -> Option { + subs.iter().position(|s| s.start == start) +} + /// The part of a clip's box that is on the bed, in the box's own pixels: /// `(left, width)` of its intersection with the visible strip. Everything drawn /// *inside* a box -- its waveform, its name, its speed badge -- is placed in diff --git a/crates/app/src/ui/inspector.rs b/crates/app/src/ui/inspector.rs index d67b546..df1328e 100644 --- a/crates/app/src/ui/inspector.rs +++ b/crates/app/src/ui/inspector.rs @@ -103,9 +103,18 @@ impl Player { image, )) }); - let head = match &picked { - Some((lane, _, name, _)) => format!("{} · {}", lane.label(), name), - None => "Nothing selected".to_string(), + // A subtitle lane holds no `Clip`, so the read above answers `None` on a + // marked caption -- while the bed draws that caption in the selection's + // own colours and this panel's Delete lifts it. The panel says what is + // marked or it is telling the user the opposite of what they can see. + let caption = self.selected.filter(|_| picked.is_none()).and_then(|(lane, idx)| { + let sub = self.session.as_ref()?.sub_lane(lane).get(idx).copied()?; + Some((lane, sub)) + }); + let head = match (&picked, &caption) { + (Some((lane, _, name, _)), _) => format!("{} · {}", lane.label(), name), + (None, Some((lane, _))) => format!("{} · caption", lane.label()), + (None, None) => "Nothing selected".to_string(), }; let detail = match &picked { Some((_, clip, _, _)) => format!( @@ -115,7 +124,17 @@ impl Player { span_label(f64::from(clip.frames()) / self.fps), clip.speed, ), - None => "Click a clip on the timeline to see its settings".to_string(), + // The words' own span, in the same shape a clip's is written in -- + // and no speed, because a caption has none to change. + None => match &caption { + Some((_, sub)) => format!( + "{} → {} · {} · words", + timecode(f64::from(sub.start) / self.fps, self.fps), + timecode(f64::from(sub.end()) / self.fps, self.fps), + span_label(f64::from(sub.frames) / self.fps), + ), + None => "Click a clip on the timeline to see its settings".to_string(), + }, }; div() .flex() @@ -128,7 +147,7 @@ impl Player { div() .flex_none() .truncate() - .text_color(rgb(match picked.is_some() { + .text_color(rgb(match picked.is_some() || caption.is_some() { true => FG_PRIMARY(), false => FG_SECONDARY(), })) @@ -139,6 +158,11 @@ impl Player { .border_color(rgb(clip_kind(lane.kind, *image))) .pl(px(6.)) }) + .when_some(caption.as_ref(), |d, (lane, _)| { + d.border_l_2() + .border_color(rgb(clip_kind(lane.kind, false))) + .pl(px(6.)) + }) .child(head), ) .child( diff --git a/crates/app/src/ui/overlays.rs b/crates/app/src/ui/overlays.rs index 0b869a5..15def03 100644 --- a/crates/app/src/ui/overlays.rs +++ b/crates/app/src/ui/overlays.rs @@ -470,8 +470,13 @@ impl Player { ) -> Option { let menu = self.context_menu?; let session = self.session.as_ref()?; - let clip = *session.lane_clips(menu.lane).get(menu.idx)?; - let source = session.sources().get(clip.source).cloned()?; + // Both `None` when the menu was opened on a caption: a subtitle lane + // holds no `Clip` and a caption plays no source file. The rows are the + // oracle's either way ([`Ctx::caption`]), so what the card *has* is + // asked for where it is used rather than at the door -- refusing here + // would be a right-click that opens nothing. + let clip = session.lane_clips(menu.lane).get(menu.idx).copied(); + let source = clip.and_then(|clip| session.sources().get(clip.source).cloned()); let secs = |frames: u32| timecode(f64::from(frames) / self.fps, self.fps); let row = |n: usize| { div() @@ -487,7 +492,7 @@ impl Player { .rounded(px(3.)) }; let mut rows: Vec = Vec::new(); - if menu.details { + if let (true, Some((clip, source))) = (menu.details, clip.zip(source.clone())) { // Read-only, so no ids and no hover: this side is a card, not a // list of things to click. Each value is one truncated line, which // is what keeps the height below the one the clamp was given. @@ -596,7 +601,10 @@ impl Player { .into_any_element(), ); } - rows.push( + // What a caption has no other side to turn over to: its file, its + // source range and its bitrate are a clip's, and a row that opened + // an empty card would be the stub this menu does not draw. + rows.extend(clip.map(|_| { row(rows.len()) .cursor_pointer() .hover(|s| s.bg(rgb(BG_HOVER()))) @@ -610,15 +618,18 @@ impl Player { // No stroke reaches this one, and a blank column would read // as one that was forgotten. .child(div().text_color(rgb(FG_SECONDARY())).child("…")) - .into_any_element(), - ); + .into_any_element() + })); } // The height the card is *placed* by and the height its list is drawn // to are one number: placed by a taller one, the card would hang off the // window's floor -- the very thing the clamp is for. let list_h = menu_rows_h(rows.len(), viewport); let (x, y) = menu_at(menu.at, viewport, MENU_PAD * 2. + list_h); - let full: SharedString = source.path.display().to_string().into(); + let full: SharedString = source + .map(|source| source.path.display().to_string()) + .unwrap_or_default() + .into(); Some( scrim() // Click away closes it, either button, and the press is diff --git a/crates/app/src/ui/timeline.rs b/crates/app/src/ui/timeline.rs index 1b23fd3..cbccc37 100644 --- a/crates/app/src/ui/timeline.rs +++ b/crates/app/src/ui/timeline.rs @@ -664,8 +664,8 @@ impl Player { // What a caption's box says clicking it does; the media boxes' tooltip // names edits a placement has none of (no group, no speed, no ripple). let sub_tip: SharedString = - "Drag it along the lane or onto another subtitle track, an end to trim it, × takes it \ - off" + "Drag it along the lane or onto another subtitle track, an end to trim it, x or the \ + right button takes it off" .into(); // What this track plays at, on the header it belongs to: shown only // when it is not unity, because a column 40 px wide has room for a @@ -1248,8 +1248,10 @@ impl Player { })) // The same bed's other kind of box: a stretch of a palette // track placed on this lane, dragged along it, dragged onto - // another subtitle lane, trimmed at either end and lifted - // off by its own ×. Empty on every lane that is not a + // another subtitle lane, trimmed at either end, marked by a + // click and lifted off by the Delete row of its own menu or + // the stroke that row names -- the doors every other box on + // the bed has. Empty on every lane that is not a // subtitle one, which is why there is one row and not two. .children(subs.iter().enumerate().map(|(i, placed)| { // What the drag payload names, and what an edge drag is @@ -1274,6 +1276,10 @@ impl Player { label.clone().unwrap_or_else(|| lane.label()).into(); let tip = sub_tip.clone(); let head = shown_sub.start; + // Marked the way every other box on this bed is marked, + // in this lane's own index space -- a caption has no + // group, so nothing else lights with it. + let on = sel == Some((lane, i)); div() .id((row_id.clone(), i)) .absolute() @@ -1284,11 +1290,18 @@ impl Player { .overflow_hidden() .rounded(px(3.)) .border_1() - .border_color(rgb(FG_SECONDARY())) + .border_color(rgb(if on { + STROKE_SELECTED() + } else { + FG_SECONDARY() + })) // The captions' own colour, dimmed on a lane whose // eye is shut: what is not being drawn over the - // picture is still on the lane, and says so. - .bg(rgb(CLIP_TEXT())) + // picture is still on the lane, and says so. Marked, + // it takes the selection's colours instead, the same + // pair a marked clip takes -- what Delete will act + // on has one look on this bed and not two. + .bg(rgb(if on { BG_SELECTED() } else { CLIP_TEXT() })) .when(!shown, |d| d.opacity(0.55)) .cursor_pointer() .hover(|s| s.border_color(rgb(ACCENT_PRIMARY()))) @@ -1309,7 +1322,22 @@ impl Player { // than jumping its head under it. this.grab = this.frame_under(event.position.x).saturating_sub(head); - cx.notify(); + // ...and it marks the caption, exactly as + // the press that may become a clip's drag + // marks the clip: picking a caption up and + // putting it back down is a click. + this.select((lane, i), cx); + }), + ) + // The right button marks it and hangs the menu at + // the pointer, the clip menu opened on the clip + // box's own rule -- the Delete row of it is this + // caption's, and the rows a caption has no use for + // are not drawn ([`oracle::enable`]). + .on_mouse_down( + MouseButton::Right, + cx.listener(move |this, event: &MouseDownEvent, _, cx| { + this.open_menu(lane, i, event.position, cx); }), ) // The two strips a drag lengthens it by, on the same @@ -1340,7 +1368,20 @@ impl Player { cx.stop_propagation(); this.timeline_wheel(event, cx); }, - )); + )) + // Occluded, so the box's own + // right-button listener never fires + // here: the same menu, opened by the + // same call, exactly as a clip's + // edge strip does it. + .on_mouse_down( + MouseButton::Right, + cx.listener( + move |this, event: &MouseDownEvent, _, cx| { + this.open_menu(lane, i, event.position, cx); + }, + ), + ); zone = match edge { Edge::Start => zone.left_0(), Edge::End => zone.right_0(), @@ -1362,47 +1403,14 @@ impl Player { .child(label), ) }) - // The way back off the lane, on the box itself: a - // caption is not in the clip selection's index - // space, so no stroke reaches it -- and a lane - // holding one cannot be removed either - // ([`Project::remove_lane`] refuses it), which - // would leave a placement nobody could undo but by - // undoing. Only where the box is wide enough to - // hold a target beside its name; narrower than that - // it is lifted after zooming in, exactly as it is - // trimmed after zooming in. - // - // Clear of the tail's own trim strip by that - // strip's width: both occlude and this one is drawn - // last, so hard against the right edge it swallowed - // every press meant for the edge and the tail could - // not be dragged at all (caught driving it). - .when(vis_w >= 2. * HIT_MIN + EDGE_W, |d| { - d.child( - div() - .id(("sub-lift", i)) - .absolute() - .top_0() - .left(px(vis_x + vis_w - HIT_MIN - EDGE_W)) - .w(px(HIT_MIN)) - .h(px(HIT_MIN)) - .flex() - .items_center() - .justify_center() - .occlude() - .rounded(px(3.)) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .on_click(cx.listener( - move |this, _: &ClickEvent, _, cx| { - cx.stop_propagation(); - this.lift_sub(lane, i, cx); - }, - )) - .child("×"), - ) - }) + // The way back off the lane is the way every other + // box takes: the Delete stroke on the marked caption + // and the Delete row of its own menu + // ([`Player::lift_sub`]). The × that used to sit + // here is gone with them -- it was drawn only where + // the box was wide enough to hold it, so the one + // removal a caption had was the one a zoomed-out + // caption did not have. })) // ...and where the words actually are inside those boxes: // the cues this lane shows on *this* timeline, in a band