diff --git a/crates/app/src/layout.rs b/crates/app/src/layout.rs index 508f571..03f398c 100644 --- a/crates/app/src/layout.rs +++ b/crates/app/src/layout.rs @@ -21,6 +21,21 @@ pub(crate) const PANEL_H: f32 = 220.; /// timeline that pushes the video off the window is not a timeline. pub(crate) const LANES_MAX: usize = 6; pub(crate) const LANE_H: f32 = 48.; +/// A caption lane's own height, thinner than a media one: a subtitle box +/// carries a name, a rate badge and the cue band under it +/// ([`Player::lane_row`]) and none of a clip's waveform or its full-height +/// plate, so the strip that used to draw the whole row's worth of nothing is +/// the regression this constant undoes. +/// +/// Floored at [`HIT_MIN`] rather than the 20 px a first pass at "thin" landed +/// on: the header's show/hide eye is the row's one surviving click target +/// once the remove button moves off it onto the right button +/// ([`Player::lane_row`]), and that eye fills the row's full height -- so +/// anything under `HIT_MIN` here is a WCAG 2.5.8 target shrunk to chase a +/// pixel count, not a thinner lane. This is the whole gap between the two +/// harness variants the task asked for: 20 is not shippable at all, 24 is, +/// so 24 is the only variant landed. +pub(crate) const SUB_LANE_H: f32 = HIT_MIN; /// The lane header column: wide enough for `V1`/`A1` and fixed, so both lanes /// and the ruler above them start at the same pixel and are the same width -- /// 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.; /// How much of the subtitle list in the library column is on screen at once, /// past which it scrolls -- the media list above it is what keeps the height. pub(crate) const SUB_ROWS_H: f32 = 3. * ROW_H; -/// The row naming the file a block of tracks came out of. Shorter than a track -/// row because nothing on it is clicked -- `HIT_MIN` binds targets and a header -/// is a label, not a way in -- and drawn at all only where the column has the -/// height to show tracks under it ([`sub_headers_fit`]). -pub(crate) const SUB_HEAD_H: f32 = 18.; -/// How much of the subtitle list is on screen at the 640x360 floor: one row, -/// measured -- the section's own heading and the Add button under it take the -/// rest of the 84 px the column has there. -pub(crate) const SUB_ROWS_AT_FLOOR: f32 = ROW_H; +/// The row naming the file a block of tracks came out of. Always drawn where +/// there is more than one file -- the list already scrolls past `SUB_ROWS_H`, +/// so a short window loses tracks under the fold rather than the name saying +/// whose they are. A click folds it, so it binds `HIT_MIN` like every other +/// target. +pub(crate) const SUB_HEAD_H: f32 = HIT_MIN; /// How much of a subtitle row's width the file's name in front of the label may /// take. Half: which file and which language are both worth reading, and a name /// 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 { total.saturating_sub(past + lanes_shown(box_h)) } +/// How tall one lane row is: [`LANE_H`] for a media track, [`SUB_LANE_H`] for +/// a caption one -- the one place that answer is decided, since +/// [`lanes_h_mixed`], [`lanes_shown_mixed`] and [`rows_below_mixed`] all walk +/// off it and a track drawn at one height and measured at another is a fold +/// line that lands on the wrong row. +pub(crate) fn lane_h(kind: LaneKind) -> f32 { + match kind { + LaneKind::Subtitle => SUB_LANE_H, + LaneKind::Video | LaneKind::Audio => LANE_H, + } +} + +/// [`lanes_h`] for a real stack of lanes rather than a bare count: a project +/// with a caption track in it is shorter than that many `LANE_H` rows, and +/// the column, the fold and the affordance below it all have to agree on +/// exactly how much shorter, or "N more below" is answering a box nothing +/// draws at. +pub(crate) fn lanes_h_mixed(kinds: &[LaneKind]) -> f32 { + match kinds.len() { + 0 => 0., + n => kinds.iter().copied().map(lane_h).sum::() + (n - 1) as f32 * 8., + } +} + +/// [`lanes_shown`] for a real stack: the largest prefix of `kinds` whose +/// drawn height still fits `box_h`, on the same boundary [`lanes_shown`] +/// draws it at (`lanes_h(k) <= box_h`) -- so a uniform stack answers exactly +/// what [`lanes_shown`] already did, and a mixed one answers the row count +/// its own heights actually reach. +pub(crate) fn lanes_shown_mixed(kinds: &[LaneKind], box_h: f32) -> usize { + (0..=kinds.len()) + .rev() + .find(|&k| lanes_h_mixed(&kinds[..k]) <= box_h) + .unwrap_or(0) + .max(1) +} + +/// [`rows_below`] for a real stack: `scrolled` read against each row's own +/// top rather than a uniform `LANE_H + 8` stride, so a column with a thin +/// caption track in it still says the true count once that track has +/// scrolled by. +pub(crate) fn rows_below_mixed(kinds: &[LaneKind], box_h: f32, scrolled: f32) -> usize { + // Row `k`'s own top, in the same units `scrolled` is given in: nothing + // for the first row, and every row before it plus the gap that follows + // each one for the rest. + let top = |k: usize| -> f32 { + match k { + 0 => 0., + k => lanes_h_mixed(&kinds[..k]) + 8., + } + }; + let past = (0..=kinds.len()) + .min_by(|&a, &b| { + (scrolled - top(a)) + .abs() + .partial_cmp(&(scrolled - top(b)).abs()) + .unwrap() + }) + .unwrap_or(0); + kinds + .len() + .saturating_sub(past + lanes_shown_mixed(kinds, box_h)) +} + /// The same question for a column whose rows are not one height -- the /// inspector's sections -- answered in pixels off what the scroll itself /// reports: how far it may still be taken (`max_offset`) less how far it has @@ -409,6 +485,15 @@ pub(crate) fn split_bounds( // lane's own pixels, and the one lane the floor promises is a header // cut in half. Split::Timeline => ( + // `LANE_H` even though the first lane could be a thinner caption + // one: a floor is a *minimum*, so the only failure mode of + // reading it off the tallest kind is a seam that refuses to go + // quite as small as it technically could -- never a lane clipped + // short of its own row. corner-cut: exact per-kind floor would + // read `session.lanes()[0].kind`, which `split_bounds` is not + // handed; ceiling is one drawn-too-tall pixel at the very floor + // of a caption-only project, upgrade is threading the real lane + // list through here the way [`lanes_h_mixed`] already takes it. timeline_fixed_h(scroll) + LANE_H + match lanes > 1 { diff --git a/crates/app/src/library_meta.rs b/crates/app/src/library_meta.rs index b24e7b8..581b9dd 100644 --- a/crates/app/src/library_meta.rs +++ b/crates/app/src/library_meta.rs @@ -370,19 +370,6 @@ pub(crate) fn clip_middle(name: &str, width: f32) -> String { ) } -/// Whether the subtitle list has the height to name each file over its tracks. -/// A header is worth its own height only where there are still tracks under it -/// to read: at the 640x360 floor the list is one row tall, and a header there -/// would name a film and show none of it -- so at the floor there are no -/// headers and the rows say which file they came from themselves. -/// -/// The window's height answers it on its own: the row above the picture and the -/// panel under it are fixed, so every pixel the window gains past the floor is a -/// pixel this column gains. -pub(crate) fn sub_headers_fit(viewport_h: f32) -> bool { - SUB_ROWS_AT_FLOOR + (viewport_h - 360.).max(0.) >= SUB_HEAD_H + 2. * ROW_H -} - /// What the window is called: the program, and what is open in it. The name is /// what the header shows, so an empty window says the program alone rather than /// "no file open — edith". diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index c260273..2b5cd57 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -43,7 +43,7 @@ use ui::widgets::*; use keymap::{ActionId, Keymap}; use std::cell::Cell; -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use std::path::{Path, PathBuf}; use std::rc::Rc; use std::sync::Arc; @@ -266,6 +266,13 @@ struct Player { /// like every other index here -- track 2 of one project is not track 2 of /// the next. sub_track: usize, + /// Which files' subtitle groups in the library are folded shut, keyed by + /// the group's own path -- the same key [`subtitle_rows`] groups on, so a + /// fold survives a track being added or removed off the file it belongs + /// to. Session-lifetime only: a fold is a "not looking at this one right + /// now", not a project setting, so it is never saved and every file opens + /// unfolded. + sub_folded: HashSet, /// Which subtitle lane is *shown*: one of them and never two, the way a /// player has one subtitle track chosen at a time -- two hundred lanes of /// different words all drawn at once is two hundred plates over one @@ -708,6 +715,7 @@ fn main() { snap: true, subs_on: true, sub_track: 0, + sub_folded: HashSet::new(), sub_lane: None, snap_cue: None, ghost: None, diff --git a/crates/app/src/render.rs b/crates/app/src/render.rs index 1ac0ee0..bdb6570 100644 --- a/crates/app/src/render.rs +++ b/crates/app/src/render.rs @@ -556,7 +556,6 @@ impl Render for Player { .flex() .child(self.library( self.split_px(Split::Library, window.viewport_size()), - f32::from(window.viewport_size().height), cx, )) // The seams, one per pair of regions: what a hand drags to diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index 2ded42c..4751983 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -92,6 +92,28 @@ fn the_line_about_what_is_below_the_fold_counts_what_is_still_below_it() { // A project that fits says nothing at all. assert_eq!(rows_below(2, box_h, 0.), 0); + // The same three questions once a lane in the stack is a thinner + // caption one: a uniform stack answers exactly what the plain + // functions above do, and a mixed one answers off the real heights, + // never the media one alone. + let uniform = [LaneKind::Video, LaneKind::Audio]; + assert_eq!(lanes_h_mixed(&uniform), lanes_h(2)); + assert_eq!(lanes_shown_mixed(&uniform, LANE_H), lanes_shown(LANE_H)); + let mixed = [LaneKind::Video, LaneKind::Audio, LaneKind::Subtitle]; + assert_eq!( + lanes_h_mixed(&mixed), + 2. * LANE_H + SUB_LANE_H + 2. * 8., + "a caption lane is not counted as a full LANE_H row" + ); + // A box exactly tall enough for the two media lanes and no more: the + // thinner third lane still does not fit above it. + assert_eq!(lanes_shown_mixed(&mixed, lanes_h(2)), 2); + // ...and with room for the caption lane too, all three show and + // nothing is below the fold. + assert_eq!(lanes_shown_mixed(&mixed, lanes_h_mixed(&mixed)), 3); + assert_eq!(rows_below_mixed(&mixed, lanes_h_mixed(&mixed), 0.), 0); + assert_eq!(rows_below_mixed(&mixed, lanes_h(2), 0.), 1); + // The inspector's rows are not one height, so its own line is measured // in pixels off the scroll instead: gpui keeps the offset negative going // down, and at the bottom the two cancel out exactly. @@ -216,6 +238,11 @@ fn nothing_clickable_is_smaller_than_the_wcag_minimum() { assert!(CONTROL_H >= HIT_MIN); assert!(RULER_HIT_H >= HIT_MIN); assert!(LANE_H >= HIT_MIN); + // A caption lane's header carries exactly one hit target now (the + // show/hide eye; remove moved to its right button), and that target + // fills the whole row -- so the row is never allowed to undercut the + // target it *is*. + assert!(SUB_LANE_H >= HIT_MIN); // A clip box is a hit target too, and its two trim strips occlude it: // on a box narrower than the pair there is no body left to press, so // 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() { "the group carries the path the tint is asked by" ); assert_eq!(file_tint(&sources, &groups[2].path), None); + // What a header's "N tracks" says: the group's own row count, which is + // 2, 2, 1 here -- a film that gave several tracks and a standalone + // `.srt` that gave exactly one. + assert_eq!( + groups.iter().map(|g| g.rows.len()).collect::>(), + [2, 2, 1] + ); + // A standalone `.srt` is already its own group, named after its own + // file ("late", not lumped under some catch-all "External" bucket) -- + // there is no sourceless case for a header to special-case. + assert_eq!(groups[2].name, "late"); + assert_eq!(groups[2].path, PathBuf::from("/subs/late.srt")); +} + +/// The fold a click on a header sets is keyed by [`SubGroup::path`] +/// (`Player::sub_folded`), so it has to survive the very thing regrouping +/// is for: a second track landing on a file already in the list, or one +/// being removed from it. The group's path is the fold's whole identity, +/// so it must not move under either. +#[test] +fn a_groups_fold_key_survives_a_track_arriving_or_leaving_its_file() { + let before = [ + sub("/films/a.mkv", Some(1), "eng"), + sub("/films/b.mkv", Some(1), "eng"), + ]; + let after_add = [ + sub("/films/a.mkv", Some(1), "eng"), + sub("/films/b.mkv", Some(1), "eng"), + sub("/films/a.mkv", Some(2), "fre"), + ]; + let (before_groups, after_groups) = (subtitle_rows(&before), subtitle_rows(&after_add)); + assert_eq!(before_groups[0].path, after_groups[0].path, "a's key held"); + assert_eq!(before_groups[1].path, after_groups[1].path, "b's key held"); + // The group a second track landed on grew; the other did not move. + assert_eq!(after_groups[0].rows.len(), 2); + assert_eq!(after_groups[1].rows.len(), 1); + // Removing that same track back off leaves the original key and count. + let after_remove = subtitle_rows(&before); + assert_eq!(after_remove[0].path, before_groups[0].path); + assert_eq!(after_remove[0].rows.len(), 1); } /// 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() { ); } +/// 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 +/// under it is what scrolls instead ([`SUB_ROWS_H`]). And it has to be a +/// real fold, not the click-cycling pattern this codebase has already +/// thrown out once: one click toggles `sub_folded` shut or open, it never +/// steps through more than those two states. +#[test] +fn a_subtitle_group_header_is_never_gated_on_window_height() { + let timeline = src_text("ui/timeline.rs"); + assert!( + !timeline.contains("sub_headers_fit"), + "the header is still gated on the viewport's height" + ); + let at = timeline + .find("let headed = ") + .expect("no `headed` computed in subtitle_section"); + let line = &timeline[at..(at + 80).min(timeline.len())]; + assert!( + line.contains("several_files") && !line.contains("viewport"), + "headed depends on something other than the file count: {line}" + ); + // The header is a click target that flips membership in a set -- + // `remove` else `insert` -- not a value stepped through several states. + let head_at = timeline + .find("subtitle-group-head") + .expect("no id on the group header"); + let block = &timeline[head_at..(head_at + 2400).min(timeline.len())]; + assert!(block.contains("sub_folded.remove"), "no fold-open path: {block}"); + assert!(block.contains("sub_folded.insert"), "no fold-shut path: {block}"); + assert!( + block.contains("\"1 track\"") || block.contains("tracks"), + "the header does not say how many tracks it holds: {block}" + ); +} + /// The one thing regrouping must not break: `sub_track` is a flat index /// into the add-order list, a click sets it and a save writes it into the /// `.edith`. Every row must still name the track it was made from -- rows diff --git a/crates/app/src/tests/media.rs b/crates/app/src/tests/media.rs index 087690d..c7b0e0f 100644 --- a/crates/app/src/tests/media.rs +++ b/crates/app/src/tests/media.rs @@ -891,19 +891,13 @@ fn the_subtitle_plate_and_lanes_fit_the_smallest_window() { // taking the media list's room. assert_eq!(SUB_ROWS_H / ROW_H, 3.); assert!(ROW_H >= HIT_MIN, "a subtitle row is clicked to pick it"); - // At the floor there are no group headers at all: the list is one row - // tall there, and a header would name a film and then show none of it. - // The rows go on naming their own file, so nothing is lost by it. - assert!(!sub_headers_fit(360.), "a header at the floor eats the track"); - // At the size the window opens on there is room for a header and the - // tracks under it, which is the only condition it is drawn on. - assert!(sub_headers_fit(720.)); - // ...and where it is drawn it fits inside the same capped list, header - // and two rows under it, without the tracks losing their budget. + // A header is always drawn with more than one file, floor included: the + // list scrolls past `SUB_ROWS_H` instead of a short window losing the + // name saying whose tracks these are. assert!(SUB_HEAD_H + 2. * ROW_H <= SUB_ROWS_H); - // A header takes no click -- there is nothing to fold and nothing to - // aim at -- which is the only reason it may be under `HIT_MIN`. - assert!(SUB_HEAD_H < HIT_MIN && SUB_HEAD_H > 0.); + // A header folds its group on a click now, so it binds `HIT_MIN` like + // every other target rather than being let off it as a bare label. + assert!(SUB_HEAD_H >= HIT_MIN); } /// What the rows of both lists do with a name too long for the column: two diff --git a/crates/app/src/tests/mod.rs b/crates/app/src/tests/mod.rs index 70586df..93b19ce 100644 --- a/crates/app/src/tests/mod.rs +++ b/crates/app/src/tests/mod.rs @@ -17,6 +17,7 @@ use super::{ Format, HEADER_GAP, HEADER_H, HEADER_W, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, KeyRow, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX, LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_PAD, MENU_ROW_H, + SUB_LANE_H, lanes_h_mixed, lanes_shown_mixed, rows_below_mixed, MBPS_DIGITS, MBPS_MAX, MBPS_MIN, MB_FLOOR, MENU_W, NO_FILE, NumberEdit, PANEL_H, ROW_ITEMS, RowCtx, RowItem, Quality, ROW_H, RULER_HIT_H, SCROLL_NOTCH_SHARE, SILENCE_ROWS, SOURCE_TINTS, SPEED_PRESETS, SPEED_STEP, BG_RAISED, SWATCH_W, Source, Speed, StreamInfo, @@ -56,7 +57,7 @@ use super::{ use super::{ SUB_BOTTOM, SUB_CUE_MIN_W, SUB_HEAD_H, SUB_LINE_H, SUB_ROWS_H, SUB_STEM_SHARE, SUB_TEXT, clip_middle, cue_box, sub_bottom, - carries_subtitles, cues_at, file_tint, is_subtitle, lang_human, row_text_w, sub_headers_fit, + carries_subtitles, cues_at, file_tint, is_subtitle, lang_human, row_text_w, Subs, subtitle_detail, subtitle_notice, subtitle_tail, sub_pick_name, subtitle_rows, subtitle_toggle_notice, walk_subtitles, }; diff --git a/crates/app/src/ui/library.rs b/crates/app/src/ui/library.rs index e57427f..0e22828 100644 --- a/crates/app/src/ui/library.rs +++ b/crates/app/src/ui/library.rs @@ -15,7 +15,7 @@ impl Player { /// the rest of this window: nothing in it takes focus, so the root keeps /// the keyboard and the play key still works after a row is clicked /// (ledger:182). - pub(crate) fn library(&self, width: f32, viewport_h: f32, cx: &mut Context) -> impl IntoElement { + pub(crate) fn library(&self, width: f32, cx: &mut Context) -> impl IntoElement { let exporting = self.exporting().is_some(); let sources = self .session @@ -484,7 +484,7 @@ impl Player { // it goes on no lane and is dragged nowhere -- but it is a thing the // timeline holds, and this is the list of those. .when(self.library_tab == LibraryTab::Text, |d| { - d.children(self.subtitle_section(width, viewport_h, cx)) + d.children(self.subtitle_section(width, cx)) }) .child(control( "add-asset", diff --git a/crates/app/src/ui/timeline.rs b/crates/app/src/ui/timeline.rs index ade71ab..b80e269 100644 --- a/crates/app/src/ui/timeline.rs +++ b/crates/app/src/ui/timeline.rs @@ -93,9 +93,10 @@ impl Player { // that crosses the line. let view = self.view(); let scrollable = view.duration > view.span(); + let kinds: Vec = lanes.iter().map(|lane| lane.kind).collect(); let region_h = self.split_px(Split::Timeline, viewport); let lanes_box = (region_h - timeline_fixed_h(scrollable)).max(LANE_H); - let overflows = lanes.len() > lanes_shown(lanes_box); + let overflows = lanes.len() > lanes_shown_mixed(&kinds, lanes_box); let lanes_box = match overflows { true => (lanes_box - LABEL_H - 8.).max(LANE_H), false => lanes_box, @@ -108,7 +109,7 @@ impl Player { // strip below reads the same number, so a thumb dragged there and a // count the affordance lets go of cannot disagree. let scrolled = -f32::from(self.lanes_scroll.offset().y); - let below = rows_below(lanes.len(), lanes_box, scrolled); + let below = rows_below_mixed(&kinds, lanes_box, scrolled); // The stack's own scrollbar: the thumb is the visible share of the // lane rows, read straight off the column's own scroll state -- the // box, the fold and how far down it has been taken are all the @@ -484,20 +485,17 @@ impl Player { /// Every row names the file it came out of itself, in words and in the tint /// that file's clips wear on the lanes -- but only where there is more than /// one file to tell apart, the way [`row_name`] numbers audio streams only - /// where a file gave several. Where the window is tall enough for it - /// ([`sub_headers_fit`]) each file's block is headed by its name as well: a - /// label and nothing more, no click and nothing to fold, so the rows under - /// it are the only things anybody has to aim at. At the 640x360 floor the - /// headers are gone and the rows still say whose they are. + /// where a file gave several. There, each file's block is headed by its + /// name as well, its swatch and its track count -- always, whatever the + /// window's height, since the list under it scrolls (`SUB_ROWS_H`) rather + /// than the header being the thing a short window drops. A click on a + /// header folds its rows shut (`Player::sub_folded`) and a second one opens + /// them back -- a fold and not a cycle, so what a click does never depends + /// on what the last one did. /// /// `None` when there are none -- an empty heading is a section about /// nothing. - pub(crate) fn subtitle_section( - &self, - width: f32, - viewport_h: f32, - cx: &mut Context, - ) -> Option { + pub(crate) fn subtitle_section(&self, width: f32, cx: &mut Context) -> Option { let tracks = self.session.as_ref()?.subtitles(); if tracks.is_empty() { return None; @@ -509,16 +507,20 @@ impl Player { // One file's tracks need no prefix saying which file: it is the only // one, and every row would carry the same word. let several_files = groups.len() > 1; - let headed = several_files && sub_headers_fit(viewport_h); + let headed = several_files; let text_w = row_text_w(width); let rows: Vec<_> = groups .into_iter() - .map(|SubGroup { name, path, rows }| { + .enumerate() + .map(|(group_ord, SubGroup { name, path, rows })| { // The file's own colour, the one its media rows and its clips // wear -- and none at all for a standalone `.srt`, which came // off no file on this timeline. let tint = file_tint(self.sources(), &path); + let track_count = rows.len(); let numbered = rows.len() > 1; + let folded = self.sub_folded.contains(&path); + let fold_path = path.clone(); // The name twice over: all of it the header can hold, and the // share of a row a prefix may take in front of the label. let head = clip_middle(&name, text_w); @@ -696,11 +698,13 @@ impl Player { .flex_col() .gap(px(2.)) // The header: which film these came out of, in words and not - // in colour alone. No id, no click, nothing to fold -- a - // label, which is why it is allowed under `HIT_MIN`. + // in colour alone -- a click folds its rows shut and a + // second click opens them, so it is its own `HIT_MIN` + // target rather than a bare label. .when(headed, |d| { d.child( div() + .id(("subtitle-group-head", group_ord)) .flex_none() .h(px(SUB_HEAD_H)) .flex() @@ -708,6 +712,24 @@ impl Player { .gap(px(6.)) .text_size(px(10.)) .text_color(rgb(FG_SECONDARY())) + .rounded(px(3.)) + .cursor_pointer() + .hover(|s| s.bg(rgb(BG_HOVER()))) + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { + match this.sub_folded.remove(&fold_path) { + true => {} + false => { + this.sub_folded.insert(fold_path.clone()); + } + } + cx.notify(); + })) + // Folded / open, in the same glyph a fold uses + // everywhere else on this row list. + .child(match folded { + true => "▸", + false => "▾", + }) .when_some(tint, |d, tint| { d.child( div() @@ -718,10 +740,14 @@ impl Player { .bg(rgb(tint)), ) }) - .child(div().flex_1().min_w(px(0.)).truncate().child(head)), + .child(div().flex_1().min_w(px(0.)).truncate().child(head)) + .child(match track_count { + 1 => "1 track".to_string(), + n => format!("{n} tracks"), + }), ) }) - .children(rows) + .when(!(headed && folded), |d| d.children(rows)) }) .collect(); Some( @@ -870,11 +896,23 @@ impl Player { .collect(), _ => Vec::new(), }; + // Thinner than a media lane's ([`SUB_LANE_H`]), so its header has room + // for one `HIT_MIN` target and not the two a stacked eye-and-remove + // pair would need -- the right button carries the remove instead, the + // same door a caption's own box already answers to (`sub_tip`), so a + // track that used to have its own × still has one, just not a second + // row to draw it in. let eye_tip: SharedString = match shown { - true => format!("{name} is the track shown over the picture"), + true => format!( + "{name} is the track shown over the picture — the right button removes it, empty \ + first, and {} brings it back", + self.keymap.display(ActionId::Undo) + ), false => format!( "Click to show {name} over the picture instead — one subtitle track is drawn at a \ - time, and an export carries every one of them" + time, and an export carries every one of them; the right button removes it, empty \ + first, and {} brings it back", + self.keymap.display(ActionId::Undo) ), } .into(); @@ -909,7 +947,7 @@ impl Player { .into(); div() .flex_none() - .h(px(LANE_H)) + .h(px(lane_h(lane.kind))) .flex() .gap(px(HEADER_GAP)) // A header let go anywhere along this row lands the track in the @@ -989,12 +1027,17 @@ impl Player { // `HIT_MIN` tall like the mix button it sits where. // The lit dot and the accent tell the shown lane from // the rest of a stack of them at a glance. + // One line, not name-over-dot: at `SUB_LANE_H` the + // whole header is one `HIT_MIN` target, and the + // shown/hidden state is already the colour, the + // background and the border below -- a second line + // saying the same thing again is a line this row no + // longer has the height to spare. false if sub => div() .id(("show-lane", lane.ord)) .flex_1() .w_full() .flex() - .flex_col() .items_center() .justify_center() .rounded(px(3.)) @@ -1011,15 +1054,20 @@ impl Player { .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { this.show_sub_lane(lane, cx) })) - .child(name.clone()) - .child( - div() - .text_size(px(9.)) - .child(match shown { - true => "◉", - false => "○", - }), + // The remove door a stacked second row used to be, + // on the same button now: the right button is + // already how a caption's own box takes itself + // off the lane (`sub_tip`), so the header answers + // to it too rather than spending a second + // `HIT_MIN` row on a thin lane that has none to + // spare. + .on_mouse_down( + MouseButton::Right, + cx.listener(move |this, _: &MouseDownEvent, _, cx| { + this.remove_lane(lane, cx) + }), ) + .child(name.clone()) .into_any_element(), false => div() .flex_1() @@ -1028,29 +1076,33 @@ impl Player { .child(name.clone()) .into_any_element(), }) - // The one thing a header does: take this track away again. - // A `HIT_MIN` target rather than a glyph-sized one, and it - // stays put on a track holding clips instead of hiding -- - // the refusal names them, and a control that vanishes - // teaches nothing. - .child( - div() - .id(remove_id) - .flex_none() - .w_full() - .h(px(HIT_MIN)) - .flex() - .items_center() - .justify_center() - .rounded(px(3.)) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .tooltip(move |_, cx| cx.new(|_| Tip(remove_tip.clone())).into()) - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { - this.remove_lane(lane, cx) - })) - .child("×"), - ), + // The one thing a media header does: take this track away + // again. A `HIT_MIN` target rather than a glyph-sized one, + // and it stays put on a track holding clips instead of + // hiding -- the refusal names them, and a control that + // vanishes teaches nothing. A subtitle lane's remove lives + // on the eye button instead ([`eye_tip`]) -- this row is + // thin enough for one `HIT_MIN` target, not two. + .when(!sub, |d| { + d.child( + div() + .id(remove_id) + .flex_none() + .w_full() + .h(px(HIT_MIN)) + .flex() + .items_center() + .justify_center() + .rounded(px(3.)) + .cursor_pointer() + .hover(|s| s.bg(rgb(BG_HOVER()))) + .tooltip(move |_, cx| cx.new(|_| Tip(remove_tip.clone())).into()) + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { + this.remove_lane(lane, cx) + })) + .child("×"), + ) + }), ) .child( // Clips are placed at their own start rather than queued edge