diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index 22efd7f..51505b2 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -3055,3 +3055,157 @@ fn the_ruler_plate_shows_the_timecode_only_while_a_scrub_is_live() { "the ticks still lose the plate's width at rest" ); } + + +/// The band overflowed its own column at 1280x720 (`$EDITH_HITMAP`: +/// `action.Export x=1113 w=80` with the column ending at x=995, the contact +/// strip measured `w=0`), so the Export chip was invisible under the dock and +/// a click on blank dock space at (1130,435) opened the export card. Three +/// things hold that shut: the row clips itself, the strip keeps a floor, and +/// the ladder sheds groups above it. +#[test] +fn the_time_band_never_paints_outside_its_own_column() { + let src = src_text("ui/timeband_stance.rs"); + let start = src.find(r#".id("stance-time-band-row")"#).expect("the band row"); + let row = &src[start..start + src[start..].find(".child(hero_timecode(").expect("the timecode")]; + assert!( + row.contains(".overflow_hidden()"), + "the band row lets its children paint (and be clicked) under the dock: {row}" + ); + assert!( + src.contains(".min_w(px(STRIP_MIN_W))"), + "the contact strip is the flex_1 that absorbs the slack; without a floor it measures 0" + ); + assert!(crate::ui::timeband_stance::STRIP_MIN_W >= 120.); +} + +/// DESIGN §7's ladder, one layer per threshold: the four things the band is +/// *for* -- timecode, cut readout, contact strip, Export -- survive every +/// rung, and the sheddable groups go in a fixed order (chords, then the +/// monitoring cluster, then sync/loop, then the range marks), never all at +/// once. Thresholds are the measured group widths; this pins their order and +/// the 1280x720 column (939px measured, spine 56 + dock 285) landing on the +/// marks-only rung, which is what makes Export fit there (it ended at x=991 +/// inside a column ending at 995, against x=1113 under the dock before). +#[test] +fn the_band_sheds_one_layer_per_threshold_in_a_fixed_order() { + use crate::ui::timeband_stance::band_layers; + let ladder = [2000., 1300., 1100., 939., 800., 0.] + .map(|w| band_layers(w)) + .map(|l| (l.chords, l.volume, l.sync, l.marks)); + assert_eq!( + ladder, + [ + (true, true, true, true), + (false, true, true, true), + (false, false, true, true), + (false, false, false, true), + (false, false, false, false), + (false, false, false, false), + ], + "the band must drop chords, then the monitoring cluster, then sync/loop, then the marks" + ); + // Monotone: a wider band never shows less than a narrower one. + let mut prev = band_layers(0.); + for w in (0..2400).step_by(10).map(|w| w as f32) { + let now = band_layers(w); + for (a, b) in [ + (prev.chords, now.chords), + (prev.volume, now.volume), + (prev.sync, now.sync), + (prev.marks, now.marks), + ] { + assert!(b || !a, "layer came back off at {w}px"); + } + prev = now; + } +} + +/// Every door in this band is at least `HIT_MIN` wide and tall (WCAG 2.5.8). +/// The hitmap read `SetIn w=8`, `VolumeDown w=12`, `Loop w=13`, `SetOut w=15`, +/// `Prev/NextSyncPoint w=16` before this: padding on the shared `ghost`, not a +/// bigger glyph. +#[test] +fn every_ghost_in_the_time_band_carries_a_full_hit_area() { + let src = src_text("ui/timeband_stance.rs"); + let start = src.find("fn ghost(").expect("the band's ghost"); + let ghost = &src[start..start + src[start..].find(".child(glyph.into())").expect("its glyph")]; + for needle in [".min_w(px(HIT_MIN))", ".min_h(px(HIT_MIN))"] { + assert!(ghost.contains(needle), "the band's ghost lost {needle}: {ghost}"); + } + assert!(HIT_MIN >= 24.); +} + +/// Mute wore `"{volume}%"` as its glyph while the slider beside it drew the +/// same value: one number, two places, and a toggle with no verb of its own. +/// The level is a mono readout beside the slider now, once. +#[test] +fn the_level_is_written_once_and_mute_wears_a_glyph() { + let src = src_text("ui/timeband_stance.rs"); + assert_eq!( + src.matches(r#"player.volume.percent()"#).count(), + 1, + "the volume level must be written in exactly one place in the band" + ); + assert!( + src.contains(r#"if player.volume.muted { "◁×" } else { "◁))" }"#), + "mute must wear a speaker glyph, struck when muted" + ); + assert!(src.contains("fn volume_readout("), "the level readout is the one place it is written"); +} + +/// `Play` and `StepForward` drew the same solid right-triangle: two verbs one +/// shape, told apart only by their chords. Step wears the frame-step pair. +#[test] +fn transport_verbs_differ_by_shape_not_only_by_chord() { + let src = src_text("ui/timeband_stance.rs"); + let glyph = |action: &str| { + let at = src.find(&format!("ActionId::{action},")).expect("the call"); + src[..at].rsplit('"').nth(1).expect("its glyph").to_string() + }; + let shapes = ["Play", "StepBack", "StepForward", "JumpBack", "JumpForward"].map(glyph); + let mut seen = shapes.to_vec(); + seen.sort(); + seen.dedup(); + assert_eq!(seen.len(), shapes.len(), "two transport verbs share one glyph: {shapes:?}"); +} + +/// DESIGN §6: "the cut readout is the odometer". Keyed off the selection it +/// read `cut —/—` immediately after a split -- two clips on the bench, the +/// playhead resting on the new cut, nothing picked. It reads the playhead +/// now: the cut under it, else the next one ahead, else the selection. +#[test] +fn the_cut_readout_counts_from_the_playhead() { + use crate::ui::timeband_stance::odometer_cut; + let at = |start: u32, len: u32| Clip { + fade_in: 0, + fade_out: 0, + transition_out: 0, + start, + in_frame: 0, + out_frame: len, + source: 0, + link: None, + eq: None, + color: None, + transform: None, + fit: FitPolicy::Fit, + speed: Speed::NORMAL, + }; + let lane = [at(0, 30), at(30, 30)]; + assert_eq!(odometer_cut(&lane, 0), Some(0)); + assert_eq!(odometer_cut(&lane, 29), Some(0)); + // The split's own frame: the playhead rests on the SECOND cut's head. + assert_eq!(odometer_cut(&lane, 30), Some(1)); + assert_eq!(odometer_cut(&lane, 59), Some(1)); + // Past the last cut there is nothing to count -- the selection answers. + assert_eq!(odometer_cut(&lane, 60), None); + // In a gap: the next cut ahead of the playhead. + let gapped = [at(0, 10), at(40, 10)]; + assert_eq!(odometer_cut(&gapped, 20), Some(1)); + assert_eq!(odometer_cut(&[], 0), None); + assert!( + src_text("ui/timeband_stance.rs").contains("odometer_cut(s.lane_clips(lane), frame)"), + "the readout must derive its odometer from the playhead" + ); +} diff --git a/crates/app/src/ui/timeband_stance.rs b/crates/app/src/ui/timeband_stance.rs index 2d9bff6..f1e8bc3 100644 --- a/crates/app/src/ui/timeband_stance.rs +++ b/crates/app/src/ui/timeband_stance.rs @@ -23,6 +23,92 @@ thread_local! { // fold both into `Player` once `main.rs` is free again. static STRIP_BOUNDS: Rc>> = Rc::new(Cell::new(Bounds::default())); static PAN_ANCHOR: Cell> = Cell::new(None); + /// The band row's own measured width, read by the frame after the one + /// that took it (`width_probe` asks for that frame whenever it changes). + /// This is what the degradation ladder below keys off: the band cannot + /// know its column's width any other way without a `Window` this + /// module's `render` is not handed. + static BAND_W: Rc> = Rc::new(Cell::new(px(0.))); + /// Set once per `render` from the ladder, read by `ghost` (which the + /// band's own helpers call three levels down) -- a render-scoped + /// constant rather than a parameter threaded through every call site. + static SHOW_CHORDS: Cell = const { Cell::new(true) }; +} + +/// The contact strip's floor: the flex_1 element absorbs the band's slack, +/// but a minimap narrower than this is not a map. +pub(crate) const STRIP_MIN_W: f32 = 120.; + +/// The band's own width probe, `timeline_math::height_probe`'s shape on the +/// other axis: a measurement is read by the frame after the one that took it, +/// so a change has to ask for that frame or a resize would leave the ladder +/// one layer behind until something else happened to draw. +fn width_probe(into: Rc>) -> impl IntoElement { + canvas( + move |bounds, window, _| { + // Only on a change: an unconditional request is a repaint loop. + if into.replace(bounds.size.width) != bounds.size.width { + window.request_animation_frame(); + } + }, + |_, _, _, _| (), + ) + .absolute() + .size_full() +} + +/// Which layers of the band are still drawn at a given column width +/// (DESIGN §7's ladder, one layer per threshold, never all at once). +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub(crate) struct BandLayers { + /// Chord badges under the transport glyphs. + pub(crate) chords: bool, + /// The audio-monitoring cluster (mute, -/+, slider, level readout). + pub(crate) volume: bool, + /// The sync-point pair and the loop toggle. + pub(crate) sync: bool, + /// The export-range marks (I / O / x). + pub(crate) marks: bool, +} + +/// The ladder itself. Every threshold is a MEASURED number: the band drawn +/// whole at 2560x1440 (`$EDITH_HITMAP`) reads 1246px of fixed groups beside a +/// 974px strip, and the same band at 1280x720 (chords off) reads each glyph's +/// door at its `HIT_MIN` floor. Fixed width + `STRIP_MIN_W`, rounded up to the +/// next 10px, is what each rung costs: +/// +/// | drawn | fixed | needs | +/// |----------------------------------------------|-------|--------| +/// | everything, chords under every glyph | 1246 | 1370px | +/// | chords dropped (-97px, doors keep `HIT_MIN`) | 1149 | 1270px | +/// | + monitoring cluster dropped (-256px) | 893 | 1020px | +/// | + sync pair and loop dropped (-102px) | 791 | 920px | +/// | + range marks dropped (-92px): the floor | 699 | 820px | +/// +/// The four things the band is *for* -- timecode, cut readout, contact strip +/// (>=`STRIP_MIN_W`, the flex_1 that absorbs the slack) and the Export chip -- +/// are on every rung; below the floor's own 820px there is nothing left to +/// shed and `overflow_hidden` is what keeps the rest inside the column. +/// There is no zoom group in this band (the charter's rung 2): the monitoring +/// cluster is the band's equivalent extra and takes its place. +pub(crate) fn band_layers(band_w: f32) -> BandLayers { + BandLayers { + chords: band_w >= 1370., + volume: band_w >= 1270., + sync: band_w >= 1020., + marks: band_w >= 920., + } +} + +/// The odometer's cut (DESIGN §6, "the cut readout is the odometer"): the cut +/// the playhead rests on, or -- when it rests in a gap -- the next one ahead +/// of it. `None` only when there is no cut at or after the playhead, which is +/// when the caller falls back to the selection. +pub(crate) fn odometer_cut(clips: &[Clip], frame: u32) -> Option { + clips + .iter() + .position(|c| frame >= c.start && frame < c.end()) + .or_else(|| clips.iter().position(|c| c.start > frame)) } /// A stacked ghost command (DESIGN §4, MOCK-SPEC "Ghost transport"/"spine"): @@ -66,6 +152,13 @@ fn ghost( .flex() .flex_col() .items_center() + .justify_center() + // WCAG 2.5.8, the same `HIT_MIN` floor `interact.rs` holds clip edges + // to: a glyph may be 8px wide, its door may not. Padding only -- + // glyph sizes and the groups' own gaps are untouched. + .min_w(px(HIT_MIN)) + .min_h(px(HIT_MIN)) + .px(px(2.)) .gap(px(1.)) .cursor_pointer() .on_click(cx.listener(move |this, _: &ClickEvent, window, cx| { @@ -76,13 +169,16 @@ fn ghost( .text_size(glyph_style.size) .text_color(rgb(if active { INK1() } else { INK2() })) .child(glyph.into()) - .child( - div() - .font(chord_style.font) - .text_size(chord_style.size) - .text_color(rgb(INK3())) - .child(player.keymap.chord(action)), - ) + .when(SHOW_CHORDS.with(Cell::get), |el| { + el.child( + div() + .flex_none() + .font(chord_style.font) + .text_size(chord_style.size) + .text_color(rgb(INK3())) + .child(player.keymap.chord(action)), + ) + }) } /// The hero timecode, digits `ink1` and colons `ink3` (DESIGN §3, MOCK-SPEC @@ -114,11 +210,24 @@ fn signed_delta(frames: i64, fps: f64) -> String { /// the subject cut's own trim deltas against where roll armed it (only real /// once [`Player::loop_trim`] has a baseline to measure against), and the /// roll word itself, on or dim. `·` separators in `ink3`, values in `ink2`. -fn cut_readout(player: &Player) -> impl IntoElement { +fn cut_readout(player: &Player, position: f64) -> impl IntoElement { let sep = || div().text_color(rgb(INK3())).child(" · "); let val = |s: String| div().text_color(rgb(INK2())).child(s); let anchor = player.selected.anchor(); - let odometer = anchor + // The odometer reads the PLAYHEAD, not the selection (DESIGN 6): right + // after a split the two halves are on the bench and nothing is picked, + // and a readout saying `cut -/-` while the playhead sits on the new cut + // is an odometer that stopped turning. The selection only answers when + // the playhead is off every cut on its lane. + let frame = (position * player.active_fps()).max(0.).round() as u32; + let at_playhead = player.session.as_ref().and_then(|s| { + let lane = anchor + .map(|(lane, _)| lane) + .or_else(|| s.lanes().into_iter().find(|l| l.kind == LaneKind::Video))?; + Some((lane, odometer_cut(s.lane_clips(lane), frame)?)) + }); + let odometer = at_playhead + .or(anchor) .and_then(|(lane, idx)| { player .session @@ -285,7 +394,10 @@ fn contact_strip(player: &Player, position: f64, cx: &mut Context) -> im .id("stance-contact-strip") .relative() .flex_1() - .min_w(px(0.)) + // The strip is what absorbs the band's slack, and it measured w=0 at + // 1280 before this: it holds a floor now and the ladder sheds groups + // above it instead of squeezing the map to nothing. + .min_w(px(STRIP_MIN_W)) .h(px(28.)) .cursor_pointer() .tooltip(|_, cx| { @@ -570,6 +682,20 @@ fn volume_slider(player: &Player, cx: &mut Context) -> impl IntoElement ) } +/// The level, written once (DESIGN 3: a number about a level is mono). It +/// sits beside the slider that sets it -- the slider's fill and this readout +/// are one truth in two forms, where the mute button used to wear a third. +fn volume_readout(player: &Player) -> impl IntoElement { + let style = mono(type_scale::CHORD_METADATA_MAX_PX, FontWeight::MEDIUM); + div() + .flex_none() + .w(px(34.)) + .font(style.font) + .text_size(style.size) + .text_color(rgb(if player.volume.muted { INK3() } else { INK2() })) + .child(format!("{}%", player.volume.percent())) +} + /// The whole band, left to right per MOCK-SPEC: hero timecode, ghost /// transport, cut readout, the contact strip filling the rest, the Export /// chip at the end. @@ -579,6 +705,12 @@ pub(crate) fn render( cx: &mut Context, ) -> impl IntoElement { let tc = timecode(position, player.active_fps()); + let band_w = BAND_W.with(Rc::clone); + // Layer decision for THIS frame, off the width the last frame measured + // (`width_probe` asks for a frame whenever that width changes, so a + // resize settles in one). + let layers = band_layers(f32::from(band_w.get())); + SHOW_CHORDS.with(|c| c.set(layers.chords)); div() .id("stance-time-band-row") // FAULT 1 fix: this div used to be `flex_none`, which sized it to its @@ -591,8 +723,13 @@ pub(crate) fn render( .h_full() .flex() .items_center() - .gap(px(16.)) + // Nothing in this band may ever paint (or be clicked) outside its own + // column again: the Export chip used to land at x=1113 under the + // dock, where a click on blank dock space opened the export card. + .overflow_hidden() + .gap(px(12.)) .px(px(12.)) + .child(width_probe(band_w)) // The most-read element anchors its region (DESIGN §5): the // timecode leads. .child(hero_timecode(&tc)) @@ -647,7 +784,7 @@ pub(crate) fn render( .child(ghost( "stance-tb-step-back", player, - "◀", + "|◂", ActionId::StepBack, false, cx, @@ -655,7 +792,7 @@ pub(crate) fn render( .child(ghost( "stance-tb-step-forward", player, - "▶", + "▸|", ActionId::StepForward, false, cx, @@ -676,36 +813,40 @@ pub(crate) fn render( false, cx, )) - .child(ghost( - "stance-tb-sync-prev", - player, - "‹|", - ActionId::PrevSyncPoint, - false, - cx, - )) - .child(ghost( - "stance-tb-sync-next", - player, - "|›", - ActionId::NextSyncPoint, - false, - cx, - )) + .when(layers.sync, |el| { + el.child(ghost( + "stance-tb-sync-prev", + player, + "‹|", + ActionId::PrevSyncPoint, + false, + cx, + )) + .child(ghost( + "stance-tb-sync-next", + player, + "|›", + ActionId::NextSyncPoint, + false, + cx, + )) + }) // Loop (homeless per this task's audit): the playback-loop // toggle -- burst-use during editing per the charter's own // classification -- earns the transport cluster it plays // alongside, not the CUT group's `LoopTrim` two files over // (a different verb already drawn on the spine, "↻" taken). // "∞" reads as "keeps going" without borrowing that glyph. - .child(ghost( - "stance-tb-loop", - player, - "∞", - ActionId::Loop, - player.loop_on, - cx, - )), + .when(layers.sync, |el| { + el.child(ghost( + "stance-tb-loop", + player, + "∞", + ActionId::Loop, + player.loop_on, + cx, + )) + }), ) // The audio-monitoring cluster (homeless per this task's audit): // ToggleMute/VolumeUp/VolumeDown, burst-use per the charter, placed @@ -717,7 +858,7 @@ pub(crate) fn render( // mute and the two ghosts flanking it nudge the level -- three // homeless actions sharing one cluster rather than three unrelated // rows. - .child( + .when(layers.volume, |el| el.child( div() .flex_none() .flex() @@ -731,19 +872,22 @@ pub(crate) fn render( false, cx, )) + // The level is NOT this button's label any more: the slider + // beside it already draws the same number as a fill and + // `volume_readout` writes it once, so wearing it here made + // mute a ghost with no glyph of its own (a percentage is not + // a verb). Speaker, struck when muted -- typographic, the + // same hand-drawn grammar as the glyphs around it. .child(ghost( "stance-tb-mute", player, - if player.volume.muted { - format!("× {}%", player.volume.percent()) - } else { - format!("{}%", player.volume.percent()) - }, + if player.volume.muted { "◁×" } else { "◁))" }, ActionId::ToggleMute, player.volume.muted, cx, )) .child(volume_slider(player, cx)) + .child(volume_readout(player)) .child(ghost( "stance-tb-vol-up", player, @@ -752,9 +896,9 @@ pub(crate) fn render( false, cx, )), - ) - .child(range_marks(player, cx)) - .child(cut_readout(player)) + )) + .when(layers.marks, |el| el.child(range_marks(player, cx))) + .child(cut_readout(player, position)) .child(contact_strip(player, position, cx)) .child(save_verb(player, cx)) .child(export_chip(player, cx))