forge
Explore
Log in

Don't you dare go Hollow

Subtitle lanes go thin and library subtitles get real groups

Browse files at this commit

2efce0f9b739ae091b5eebdc134472e586b824dfAhmet Kaan GümüşParent: 3fe48b0791ea9f
  • style
    • subtitle lanes go thin and library subtitles get real groups
Show full message
🎨 style(app): subtitle lanes go thin and library subtitles get real groups

SUB_LANE_H=24 (WCAG hit-target floor) with per-kind lane math restores
the thin caption look f85f4db lost; lane remove moves to right-click on
the eye. Library subtitle group headers are always on when several
sources exist, foldable per source, with tint and track count.
crates/app/src/layout.rsmodified+94 -9
@@ -21,6 +21,21 @@ pub(crate) const PANEL_H: f32 = 220.;
21 /// timeline that pushes the video off the window is not a timeline.21 /// timeline that pushes the video off the window is not a timeline.
22 pub(crate) const LANES_MAX: usize = 6;22 pub(crate) const LANES_MAX: usize = 6;
23 pub(crate) const LANE_H: f32 = 48.;23 pub(crate) const LANE_H: f32 = 48.;
24+/// A caption lane's own height, thinner than a media one: a subtitle box
25+/// carries a name, a rate badge and the cue band under it
26+/// ([`Player::lane_row`]) and none of a clip's waveform or its full-height
27+/// plate, so the strip that used to draw the whole row's worth of nothing is
28+/// the regression this constant undoes.
29+///
30+/// Floored at [`HIT_MIN`] rather than the 20 px a first pass at "thin" landed
31+/// on: the header's show/hide eye is the row's one surviving click target
32+/// once the remove button moves off it onto the right button
33+/// ([`Player::lane_row`]), and that eye fills the row's full height -- so
34+/// anything under `HIT_MIN` here is a WCAG 2.5.8 target shrunk to chase a
35+/// pixel count, not a thinner lane. This is the whole gap between the two
36+/// harness variants the task asked for: 20 is not shippable at all, 24 is,
37+/// so 24 is the only variant landed.
38+pub(crate) const SUB_LANE_H: f32 = HIT_MIN;
24 /// The lane header column: wide enough for `V1`/`A1` and fixed, so both lanes39 /// The lane header column: wide enough for `V1`/`A1` and fixed, so both lanes
25 /// and the ruler above them start at the same pixel and are the same width --40 /// and the ruler above them start at the same pixel and are the same width --
26 /// one x-to-time mapping for the whole timeline. `HEADER_GAP` is part of that41 /// one x-to-time mapping for the whole timeline. `HEADER_GAP` is part of that
@@ -158,15 +173,12 @@ pub(crate) const SUB_CUE_MIN_W: f32 = 2.;
158 /// 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,
159 /// 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.
160 pub(crate) const SUB_ROWS_H: f32 = 3. * ROW_H;175 pub(crate) const SUB_ROWS_H: f32 = 3. * ROW_H;
161-/// 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
162-/// 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`,
163-/// 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
164-/// 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
165-pub(crate) const SUB_HEAD_H: f32 = 18.;180+/// target.
166-/// 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;
167-/// measured -- the section's own heading and the Add button under it take the
168-/// rest of the 84 px the column has there.
169-pub(crate) const SUB_ROWS_AT_FLOOR: f32 = ROW_H;
170 /// 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
171 /// 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
172 /// 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.
@@ -225,6 +237,70 @@ pub(crate) fn rows_below(total: usize, box_h: f32, scrolled: f32) -> usize {
225 total.saturating_sub(past + lanes_shown(box_h))237 total.saturating_sub(past + lanes_shown(box_h))
226 }238 }
227 239
240+/// How tall one lane row is: [`LANE_H`] for a media track, [`SUB_LANE_H`] for
241+/// a caption one -- the one place that answer is decided, since
242+/// [`lanes_h_mixed`], [`lanes_shown_mixed`] and [`rows_below_mixed`] all walk
243+/// off it and a track drawn at one height and measured at another is a fold
244+/// line that lands on the wrong row.
245+pub(crate) fn lane_h(kind: LaneKind) -> f32 {
246+ match kind {
247+ LaneKind::Subtitle => SUB_LANE_H,
248+ LaneKind::Video | LaneKind::Audio => LANE_H,
249+ }
250+}
251+
252+/// [`lanes_h`] for a real stack of lanes rather than a bare count: a project
253+/// with a caption track in it is shorter than that many `LANE_H` rows, and
254+/// the column, the fold and the affordance below it all have to agree on
255+/// exactly how much shorter, or "N more below" is answering a box nothing
256+/// draws at.
257+pub(crate) fn lanes_h_mixed(kinds: &[LaneKind]) -> f32 {
258+ match kinds.len() {
259+ 0 => 0.,
260+ n => kinds.iter().copied().map(lane_h).sum::<f32>() + (n - 1) as f32 * 8.,
261+ }
262+}
263+
264+/// [`lanes_shown`] for a real stack: the largest prefix of `kinds` whose
265+/// drawn height still fits `box_h`, on the same boundary [`lanes_shown`]
266+/// draws it at (`lanes_h(k) <= box_h`) -- so a uniform stack answers exactly
267+/// what [`lanes_shown`] already did, and a mixed one answers the row count
268+/// its own heights actually reach.
269+pub(crate) fn lanes_shown_mixed(kinds: &[LaneKind], box_h: f32) -> usize {
270+ (0..=kinds.len())
271+ .rev()
272+ .find(|&k| lanes_h_mixed(&kinds[..k]) <= box_h)
273+ .unwrap_or(0)
274+ .max(1)
275+}
276+
277+/// [`rows_below`] for a real stack: `scrolled` read against each row's own
278+/// top rather than a uniform `LANE_H + 8` stride, so a column with a thin
279+/// caption track in it still says the true count once that track has
280+/// scrolled by.
281+pub(crate) fn rows_below_mixed(kinds: &[LaneKind], box_h: f32, scrolled: f32) -> usize {
282+ // Row `k`'s own top, in the same units `scrolled` is given in: nothing
283+ // for the first row, and every row before it plus the gap that follows
284+ // each one for the rest.
285+ let top = |k: usize| -> f32 {
286+ match k {
287+ 0 => 0.,
288+ k => lanes_h_mixed(&kinds[..k]) + 8.,
289+ }
290+ };
291+ let past = (0..=kinds.len())
292+ .min_by(|&a, &b| {
293+ (scrolled - top(a))
294+ .abs()
295+ .partial_cmp(&(scrolled - top(b)).abs())
296+ .unwrap()
297+ })
298+ .unwrap_or(0);
299+ kinds
300+ .len()
301+ .saturating_sub(past + lanes_shown_mixed(kinds, box_h))
302+}
303+
228 /// The same question for a column whose rows are not one height -- the304 /// The same question for a column whose rows are not one height -- the
229 /// inspector's sections -- answered in pixels off what the scroll itself305 /// inspector's sections -- answered in pixels off what the scroll itself
230 /// reports: how far it may still be taken (`max_offset`) less how far it has306 /// reports: how far it may still be taken (`max_offset`) less how far it has
@@ -409,6 +485,15 @@ pub(crate) fn split_bounds(
409 // lane's own pixels, and the one lane the floor promises is a header485 // lane's own pixels, and the one lane the floor promises is a header
410 // cut in half.486 // cut in half.
411 Split::Timeline => (487 Split::Timeline => (
488+ // `LANE_H` even though the first lane could be a thinner caption
489+ // one: a floor is a *minimum*, so the only failure mode of
490+ // reading it off the tallest kind is a seam that refuses to go
491+ // quite as small as it technically could -- never a lane clipped
492+ // short of its own row. corner-cut: exact per-kind floor would
493+ // read `session.lanes()[0].kind`, which `split_bounds` is not
494+ // handed; ceiling is one drawn-too-tall pixel at the very floor
495+ // of a caption-only project, upgrade is threading the real lane
496+ // list through here the way [`lanes_h_mixed`] already takes it.
412 timeline_fixed_h(scroll)497 timeline_fixed_h(scroll)
413 + LANE_H498 + LANE_H
414 + match lanes > 1 {499 + match lanes > 1 {
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
@@ -708,6 +715,7 @@ fn main() {
708 snap: true,715 snap: true,
709 subs_on: true,716 subs_on: true,
710 sub_track: 0,717 sub_track: 0,
718+ sub_folded: HashSet::new(),
711 sub_lane: None,719 sub_lane: None,
712 snap_cue: None,720 snap_cue: None,
713 ghost: None,721 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+103 -0
@@ -92,6 +92,28 @@ fn the_line_about_what_is_below_the_fold_counts_what_is_still_below_it() {
92 // A project that fits says nothing at all.92 // A project that fits says nothing at all.
93 assert_eq!(rows_below(2, box_h, 0.), 0);93 assert_eq!(rows_below(2, box_h, 0.), 0);
94 94
95+ // The same three questions once a lane in the stack is a thinner
96+ // caption one: a uniform stack answers exactly what the plain
97+ // functions above do, and a mixed one answers off the real heights,
98+ // never the media one alone.
99+ let uniform = [LaneKind::Video, LaneKind::Audio];
100+ assert_eq!(lanes_h_mixed(&uniform), lanes_h(2));
101+ assert_eq!(lanes_shown_mixed(&uniform, LANE_H), lanes_shown(LANE_H));
102+ let mixed = [LaneKind::Video, LaneKind::Audio, LaneKind::Subtitle];
103+ assert_eq!(
104+ lanes_h_mixed(&mixed),
105+ 2. * LANE_H + SUB_LANE_H + 2. * 8.,
106+ "a caption lane is not counted as a full LANE_H row"
107+ );
108+ // A box exactly tall enough for the two media lanes and no more: the
109+ // thinner third lane still does not fit above it.
110+ assert_eq!(lanes_shown_mixed(&mixed, lanes_h(2)), 2);
111+ // ...and with room for the caption lane too, all three show and
112+ // nothing is below the fold.
113+ assert_eq!(lanes_shown_mixed(&mixed, lanes_h_mixed(&mixed)), 3);
114+ assert_eq!(rows_below_mixed(&mixed, lanes_h_mixed(&mixed), 0.), 0);
115+ assert_eq!(rows_below_mixed(&mixed, lanes_h(2), 0.), 1);
116+
95 // The inspector's rows are not one height, so its own line is measured117 // The inspector's rows are not one height, so its own line is measured
96 // in pixels off the scroll instead: gpui keeps the offset negative going118 // in pixels off the scroll instead: gpui keeps the offset negative going
97 // down, and at the bottom the two cancel out exactly.119 // down, and at the bottom the two cancel out exactly.
@@ -216,6 +238,11 @@ fn nothing_clickable_is_smaller_than_the_wcag_minimum() {
216 assert!(CONTROL_H >= HIT_MIN);238 assert!(CONTROL_H >= HIT_MIN);
217 assert!(RULER_HIT_H >= HIT_MIN);239 assert!(RULER_HIT_H >= HIT_MIN);
218 assert!(LANE_H >= HIT_MIN);240 assert!(LANE_H >= HIT_MIN);
241+ // A caption lane's header carries exactly one hit target now (the
242+ // show/hide eye; remove moved to its right button), and that target
243+ // fills the whole row -- so the row is never allowed to undercut the
244+ // target it *is*.
245+ assert!(SUB_LANE_H >= HIT_MIN);
219 // A clip box is a hit target too, and its two trim strips occlude it:246 // A clip box is a hit target too, and its two trim strips occlude it:
220 // on a box narrower than the pair there is no body left to press, so247 // on a box narrower than the pair there is no body left to press, so
221 // the clip cannot be selected, dragged or menued at all -- which is248 // the clip cannot be selected, dragged or menued at all -- which is
@@ -1097,6 +1124,46 @@ fn subtitle_rows_group_a_source_however_they_were_added() {
1097 "the group carries the path the tint is asked by"1124 "the group carries the path the tint is asked by"
1098 );1125 );
1099 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);
1100 }1167 }
1101 1168
1102 /// 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
@@ -1192,6 +1259,42 @@ fn the_text_tab_carries_the_add_subtitles_door() {
1192 );1259 );
1193 }1260 }
1194 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+
1195 /// 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
1196 /// 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
1197 /// `.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
@@ -891,19 +891,13 @@ fn the_subtitle_plate_and_lanes_fit_the_smallest_window() {
891 // taking the media list's room.891 // taking the media list's room.
892 assert_eq!(SUB_ROWS_H / ROW_H, 3.);892 assert_eq!(SUB_ROWS_H / ROW_H, 3.);
893 assert!(ROW_H >= HIT_MIN, "a subtitle row is clicked to pick it");893 assert!(ROW_H >= HIT_MIN, "a subtitle row is clicked to pick it");
894- // At the floor there are no group headers at all: the list is one row894+ // A header is always drawn with more than one file, floor included: the
895- // tall there, and a header would name a film and then show none of it.895+ // list scrolls past `SUB_ROWS_H` instead of a short window losing the
896- // The rows go on naming their own file, so nothing is lost by it.896+ // name saying whose tracks these are.
897- assert!(!sub_headers_fit(360.), "a header at the floor eats the track");
898- // At the size the window opens on there is room for a header and the
899- // tracks under it, which is the only condition it is drawn on.
900- assert!(sub_headers_fit(720.));
901- // ...and where it is drawn it fits inside the same capped list, header
902- // and two rows under it, without the tracks losing their budget.
903 assert!(SUB_HEAD_H + 2. * ROW_H <= SUB_ROWS_H);897 assert!(SUB_HEAD_H + 2. * ROW_H <= SUB_ROWS_H);
904- // A header takes no click -- there is nothing to fold and nothing to898+ // A header folds its group on a click now, so it binds `HIT_MIN` like
905- // aim at -- which is the only reason it may be under `HIT_MIN`.899+ // every other target rather than being let off it as a bare label.
906- assert!(SUB_HEAD_H < HIT_MIN && SUB_HEAD_H > 0.);900+ assert!(SUB_HEAD_H >= HIT_MIN);
907 }901 }
908 902
909 /// What the rows of both lists do with a name too long for the column: two903 /// What the rows of both lists do with a name too long for the column: two
crates/app/src/tests/mod.rsmodified+2 -1
@@ -17,6 +17,7 @@ use super::{
17 Format, HEADER_GAP, HEADER_H, HEADER_W, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN,17 Format, HEADER_GAP, HEADER_H, HEADER_W, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN,
18 KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, KeyRow, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX,18 KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, KeyRow, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX,
19 LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_PAD, MENU_ROW_H,19 LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_PAD, MENU_ROW_H,
20+ SUB_LANE_H, lanes_h_mixed, lanes_shown_mixed, rows_below_mixed,
20 MBPS_DIGITS, MBPS_MAX, MBPS_MIN, MB_FLOOR, MENU_W, NO_FILE, NumberEdit, PANEL_H, ROW_ITEMS, RowCtx, RowItem,21 MBPS_DIGITS, MBPS_MAX, MBPS_MIN, MB_FLOOR, MENU_W, NO_FILE, NumberEdit, PANEL_H, ROW_ITEMS, RowCtx, RowItem,
21 Quality, ROW_H, RULER_HIT_H, SCROLL_NOTCH_SHARE, SILENCE_ROWS,22 Quality, ROW_H, RULER_HIT_H, SCROLL_NOTCH_SHARE, SILENCE_ROWS,
22 SOURCE_TINTS, SPEED_PRESETS, SPEED_STEP, BG_RAISED, SWATCH_W, Source, Speed, StreamInfo,23 SOURCE_TINTS, SPEED_PRESETS, SPEED_STEP, BG_RAISED, SWATCH_W, Source, Speed, StreamInfo,
@@ -56,7 +57,7 @@ use super::{
56 use super::{57 use super::{
57 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,
58 SUB_STEM_SHARE, SUB_TEXT, clip_middle, cue_box, sub_bottom,59 SUB_STEM_SHARE, SUB_TEXT, clip_middle, cue_box, sub_bottom,
59- 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,
60 Subs, subtitle_detail, subtitle_notice, subtitle_tail,61 Subs, subtitle_detail, subtitle_notice, subtitle_tail,
61 sub_pick_name, subtitle_rows, subtitle_toggle_notice, walk_subtitles,62 sub_pick_name, subtitle_rows, subtitle_toggle_notice, walk_subtitles,
62 };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+106 -54
@@ -93,9 +93,10 @@ impl Player {
93 // that crosses the line.93 // that crosses the line.
94 let view = self.view();94 let view = self.view();
95 let scrollable = view.duration > view.span();95 let scrollable = view.duration > view.span();
96+ let kinds: Vec<LaneKind> = lanes.iter().map(|lane| lane.kind).collect();
96 let region_h = self.split_px(Split::Timeline, viewport);97 let region_h = self.split_px(Split::Timeline, viewport);
97 let lanes_box = (region_h - timeline_fixed_h(scrollable)).max(LANE_H);98 let lanes_box = (region_h - timeline_fixed_h(scrollable)).max(LANE_H);
98- let overflows = lanes.len() > lanes_shown(lanes_box);99+ let overflows = lanes.len() > lanes_shown_mixed(&kinds, lanes_box);
99 let lanes_box = match overflows {100 let lanes_box = match overflows {
100 true => (lanes_box - LABEL_H - 8.).max(LANE_H),101 true => (lanes_box - LABEL_H - 8.).max(LANE_H),
101 false => lanes_box,102 false => lanes_box,
@@ -108,7 +109,7 @@ impl Player {
108 // strip below reads the same number, so a thumb dragged there and a109 // strip below reads the same number, so a thumb dragged there and a
109 // count the affordance lets go of cannot disagree.110 // count the affordance lets go of cannot disagree.
110 let scrolled = -f32::from(self.lanes_scroll.offset().y);111 let scrolled = -f32::from(self.lanes_scroll.offset().y);
111- let below = rows_below(lanes.len(), lanes_box, scrolled);112+ let below = rows_below_mixed(&kinds, lanes_box, scrolled);
112 // The stack's own scrollbar: the thumb is the visible share of the113 // The stack's own scrollbar: the thumb is the visible share of the
113 // lane rows, read straight off the column's own scroll state -- the114 // lane rows, read straight off the column's own scroll state -- the
114 // box, the fold and how far down it has been taken are all the115 // box, the fold and how far down it has been taken are all the
@@ -484,20 +485,17 @@ impl Player {
484 /// 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
485 /// 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
486 /// 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
487- /// 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
488- /// ([`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
489- /// 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
490- /// 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
491- /// 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.
492 ///495 ///
493 /// `None` when there are none -- an empty heading is a section about496 /// `None` when there are none -- an empty heading is a section about
494 /// nothing.497 /// nothing.
495- pub(crate) fn subtitle_section(498+ pub(crate) fn subtitle_section(&self, width: f32, cx: &mut Context<Self>) -> Option<impl IntoElement> {
496- &self,
497- width: f32,
498- viewport_h: f32,
499- cx: &mut Context<Self>,
500- ) -> Option<impl IntoElement> {
501 let tracks = self.session.as_ref()?.subtitles();499 let tracks = self.session.as_ref()?.subtitles();
502 if tracks.is_empty() {500 if tracks.is_empty() {
503 return None;501 return None;
@@ -509,16 +507,20 @@ impl Player {
509 // 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
510 // one, and every row would carry the same word.508 // one, and every row would carry the same word.
511 let several_files = groups.len() > 1;509 let several_files = groups.len() > 1;
512- let headed = several_files && sub_headers_fit(viewport_h);510+ let headed = several_files;
513 let text_w = row_text_w(width);511 let text_w = row_text_w(width);
514 let rows: Vec<_> = groups512 let rows: Vec<_> = groups
515 .into_iter()513 .into_iter()
516- .map(|SubGroup { name, path, rows }| {514+ .enumerate()
515+ .map(|(group_ord, SubGroup { name, path, rows })| {
517 // 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
518 // wear -- and none at all for a standalone `.srt`, which came517 // wear -- and none at all for a standalone `.srt`, which came
519 // off no file on this timeline.518 // off no file on this timeline.
520 let tint = file_tint(self.sources(), &path);519 let tint = file_tint(self.sources(), &path);
520+ let track_count = rows.len();
521 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();
522 // 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
523 // 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.
524 let head = clip_middle(&name, text_w);526 let head = clip_middle(&name, text_w);
@@ -696,11 +698,13 @@ impl Player {
696 .flex_col()698 .flex_col()
697 .gap(px(2.))699 .gap(px(2.))
698 // The header: which film these came out of, in words and not700 // The header: which film these came out of, in words and not
699- // in colour alone. No id, no click, nothing to fold -- a701+ // in colour alone -- a click folds its rows shut and a
700- // 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.
701 .when(headed, |d| {704 .when(headed, |d| {
702 d.child(705 d.child(
703 div()706 div()
707+ .id(("subtitle-group-head", group_ord))
704 .flex_none()708 .flex_none()
705 .h(px(SUB_HEAD_H))709 .h(px(SUB_HEAD_H))
706 .flex()710 .flex()
@@ -708,6 +712,24 @@ impl Player {
708 .gap(px(6.))712 .gap(px(6.))
709 .text_size(px(10.))713 .text_size(px(10.))
710 .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+ })
711 .when_some(tint, |d, tint| {733 .when_some(tint, |d, tint| {
712 d.child(734 d.child(
713 div()735 div()
@@ -718,10 +740,14 @@ impl Player {
718 .bg(rgb(tint)),740 .bg(rgb(tint)),
719 )741 )
720 })742 })
721- .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+ }),
722 )748 )
723 })749 })
724- .children(rows)750+ .when(!(headed && folded), |d| d.children(rows))
725 })751 })
726 .collect();752 .collect();
727 Some(753 Some(
@@ -870,11 +896,23 @@ impl Player {
870 .collect(),896 .collect(),
871 _ => Vec::new(),897 _ => Vec::new(),
872 };898 };
899+ // Thinner than a media lane's ([`SUB_LANE_H`]), so its header has room
900+ // for one `HIT_MIN` target and not the two a stacked eye-and-remove
901+ // pair would need -- the right button carries the remove instead, the
902+ // same door a caption's own box already answers to (`sub_tip`), so a
903+ // track that used to have its own × still has one, just not a second
904+ // row to draw it in.
873 let eye_tip: SharedString = match shown {905 let eye_tip: SharedString = match shown {
874- true => format!("{name} is the track shown over the picture"),906+ true => format!(
907+ "{name} is the track shown over the picture — the right button removes it, empty \
908+ first, and {} brings it back",
909+ self.keymap.display(ActionId::Undo)
910+ ),
875 false => format!(911 false => format!(
876 "Click to show {name} over the picture instead — one subtitle track is drawn at a \912 "Click to show {name} over the picture instead — one subtitle track is drawn at a \
877- time, and an export carries every one of them"913+ time, and an export carries every one of them; the right button removes it, empty \
914+ first, and {} brings it back",
915+ self.keymap.display(ActionId::Undo)
878 ),916 ),
879 }917 }
880 .into();918 .into();
@@ -909,7 +947,7 @@ impl Player {
909 .into();947 .into();
910 div()948 div()
911 .flex_none()949 .flex_none()
912- .h(px(LANE_H))950+ .h(px(lane_h(lane.kind)))
913 .flex()951 .flex()
914 .gap(px(HEADER_GAP))952 .gap(px(HEADER_GAP))
915 // A header let go anywhere along this row lands the track in the953 // A header let go anywhere along this row lands the track in the
@@ -989,12 +1027,17 @@ impl Player {
989 // `HIT_MIN` tall like the mix button it sits where.1027 // `HIT_MIN` tall like the mix button it sits where.
990 // The lit dot and the accent tell the shown lane from1028 // The lit dot and the accent tell the shown lane from
991 // the rest of a stack of them at a glance.1029 // the rest of a stack of them at a glance.
1030+ // One line, not name-over-dot: at `SUB_LANE_H` the
1031+ // whole header is one `HIT_MIN` target, and the
1032+ // shown/hidden state is already the colour, the
1033+ // background and the border below -- a second line
1034+ // saying the same thing again is a line this row no
1035+ // longer has the height to spare.
992 false if sub => div()1036 false if sub => div()
993 .id(("show-lane", lane.ord))1037 .id(("show-lane", lane.ord))
994 .flex_1()1038 .flex_1()
995 .w_full()1039 .w_full()
996 .flex()1040 .flex()
997- .flex_col()
998 .items_center()1041 .items_center()
999 .justify_center()1042 .justify_center()
1000 .rounded(px(3.))1043 .rounded(px(3.))
@@ -1011,15 +1054,20 @@ impl Player {
1011 .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {1054 .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
1012 this.show_sub_lane(lane, cx)1055 this.show_sub_lane(lane, cx)
1013 }))1056 }))
1014- .child(name.clone())1057+ // The remove door a stacked second row used to be,
1015- .child(1058+ // on the same button now: the right button is
1016- div()1059+ // already how a caption's own box takes itself
1017- .text_size(px(9.))1060+ // off the lane (`sub_tip`), so the header answers
1018- .child(match shown {1061+ // to it too rather than spending a second
1019- true => "◉",1062+ // `HIT_MIN` row on a thin lane that has none to
1020- false => "○",1063+ // spare.
1021- }),1064+ .on_mouse_down(
1065+ MouseButton::Right,
1066+ cx.listener(move |this, _: &MouseDownEvent, _, cx| {
1067+ this.remove_lane(lane, cx)
1068+ }),
1022 )1069 )
1070+ .child(name.clone())
1023 .into_any_element(),1071 .into_any_element(),
1024 false => div()1072 false => div()
1025 .flex_1()1073 .flex_1()
@@ -1028,29 +1076,33 @@ impl Player {
1028 .child(name.clone())1076 .child(name.clone())
1029 .into_any_element(),1077 .into_any_element(),
1030 })1078 })
1031- // The one thing a header does: take this track away again.1079+ // The one thing a media header does: take this track away
1032- // A `HIT_MIN` target rather than a glyph-sized one, and it1080+ // again. A `HIT_MIN` target rather than a glyph-sized one,
1033- // stays put on a track holding clips instead of hiding --1081+ // and it stays put on a track holding clips instead of
1034- // the refusal names them, and a control that vanishes1082+ // hiding -- the refusal names them, and a control that
1035- // teaches nothing.1083+ // vanishes teaches nothing. A subtitle lane's remove lives
1036- .child(1084+ // on the eye button instead ([`eye_tip`]) -- this row is
1037- div()1085+ // thin enough for one `HIT_MIN` target, not two.
1038- .id(remove_id)1086+ .when(!sub, |d| {
1039- .flex_none()1087+ d.child(
1040- .w_full()1088+ div()
1041- .h(px(HIT_MIN))1089+ .id(remove_id)
1042- .flex()1090+ .flex_none()
1043- .items_center()1091+ .w_full()
1044- .justify_center()1092+ .h(px(HIT_MIN))
1045- .rounded(px(3.))1093+ .flex()
1046- .cursor_pointer()1094+ .items_center()
1047- .hover(|s| s.bg(rgb(BG_HOVER())))1095+ .justify_center()
1048- .tooltip(move |_, cx| cx.new(|_| Tip(remove_tip.clone())).into())1096+ .rounded(px(3.))
1049- .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {1097+ .cursor_pointer()
1050- this.remove_lane(lane, cx)1098+ .hover(|s| s.bg(rgb(BG_HOVER())))
1051- }))1099+ .tooltip(move |_, cx| cx.new(|_| Tip(remove_tip.clone())).into())
1052- .child("×"),1100+ .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
1053- ),1101+ this.remove_lane(lane, cx)
1102+ }))
1103+ .child("×"),
1104+ )
1105+ }),
1054 )1106 )
1055 .child(1107 .child(
1056 // Clips are placed at their own start rather than queued edge1108 // Clips are placed at their own start rather than queued edge