From 0a5590f127190edf2efeba7984306f893366ef5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 19 Aug 2026 20:30:46 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(app):=20the=20caption=20stri?= =?UTF-8?q?p=20is=20thin=20again,=20and=20the=20header=20still=20fits=20it?= =?UTF-8?q?s=20own=20doors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit f85f4db drew subtitle lanes as full LANE_H media rows and kept only a 4px cue band -- SUB_LANE_H (== HIT_MIN, 24px) undoes that: a caption lane's row, its box and its bed all draw at it now, branched off `lane.kind` at the one place a row's height is set. A thinner header has no room for two stacked HIT_MIN targets, so the subtitle lane's remove control moves off its own row onto the right button of the show/hide eye -- the same door a caption's own box already answers to. 20px, the other harness candidate the task asked for, was never shippable: the eye button is the row's one surviving hit target and fills the whole row, so anything under HIT_MIN there is a WCAG 2.5.8 target shrunk to chase a pixel count. lanes_h_mixed/lanes_shown_mixed/rows_below_mixed generalise the panel's overflow math off each lane's own height instead of assuming every row is LANE_H, so a caption track in the stack does not throw off the "N more below" affordance. The uniform lanes_h/lanes_shown/rows_below and their pinned tests are untouched. --- crates/app/src/layout.rs | 88 ++++++++++++++++++++++++++++ crates/app/src/tests/layout.rs | 27 +++++++++ crates/app/src/tests/mod.rs | 1 + crates/app/src/ui/timeline.rs | 101 +++++++++++++++++++++------------ 4 files changed, 180 insertions(+), 37 deletions(-) diff --git a/crates/app/src/layout.rs b/crates/app/src/layout.rs index 508f571..4dd784e 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 @@ -225,6 +240,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 +488,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/tests/layout.rs b/crates/app/src/tests/layout.rs index 2ded42c..9844ab9 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 diff --git a/crates/app/src/tests/mod.rs b/crates/app/src/tests/mod.rs index cef1de3..c1e391b 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, diff --git a/crates/app/src/ui/timeline.rs b/crates/app/src/ui/timeline.rs index ade71ab..30529c6 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 @@ -870,11 +871,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 +922,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 +1002,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 +1029,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 +1051,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