diff --git a/crates/app/src/ui/dock_stance.rs b/crates/app/src/ui/dock_stance.rs index 15de432..013adc8 100644 --- a/crates/app/src/ui/dock_stance.rs +++ b/crates/app/src/ui/dock_stance.rs @@ -468,9 +468,15 @@ fn sources_tab(player: &Player, cx: &mut Context) -> impl IntoElement { )), ) .child({ - let style = mono(9., FontWeight::MEDIUM); + // FAULT 2: metadata, not a row -- DESIGN §3's 9.5-10px band via + // the named constant (a bespoke 9px literal was neither the + // metadata size nor any other named role), and the quietest text + // in the dock: ink3, tight leading so it never competes with the + // 10.5px source rows above it. + let style = mono(type_scale::CHORD_METADATA_MIN_PX, FontWeight::MEDIUM); div() .flex_none() + .line_height(relative(1.25)) .font(style.font) .text_size(style.size) .text_color(rgb(INK3())) diff --git a/crates/app/src/ui/spine_stance.rs b/crates/app/src/ui/spine_stance.rs index 0264e84..e44b938 100644 --- a/crates/app/src/ui/spine_stance.rs +++ b/crates/app/src/ui/spine_stance.rs @@ -21,7 +21,8 @@ const GLYPH_SIZE: f32 = 13.; fn group_head(label: &str) -> impl IntoElement { div() .flex_none() - .pt(px(10.)) + .pt(px(6.)) + .line_height(relative(1.1)) .type_style(type_scale::head()) .text_color(rgb(INK3())) .child(label.to_uppercase()) @@ -63,26 +64,30 @@ fn glyph( .items_center() .gap(px(1.)) .px(px(4.)) - .py(px(2.)) + .py(px(1.)) .rounded(px(3.)) .when(active, |d| d.bg(rgb(DARK_RAISED()))) .tooltip(move |_, cx| cx.new(|_| Tip(say.clone())).into()) .when(!on, |d| d.opacity(0.4).cursor_not_allowed()) .when(on, |d| { d.cursor_pointer() - .hover(|s| s.bg(rgb(DARK_RAISED()))) + .hover(|s| s.bg(rgb(DARK_RAISED())).text_color(rgb(INK1()))) .on_click(cx.listener(move |this, _: &ClickEvent, window, cx| { this.act(action, window, cx) })) }) .child( div() - .type_style(type_scale::label(GLYPH_SIZE, gpui::FontWeight::MEDIUM)) + .line_height(relative(1.05)) + // FAULT 1: the glyph is the loudest thing in its row -- BOLD, + // not the MEDIUM weight the chord beneath it also wears. + .type_style(type_scale::label(GLYPH_SIZE, gpui::FontWeight::BOLD)) .text_color(rgb(if active { INK1() } else { INK2() })) .child(glyph), ) .child( div() + .line_height(relative(1.05)) .type_style(type_scale::mono( type_scale::CHORD_METADATA_MIN_PX, gpui::FontWeight::MEDIUM, @@ -92,6 +97,74 @@ fn glyph( ) } +/// The trim control (MOCK-SPEC "Spine"): one row read as ONE control with +/// two strokes, not two identical `±1` boxes each carrying its own `[`/`]` +/// chord underneath (the shipped defect this replaces). `−1`/`+1` distinguish +/// the two strokes visually where a doubled `±1` couldn't; the chord line +/// beneath is shared and shows both strokes together (`[ ]`), the way the +/// mock's single `±1` / `[ ]` pair reads as one thing, not two. +fn trim_control(active: bool, player: &Player, cx: &mut Context) -> impl IntoElement { + let half = |id: &'static str, txt: &'static str, action: ActionId, cx: &mut Context| { + let enabled = player.enable(action, None); + let full = player.keymap.display(action); + let say: SharedString = match enabled.why() { + Some(why) => format!("{full} — {why}"), + None => format!("{full} — {}", action.label()), + } + .into(); + let on = enabled.yes(); + div() + .id(id) + .flex_none() + .px(px(2.)) + .rounded(px(3.)) + .tooltip(move |_, cx| cx.new(|_| Tip(say.clone())).into()) + .when(!on, |d| d.opacity(0.4).cursor_not_allowed()) + .when(on, |d| { + d.cursor_pointer() + .hover(|s| s.bg(rgb(DARK_RAISED())).text_color(rgb(INK1()))) + .on_click(cx.listener(move |this, _: &ClickEvent, window, cx| { + this.act(action, window, cx) + })) + }) + .child( + div() + .line_height(relative(1.05)) + .type_style(type_scale::label(GLYPH_SIZE, gpui::FontWeight::BOLD)) + .text_color(rgb(if active { INK1() } else { INK2() })) + .child(txt), + ) + }; + div() + .flex_none() + .flex() + .flex_col() + .items_center() + .gap(px(1.)) + .px(px(4.)) + .py(px(1.)) + .rounded(px(3.)) + .when(active, |d| d.bg(rgb(DARK_RAISED()))) + .child( + div() + .flex() + .items_center() + .gap(px(2.)) + .child(half("spine-trim-in", "−1", ActionId::TrimIn, cx)) + .child(half("spine-trim-out", "+1", ActionId::TrimOut, cx)), + ) + .child( + div() + .line_height(relative(1.05)) + .type_style(type_scale::mono( + type_scale::CHORD_METADATA_MIN_PX, + gpui::FontWeight::MEDIUM, + )) + .text_color(rgb(INK3())) + .child("[ ]"), + ) +} + /// Two commands side by side in one row -- the opposite-direction pairs /// (walk cuts, no-aim trim) that share a row in the mock rather than each /// eating a full row of the spine's own height. @@ -128,10 +201,12 @@ pub(crate) fn render(player: &Player, cx: &mut Context) -> impl IntoElem .flex() .flex_col() .items_center() - // FAULT 2: rows close under their group head, real space (the group + // FAULT 1: rows close under their group head, real space (the group // head's own `pt`) only between one group and the next -- not one - // uniform gap stretching every row down the window. - .gap(px(2.)) + // uniform gap stretching every row down the window. The gap itself + // is now the smallest gpui will draw (1px) rather than the 2px that + // still read as "spread" against the mock's tight top-third rail. + .gap(px(1.)) .overflow_y_scroll() .child(group_head("edit")) .child(glyph("spine-split", "||", ActionId::Cut, false, player, cx)) @@ -142,24 +217,7 @@ pub(crate) fn render(player: &Player, cx: &mut Context) -> impl IntoElem glyph("spine-cut-prev", "‹", ActionId::WalkCutPrev, false, player, cx), glyph("spine-cut-next", "›", ActionId::WalkCutNext, false, player, cx), )) - .child(pair( - glyph( - "spine-trim-in", - "±1", - ActionId::TrimIn, - player.loop_trim.is_some(), - player, - cx, - ), - glyph( - "spine-trim-out", - "±1", - ActionId::TrimOut, - player.loop_trim.is_some(), - player, - cx, - ), - )) + .child(trim_control(player.loop_trim.is_some(), player, cx)) .child(glyph( "spine-loop-trim", "↻", diff --git a/crates/app/src/ui/stance.rs b/crates/app/src/ui/stance.rs index b951550..e922af8 100644 --- a/crates/app/src/ui/stance.rs +++ b/crates/app/src/ui/stance.rs @@ -31,6 +31,93 @@ const LEDGER_H: f32 = 28.; /// Right side panel, fixed width, carrying the Src/Clip tab pair. const DOCK_W: f32 = 280.; +thread_local! { + // FAULT 3: the picture region's own laid-out box, measured each frame by + // a [`bounds_probe`] the same shape `timeband_stance`'s contact strip + // keeps (`STRIP_BOUNDS`) -- the scale plate needs the box the picture was + // fitted into, which nothing upstream of paint knows. + static PICTURE_BOUNDS: Rc>> = Rc::new(Cell::new(Bounds::default())); +} + +/// The pure half of [`picture_scale`]: given a box and the image's native +/// size, its `Contain` fit factor -- gpui's own tested `get_bounds` math +/// ([`letterboxed_image`] fits the picture the same way), not a ratio +/// reimplemented here. Split out from `picture_scale` so this arithmetic has +/// a runnable check with no `Player`/window to stand up. +fn fit_scale(bounds: Bounds, native: gpui::Size) -> Option { + if bounds.size.width <= px(0.) || bounds.size.height <= px(0.) || native.width.0 <= 0 || native.height.0 <= 0 { + return None; + } + let fitted = gpui::ObjectFit::Contain.get_bounds(bounds, native); + Some(f32::from(fitted.size.width) / native.width.0 as f32) +} + +/// The picture's own fit factor against its native size, read off the last +/// frame's measured box (see [`PICTURE_BOUNDS`]). `None` with nothing open +/// or before the first paint has measured anything. +fn picture_scale(player: &Player) -> Option { + let image = player.image.clone()?; + fit_scale(PICTURE_BOUNDS.with(Rc::clone).get(), image.size(0)) +} + +#[cfg(test)] +mod tests { + use super::*; + + /// A 400x100 source fit into a 200x100 box: width-bound (bounds_ratio + /// 2 < image_ratio 4), so the picture lands at half its native width -- + /// the number the scale plate would read as `scale 0.50`. + #[test] + fn the_scale_plate_reads_contains_own_fit_factor() { + let bounds = Bounds { + origin: point(px(0.), px(0.)), + size: size(px(200.), px(100.)), + }; + let native = size(gpui::DevicePixels(400), gpui::DevicePixels(100)); + assert!((fit_scale(bounds, native).unwrap() - 0.5).abs() < 0.001); + } + + /// A degenerate (zero-size) box never divides by zero -- it says "no + /// reading yet" instead of NaN or a panic, the same guard every other + /// `bounds_probe`-fed measurement in this file makes before its first + /// paint. + #[test] + fn an_unmeasured_box_reads_no_scale_rather_than_nan() { + let bounds = Bounds { + origin: point(px(0.), px(0.)), + size: size(px(0.), px(0.)), + }; + let native = size(gpui::DevicePixels(400), gpui::DevicePixels(100)); + assert_eq!(fit_scale(bounds, native), None); + } +} + +/// The scale plate (MOCK-SPEC.md "Screen": `scale 1.12`, label `ink3`, value +/// in ink): a readout, so a plate (DESIGN §4), never a chip. Lives in the +/// screen region's own margin row above the picture -- a flex sibling, not +/// an overlay, so it can never cover a picture pixel (§11 check 6) whatever +/// the source's aspect ratio does to the letterbox. +fn scale_plate(player: &Player) -> impl IntoElement { + let value = picture_scale(player) + .map(|s| format!("{s:.2}")) + .unwrap_or_else(|| "--".to_string()); + let style = type_scale::mono(type_scale::CHORD_METADATA_MIN_PX, gpui::FontWeight::MEDIUM); + div() + .id("stance-scale-plate") + .flex_none() + .flex() + .items_center() + .gap(px(4.)) + .px(px(6.)) + .py(px(2.)) + .rounded(px(2.)) + .bg(rgb(DARK_CANVAS())) + .font(style.font) + .text_size(style.size) + .child(div().text_color(rgb(INK3())).child("scale")) + .child(div().text_color(rgb(INK1())).child(value)) +} + /// A section head: 9px, uppercase, `ink3` -- DESIGN §3's scale for the label /// that names a region before anything else lives in it. fn section_head(label: &str) -> impl IntoElement { @@ -220,6 +307,19 @@ fn screen(player: &mut Player, position: f64, window: &mut Window, cx: &mut Cont // §4: room chrome takes 0 radius. .rounded(px(0.)) .bg(rgb(DARK_CANVAS())) + // FAULT 3: the scale plate's own margin row, above the picture -- + // a flex sibling shrinks the picture's `flex_1` to make room for it + // exactly as `two_up` already does below, so it is never drawn over + // real picture pixels. + .child( + div() + .flex_none() + .flex() + .justify_end() + .px(px(6.)) + .pt(px(4.)) + .child(scale_plate(player)), + ) .child( div() .id("stance-picture") @@ -227,7 +327,8 @@ fn screen(player: &mut Player, position: f64, window: &mut Window, cx: &mut Cont .min_h(px(0.)) .flex() .relative() - .child(player.picture_area(position, window, cx)), + .child(player.picture_area(position, window, cx)) + .child(bounds_probe(PICTURE_BOUNDS.with(Rc::clone))), ) .children(two_up) } diff --git a/crates/app/src/ui/timeband_stance.rs b/crates/app/src/ui/timeband_stance.rs index b8a8f3f..1a6c8e1 100644 --- a/crates/app/src/ui/timeband_stance.rs +++ b/crates/app/src/ui/timeband_stance.rs @@ -32,17 +32,35 @@ thread_local! { /// so a rebind can never leave the band showing a stroke that no longer /// fires it -- the same shape `stance::ghost` draws for the spine, kept local /// here so this module owns its own region end to end. -fn ghost(player: &Player, glyph: &str, action: ActionId) -> impl IntoElement { +/// +/// FAULT 2 fix: this used to read [`Keymap::display`], the full-sentence +/// form (`ctrl+left`) meant for the keys overlay's own list -- MOCK-SPEC's +/// band wants the compact badge (`J`, `spc`, `L`) the spine already reads +/// via [`Keymap::chord`] (`stance::ghost`). Switched to `chord` here so every +/// badge in the band matches that same compact grammar. +/// +/// Also FAULT 2: this glyph drew no `on_click` at all -- a badge that names +/// a stroke but does not fire it on a click is the same "glyph, badge and +/// what fires must agree" defect the chord text was, so it now dispatches +/// `action` through [`Player::act`] the same way `stance::ghost` (spine) and +/// `spine_stance`'s own ghost already do, `id` making the three transport +/// ghosts distinct elements gpui can track. +fn ghost(id: &'static str, player: &Player, glyph: &str, action: ActionId, cx: &mut Context) -> impl IntoElement { let glyph_style = label(type_scale::HERO_TIMECODE_PX, FontWeight::MEDIUM); // The chord names a key, so DESIGN §3's mono rule ("if a string is about // ... a key, it is mono") applies here same as everywhere else in the band. let chord_style = mono(type_scale::CHORD_METADATA_MIN_PX, FontWeight::MEDIUM); div() + .id(id) .flex_none() .flex() .flex_col() .items_center() .gap(px(1.)) + .cursor_pointer() + .on_click(cx.listener(move |this, _: &ClickEvent, window, cx| { + this.act(action, window, cx); + })) .font(glyph_style.font) .text_size(glyph_style.size) .text_color(rgb(INK2())) @@ -52,7 +70,7 @@ fn ghost(player: &Player, glyph: &str, action: ActionId) -> impl IntoElement { .font(chord_style.font) .text_size(chord_style.size) .text_color(rgb(INK3())) - .child(player.keymap.display(action)), + .child(player.keymap.chord(action)), ) } @@ -142,12 +160,13 @@ fn cut_readout(player: &Player) -> impl IntoElement { /// where the bench's own window sits. Click jumps the playhead; drag pans /// the bench window. /// -/// hook: the trace itself is splice positions (real clip boundaries, from -/// [`PlaybackSession::lanes`]/`lane_clips` -- data the app already has), not -/// a motion or audio trace -- that needs a per-frame decode of the whole -/// film this task did not budget for. What would make it real: a cached -/// low-res luma/RMS pass over each source at import, sampled here instead of -/// clip boundaries. +/// The trace is real audio, not a placeholder: [`Player::waves`] already +/// caches each source's peaks for the bench's own waveform clips +/// ([`bench_stance`]'s `clip_box`), so every audio-lane clip draws its own +/// stretch of that same envelope here, positioned by its timeline fraction +/// instead of `bench_stance`'s per-lane pixel scale -- the cheapest honest +/// whole-film trace this app can draw without a new decode pass. Splice +/// ticks (video-lane clip boundaries) still mark cut points on top of it. fn contact_strip(player: &Player, cx: &mut Context) -> impl IntoElement { let duration = player.drawn_duration(); let view = player.view(); @@ -160,6 +179,7 @@ fn contact_strip(player: &Player, cx: &mut Context) -> impl IntoElement (0., 1.) }; let fps = player.active_fps(); + let frac = |f: u32| ((f64::from(f) / fps) / duration).clamp(0., 1.) as f32; let ticks: Vec = player .session .as_ref() @@ -173,8 +193,28 @@ fn contact_strip(player: &Player, cx: &mut Context) -> impl IntoElement .unwrap_or_default() .into_iter() .filter(|_| duration > 0.) - .map(|f| ((f64::from(f) / fps) / duration).clamp(0., 1.) as f32) + .map(frac) .collect(); + let traces: Vec<(f32, f32, Arc>, f64, f64, u32)> = player + .session + .as_ref() + .filter(|_| duration > 0.) + .map(|s| { + s.lanes() + .into_iter() + .filter(|l| l.kind == LaneKind::Audio) + .flat_map(|l| s.lane_clips(l).to_vec()) + .filter_map(|clip| { + let source = player.sources().get(clip.source)?; + let Wave::Peaks(peaks) = player.waves.get(&(source.path.clone(), source.audio_stream))?.clone() else { + return None; + }; + let (in_f, out_f) = (f64::from(clip.in_frame) / fps, f64::from(clip.out_frame) / fps); + Some((frac(clip.start), frac(clip.end()), peaks, in_f, out_f, source_tint(clip.source))) + }) + .collect() + }) + .unwrap_or_default(); let strip_bounds = STRIP_BOUNDS.with(Rc::clone); div() .id("stance-contact-strip") @@ -228,7 +268,8 @@ fn contact_strip(player: &Player, cx: &mut Context) -> impl IntoElement cx.listener(|_, _, _, _| PAN_ANCHOR.with(|a| a.set(None))), ) .child(bounds_probe(strip_bounds)) - // The baseline trace (see the `hook:` above). + // Baseline: a quiet hairline under the real traces below it, so an + // audio-free stretch of film still reads as film rather than gap. .child( div() .absolute() @@ -238,18 +279,34 @@ fn contact_strip(player: &Player, cx: &mut Context) -> impl IntoElement .h(px(2.)) .bg(rgb(DARK_HAIRLINE())), ) + // The real trace: each audio-lane clip's own envelope, in the + // source's ink, positioned by timeline fraction (see the fn doc + // above) -- the whole-film minimap MOCK-SPEC asks for, not a + // placeholder line. + .children(traces.into_iter().map(|(from, to, peaks, in_f, out_f, ink)| { + div() + .absolute() + .left(relative(from)) + .top(px(4.)) + .bottom(px(4.)) + .w(relative((to - from).max(0.002))) + .child(waveform_ink(peaks, in_f, out_f, ink)) + })) .children(ticks.into_iter().map(|frac| { div() .absolute() .left(relative(frac)) - .top(px(9.)) + .top(px(2.)) .w(px(1.)) - .h(px(10.)) + .h(px(24.)) .bg(rgb(LAMP_WHITE())) })) - // The viewport bracket: the bench window's own span, with grip - // notches at each edge (MOCK-SPEC: "1px viewport bracket (with grip - // notches)"). + // The viewport bracket (MOCK-SPEC: "1px viewport bracket (with grip + // notches)"): FAULT 1's box fix -- DESIGN §4 reserves the full + // bordered rectangle for the room's one commit chip (Export), so this + // draws only the two edges (left/right verticals + corner notches), + // never a closed box, and stays visually distinct from the trace it + // sits over (ink1 lines/notches vs the trace's film ink fills). .child( div() .absolute() @@ -257,7 +314,8 @@ fn contact_strip(player: &Player, cx: &mut Context) -> impl IntoElement .top_0() .h_full() .w(relative(width_frac.max(0.01))) - .border_1() + .border_l_1() + .border_r_1() .border_color(rgb(INK1())) .child( div() @@ -268,6 +326,24 @@ fn contact_strip(player: &Player, cx: &mut Context) -> impl IntoElement .h(px(6.)) .bg(rgb(INK1())), ) + .child( + div() + .absolute() + .left_0() + .bottom_0() + .w(px(2.)) + .h(px(6.)) + .bg(rgb(INK1())), + ) + .child( + div() + .absolute() + .right_0() + .top_0() + .w(px(2.)) + .h(px(6.)) + .bg(rgb(INK1())), + ) .child( div() .absolute() @@ -327,7 +403,9 @@ fn export_chip(player: &Player, cx: &mut Context) -> impl IntoElement { .font(chord_style.font) .text_size(chord_style.size) .text_color(rgb(INK3())) - .child(player.keymap.display(ActionId::Export)), + // FAULT 2: compact badge everywhere in the band, same fix as + // `ghost` above (`Export ^e`, not `Export ctrl+e`). + .child(player.keymap.chord(ActionId::Export)), ) } @@ -353,19 +431,47 @@ pub(crate) fn render(player: &mut Player, position: f64, cx: &mut Context