forge
Explore
Log in

Don't you dare go Hollow

A library full of subtitles reads as its films again

Browse files at this commit

791ea9f0037e1f3587d8154ca66e45bb59d9c14fAhmet Kaan GümüşParent: 0a5590f
  • feat
    • a library full of subtitles reads as its films again
Show full message
✨ feat(app): a library full of subtitles reads as its films again

Group headers in the Text tab used to vanish under sub_headers_fit's
viewport gate, which was the one thing carrying "whose tracks these
are" once a window got short -- so a short window left every track
looking like it belonged to whichever film happened to be scrolled
into view. The row list already scrolls past SUB_ROWS_H, so the gate
was solving a problem the scrollbar had already solved: headers are
now drawn whenever there is more than one source, full stop.

Each header now also says how many tracks it holds and folds its
rows shut on a click (Player::sub_folded, session-lifetime, never
saved) -- a plain toggle and not the click-cycling pattern this
codebase has already thrown out once. Its hit target moved up to
HIT_MIN to earn the click.

A standalone .srt was already its own named group (by its own
filename) rather than a sourceless catch-all, so no "External"
bucket was needed for it.
crates/app/src/layout.rsmodified+6 -9
@@ -173,15 +173,12 @@ pub(crate) const SUB_CUE_MIN_W: f32 = 2.;
173 /// How much of the subtitle list in the library column is on screen at once,173 /// How much of the subtitle list in the library column is on screen at once,
174 /// past which it scrolls -- the media list above it is what keeps the height.174 /// past which it scrolls -- the media list above it is what keeps the height.
175 pub(crate) const SUB_ROWS_H: f32 = 3. * ROW_H;175 pub(crate) const SUB_ROWS_H: f32 = 3. * ROW_H;
176-/// The row naming the file a block of tracks came out of. Shorter than a track176+/// The row naming the file a block of tracks came out of. Always drawn where
177-/// row because nothing on it is clicked -- `HIT_MIN` binds targets and a header177+/// there is more than one file -- the list already scrolls past `SUB_ROWS_H`,
178-/// is a label, not a way in -- and drawn at all only where the column has the178+/// so a short window loses tracks under the fold rather than the name saying
179-/// height to show tracks under it ([`sub_headers_fit`]).179+/// whose they are. A click folds it, so it binds `HIT_MIN` like every other
180-pub(crate) const SUB_HEAD_H: f32 = 18.;180+/// target.
181-/// How much of the subtitle list is on screen at the 640x360 floor: one row,181+pub(crate) const SUB_HEAD_H: f32 = HIT_MIN;
182-/// measured -- the section's own heading and the Add button under it take the
183-/// rest of the 84 px the column has there.
184-pub(crate) const SUB_ROWS_AT_FLOOR: f32 = ROW_H;
185 /// How much of a subtitle row's width the file's name in front of the label may182 /// How much of a subtitle row's width the file's name in front of the label may
186 /// take. Half: which file and which language are both worth reading, and a name183 /// take. Half: which file and which language are both worth reading, and a name
187 /// given the whole row is a row where the language is what gets truncated.184 /// given the whole row is a row where the language is what gets truncated.
crates/app/src/library_meta.rsmodified+0 -13
@@ -370,19 +370,6 @@ pub(crate) fn clip_middle(name: &str, width: f32) -> String {
370 )370 )
371 }371 }
372 372
373-/// Whether the subtitle list has the height to name each file over its tracks.
374-/// A header is worth its own height only where there are still tracks under it
375-/// to read: at the 640x360 floor the list is one row tall, and a header there
376-/// would name a film and show none of it -- so at the floor there are no
377-/// headers and the rows say which file they came from themselves.
378-///
379-/// The window's height answers it on its own: the row above the picture and the
380-/// panel under it are fixed, so every pixel the window gains past the floor is a
381-/// pixel this column gains.
382-pub(crate) fn sub_headers_fit(viewport_h: f32) -> bool {
383- SUB_ROWS_AT_FLOOR + (viewport_h - 360.).max(0.) >= SUB_HEAD_H + 2. * ROW_H
384-}
385-
386 /// What the window is called: the program, and what is open in it. The name is373 /// What the window is called: the program, and what is open in it. The name is
387 /// what the header shows, so an empty window says the program alone rather than374 /// what the header shows, so an empty window says the program alone rather than
388 /// "no file open — edith".375 /// "no file open — edith".
crates/app/src/main.rsmodified+9 -1
@@ -43,7 +43,7 @@ use ui::widgets::*;
43 use keymap::{ActionId, Keymap};43 use keymap::{ActionId, Keymap};
44 44
45 use std::cell::Cell;45 use std::cell::Cell;
46-use std::collections::HashMap;46+use std::collections::{HashMap, HashSet};
47 use std::path::{Path, PathBuf};47 use std::path::{Path, PathBuf};
48 use std::rc::Rc;48 use std::rc::Rc;
49 use std::sync::Arc;49 use std::sync::Arc;
@@ -266,6 +266,13 @@ struct Player {
266 /// like every other index here -- track 2 of one project is not track 2 of266 /// like every other index here -- track 2 of one project is not track 2 of
267 /// the next.267 /// the next.
268 sub_track: usize,268 sub_track: usize,
269+ /// Which files' subtitle groups in the library are folded shut, keyed by
270+ /// the group's own path -- the same key [`subtitle_rows`] groups on, so a
271+ /// fold survives a track being added or removed off the file it belongs
272+ /// to. Session-lifetime only: a fold is a "not looking at this one right
273+ /// now", not a project setting, so it is never saved and every file opens
274+ /// unfolded.
275+ sub_folded: HashSet<PathBuf>,
269 /// Which subtitle lane is *shown*: one of them and never two, the way a276 /// Which subtitle lane is *shown*: one of them and never two, the way a
270 /// player has one subtitle track chosen at a time -- two hundred lanes of277 /// player has one subtitle track chosen at a time -- two hundred lanes of
271 /// different words all drawn at once is two hundred plates over one278 /// different words all drawn at once is two hundred plates over one
@@ -701,6 +708,7 @@ fn main() {
701 snap: true,708 snap: true,
702 subs_on: true,709 subs_on: true,
703 sub_track: 0,710 sub_track: 0,
711+ sub_folded: HashSet::new(),
704 sub_lane: None,712 sub_lane: None,
705 snap_cue: None,713 snap_cue: None,
706 ghost: None,714 ghost: None,
crates/app/src/render.rsmodified+0 -1
@@ -556,7 +556,6 @@ impl Render for Player {
556 .flex()556 .flex()
557 .child(self.library(557 .child(self.library(
558 self.split_px(Split::Library, window.viewport_size()),558 self.split_px(Split::Library, window.viewport_size()),
559- f32::from(window.viewport_size().height),
560 cx,559 cx,
561 ))560 ))
562 // The seams, one per pair of regions: what a hand drags to561 // The seams, one per pair of regions: what a hand drags to
crates/app/src/tests/layout.rsmodified+76 -0
@@ -1124,6 +1124,46 @@ fn subtitle_rows_group_a_source_however_they_were_added() {
1124 "the group carries the path the tint is asked by"1124 "the group carries the path the tint is asked by"
1125 );1125 );
1126 assert_eq!(file_tint(&sources, &groups[2].path), None);1126 assert_eq!(file_tint(&sources, &groups[2].path), None);
1127+ // What a header's "N tracks" says: the group's own row count, which is
1128+ // 2, 2, 1 here -- a film that gave several tracks and a standalone
1129+ // `.srt` that gave exactly one.
1130+ assert_eq!(
1131+ groups.iter().map(|g| g.rows.len()).collect::<Vec<_>>(),
1132+ [2, 2, 1]
1133+ );
1134+ // A standalone `.srt` is already its own group, named after its own
1135+ // file ("late", not lumped under some catch-all "External" bucket) --
1136+ // there is no sourceless case for a header to special-case.
1137+ assert_eq!(groups[2].name, "late");
1138+ assert_eq!(groups[2].path, PathBuf::from("/subs/late.srt"));
1139+}
1140+
1141+/// The fold a click on a header sets is keyed by [`SubGroup::path`]
1142+/// (`Player::sub_folded`), so it has to survive the very thing regrouping
1143+/// is for: a second track landing on a file already in the list, or one
1144+/// being removed from it. The group's path is the fold's whole identity,
1145+/// so it must not move under either.
1146+#[test]
1147+fn a_groups_fold_key_survives_a_track_arriving_or_leaving_its_file() {
1148+ let before = [
1149+ sub("/films/a.mkv", Some(1), "eng"),
1150+ sub("/films/b.mkv", Some(1), "eng"),
1151+ ];
1152+ let after_add = [
1153+ sub("/films/a.mkv", Some(1), "eng"),
1154+ sub("/films/b.mkv", Some(1), "eng"),
1155+ sub("/films/a.mkv", Some(2), "fre"),
1156+ ];
1157+ let (before_groups, after_groups) = (subtitle_rows(&before), subtitle_rows(&after_add));
1158+ assert_eq!(before_groups[0].path, after_groups[0].path, "a's key held");
1159+ assert_eq!(before_groups[1].path, after_groups[1].path, "b's key held");
1160+ // The group a second track landed on grew; the other did not move.
1161+ assert_eq!(after_groups[0].rows.len(), 2);
1162+ assert_eq!(after_groups[1].rows.len(), 1);
1163+ // Removing that same track back off leaves the original key and count.
1164+ let after_remove = subtitle_rows(&before);
1165+ assert_eq!(after_remove[0].path, before_groups[0].path);
1166+ assert_eq!(after_remove[0].rows.len(), 1);
1127 }1167 }
1128 1168
1129 /// What the strip header, the section heading and the toggle's notice all1169 /// What the strip header, the section heading and the toggle's notice all
@@ -1219,6 +1259,42 @@ fn the_text_tab_carries_the_add_subtitles_door() {
1219 );1259 );
1220 }1260 }
1221 1261
1262+/// A source's group header in the library must not vanish on a short
1263+/// window: it is drawn whenever there is more than one source
1264+/// (`several_files`), never gated on the viewport's height, and the list
1265+/// under it is what scrolls instead ([`SUB_ROWS_H`]). And it has to be a
1266+/// real fold, not the click-cycling pattern this codebase has already
1267+/// thrown out once: one click toggles `sub_folded` shut or open, it never
1268+/// steps through more than those two states.
1269+#[test]
1270+fn a_subtitle_group_header_is_never_gated_on_window_height() {
1271+ let timeline = src_text("ui/timeline.rs");
1272+ assert!(
1273+ !timeline.contains("sub_headers_fit"),
1274+ "the header is still gated on the viewport's height"
1275+ );
1276+ let at = timeline
1277+ .find("let headed = ")
1278+ .expect("no `headed` computed in subtitle_section");
1279+ let line = &timeline[at..(at + 80).min(timeline.len())];
1280+ assert!(
1281+ line.contains("several_files") && !line.contains("viewport"),
1282+ "headed depends on something other than the file count: {line}"
1283+ );
1284+ // The header is a click target that flips membership in a set --
1285+ // `remove` else `insert` -- not a value stepped through several states.
1286+ let head_at = timeline
1287+ .find("subtitle-group-head")
1288+ .expect("no id on the group header");
1289+ let block = &timeline[head_at..(head_at + 2400).min(timeline.len())];
1290+ assert!(block.contains("sub_folded.remove"), "no fold-open path: {block}");
1291+ assert!(block.contains("sub_folded.insert"), "no fold-shut path: {block}");
1292+ assert!(
1293+ block.contains("\"1 track\"") || block.contains("tracks"),
1294+ "the header does not say how many tracks it holds: {block}"
1295+ );
1296+}
1297+
1222 /// The one thing regrouping must not break: `sub_track` is a flat index1298 /// The one thing regrouping must not break: `sub_track` is a flat index
1223 /// into the add-order list, a click sets it and a save writes it into the1299 /// into the add-order list, a click sets it and a save writes it into the
1224 /// `.edith`. Every row must still name the track it was made from -- rows1300 /// `.edith`. Every row must still name the track it was made from -- rows
crates/app/src/tests/media.rsmodified+6 -12
@@ -831,19 +831,13 @@ fn the_subtitle_plate_and_lanes_fit_the_smallest_window() {
831 // taking the media list's room.831 // taking the media list's room.
832 assert_eq!(SUB_ROWS_H / ROW_H, 3.);832 assert_eq!(SUB_ROWS_H / ROW_H, 3.);
833 assert!(ROW_H >= HIT_MIN, "a subtitle row is clicked to pick it");833 assert!(ROW_H >= HIT_MIN, "a subtitle row is clicked to pick it");
834- // At the floor there are no group headers at all: the list is one row834+ // A header is always drawn with more than one file, floor included: the
835- // tall there, and a header would name a film and then show none of it.835+ // list scrolls past `SUB_ROWS_H` instead of a short window losing the
836- // The rows go on naming their own file, so nothing is lost by it.836+ // name saying whose tracks these are.
837- assert!(!sub_headers_fit(360.), "a header at the floor eats the track");
838- // At the size the window opens on there is room for a header and the
839- // tracks under it, which is the only condition it is drawn on.
840- assert!(sub_headers_fit(720.));
841- // ...and where it is drawn it fits inside the same capped list, header
842- // and two rows under it, without the tracks losing their budget.
843 assert!(SUB_HEAD_H + 2. * ROW_H <= SUB_ROWS_H);837 assert!(SUB_HEAD_H + 2. * ROW_H <= SUB_ROWS_H);
844- // A header takes no click -- there is nothing to fold and nothing to838+ // A header folds its group on a click now, so it binds `HIT_MIN` like
845- // aim at -- which is the only reason it may be under `HIT_MIN`.839+ // every other target rather than being let off it as a bare label.
846- assert!(SUB_HEAD_H < HIT_MIN && SUB_HEAD_H > 0.);840+ assert!(SUB_HEAD_H >= HIT_MIN);
847 }841 }
848 842
849 /// What the rows of both lists do with a name too long for the column: two843 /// What the rows of both lists do with a name too long for the column: two
crates/app/src/tests/mod.rsmodified+1 -1
@@ -57,7 +57,7 @@ use super::{
57 use super::{57 use super::{
58 SUB_BOTTOM, SUB_CUE_MIN_W, SUB_HEAD_H, SUB_LINE_H, SUB_ROWS_H,58 SUB_BOTTOM, SUB_CUE_MIN_W, SUB_HEAD_H, SUB_LINE_H, SUB_ROWS_H,
59 SUB_STEM_SHARE, SUB_TEXT, clip_middle, cue_box, sub_bottom,59 SUB_STEM_SHARE, SUB_TEXT, clip_middle, cue_box, sub_bottom,
60- carries_subtitles, cues_at, file_tint, is_subtitle, lang_human, row_text_w, sub_headers_fit,60+ carries_subtitles, cues_at, file_tint, is_subtitle, lang_human, row_text_w,
61 Subs, subtitle_detail, subtitle_notice, subtitle_tail,61 Subs, subtitle_detail, subtitle_notice, subtitle_tail,
62 sub_pick_name, subtitle_rows, subtitle_toggle_notice, walk_subtitles,62 sub_pick_name, subtitle_rows, subtitle_toggle_notice, walk_subtitles,
63 };63 };
crates/app/src/ui/library.rsmodified+2 -2
@@ -15,7 +15,7 @@ impl Player {
15 /// the rest of this window: nothing in it takes focus, so the root keeps15 /// the rest of this window: nothing in it takes focus, so the root keeps
16 /// the keyboard and the play key still works after a row is clicked16 /// the keyboard and the play key still works after a row is clicked
17 /// (ledger:182).17 /// (ledger:182).
18- pub(crate) fn library(&self, width: f32, viewport_h: f32, cx: &mut Context<Self>) -> impl IntoElement {18+ pub(crate) fn library(&self, width: f32, cx: &mut Context<Self>) -> impl IntoElement {
19 let exporting = self.exporting().is_some();19 let exporting = self.exporting().is_some();
20 let sources = self20 let sources = self
21 .session21 .session
@@ -484,7 +484,7 @@ impl Player {
484 // it goes on no lane and is dragged nowhere -- but it is a thing the484 // it goes on no lane and is dragged nowhere -- but it is a thing the
485 // timeline holds, and this is the list of those.485 // timeline holds, and this is the list of those.
486 .when(self.library_tab == LibraryTab::Text, |d| {486 .when(self.library_tab == LibraryTab::Text, |d| {
487- d.children(self.subtitle_section(width, viewport_h, cx))487+ d.children(self.subtitle_section(width, cx))
488 })488 })
489 .child(control(489 .child(control(
490 "add-asset",490 "add-asset",
crates/app/src/ui/timeline.rsmodified+42 -17
@@ -485,20 +485,17 @@ impl Player {
485 /// Every row names the file it came out of itself, in words and in the tint485 /// Every row names the file it came out of itself, in words and in the tint
486 /// that file's clips wear on the lanes -- but only where there is more than486 /// that file's clips wear on the lanes -- but only where there is more than
487 /// one file to tell apart, the way [`row_name`] numbers audio streams only487 /// one file to tell apart, the way [`row_name`] numbers audio streams only
488- /// where a file gave several. Where the window is tall enough for it488+ /// where a file gave several. There, each file's block is headed by its
489- /// ([`sub_headers_fit`]) each file's block is headed by its name as well: a489+ /// name as well, its swatch and its track count -- always, whatever the
490- /// label and nothing more, no click and nothing to fold, so the rows under490+ /// window's height, since the list under it scrolls (`SUB_ROWS_H`) rather
491- /// it are the only things anybody has to aim at. At the 640x360 floor the491+ /// than the header being the thing a short window drops. A click on a
492- /// headers are gone and the rows still say whose they are.492+ /// header folds its rows shut (`Player::sub_folded`) and a second one opens
493+ /// them back -- a fold and not a cycle, so what a click does never depends
494+ /// on what the last one did.
493 ///495 ///
494 /// `None` when there are none -- an empty heading is a section about496 /// `None` when there are none -- an empty heading is a section about
495 /// nothing.497 /// nothing.
496- pub(crate) fn subtitle_section(498+ pub(crate) fn subtitle_section(&self, width: f32, cx: &mut Context<Self>) -> Option<impl IntoElement> {
497- &self,
498- width: f32,
499- viewport_h: f32,
500- cx: &mut Context<Self>,
501- ) -> Option<impl IntoElement> {
502 let tracks = self.session.as_ref()?.subtitles();499 let tracks = self.session.as_ref()?.subtitles();
503 if tracks.is_empty() {500 if tracks.is_empty() {
504 return None;501 return None;
@@ -510,16 +507,20 @@ impl Player {
510 // One file's tracks need no prefix saying which file: it is the only507 // One file's tracks need no prefix saying which file: it is the only
511 // one, and every row would carry the same word.508 // one, and every row would carry the same word.
512 let several_files = groups.len() > 1;509 let several_files = groups.len() > 1;
513- let headed = several_files && sub_headers_fit(viewport_h);510+ let headed = several_files;
514 let text_w = row_text_w(width);511 let text_w = row_text_w(width);
515 let rows: Vec<_> = groups512 let rows: Vec<_> = groups
516 .into_iter()513 .into_iter()
517- .map(|SubGroup { name, path, rows }| {514+ .enumerate()
515+ .map(|(group_ord, SubGroup { name, path, rows })| {
518 // The file's own colour, the one its media rows and its clips516 // The file's own colour, the one its media rows and its clips
519 // wear -- and none at all for a standalone `.srt`, which came517 // wear -- and none at all for a standalone `.srt`, which came
520 // off no file on this timeline.518 // off no file on this timeline.
521 let tint = file_tint(self.sources(), &path);519 let tint = file_tint(self.sources(), &path);
520+ let track_count = rows.len();
522 let numbered = rows.len() > 1;521 let numbered = rows.len() > 1;
522+ let folded = self.sub_folded.contains(&path);
523+ let fold_path = path.clone();
523 // The name twice over: all of it the header can hold, and the524 // The name twice over: all of it the header can hold, and the
524 // share of a row a prefix may take in front of the label.525 // share of a row a prefix may take in front of the label.
525 let head = clip_middle(&name, text_w);526 let head = clip_middle(&name, text_w);
@@ -697,11 +698,13 @@ impl Player {
697 .flex_col()698 .flex_col()
698 .gap(px(2.))699 .gap(px(2.))
699 // The header: which film these came out of, in words and not700 // The header: which film these came out of, in words and not
700- // in colour alone. No id, no click, nothing to fold -- a701+ // in colour alone -- a click folds its rows shut and a
701- // label, which is why it is allowed under `HIT_MIN`.702+ // second click opens them, so it is its own `HIT_MIN`
703+ // target rather than a bare label.
702 .when(headed, |d| {704 .when(headed, |d| {
703 d.child(705 d.child(
704 div()706 div()
707+ .id(("subtitle-group-head", group_ord))
705 .flex_none()708 .flex_none()
706 .h(px(SUB_HEAD_H))709 .h(px(SUB_HEAD_H))
707 .flex()710 .flex()
@@ -709,6 +712,24 @@ impl Player {
709 .gap(px(6.))712 .gap(px(6.))
710 .text_size(px(10.))713 .text_size(px(10.))
711 .text_color(rgb(FG_SECONDARY()))714 .text_color(rgb(FG_SECONDARY()))
715+ .rounded(px(3.))
716+ .cursor_pointer()
717+ .hover(|s| s.bg(rgb(BG_HOVER())))
718+ .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
719+ match this.sub_folded.remove(&fold_path) {
720+ true => {}
721+ false => {
722+ this.sub_folded.insert(fold_path.clone());
723+ }
724+ }
725+ cx.notify();
726+ }))
727+ // Folded / open, in the same glyph a fold uses
728+ // everywhere else on this row list.
729+ .child(match folded {
730+ true => "▸",
731+ false => "▾",
732+ })
712 .when_some(tint, |d, tint| {733 .when_some(tint, |d, tint| {
713 d.child(734 d.child(
714 div()735 div()
@@ -719,10 +740,14 @@ impl Player {
719 .bg(rgb(tint)),740 .bg(rgb(tint)),
720 )741 )
721 })742 })
722- .child(div().flex_1().min_w(px(0.)).truncate().child(head)),743+ .child(div().flex_1().min_w(px(0.)).truncate().child(head))
744+ .child(match track_count {
745+ 1 => "1 track".to_string(),
746+ n => format!("{n} tracks"),
747+ }),
723 )748 )
724 })749 })
725- .children(rows)750+ .when(!(headed && folded), |d| d.children(rows))
726 })751 })
727 .collect();752 .collect();
728 Some(753 Some(