diff --git a/crates/app/src/ui/bench_stance.rs b/crates/app/src/ui/bench_stance.rs new file mode 100644 index 0000000..4df47b0 --- /dev/null +++ b/crates/app/src/ui/bench_stance.rs @@ -0,0 +1,363 @@ +//! The bench's own content: lanes, ruler and clips (DESIGN.md §5's clip +//! anatomy, §7's degradation ladder). `stance.rs::bench()` owns the frame +//! (height, surfaces, section head); this module owns what fills it, the way +//! `dock_stance.rs` owns the dock's content next to `stance.rs::dock()`'s +//! frame. +//! +//! Reused rather than reimplemented (`ui/timeline.rs` already shipped this +//! plumbing on the legacy timeline): `Player::insert_source` and the +//! `AssetDrag` payload for add-at-playhead and drag-drop from the Sources +//! tab, `Player::pick`/`Player::marks`/`marked` for selection, and +//! `Player::nudge_cut`/`walk_cut`/`cut`/`toggle_loop_trim` (DESIGN §6, wired +//! in `player/actions.rs` already, and answered to by every keystroke the +//! stance's own key handler forwards) for the whole cut grammar -- none of +//! that is touched here, because a clip's `start`/`frames()` already reflect +//! a commit the moment the keymap makes one (`nudge_cut` writes straight to +//! the session), so this module reads the session straight, needing no live +//! drag-preview state to mirror it. New here: the clip anatomy (ink spine, +//! trace, name plate, splice gaps) and the width ladder that degrades it +//! (DESIGN §7) -- neither existed on the legacy timeline in this shape. +//! +//! Not reused, deferred: `ClipDrag` (moving a placed clip to another lane by +//! hand), the mouse edge-trim strips, fades/dissolve glyphs and the lane +//! header reorder drag. The cut grammar (`,` `.` `[` `]` `/` `s`) never needs +//! any of them -- `nudge_cut` and friends act on `Player::selected` directly, +//! with no element under the pointer required -- so they are out of this +//! slice's reach; `Player::pick` (click-select) and the asset drop (place) +//! are the two pointer gestures the charter actually asked this surface to +//! answer for. + +use crate::*; +use crate::ui::widgets::waveform; + +/// The pinned ruler's own height, above the lane stack. +const RULER_H: f32 = 10.; +/// The pinned track-head column, DESIGN §5's "track heads" -- narrower than +/// the legacy timeline's `HEADER_W` since a darkroom lane carries no mix/eye +/// button yet (deferred with the rest of the header's verbs). +const HEAD_W: f32 = 28.; +const ROW_GAP: f32 = 2.; +/// DESIGN §7: lanes compress evenly up to this many rows before the column +/// scrolls behind the pinned ruler and heads instead of compressing further. +const LANES_COMPRESS: usize = 5; +const LANE_FULL_H: f32 = 40.; +const LANE_MIN_H: f32 = 18.; + +/// One clip's degradation tier (DESIGN §7), picked off the clip's own worth +/// in pixels (`span`, unclamped) rather than its drawn floor +/// ([`clip_width`]'s `HIT_MIN`) -- a clip zoomed far out is worth a fraction +/// of a pixel long before its box stops shrinking, and the ladder has to see +/// that or "sliver" would never fire under the floor that keeps it clickable. +#[derive(Clone, Copy, PartialEq)] +enum Tier { + /// Trace + name plate + speed chip. + Full, + /// Trace + name plate. + NoChip, + /// Trace only -- DESIGN §7's explicit "<48px" boundary. + NoLabel, + /// Spine + trace only, thinned. + SpineTrace, + /// Sliver fill + splice gaps: film scale. + Sliver, +} + +fn tier(span: f32) -> Tier { + match span { + s if s >= 120. => Tier::Full, + s if s >= 48. => Tier::NoChip, + s if s >= 24. => Tier::NoLabel, + s if s >= 10. => Tier::SpineTrace, + _ => Tier::Sliver, + } +} + +/// The lane stack's own height budget, split evenly across up to +/// [`LANES_COMPRESS`] rows before the column scrolls instead (DESIGN §7). +fn row_h(lanes: usize, box_h: f32) -> f32 { + let n = lanes.clamp(1, LANES_COMPRESS) as f32; + ((box_h - (n - 1.) * ROW_GAP) / n).clamp(LANE_MIN_H, LANE_FULL_H) +} + +/// A clip's ink spine + body, degrading by [`Tier`] (DESIGN §5, §7). A single +/// placeholder ink stands in for every source until real extraction lands. +/// +/// hook: §12 step 5 -- per-source film ink attaches here, replacing +/// `INK2()` with the source's own quantized hue. +fn clip_box( + player: &Player, + lane: Lane, + idx: usize, + clip: &Clip, + scale: Scale, + picks: &[(Lane, usize)], + pick_links: &[Option], + cx: &mut Context, +) -> impl IntoElement + use<> { + let (start, len) = ( + f64::from(clip.start) / player.fps, + f64::from(clip.frames()) / player.fps, + ); + let span = scale.width_px(len); + let width = clip_width(span); + let left = scale.px_at(start); + let on = marked((lane, idx), clip.link, picks, pick_links); + let t = tier(span); + let label = player.sources().get(clip.source).map(|s| file_name(&s.path)); + let audio = lane.kind == LaneKind::Audio; + let wave = player + .sources() + .get(clip.source) + .and_then(|s| player.waves.get(&(s.path.clone(), s.audio_stream))) + .cloned(); + let has_trace = t != Tier::Sliver; + let has_spine = t != Tier::Sliver; + let has_label = matches!(t, Tier::Full | Tier::NoChip); + let has_chip = t == Tier::Full && !clip.speed.is_normal(); + let (in_frame, out_frame) = (f64::from(clip.in_frame) / player.fps, f64::from(clip.out_frame) / player.fps); + let speed = clip.speed; + div() + .id(("bench-clip", lane.ord * 1000 + lane.kind as usize * 100 + idx)) + .absolute() + .top_0() + .h_full() + .left(px(left)) + .w(px(width)) + .overflow_hidden() + .rounded(px(0.)) + .bg(rgb(DARK_PANEL())) + // Focus/selection ring, 1px `ink1`, lamp-adjacent and never coloured + // (DESIGN §4). + .when(on, |d| d.border_1().border_color(rgb(INK1()))) + .cursor_pointer() + // Selection: reuses `Player::pick`, the same call the legacy + // timeline's clip box makes. + .on_mouse_down( + MouseButton::Left, + cx.listener(move |this, event: &MouseDownEvent, _, cx| { + this.pick((lane, idx), event.modifiers.control, cx); + }), + ) + // Ink spine: 3px left edge, the placeholder ink until §12 step 5. + .when(has_spine, |d| { + d.child( + div() + .absolute() + .left_0() + .top_0() + .h_full() + .w(px(3.)) + .bg(rgb(INK2())), + ) + }) + // Trace: real waveform for audio, a flat placeholder body for video + // (thumbnails are §12 step 5's, same hook). + .when(has_trace && audio, |d| { + d.children(wave.and_then(|w| match w { + Wave::Peaks(peaks) => Some( + div() + .absolute() + .left(px(3.)) + .right_0() + .top_0() + .bottom_0() + .child(waveform(peaks, in_frame, out_frame)), + ), + _ => None, + })) + }) + .when(has_trace && !audio, |d| { + d.child( + div() + .absolute() + .left(px(3.)) + .right_0() + .top(px(2.)) + .bottom(px(2.)) + .bg(rgb(INK4())), + ) + }) + // Name plate: DESIGN §4's plate (canvas-on-panel), mono label. + .when_some(label.filter(|_| has_label), |d, label| { + d.child( + div() + .absolute() + .left(px(3.)) + .right_0() + .bottom_0() + .h(px(13.)) + .px(px(3.)) + .bg(rgba(DARK_SEAM())) + .truncate() + .text_size(px(9.5)) + .text_color(rgb(INK1())) + .child(label), + ) + }) + // Speed chip: dropped first in the ladder. + .when(has_chip, |d| { + d.child( + div() + .absolute() + .top_0() + .right_0() + .px(px(3.)) + .bg(rgb(DARK_RAISED())) + .text_size(px(9.)) + .text_color(rgb(INK2())) + .child(format!("{speed}")), + ) + }) + // Splice gap: the lamp-white sliver at every clip's trailing edge -- + // DESIGN §1 law 3's other legal white, present at every tier (a + // sliver at film scale is spine gone too, so the splice is what is + // left to read). + .child( + div() + .absolute() + .top_0() + .right_0() + .h_full() + .w(px(1.)) + .bg(rgb(LAMP_WHITE())), + ) +} + +/// One lane row: pinned head + bed of clips, DESIGN §5's "lanes V/A/S", drawn +/// at the compressed height [`row_h`] gives it. +fn lane_row( + player: &Player, + lane: Lane, + h: f32, + scale: Scale, + picks: &[(Lane, usize)], + pick_links: &[Option], + cx: &mut Context, +) -> impl IntoElement + use<> { + let clips: Vec = player + .session + .as_ref() + .map_or(&[][..], |s| s.lane_clips(lane)) + .to_vec(); + let boxes: Vec<_> = clips + .iter() + .enumerate() + .map(|(idx, clip)| clip_box(player, lane, idx, clip, scale, picks, pick_links, cx)) + .collect(); + div() + .id(("bench-lane", lane.ord * 10 + lane.kind as usize)) + .flex_none() + .h(px(h)) + .flex() + .child( + // Pinned track head. + div() + .flex_none() + .w(px(HEAD_W)) + .h_full() + .flex() + .items_center() + .justify_center() + .bg(rgb(DARK_PANEL())) + .text_size(px(9.5)) + .text_color(rgb(INK2())) + .child(lane.label()), + ) + .child( + // The bed: a drop target for the Sources tab (`AssetDrag`, + // reused from `ui/timeline.rs`) and every clip on it. + div() + .id(("bench-bed", lane.ord * 10 + lane.kind as usize)) + .relative() + .flex_1() + .min_w(px(0.)) + .h_full() + .bg(rgb(DARK_CANVAS())) + .border_l_1() + .border_color(rgba(DARK_SEAM())) + .drag_over::(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) + .on_drop(cx.listener(move |this, drag: &AssetDrag, window, cx| { + let at = this.place_frame(window.mouse_position().x).0; + this.insert_source(&drag.0.clone(), drag.1, Some(lane), Some(at), cx) + })) + .children(boxes), + ) +} + +/// The bench's content: pinned ruler, pinned heads, lane stack -- compressed +/// evenly to [`LANES_COMPRESS`] rows and then scrolling (DESIGN §7). +pub(crate) fn render(player: &mut Player, box_h: f32, cx: &mut Context) -> impl IntoElement { + let lanes = player + .session + .as_ref() + .map_or_else(|| vec![Lane::V1, Lane::A1], PlaybackSession::lanes); + let position = player.active_session().map_or(0., PlaybackSession::now); + let scale = player.scale; + let bed_w = f32::from(player.ruler.get().size.width).max(1.); + let filled = scale.px_at(position).clamp(0., bed_w); + let (picks, pick_links) = player.marks(); + let h = row_h(lanes.len(), (box_h - RULER_H - ROW_GAP).max(LANE_MIN_H)); + let mut rows = Vec::new(); + for &lane in &lanes { + rows.push(lane_row(player, lane, h, scale, &picks, &pick_links, cx)); + } + div() + .id("bench-content") + .flex_1() + .min_w(px(0.)) + .h_full() + .flex() + .flex_col() + .gap(px(ROW_GAP)) + .child( + // Pinned ruler: click/drag to seek (reuses `Player::scrub_to`, + // the same call the legacy ruler makes), the playhead's own + // lamp-white line (DESIGN §1 law 3 -- the only other legal use + // of pure white besides the splice). + div() + .id("bench-ruler") + .flex_none() + .h(px(RULER_H)) + .ml(px(HEAD_W)) + .relative() + .rounded(px(2.)) + .bg(rgb(DARK_HAIRLINE())) + .cursor_pointer() + .child(bounds_probe(player.ruler.clone())) + .on_mouse_down( + MouseButton::Left, + cx.listener(|this, event: &MouseDownEvent, _, cx| { + this.scrubbing = true; + this.scrub_to(event.position.x, true, cx); + }), + ) + .child( + div() + .h_full() + .w(px(filled)) + .rounded(px(2.)) + .bg(rgb(INK1())), + ) + .child( + div() + .absolute() + .top_0() + .h_full() + .left(px(filled)) + .w(px(1.)) + .bg(rgb(LAMP_WHITE())), + ), + ) + .child( + div() + .id("bench-lanes") + .flex_1() + .min_h(px(0.)) + .overflow_y_scroll() + .track_scroll(&player.lanes_scroll) + .flex() + .flex_col() + .gap(px(ROW_GAP)) + .children(rows), + ) +} diff --git a/crates/app/src/ui/mod.rs b/crates/app/src/ui/mod.rs index 38ebf22..8a22bca 100644 --- a/crates/app/src/ui/mod.rs +++ b/crates/app/src/ui/mod.rs @@ -3,6 +3,7 @@ //! The whole UI used to be one 19,916-line file with one `Render` impl in it, //! which is why a colour or a rule fixed in one place kept surviving in the //! next: there was no seam to sweep. The seams are the regions themselves. +pub mod bench_stance; pub mod cards; pub mod dock_stance; pub mod inspector; diff --git a/crates/app/src/ui/stance.rs b/crates/app/src/ui/stance.rs index ba70da5..3e953ea 100644 --- a/crates/app/src/ui/stance.rs +++ b/crates/app/src/ui/stance.rs @@ -8,6 +8,7 @@ //! later steps in DESIGN §12's package attach. use crate::*; +use crate::ui::bench_stance; use crate::ui::dock_stance; /// Left rail, full height (DESIGN §5). @@ -15,10 +16,12 @@ const SPINE_W: f32 = 56.; /// Fixed strip under the screen: timecode, transport, cut readout, contact /// strip, Export -- all placeholder at this step. const TIME_BAND_H: f32 = 88.; -/// corner-cut: the lane bed has no lanes to size itself against yet, so this -/// is a placeholder height rather than a measured one. Ceiling: replaced by -/// the real lane stack's own height once DESIGN §12 step 4 fills the bench. -const BENCH_H: f32 = 160.; +/// corner-cut: a fixed share of the window rather than one measured against +/// the picture's own room, matching the placeholder every other stance +/// region still carries at this step. Ceiling: fold into the same split the +/// legacy timeline's `Split::Timeline` answers once the stance grows a +/// resizable seam of its own. +const BENCH_H: f32 = 200.; /// Thin strip at the foot of the centre column. const LEDGER_H: f32 = 28.; /// Right side panel, fixed width, carrying the Src/Clip tab pair. @@ -174,7 +177,7 @@ fn time_band(player: &Player) -> impl IntoElement { /// Lanes, under the time band. `canvas` is the bench background too (DESIGN /// §2's token table), so it shares its surface with the screen above it. -fn bench() -> impl IntoElement { +fn bench(player: &mut Player, cx: &mut Context) -> impl IntoElement { div() .id("stance-bench") .flex_none() @@ -185,10 +188,11 @@ fn bench() -> impl IntoElement { .border_t_1() .border_color(rgba(DARK_SEAM())) .flex() - .items_center() + .flex_col() .px(px(12.)) + .py(px(4.)) .child(section_head("bench")) - // hook: §12 step 4 -- lanes V/A/S; ink spine + thumbnails/waveform + name plate + splice gaps. + .child(bench_stance::render(player, BENCH_H - 20., cx)) } /// Thin strip at the bottom of the centre column: project identity, last @@ -292,7 +296,7 @@ pub(crate) fn render( .flex_col() .child(screen(player, position, window, cx)) .child(time_band(player)) - .child(bench()) + .child(bench(player, cx)) .child(ledger()), ) .child(dock(player, window_h, cx))