diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index 5a7737e..d26cdb1 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -1380,6 +1380,37 @@ fn the_text_tab_carries_the_add_subtitles_door() { ); } +/// The Darkroom keeps imported subtitle tracks in the Sources dock, where a +/// row can be selected, folded with its source, removed, and dragged to the +/// bench's existing subtitle-lane target. +#[test] +fn the_darkroom_subtitle_palette_drags_tracks_to_subtitle_lanes() { + let dock = src_text("ui/dock_stance.rs"); + let palette = &dock[dock + .find("fn subtitle_palette") + .expect("no Darkroom subtitle palette")..]; + for required in [ + "subtitle_rows", + "dock-subtitle-group", + "sub_folded.remove", + "sub_folded.insert", + "this.sub_track = track", + ".on_drag(SubPick(track)", + "remove_subtitle_track(track", + ] { + assert!(palette.contains(required), "palette lost {required}"); + } + let bench = src_text("ui/bench_stance.rs"); + let drop_at = bench + .find(".drag_over::") + .expect("no subtitle-track lane target"); + let drop = &bench[drop_at..(drop_at + 500).min(bench.len())]; + assert!( + drop.contains("this.place_sub(drag.0, lane"), + "a dock subtitle drag does not place on the lane: {drop}" + ); +} + /// A source's group header in the library must not vanish on a short /// window: it is drawn whenever there is more than one source /// (`several_files`), never gated on the viewport's height, and the list diff --git a/crates/app/src/ui/dock_stance.rs b/crates/app/src/ui/dock_stance.rs index 7a24fb1..e8eab9c 100644 --- a/crates/app/src/ui/dock_stance.rs +++ b/crates/app/src/ui/dock_stance.rs @@ -11,7 +11,7 @@ //! still supply the row facts ([`library_rows`], [`source_tint`], //! [`clip_middle`]...), only the anatomy around them is new. -use crate::ui::type_scale::{self, head, label, mono}; +use crate::ui::type_scale::{self, Typeset, head, label, mono}; use crate::*; use gpui::FontWeight; @@ -546,6 +546,182 @@ fn source_row( }) } +/// Imported subtitle tracks, grouped by their source. A row selects and drags +/// its track; its header folds that source's rows without becoming a cycle. +fn subtitle_palette(player: &Player, cx: &mut Context) -> Option { + let groups = subtitle_rows(player.session.as_ref()?.subtitles()); + if groups.is_empty() { + return None; + } + let count: usize = groups.iter().map(|group| group.rows.len()).sum(); + let rows: Vec<_> = groups + .into_iter() + .enumerate() + .map(|(group_ord, group)| { + let folded = player.sub_folded.contains(&group.path); + let fold_path = group.path.clone(); + let tint = file_tint(player.sources(), &group.path); + let track_count = group.rows.len(); + let tracks: Vec<_> = group + .rows + .into_iter() + .map(|row| { + let track = row.track; + let picked = track == player.sub_track; + let usable = row.refused.is_none(); + let title: SharedString = match track_count { + 1 => row.label, + _ => format!("{} {}", row.label, row.number), + } + .into(); + let detail: SharedString = row + .refused + .unwrap_or_else(|| "drag onto an S lane to place".to_string()) + .into(); + let ghost = title.clone(); + div() + .id(("dock-subtitle-track", track)) + .flex_none() + .h(px(CONTROL_H)) + .flex() + .items_center() + .gap(px(6.)) + .px(px(8.)) + .rounded(px(3.)) + .when(picked, |d| d.border_1().border_color(rgb(INK1()))) + .when(!usable, |d| d.opacity(0.5)) + .when(usable, |d| { + d.cursor_pointer() + .hover(|s| s.bg(rgb(DARK_RAISED()))) + .on_drag(SubPick(track), move |_, _, _, cx| { + cx.new(|_| Tip(ghost.clone())) + }) + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { + this.sub_track = track; + cx.notify(); + })) + }) + .child( + div() + .flex_none() + .w(px(4.)) + .h(px(16.)) + .rounded(px(2.)) + .when_some(tint, |d, tint| d.bg(rgb(tint))), + ) + .child( + div() + .flex_1() + .min_w(px(0.)) + .truncate() + .type_style(mono( + type_scale::CHORD_METADATA_MIN_PX, + FontWeight::MEDIUM, + )) + .text_color(rgb(INK2())) + .child(title), + ) + .child( + div() + .flex_none() + .truncate() + .type_style(mono(type_scale::FLOOR_PX, FontWeight::MEDIUM)) + .text_color(rgb(INK3())) + .child(detail), + ) + .child( + div() + .id(("dock-subtitle-remove", track)) + .flex_none() + .w(px(HIT_MIN)) + .h_full() + .flex() + .items_center() + .justify_center() + .rounded(px(3.)) + .cursor_pointer() + .hover(|s| s.bg(rgb(DARK_RAISED())).text_color(rgb(INK1()))) + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { + cx.stop_propagation(); + this.remove_subtitle_track(track, cx); + })) + .child("×"), + ) + }) + .collect(); + div() + .flex_none() + .flex() + .flex_col() + .gap(px(2.)) + .child( + div() + .id(("dock-subtitle-group", group_ord)) + .flex_none() + .h(px(CONTROL_H)) + .flex() + .items_center() + .gap(px(6.)) + .px(px(8.)) + .rounded(px(3.)) + .cursor_pointer() + .hover(|s| s.bg(rgb(DARK_RAISED()))) + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { + if !this.sub_folded.remove(&fold_path) { + this.sub_folded.insert(fold_path.clone()); + } + cx.notify(); + })) + .child(if folded { "▸" } else { "▾" }) + .when_some(tint, |d, tint| { + d.child( + div() + .flex_none() + .w(px(4.)) + .h(px(16.)) + .rounded(px(2.)) + .bg(rgb(tint)), + ) + }) + .child( + div() + .flex_1() + .min_w(px(0.)) + .truncate() + .type_style(label(type_scale::LABEL_ROW_PX, FontWeight::MEDIUM)) + .text_color(rgb(INK2())) + .child(group.name), + ) + .child( + div() + .flex_none() + .type_style(mono( + type_scale::CHORD_METADATA_MIN_PX, + FontWeight::MEDIUM, + )) + .text_color(rgb(INK3())) + .child(format!( + "{track_count} track{}", + if track_count == 1 { "" } else { "s" } + )), + ), + ) + .when(!folded, |d| d.children(tracks)) + }) + .collect(); + Some( + div() + .id("dock-subtitle-palette") + .flex_none() + .flex() + .flex_col() + .gap(px(2.)) + .child(section_head(format!("SUBTITLES · {count}"))) + .children(rows) + .into_any_element(), + ) +} + /// The Sources tab, built off MOCK-SPEC.md's "Dock" section: count line, /// filter, sort chips, rows, IMPORT, hint -- none of it the legacy /// Media/Audio/Text panel `library.rs` draws. That panel's row facts @@ -725,6 +901,7 @@ fn sources_tab(player: &Player, cx: &mut Context) -> impl IntoElement { elements }), ) + .children(subtitle_palette(player, cx)) .child(section_head("IMPORT")) .child( div()