forge
Explore
Log in

Don't you dare go Hollow

The caption strip is thin again, and the header still fits its own doors

Browse files at this commit

0a5590f127190edf2efeba7984306f893366ef5cAhmet Kaan GümüşParent: 31449fc
  • fix
    • the caption strip is thin again, and the header still fits its own doors
Show full message
🐛 fix(app): the caption strip is thin again, and the header still fits its own doors

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.rsmodified+88 -0
@@ -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
@@ -225,6 +240,70 @@ pub(crate) fn rows_below(total: usize, box_h: f32, scrolled: f32) -> usize {
225 total.saturating_sub(past + lanes_shown(box_h))240 total.saturating_sub(past + lanes_shown(box_h))
226 }241 }
227 242
243+/// How tall one lane row is: [`LANE_H`] for a media track, [`SUB_LANE_H`] for
244+/// a caption one -- the one place that answer is decided, since
245+/// [`lanes_h_mixed`], [`lanes_shown_mixed`] and [`rows_below_mixed`] all walk
246+/// off it and a track drawn at one height and measured at another is a fold
247+/// line that lands on the wrong row.
248+pub(crate) fn lane_h(kind: LaneKind) -> f32 {
249+ match kind {
250+ LaneKind::Subtitle => SUB_LANE_H,
251+ LaneKind::Video | LaneKind::Audio => LANE_H,
252+ }
253+}
254+
255+/// [`lanes_h`] for a real stack of lanes rather than a bare count: a project
256+/// with a caption track in it is shorter than that many `LANE_H` rows, and
257+/// the column, the fold and the affordance below it all have to agree on
258+/// exactly how much shorter, or "N more below" is answering a box nothing
259+/// draws at.
260+pub(crate) fn lanes_h_mixed(kinds: &[LaneKind]) -> f32 {
261+ match kinds.len() {
262+ 0 => 0.,
263+ n => kinds.iter().copied().map(lane_h).sum::<f32>() + (n - 1) as f32 * 8.,
264+ }
265+}
266+
267+/// [`lanes_shown`] for a real stack: the largest prefix of `kinds` whose
268+/// drawn height still fits `box_h`, on the same boundary [`lanes_shown`]
269+/// draws it at (`lanes_h(k) <= box_h`) -- so a uniform stack answers exactly
270+/// what [`lanes_shown`] already did, and a mixed one answers the row count
271+/// its own heights actually reach.
272+pub(crate) fn lanes_shown_mixed(kinds: &[LaneKind], box_h: f32) -> usize {
273+ (0..=kinds.len())
274+ .rev()
275+ .find(|&k| lanes_h_mixed(&kinds[..k]) <= box_h)
276+ .unwrap_or(0)
277+ .max(1)
278+}
279+
280+/// [`rows_below`] for a real stack: `scrolled` read against each row's own
281+/// top rather than a uniform `LANE_H + 8` stride, so a column with a thin
282+/// caption track in it still says the true count once that track has
283+/// scrolled by.
284+pub(crate) fn rows_below_mixed(kinds: &[LaneKind], box_h: f32, scrolled: f32) -> usize {
285+ // Row `k`'s own top, in the same units `scrolled` is given in: nothing
286+ // for the first row, and every row before it plus the gap that follows
287+ // each one for the rest.
288+ let top = |k: usize| -> f32 {
289+ match k {
290+ 0 => 0.,
291+ k => lanes_h_mixed(&kinds[..k]) + 8.,
292+ }
293+ };
294+ let past = (0..=kinds.len())
295+ .min_by(|&a, &b| {
296+ (scrolled - top(a))
297+ .abs()
298+ .partial_cmp(&(scrolled - top(b)).abs())
299+ .unwrap()
300+ })
301+ .unwrap_or(0);
302+ kinds
303+ .len()
304+ .saturating_sub(past + lanes_shown_mixed(kinds, box_h))
305+}
306+
228 /// The same question for a column whose rows are not one height -- the307 /// The same question for a column whose rows are not one height -- the
229 /// inspector's sections -- answered in pixels off what the scroll itself308 /// 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 has309 /// reports: how far it may still be taken (`max_offset`) less how far it has
@@ -409,6 +488,15 @@ pub(crate) fn split_bounds(
409 // lane's own pixels, and the one lane the floor promises is a header488 // lane's own pixels, and the one lane the floor promises is a header
410 // cut in half.489 // cut in half.
411 Split::Timeline => (490 Split::Timeline => (
491+ // `LANE_H` even though the first lane could be a thinner caption
492+ // one: a floor is a *minimum*, so the only failure mode of
493+ // reading it off the tallest kind is a seam that refuses to go
494+ // quite as small as it technically could -- never a lane clipped
495+ // short of its own row. corner-cut: exact per-kind floor would
496+ // read `session.lanes()[0].kind`, which `split_bounds` is not
497+ // handed; ceiling is one drawn-too-tall pixel at the very floor
498+ // of a caption-only project, upgrade is threading the real lane
499+ // list through here the way [`lanes_h_mixed`] already takes it.
412 timeline_fixed_h(scroll)500 timeline_fixed_h(scroll)
413 + LANE_H501 + LANE_H
414 + match lanes > 1 {502 + match lanes > 1 {
crates/app/src/tests/layout.rsmodified+27 -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
crates/app/src/tests/mod.rsmodified+1 -0
@@ -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,
crates/app/src/ui/timeline.rsmodified+64 -37
@@ -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
@@ -870,11 +871,23 @@ impl Player {
870 .collect(),871 .collect(),
871 _ => Vec::new(),872 _ => Vec::new(),
872 };873 };
874+ // Thinner than a media lane's ([`SUB_LANE_H`]), so its header has room
875+ // for one `HIT_MIN` target and not the two a stacked eye-and-remove
876+ // pair would need -- the right button carries the remove instead, the
877+ // same door a caption's own box already answers to (`sub_tip`), so a
878+ // track that used to have its own × still has one, just not a second
879+ // row to draw it in.
873 let eye_tip: SharedString = match shown {880 let eye_tip: SharedString = match shown {
874- true => format!("{name} is the track shown over the picture"),881+ true => format!(
882+ "{name} is the track shown over the picture — the right button removes it, empty \
883+ first, and {} brings it back",
884+ self.keymap.display(ActionId::Undo)
885+ ),
875 false => format!(886 false => format!(
876 "Click to show {name} over the picture instead — one subtitle track is drawn at a \887 "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"888+ time, and an export carries every one of them; the right button removes it, empty \
889+ first, and {} brings it back",
890+ self.keymap.display(ActionId::Undo)
878 ),891 ),
879 }892 }
880 .into();893 .into();
@@ -909,7 +922,7 @@ impl Player {
909 .into();922 .into();
910 div()923 div()
911 .flex_none()924 .flex_none()
912- .h(px(LANE_H))925+ .h(px(lane_h(lane.kind)))
913 .flex()926 .flex()
914 .gap(px(HEADER_GAP))927 .gap(px(HEADER_GAP))
915 // A header let go anywhere along this row lands the track in the928 // A header let go anywhere along this row lands the track in the
@@ -989,12 +1002,17 @@ impl Player {
989 // `HIT_MIN` tall like the mix button it sits where.1002 // `HIT_MIN` tall like the mix button it sits where.
990 // The lit dot and the accent tell the shown lane from1003 // The lit dot and the accent tell the shown lane from
991 // the rest of a stack of them at a glance.1004 // the rest of a stack of them at a glance.
1005+ // One line, not name-over-dot: at `SUB_LANE_H` the
1006+ // whole header is one `HIT_MIN` target, and the
1007+ // shown/hidden state is already the colour, the
1008+ // background and the border below -- a second line
1009+ // saying the same thing again is a line this row no
1010+ // longer has the height to spare.
992 false if sub => div()1011 false if sub => div()
993 .id(("show-lane", lane.ord))1012 .id(("show-lane", lane.ord))
994 .flex_1()1013 .flex_1()
995 .w_full()1014 .w_full()
996 .flex()1015 .flex()
997- .flex_col()
998 .items_center()1016 .items_center()
999 .justify_center()1017 .justify_center()
1000 .rounded(px(3.))1018 .rounded(px(3.))
@@ -1011,15 +1029,20 @@ impl Player {
1011 .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {1029 .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
1012 this.show_sub_lane(lane, cx)1030 this.show_sub_lane(lane, cx)
1013 }))1031 }))
1014- .child(name.clone())1032+ // The remove door a stacked second row used to be,
1015- .child(1033+ // on the same button now: the right button is
1016- div()1034+ // already how a caption's own box takes itself
1017- .text_size(px(9.))1035+ // off the lane (`sub_tip`), so the header answers
1018- .child(match shown {1036+ // to it too rather than spending a second
1019- true => "◉",1037+ // `HIT_MIN` row on a thin lane that has none to
1020- false => "○",1038+ // spare.
1021- }),1039+ .on_mouse_down(
1040+ MouseButton::Right,
1041+ cx.listener(move |this, _: &MouseDownEvent, _, cx| {
1042+ this.remove_lane(lane, cx)
1043+ }),
1022 )1044 )
1045+ .child(name.clone())
1023 .into_any_element(),1046 .into_any_element(),
1024 false => div()1047 false => div()
1025 .flex_1()1048 .flex_1()
@@ -1028,29 +1051,33 @@ impl Player {
1028 .child(name.clone())1051 .child(name.clone())
1029 .into_any_element(),1052 .into_any_element(),
1030 })1053 })
1031- // The one thing a header does: take this track away again.1054+ // The one thing a media header does: take this track away
1032- // A `HIT_MIN` target rather than a glyph-sized one, and it1055+ // again. A `HIT_MIN` target rather than a glyph-sized one,
1033- // stays put on a track holding clips instead of hiding --1056+ // and it stays put on a track holding clips instead of
1034- // the refusal names them, and a control that vanishes1057+ // hiding -- the refusal names them, and a control that
1035- // teaches nothing.1058+ // vanishes teaches nothing. A subtitle lane's remove lives
1036- .child(1059+ // on the eye button instead ([`eye_tip`]) -- this row is
1037- div()1060+ // thin enough for one `HIT_MIN` target, not two.
1038- .id(remove_id)1061+ .when(!sub, |d| {
1039- .flex_none()1062+ d.child(
1040- .w_full()1063+ div()
1041- .h(px(HIT_MIN))1064+ .id(remove_id)
1042- .flex()1065+ .flex_none()
1043- .items_center()1066+ .w_full()
1044- .justify_center()1067+ .h(px(HIT_MIN))
1045- .rounded(px(3.))1068+ .flex()
1046- .cursor_pointer()1069+ .items_center()
1047- .hover(|s| s.bg(rgb(BG_HOVER())))1070+ .justify_center()
1048- .tooltip(move |_, cx| cx.new(|_| Tip(remove_tip.clone())).into())1071+ .rounded(px(3.))
1049- .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {1072+ .cursor_pointer()
1050- this.remove_lane(lane, cx)1073+ .hover(|s| s.bg(rgb(BG_HOVER())))
1051- }))1074+ .tooltip(move |_, cx| cx.new(|_| Tip(remove_tip.clone())).into())
1052- .child("×"),1075+ .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
1053- ),1076+ this.remove_lane(lane, cx)
1077+ }))
1078+ .child("×"),
1079+ )
1080+ }),
1054 )1081 )
1055 .child(1082 .child(
1056 // Clips are placed at their own start rather than queued edge1083 // Clips are placed at their own start rather than queued edge