forge
Explore
Log in

Don't you dare go Hollow

The tracks below the fold say so, and stop saying it once they are up

Browse files at this commit

0e5864c4373565bd96320d99bd8da53257298907Ahmet Kaan GümüşParent: fc6f9b0
  • fix
    • the tracks below the fold say so, and stop saying it once they are up
Show full message
🐛 fix(ui): the tracks below the fold say so, and stop saying it once they are up

At the 640x360 floor the timeline takes its share of the window and the lane
column scrolls inside it, which is the right arrangement and an invisible
one: a third track behind a scroll is a track nobody knows exists. The lanes
carry a line now, in the one place the eye is already looking, and the
inspector carries the same line for the same reason -- at the floor its
project section is below the fold.

The line is live. A count of `total - shown` is true once and wrong from the
first notch of the wheel: it goes on insisting two tracks are below with the
last of them on screen, and an affordance nobody can make go away reads as a
bug rather than as an instruction. Both columns report where they have been
taken to (`track_scroll`), and the count is of what is *still* below --
`rows_below` for lanes, which are one height, and `px_below` for the
inspector's sections, which are not.

Whether the line is drawn at all is decided without the scroll, so it cannot
flicker in and out under the pointer that is scrolling it: it is there while
the column overflows, and it says "the last track" rather than vanishing.
Its own flex_none row under a flex_1 column, so the thing announcing the
overflow is never the thing the overflow pushes off the window.
crates/app/src/main.rsmodified+80 -1
@@ -1315,6 +1315,13 @@ struct Player {
1315 /// and the rows past the fold have to be reachable from the keyboard that1315 /// and the rows past the fold have to be reachable from the keyboard that
1316 /// is already typing in the search box.1316 /// is already typing in the search box.
1317 keys_scroll: ScrollHandle,1317 keys_scroll: ScrollHandle,
1318+ /// Where the lane column and the inspector's rows have been taken to. Read
1319+ /// back at render, not only written by the wheel: the line each of them
1320+ /// carries about what is below the fold is a count of what is *still* below
1321+ /// it, and a scroll that nothing reads is a scroll the affordance cannot
1322+ /// follow.
1323+ lanes_scroll: ScrollHandle,
1324+ inspector_scroll: ScrollHandle,
1318 /// The export options card is up: what the export action opens now, so1325 /// The export options card is up: what the export action opens now, so
1319 /// nothing is written until the card's own button says so. One card at a1326 /// nothing is written until the card's own button says so. One card at a
1320 /// time -- opening either closes the other, since both are the whole window1327 /// time -- opening either closes the other, since both are the whole window
@@ -8341,6 +8348,35 @@ fn lanes_h(lanes: usize) -> f32 {
8341 }8348 }
8342 }8349 }
8343 8350
8351+/// How many whole lane rows a box this tall shows. At least one: a box too
8352+/// short for a single lane still shows part of one, and "0 shown" would count
8353+/// every lane there is as hidden.
8354+fn lanes_shown(box_h: f32) -> usize {
8355+ (((box_h + 8.) / (LANE_H + 8.)).floor() as usize).max(1)
8356+}
8357+
8358+/// How many rows are still below the fold *now*: the count the affordance says
8359+/// out loud, and the reason it is a function of the scroll rather than of the
8360+/// lane count alone. A line that keeps saying "2 more tracks below" after the
8361+/// user has scrolled to the last one is a line that has stopped being true, and
8362+/// an affordance nobody can make go away is read as a bug rather than as an
8363+/// instruction.
8364+///
8365+/// `scrolled` is how far down the column has been taken, in pixels. Rounded to
8366+/// the nearest row: a half-scrolled row is showing, so it is not below.
8367+fn rows_below(total: usize, box_h: f32, scrolled: f32) -> usize {
8368+ let past = ((scrolled / (LANE_H + 8.)).round().max(0.)) as usize;
8369+ total.saturating_sub(past + lanes_shown(box_h))
8370+}
8371+
8372+/// The same question for a column whose rows are not one height -- the
8373+/// inspector's sections -- answered in pixels off what the scroll itself
8374+/// reports: how far it may still be taken (`max_offset`) less how far it has
8375+/// been (`offset`, which gpui keeps negative going down).
8376+fn px_below(max_offset_h: f32, offset_y: f32) -> f32 {
8377+ (max_offset_h + offset_y).max(0.)
8378+}
8379+
8344 /// What the subtitle strip adds to the panel: its own row and the panel's gap8380 /// What the subtitle strip adds to the panel: its own row and the panel's gap
8345 /// above it, and nothing at all for a timeline with no subtitles on it -- the8381 /// above it, and nothing at all for a timeline with no subtitles on it -- the
8346 /// picture does not pay for a strip that is not drawn.8382 /// picture does not pay for a strip that is not drawn.
@@ -9556,7 +9592,8 @@ mod tests {
9556 marked, menu_at, menu_items, menu_rows_h, next_audio_kbps, next_container, normalise, nothing_to_play, panel_h, project_path,9592 marked, menu_at, menu_items, menu_rows_h, next_audio_kbps, next_container, normalise, nothing_to_play, panel_h, project_path,
9557 retarget, row_enable, row_items, scrub_due, secs_label, show_label, silence_rate, size_label, snap_cue, snap_marks, snapped,9593 retarget, row_enable, row_items, scrub_due, secs_label, show_label, silence_rate, size_label, snap_cue, snap_marks, snapped,
9558 SUB_PLAN_CHARS, source_tint, span_partner, speed_at, sub_pick_after_removal, subtitle_plan, summary_head, summary_tail, timecode, transport,9594 SUB_PLAN_CHARS, source_tint, span_partner, speed_at, sub_pick_after_removal, subtitle_plan, summary_head, summary_tail, timecode, transport,
9559- EXPORT_DONE, NOTICES_MAX, STATUS_ERROR, STATUS_SUCCESS, STATUS_WARNING, notice_tone,9595+ EXPORT_DONE, NOTICES_MAX, STATUS_ERROR, TIMELINE_FIXED_H, TIMELINE_SHARE, lanes_shown,
9596+ px_below, rows_below, STATUS_SUCCESS, STATUS_WARNING, notice_tone,
9560 push_notice, typed, unseen_paths, unseen_sources,9597 push_notice, typed, unseen_paths, unseen_sources,
9561 whole_take, window_title,9598 whole_take, window_title,
9562 };9599 };
@@ -14327,6 +14364,46 @@ mod tests {
14327 assert!(stray.is_empty(), "colour written outside the theme: {stray:?}");14364 assert!(stray.is_empty(), "colour written outside the theme: {stray:?}");
14328 }14365 }
14329 14366
14367+ /// "It scrolls" is not "it can be found": at the 640x360 floor the timeline
14368+ /// takes its share and no more, so a third track is behind a scroll -- and
14369+ /// the line that says so has to keep telling the truth *while* the column is
14370+ /// being scrolled, or it is an instruction nobody can carry out.
14371+ #[test]
14372+ fn the_line_about_what_is_below_the_fold_counts_what_is_still_below_it() {
14373+ // The timeline is a region and not the window: its chrome and one whole
14374+ // lane fit the share it may take at the floor.
14375+ let floor = 360. * TIMELINE_SHARE;
14376+ assert!(
14377+ TIMELINE_FIXED_H + LANE_H <= floor,
14378+ "{TIMELINE_FIXED_H} px of chrome and a lane will not fit {floor} px"
14379+ );
14380+ // What is left over is measured in whole lanes, at least one.
14381+ assert_eq!(lanes_shown(LANE_H), 1);
14382+ assert_eq!(lanes_shown(LANE_H - 10.), 1);
14383+ assert_eq!(lanes_shown(2. * LANE_H + 8.), 2);
14384+
14385+ // Four tracks in a two-lane box: two are below, and each row scrolled
14386+ // past takes one off that count until none is left. This is the bug the
14387+ // graft fixes -- the count used to be `total - shown` forever, so the
14388+ // line still said "2 more below" with the last track on screen.
14389+ let box_h = 2. * LANE_H + 8.;
14390+ assert_eq!(rows_below(4, box_h, 0.), 2);
14391+ assert_eq!(rows_below(4, box_h, LANE_H + 8.), 1);
14392+ assert_eq!(rows_below(4, box_h, 2. * (LANE_H + 8.)), 0);
14393+ // Past the end (gpui clamps, but the arithmetic must not wrap).
14394+ assert_eq!(rows_below(4, box_h, 900.), 0);
14395+ // A project that fits says nothing at all.
14396+ assert_eq!(rows_below(2, box_h, 0.), 0);
14397+
14398+ // The inspector's rows are not one height, so its own line is measured
14399+ // in pixels off the scroll instead: gpui keeps the offset negative going
14400+ // down, and at the bottom the two cancel out exactly.
14401+ assert_eq!(px_below(120., 0.), 120.);
14402+ assert_eq!(px_below(120., -40.), 80.);
14403+ assert_eq!(px_below(120., -120.), 0.);
14404+ assert_eq!(px_below(0., 0.), 0.);
14405+ }
14406+
14330 /// The failure a user never learns about is the one that was answered by14407 /// The failure a user never learns about is the one that was answered by
14331 /// another failure: two imports failing back to back are two messages, in14408 /// another failure: two imports failing back to back are two messages, in
14332 /// the order they happened, and the second does not overwrite the first14409 /// the order they happened, and the second does not overwrite the first
@@ -15419,6 +15496,8 @@ fn main() {
15419 keys_open: false,15496 keys_open: false,
15420 keys_search: String::new(),15497 keys_search: String::new(),
15421 keys_scroll: ScrollHandle::new(),15498 keys_scroll: ScrollHandle::new(),
15499+ lanes_scroll: ScrollHandle::new(),
15500+ inspector_scroll: ScrollHandle::new(),
15422 export_open: false,15501 export_open: false,
15423 export_grouped: true,15502 export_grouped: true,
15424 export_refusals_inline: false,15503 export_refusals_inline: false,
crates/app/src/ui/inspector.rsmodified+32 -0
@@ -21,6 +21,17 @@ impl Player {
21 // The cards measure themselves against the room they are given, and the21 // The cards measure themselves against the room they are given, and the
22 // room they are given is this column -- not the window.22 // room they are given is this column -- not the window.
23 let room = size(px(width), viewport.height);23 let room = size(px(width), viewport.height);
24+ // The same affordance the lanes carry, on the column that needs it for
25+ // the same reason: at the 640x360 floor the project section is below the
26+ // fold, and a section nobody knows is there is a section that is not
27+ // there. Rows here are not a fixed height, so the column is asked how
28+ // far it can still be taken rather than counted -- and it answers with
29+ // the previous frame's layout, which is what makes the line live.
30+ let can_scroll = f32::from(self.inspector_scroll.max_offset().height) > 1.;
31+ let below = px_below(
32+ f32::from(self.inspector_scroll.max_offset().height),
33+ f32::from(self.inspector_scroll.offset().y),
34+ );
24 div()35 div()
25 .id("inspector")36 .id("inspector")
26 .flex_none()37 .flex_none()
@@ -41,6 +52,7 @@ impl Player {
41 .flex_1()52 .flex_1()
42 .min_h(px(0.))53 .min_h(px(0.))
43 .overflow_y_scroll()54 .overflow_y_scroll()
55+ .track_scroll(&self.inspector_scroll)
44 .flex()56 .flex()
45 .flex_col()57 .flex_col()
46 .gap(px(8.))58 .gap(px(8.))
@@ -48,6 +60,26 @@ impl Player {
48 .child(self.selection_section(cx))60 .child(self.selection_section(cx))
49 .child(self.project_section(cx)),61 .child(self.project_section(cx)),
50 )62 )
63+ .when(can_scroll, |d| {
64+ d.child(
65+ div()
66+ .flex_none()
67+ .h(px(LABEL_H))
68+ .flex()
69+ .items_center()
70+ .justify_end()
71+ .px(px(8.))
72+ .text_size(px(10.))
73+ .text_color(rgb(match below > 1. {
74+ true => ACCENT_PRIMARY,
75+ false => FG_SECONDARY,
76+ }))
77+ .child(match below > 1. {
78+ true => "more below — scroll the inspector",
79+ false => "the end — scroll up for the rest",
80+ }),
81+ )
82+ })
51 .children(self.eq_card(room, cx))83 .children(self.eq_card(room, cx))
52 .children(self.color_card(cx))84 .children(self.color_card(cx))
53 .children(self.speed_card(cx))85 .children(self.speed_card(cx))
crates/app/src/ui/timeline.rsmodified+44 -1
@@ -99,12 +99,28 @@ impl Player {
99 filled,99 filled,
100 )100 )
101 };101 };
102+ // What the region got, and what is left inside it for the lanes: the
103+ // number a scroll is measured against, and the one the affordance below
104+ // counts with. The line it costs is taken off the box before the count,
105+ // or the row that says "1 more" would be the row hiding it.
106+ let region_h = (timeline_h(lanes.len()) + strip_h).min(viewport_h * TIMELINE_SHARE);
107+ let lanes_box = (region_h - TIMELINE_FIXED_H - strip_h).max(LANE_H);
108+ let overflows = lanes.len() > lanes_shown(lanes_box);
109+ let lanes_box = match overflows {
110+ true => (lanes_box - LABEL_H - 8.).max(LANE_H),
111+ false => lanes_box,
112+ };
113+ // Live, not a count of the lanes: the column reports where it has been
114+ // taken to, so the line empties itself as the last track comes up
115+ // instead of insisting there is still something below.
116+ let scrolled = -f32::from(self.lanes_scroll.offset().y);
117+ let below = rows_below(lanes.len(), lanes_box, scrolled);
102 div()118 div()
103 .flex_none()119 .flex_none()
104 // Never more than its share of a short window: the lane column120 // Never more than its share of a short window: the lane column
105 // scrolls inside whatever it gets, and a timeline that pushes the121 // scrolls inside whatever it gets, and a timeline that pushes the
106 // picture off the screen at the 640x360 floor is not a timeline.122 // picture off the screen at the 640x360 floor is not a timeline.
107- .h(px((timeline_h(lanes.len()) + strip_h).min(viewport_h * TIMELINE_SHARE)))123+ .h(px(region_h))
108 .flex()124 .flex()
109 .flex_col()125 .flex_col()
110 .gap(px(8.))126 .gap(px(8.))
@@ -242,8 +258,35 @@ impl Player {
242 .gap(px(8.))258 .gap(px(8.))
243 .max_h(px(lanes_h(LANES_MAX)))259 .max_h(px(lanes_h(LANES_MAX)))
244 .overflow_y_scroll()260 .overflow_y_scroll()
261+ .track_scroll(&self.lanes_scroll)
245 .children(rows),262 .children(rows),
246 )263 )
264+ // "It scrolls" is not "it can be found": when the region is too
265+ // short for every track -- which is what the 640x360 floor does to a
266+ // three-track project -- the lanes below the fold say so, in the one
267+ // place the eye is already looking. Its own flex_none row under a
268+ // flex_1 column, so the thing announcing the overflow cannot be the
269+ // thing the overflow pushes off the window.
270+ .when(overflows, |d| {
271+ d.child(
272+ div()
273+ .flex_none()
274+ .h(px(LABEL_H))
275+ .flex()
276+ .items_center()
277+ .justify_end()
278+ .text_size(px(10.))
279+ .text_color(rgb(match below {
280+ 0 => FG_SECONDARY,
281+ _ => ACCENT_PRIMARY,
282+ }))
283+ .child(match below {
284+ 0 => "the last track — scroll up for the rest".to_string(),
285+ 1 => "1 more track below — scroll the lanes".to_string(),
286+ n => format!("{n} more tracks below — scroll the lanes"),
287+ }),
288+ )
289+ })
247 // Under the tracks and outside their scrolling column: a subtitle is290 // Under the tracks and outside their scrolling column: a subtitle is
248 // not a track -- nothing can be dropped on it and nothing dragged291 // not a track -- nothing can be dropped on it and nothing dragged
249 // along it -- and a strip that scrolled away with the sixth lane292 // along it -- and a strip that scrolled away with the sixth lane