diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 29fa904..b303682 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -1315,6 +1315,13 @@ struct Player { /// and the rows past the fold have to be reachable from the keyboard that /// is already typing in the search box. keys_scroll: ScrollHandle, + /// Where the lane column and the inspector's rows have been taken to. Read + /// back at render, not only written by the wheel: the line each of them + /// carries about what is below the fold is a count of what is *still* below + /// it, and a scroll that nothing reads is a scroll the affordance cannot + /// follow. + lanes_scroll: ScrollHandle, + inspector_scroll: ScrollHandle, /// The export options card is up: what the export action opens now, so /// nothing is written until the card's own button says so. One card at a /// time -- opening either closes the other, since both are the whole window @@ -8341,6 +8348,35 @@ fn lanes_h(lanes: usize) -> f32 { } } +/// How many whole lane rows a box this tall shows. At least one: a box too +/// short for a single lane still shows part of one, and "0 shown" would count +/// every lane there is as hidden. +fn lanes_shown(box_h: f32) -> usize { + (((box_h + 8.) / (LANE_H + 8.)).floor() as usize).max(1) +} + +/// How many rows are still below the fold *now*: the count the affordance says +/// out loud, and the reason it is a function of the scroll rather than of the +/// lane count alone. A line that keeps saying "2 more tracks below" after the +/// user has scrolled to the last one is a line that has stopped being true, and +/// an affordance nobody can make go away is read as a bug rather than as an +/// instruction. +/// +/// `scrolled` is how far down the column has been taken, in pixels. Rounded to +/// the nearest row: a half-scrolled row is showing, so it is not below. +fn rows_below(total: usize, box_h: f32, scrolled: f32) -> usize { + let past = ((scrolled / (LANE_H + 8.)).round().max(0.)) as usize; + total.saturating_sub(past + lanes_shown(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 +/// been (`offset`, which gpui keeps negative going down). +fn px_below(max_offset_h: f32, offset_y: f32) -> f32 { + (max_offset_h + offset_y).max(0.) +} + /// What the subtitle strip adds to the panel: its own row and the panel's gap /// above it, and nothing at all for a timeline with no subtitles on it -- the /// picture does not pay for a strip that is not drawn. @@ -9556,7 +9592,8 @@ mod tests { marked, menu_at, menu_items, menu_rows_h, next_audio_kbps, next_container, normalise, nothing_to_play, panel_h, project_path, retarget, row_enable, row_items, scrub_due, secs_label, show_label, silence_rate, size_label, snap_cue, snap_marks, snapped, SUB_PLAN_CHARS, source_tint, span_partner, speed_at, sub_pick_after_removal, subtitle_plan, summary_head, summary_tail, timecode, transport, - EXPORT_DONE, NOTICES_MAX, STATUS_ERROR, STATUS_SUCCESS, STATUS_WARNING, notice_tone, + EXPORT_DONE, NOTICES_MAX, STATUS_ERROR, TIMELINE_FIXED_H, TIMELINE_SHARE, lanes_shown, + px_below, rows_below, STATUS_SUCCESS, STATUS_WARNING, notice_tone, push_notice, typed, unseen_paths, unseen_sources, whole_take, window_title, }; @@ -14327,6 +14364,46 @@ mod tests { assert!(stray.is_empty(), "colour written outside the theme: {stray:?}"); } + /// "It scrolls" is not "it can be found": at the 640x360 floor the timeline + /// takes its share and no more, so a third track is behind a scroll -- and + /// the line that says so has to keep telling the truth *while* the column is + /// being scrolled, or it is an instruction nobody can carry out. + #[test] + fn the_line_about_what_is_below_the_fold_counts_what_is_still_below_it() { + // The timeline is a region and not the window: its chrome and one whole + // lane fit the share it may take at the floor. + let floor = 360. * TIMELINE_SHARE; + assert!( + TIMELINE_FIXED_H + LANE_H <= floor, + "{TIMELINE_FIXED_H} px of chrome and a lane will not fit {floor} px" + ); + // What is left over is measured in whole lanes, at least one. + assert_eq!(lanes_shown(LANE_H), 1); + assert_eq!(lanes_shown(LANE_H - 10.), 1); + assert_eq!(lanes_shown(2. * LANE_H + 8.), 2); + + // Four tracks in a two-lane box: two are below, and each row scrolled + // past takes one off that count until none is left. This is the bug the + // graft fixes -- the count used to be `total - shown` forever, so the + // line still said "2 more below" with the last track on screen. + let box_h = 2. * LANE_H + 8.; + assert_eq!(rows_below(4, box_h, 0.), 2); + assert_eq!(rows_below(4, box_h, LANE_H + 8.), 1); + assert_eq!(rows_below(4, box_h, 2. * (LANE_H + 8.)), 0); + // Past the end (gpui clamps, but the arithmetic must not wrap). + assert_eq!(rows_below(4, box_h, 900.), 0); + // A project that fits says nothing at all. + assert_eq!(rows_below(2, box_h, 0.), 0); + + // 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. + assert_eq!(px_below(120., 0.), 120.); + assert_eq!(px_below(120., -40.), 80.); + assert_eq!(px_below(120., -120.), 0.); + assert_eq!(px_below(0., 0.), 0.); + } + /// The failure a user never learns about is the one that was answered by /// another failure: two imports failing back to back are two messages, in /// the order they happened, and the second does not overwrite the first @@ -15419,6 +15496,8 @@ fn main() { keys_open: false, keys_search: String::new(), keys_scroll: ScrollHandle::new(), + lanes_scroll: ScrollHandle::new(), + inspector_scroll: ScrollHandle::new(), export_open: false, export_grouped: true, export_refusals_inline: false, diff --git a/crates/app/src/ui/inspector.rs b/crates/app/src/ui/inspector.rs index 0d10372..16c7cfd 100644 --- a/crates/app/src/ui/inspector.rs +++ b/crates/app/src/ui/inspector.rs @@ -21,6 +21,17 @@ impl Player { // The cards measure themselves against the room they are given, and the // room they are given is this column -- not the window. let room = size(px(width), viewport.height); + // The same affordance the lanes carry, on the column that needs it for + // the same reason: at the 640x360 floor the project section is below the + // fold, and a section nobody knows is there is a section that is not + // there. Rows here are not a fixed height, so the column is asked how + // far it can still be taken rather than counted -- and it answers with + // the previous frame's layout, which is what makes the line live. + let can_scroll = f32::from(self.inspector_scroll.max_offset().height) > 1.; + let below = px_below( + f32::from(self.inspector_scroll.max_offset().height), + f32::from(self.inspector_scroll.offset().y), + ); div() .id("inspector") .flex_none() @@ -41,6 +52,7 @@ impl Player { .flex_1() .min_h(px(0.)) .overflow_y_scroll() + .track_scroll(&self.inspector_scroll) .flex() .flex_col() .gap(px(8.)) @@ -48,6 +60,26 @@ impl Player { .child(self.selection_section(cx)) .child(self.project_section(cx)), ) + .when(can_scroll, |d| { + d.child( + div() + .flex_none() + .h(px(LABEL_H)) + .flex() + .items_center() + .justify_end() + .px(px(8.)) + .text_size(px(10.)) + .text_color(rgb(match below > 1. { + true => ACCENT_PRIMARY, + false => FG_SECONDARY, + })) + .child(match below > 1. { + true => "more below — scroll the inspector", + false => "the end — scroll up for the rest", + }), + ) + }) .children(self.eq_card(room, cx)) .children(self.color_card(cx)) .children(self.speed_card(cx)) diff --git a/crates/app/src/ui/timeline.rs b/crates/app/src/ui/timeline.rs index c8dc055..d85c2b0 100644 --- a/crates/app/src/ui/timeline.rs +++ b/crates/app/src/ui/timeline.rs @@ -99,12 +99,28 @@ impl Player { filled, ) }; + // What the region got, and what is left inside it for the lanes: the + // number a scroll is measured against, and the one the affordance below + // counts with. The line it costs is taken off the box before the count, + // or the row that says "1 more" would be the row hiding it. + let region_h = (timeline_h(lanes.len()) + strip_h).min(viewport_h * TIMELINE_SHARE); + let lanes_box = (region_h - TIMELINE_FIXED_H - strip_h).max(LANE_H); + let overflows = lanes.len() > lanes_shown(lanes_box); + let lanes_box = match overflows { + true => (lanes_box - LABEL_H - 8.).max(LANE_H), + false => lanes_box, + }; + // Live, not a count of the lanes: the column reports where it has been + // taken to, so the line empties itself as the last track comes up + // instead of insisting there is still something below. + let scrolled = -f32::from(self.lanes_scroll.offset().y); + let below = rows_below(lanes.len(), lanes_box, scrolled); div() .flex_none() // Never more than its share of a short window: the lane column // scrolls inside whatever it gets, and a timeline that pushes the // picture off the screen at the 640x360 floor is not a timeline. - .h(px((timeline_h(lanes.len()) + strip_h).min(viewport_h * TIMELINE_SHARE))) + .h(px(region_h)) .flex() .flex_col() .gap(px(8.)) @@ -242,8 +258,35 @@ impl Player { .gap(px(8.)) .max_h(px(lanes_h(LANES_MAX))) .overflow_y_scroll() + .track_scroll(&self.lanes_scroll) .children(rows), ) + // "It scrolls" is not "it can be found": when the region is too + // short for every track -- which is what the 640x360 floor does to a + // three-track project -- the lanes below the fold say so, in the one + // place the eye is already looking. Its own flex_none row under a + // flex_1 column, so the thing announcing the overflow cannot be the + // thing the overflow pushes off the window. + .when(overflows, |d| { + d.child( + div() + .flex_none() + .h(px(LABEL_H)) + .flex() + .items_center() + .justify_end() + .text_size(px(10.)) + .text_color(rgb(match below { + 0 => FG_SECONDARY, + _ => ACCENT_PRIMARY, + })) + .child(match below { + 0 => "the last track — scroll up for the rest".to_string(), + 1 => "1 more track below — scroll the lanes".to_string(), + n => format!("{n} more tracks below — scroll the lanes"), + }), + ) + }) // Under the tracks and outside their scrolling column: a subtitle is // not a track -- nothing can be dropped on it and nothing dragged // along it -- and a strip that scrolled away with the sixth lane