From 5dcc6c244030c27d97ac5790b20a677c1c0ecb6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 26 Aug 2026 22:41:57 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20remove(ui):=20the=20legacy=20tre?= =?UTF-8?q?e=20=E2=80=94=20darkroom=20is=20the=20only=20room?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Delete the whole legacy UI (timeline.rs, toolbar.rs, inspector.rs, legacy render body, OLD_GUI gate — the env read is gone, not a switch) and every helper only it reached: ~6,900 LOC out. Darkroom stance is the only room. Real gaps the removal flushed out, fixed here: - typed bitrate in the export card was completely dead — NumberEdit digits/backspace/enter/esc now wired in param_card_key - ActionId::CancelExport was a no-op while the progress card promised the chord — now calls cancel_export (ctrl+esc, oracle-enabled during export) - actions card had no pointer entry — "?" ghost is clickable, scrim click closes, inner list swallows - snap toggle got a button beside zoom-fit in the VIEW group Dead-by-construction machinery deleted with its tests: key rebinding (rebinding/rebind_action/capture never set live), keys_search (no search box exists), cancels_export/format_key/next_audio_kbps, 17 layout.rs consts/fns, and the rest of the 32 no-—tests dead-code warnings; both `cargo build -p edith` and `--tests` are warning-free, 245 tests green. --- DESIGN.md | 3 +- crates/app/src/export_ui.rs | 32 - crates/app/src/importing.rs | 21 - crates/app/src/interact.rs | 24 +- crates/app/src/keymap.rs | 125 +- crates/app/src/layout.rs | 141 -- crates/app/src/library_meta.rs | 36 - crates/app/src/main.rs | 46 +- crates/app/src/menus.rs | 50 - crates/app/src/notices.rs | 11 - crates/app/src/oracle.rs | 6 - crates/app/src/player/actions.rs | 62 +- crates/app/src/player/cards.rs | 26 +- crates/app/src/player/export.rs | 45 - crates/app/src/player/timeline_edit.rs | 67 +- crates/app/src/player/view.rs | 98 -- crates/app/src/render.rs | 490 +----- crates/app/src/tests/cards.rs | 177 +-- crates/app/src/tests/editing.rs | 37 +- crates/app/src/tests/layout.rs | 435 ++--- crates/app/src/tests/media.rs | 81 - crates/app/src/tests/mod.rs | 63 +- crates/app/src/tests/view.rs | 18 - crates/app/src/timeline_math.rs | 74 +- crates/app/src/ui/cards.rs | 1432 ++++------------- crates/app/src/ui/dock_stance.rs | 38 +- crates/app/src/ui/inspector.rs | 536 ------- crates/app/src/ui/library.rs | 550 +------ crates/app/src/ui/mod.rs | 3 - crates/app/src/ui/overlays.rs | 402 +---- crates/app/src/ui/preview.rs | 98 +- crates/app/src/ui/spine_stance.rs | 28 +- crates/app/src/ui/stance.rs | 83 +- crates/app/src/ui/theme.rs | 15 - crates/app/src/ui/timeline.rs | 2018 ------------------------ crates/app/src/ui/toolbar.rs | 539 ------- crates/app/src/ui/widgets.rs | 149 -- crates/app/src/viewport.rs | 15 - 38 files changed, 709 insertions(+), 7365 deletions(-) delete mode 100644 crates/app/src/ui/inspector.rs delete mode 100644 crates/app/src/ui/timeline.rs delete mode 100644 crates/app/src/ui/toolbar.rs diff --git a/DESIGN.md b/DESIGN.md index e9fe617..5e00ef3 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -178,7 +178,8 @@ capability is genuinely absent — otherwise it is a bug, not a message. A verb verbs; source dot: ink acts). Plate styling, chords on every row, destructive verbs below a rule line. Never a junk drawer. - **`?` held** dims the room one fill step and surfaces chords *in place* beside their controls; - release restores. No modal cheat-sheet; learning stays geographic. The film keeps playing. + release restores, and a click on the scrim also dismisses it. Hold-to-peek, not a latch; + learning stays geographic. The film keeps playing. **Amendment (2026-08-20), explicit per this section's own rule:** the geographic reading above is only partly built and edith currently ships the fallback instead — named here rather than diff --git a/crates/app/src/export_ui.rs b/crates/app/src/export_ui.rs index a130398..8b6df46 100644 --- a/crates/app/src/export_ui.rs +++ b/crates/app/src/export_ui.rs @@ -262,19 +262,6 @@ pub(crate) const FORMATS: [(&[Format], &str, &str, &str); 8] = [ (&[], "", "VP9", "AV1 above replaces it"), ]; -/// The codec row a key picks, landed in the container already chosen: pressing -/// `a` after an mp4 gives AV1 *in mp4*, because a box decided once is not a -/// question again. A letter of the row's own name, spelled out in the table -/// rather than taken from the initial (`MP4` and `MP3` share one). Never a -/// digit -- those are the bitrate field's. `None` for every other stroke, the rows -/// that cannot be picked included. -pub(crate) fn format_key(key: &str, current: Format) -> Option { - FORMATS - .into_iter() - .filter(|(_, stroke, ..)| !stroke.is_empty() && stroke.eq_ignore_ascii_case(key)) - .find_map(|(row, ..)| same_box(row, current)) -} - /// The boxes one codec may be written into, in the order its container row /// cycles them. Empty for a codec this program cannot write at all. pub(crate) fn containers(format: Format) -> &'static [Format] { @@ -306,14 +293,6 @@ pub(crate) fn next_container(format: Format) -> Format { .unwrap_or(format) } -/// The next rate the Sound row offers, wrapping -- what its key does, and what -/// the row itself names so the stroke is never a guess. [`next_container`]'s -/// shape, for the same reason: one place decides what "next" means. -pub(crate) fn next_audio_kbps(kbps: u32) -> u32 { - let at = AUDIO_KBPS.iter().position(|&k| k == kbps).unwrap_or(0); - AUDIO_KBPS[(at + 1) % AUDIO_KBPS.len()] -} - /// Why the quality rows say nothing about this format, or `None` where they /// decide the picture. Only a picture encoder is given a bitrate here: the two /// lossless audio formats have none to give and MP3 is written at one fixed @@ -1028,17 +1007,6 @@ pub(crate) fn commit_mbps(text: &str) -> Result { } } -/// Whether a stroke gets out of a running export. `ctrl+escape` does -- a chord -/// and not the bare key, which used to end an hour of encoding on the stroke a -/// hand reaches for to shut a menu it has already shut. Bare escape does nothing -/// at all here: the progress card is not dismissable, so there is nothing left -/// for it to mean. Whatever the keymap has on cancel works too, so rebinding it -/// adds a way rather than replacing this one -- and that binding is what the -/// card shows. -pub(crate) fn cancels_export(key: &str, ctrl: bool, action: Option) -> bool { - (ctrl && key == ESCAPE) || action == Some(ActionId::CancelExport) -} - /// A clip's share of the lane. A timeline with no length reads as one full-width /// box rather than as NaN, which gpui would carry into layout. /// Why this timeline cannot be written in `format`, if it cannot. diff --git a/crates/app/src/importing.rs b/crates/app/src/importing.rs index 84c385c..97b6748 100644 --- a/crates/app/src/importing.rs +++ b/crates/app/src/importing.rs @@ -109,27 +109,6 @@ pub(crate) enum Proxy { Failed, } -impl Proxy { - /// What the library row says about it, or nothing at all for a file that - /// never wanted one -- a row per source is not the place to announce that - /// nothing is happening. - pub(crate) fn detail(&self) -> String { - match self { - Self::Asked | Self::Native => String::new(), - // Rounded down: a bar that says 100% while the encoder is still - // writing is the one number a progress line must never show. - Self::Making(job) => format!("proxy {}%", (job.progress() * 100.) as u32), - // Its own word while the worker is still winding down: "no proxy" - // the instant the × is clicked would be a claim about a file that - // is at that moment still being written. - Self::Cancelling(_) => "proxy stopping…".to_string(), - Self::Cancelled => "no proxy — stopped".to_string(), - Self::Ready => "proxy".to_string(), - Self::Failed => "no proxy".to_string(), - } - } -} - /// The import a worker is reading, as the line above the panel shows it. No /// fraction anywhere: neither read reports how far into the file it has come, /// so what is honest is the file's name, the stage, and two clocks -- one that diff --git a/crates/app/src/interact.rs b/crates/app/src/interact.rs index a3ca4a9..5c5b7f6 100644 --- a/crates/app/src/interact.rs +++ b/crates/app/src/interact.rs @@ -194,7 +194,7 @@ pub(crate) fn scrim() -> Div { /// is old too". A plate is `panel` with a seam around it and a 6px radius /// (DESIGN §2/§4); the legacy tree keeps its own raised sheet. One function, /// so the next change reaches all three or none. -pub(crate) fn menu_plate(id: &'static str, x: f32, y: f32, darkroom: bool) -> Stateful
{ +pub(crate) fn menu_plate(id: &'static str, x: f32, y: f32) -> Stateful
{ div() .id(id) .absolute() @@ -205,15 +205,9 @@ pub(crate) fn menu_plate(id: &'static str, x: f32, y: f32, darkroom: bool) -> St .flex_col() .p(px(crate::layout::MENU_PAD)) .rounded(px(6.)) - .bg(rgb(if darkroom { - crate::ui::theme::DARK_PANEL() - } else { - crate::ui::theme::BG_RAISED() - })) - .when(darkroom, |d| { - d.border_1() - .border_color(rgba(crate::ui::theme::DARK_SEAM())) - }) + .bg(rgb(crate::ui::theme::DARK_PANEL())) + .border_1() + .border_color(rgba(crate::ui::theme::DARK_SEAM())) } /// The sheet a card with a *slider* in it takes instead: the same scrim, with @@ -334,13 +328,3 @@ pub(crate) fn repeats(scope: Repeat, key: &str, action: Option) -> boo } } -/// The keys that are only ever half a chord. gpui delivers a lone modifier -/// press as a keystroke of its own, and taking one as a binding would leave an -/// action that fires the moment the user reaches for any chord that uses it -- -/// so a capture waits through them instead. -pub(crate) fn is_bare_modifier(key: &str) -> bool { - matches!( - key, - "control" | "shift" | "alt" | "super" | "platform" | "function" | "fn" | "meta" | "command" - ) -} diff --git a/crates/app/src/keymap.rs b/crates/app/src/keymap.rs index 3986046..68afeb8 100644 --- a/crates/app/src/keymap.rs +++ b/crates/app/src/keymap.rs @@ -969,8 +969,8 @@ pub struct Binding { } /// Every binding in force, in display order. No chord appears twice -- that is -/// the invariant [`Keymap::rebind_action`] and [`parse`] both defend, and it is what -/// lets [`Keymap::lookup`] answer with the first match. +/// the invariant [`parse`] defends, and it is what lets [`Keymap::lookup`] +/// answer with the first match. #[derive(Clone, PartialEq, Eq, Debug)] pub struct Keymap { bindings: Vec, @@ -1284,9 +1284,9 @@ impl Keymap { /// The primary chord for `action`, compact ([`Chord::compact`]) -- a /// badge that has room for one token, not [`Keymap::display`]'s sentence. /// The first bound stroke wins (`defaults`' own insertion order, and - /// `rebind_action`'s "makes `chord` the whole of what reaches `action`" - /// leaves at most one anyway); an action with no stroke reads `--` - /// rather than the unbound sentence, since a badge is not a warning. + /// [`parse`]'s "no chord appears twice" leaves at most one anyway); an + /// action with no stroke reads `--` rather than the unbound sentence, + /// since a badge is not a warning. pub fn chord(&self, action: ActionId) -> String { self.bindings .iter() @@ -1300,35 +1300,6 @@ impl Keymap { &self.bindings } - /// Makes `chord` the whole of what reaches `action`: its other chords go, so - /// what the editor shows for an action is what a rebind replaced. Two - /// strokes for one action stay expressible, but only in the file -- the - /// parser takes as many lines per action as it is given. - /// - /// `Err` names the action that already holds the chord and nothing changes: - /// two actions on one stroke would make the second unreachable, and silently - /// stealing it is worse than refusing. A chord the action already holds is - /// not a conflict with itself -- it collapses the action onto that one. - pub fn rebind_action(&mut self, action: ActionId, chord: Chord) -> Result<(), ActionId> { - if let Some(held) = self - .bindings - .iter() - .find(|b| b.action != action && b.chord == chord) - { - return Err(held.action); - } - self.bindings.retain(|b| b.action != action); - // Back into its own place in the display order rather than onto the end, - // so the file and the editor keep reading in the order of `ALL`. - let at = self - .bindings - .iter() - .position(|b| rank(b.action) > rank(action)) - .unwrap_or(self.bindings.len()); - self.bindings.insert(at, Binding { action, chord }); - Ok(()) - } - /// The keymap in force, and what to tell the user if the file could not be /// used. A file that is merely absent is the normal case and says nothing; /// anything else -- unreadable, or a line this parser refuses -- falls back @@ -1414,15 +1385,6 @@ impl Keymap { } } -/// Where an action sits in the display order, which is the order of -/// [`ActionId::ALL`] and the order the file is written in. -fn rank(action: ActionId) -> usize { - ActionId::ALL - .iter() - .position(|a| *a == action) - .unwrap_or(ActionId::ALL.len()) -} - /// The path rule, with the environment handed in so it can be checked. An /// `XDG_CONFIG_HOME` that is empty is one the spec says to ignore; with no /// `HOME` either there is nowhere but here, and a relative path is still better @@ -1743,67 +1705,13 @@ mod tests { assert!(!chord("", false).bindable()); assert!(!chord("X", false).bindable()); assert!(!chord("page up", false).bindable()); - // A bindable chord is one `rebind_action` may keep: what it writes is - // what the next load reads, for every stroke that passes here. - let mut k = Keymap::defaults(); - // Any free chord will do here; ctrl+= is the zoom's. - k.rebind_action(ActionId::Play, chord("w", true)).unwrap(); + // A bindable chord is one the file's own grammar can spell: what it + // writes is what the next load reads, for every stroke that passes + // here. + let k = whole("edith-keys 1\nplay ctrl+w\n"); assert_eq!(whole(&emit(&k)), k); } - #[test] - fn rebinding_refuses_to_steal_another_actions_stroke() { - let mut k = Keymap::defaults(); - assert_eq!( - k.rebind_action(ActionId::Export, chord("space", false)), - Err(ActionId::Play) - ); - // Refused means unchanged, on both sides of the conflict. - assert_eq!(k.lookup("e", false), Some(ActionId::Export)); - assert_eq!(k.lookup("space", false), Some(ActionId::Play)); - // And the refusal is a name, not a shrug: it is the holder's own label - // the card prints back at the waiting row (`Player::capture`, "ALREADY - // BOUND — space is Play / Pause"). - assert_eq!(ActionId::Play.label(), "Play / Pause"); - // A free stroke takes, and the old one stops meaning anything. - assert_eq!(k.rebind_action(ActionId::Export, chord("w", true)), Ok(())); - assert_eq!(k.lookup("w", true), Some(ActionId::Export)); - assert_eq!(k.lookup("e", false), None); - assert_eq!(k.display(ActionId::Export), "ctrl+w"); - } - - #[test] - fn a_rebound_action_keeps_only_the_new_stroke() { - let mut k = Keymap::defaults(); - assert_eq!(k.display(ActionId::Delete), "x or delete"); - // One stroke replaces the whole set: what the row showed is what went. - assert_eq!(k.rebind_action(ActionId::Delete, chord("d", true)), Ok(())); - assert_eq!(k.display(ActionId::Delete), "ctrl+d"); - assert_eq!(k.lookup("x", false), None); - assert_eq!(k.lookup("delete", false), None); - assert_eq!(k.lookup("d", true), Some(ActionId::Delete)); - // One of its own chords is not a conflict with itself -- it collapses - // the action onto that one. - assert_eq!(k.rebind_action(ActionId::Undo, chord("z", true)), Ok(())); - assert_eq!(k.display(ActionId::Undo), "ctrl+z"); - assert_eq!(k.lookup("z", false), None); - // The action keeps its place in the display order, and the file keeps - // reading in that order too. Deduped only for safety -- both actions - // this test rebinds (Delete and Undo) started with two default - // chords each, but both rebinds above collapse them to one, so no - // action here still appears twice. - let mut order: Vec<_> = k.entries().iter().map(|b| b.action).collect(); - order.dedup(); - assert_eq!(order, ActionId::ALL); - assert_eq!(emit(&k), emit(&whole(&emit(&k)))); - // With Delete and Undo both collapsed to one chord, every action is - // single-bound: one line each. The stride-10 walk - // (WalkCutNext10/WalkCutPrev10) is its own action now, each bound to - // exactly one literal chord (`>`/`<`), not a second chord on - // WalkCutNext/WalkCutPrev. - assert_eq!(k.entries().len(), ActionId::ALL.len()); - } - #[test] fn display_reads_as_a_person_would_say_it() { let k = Keymap::defaults(); @@ -1881,10 +1789,17 @@ mod tests { // Its own directory, never the real config one: this test writes. let dir = Scratch::dir("edith-keymap"); let path = dir.join("edith").join("keybindings"); - let mut written = Keymap::defaults(); - written - .rebind_action(ActionId::Export, chord("w", true)) - .unwrap(); + // A defaults file with Export's own line swapped for a free stroke -- + // parsed rather than rebound, since nothing left in the API mutates + // a `Keymap` in place. + let text: String = emit(&Keymap::defaults()) + .lines() + .filter(|l| !l.starts_with("export ")) + .chain(std::iter::once("export ctrl+w")) + .collect::>() + .join("\n") + + "\n"; + let written = whole(&text); // The config directory does not exist yet -- the first save makes it. written.save_to(&path).unwrap(); let (read, notice) = Keymap::load_from(&path); diff --git a/crates/app/src/layout.rs b/crates/app/src/layout.rs index fc72785..ecba611 100644 --- a/crates/app/src/layout.rs +++ b/crates/app/src/layout.rs @@ -21,32 +21,8 @@ pub(crate) const PANEL_H: f32 = 220.; /// timeline that pushes the video off the window is not a timeline. pub(crate) const LANES_MAX: usize = 6; pub(crate) const LANE_H: f32 = 48.; -/// A caption lane's own height, thinner than a media one: a subtitle box -/// carries a name, a rate badge and the cue band under it -/// ([`Player::lane_row`]) and none of a clip's waveform or its full-height -/// plate, so the strip that used to draw the whole row's worth of nothing is -/// the regression this constant undoes. -/// -/// Floored at [`HIT_MIN`] rather than the 20 px a first pass at "thin" landed -/// on: the header's show/hide eye is the row's one surviving click target -/// once the remove button moves off it onto the right button -/// ([`Player::lane_row`]), and that eye fills the row's full height -- so -/// anything under `HIT_MIN` here is a WCAG 2.5.8 target shrunk to chase a -/// pixel count, not a thinner lane. This is the whole gap between the two -/// harness variants the task asked for: 20 is not shippable at all, 24 is, -/// so 24 is the only variant landed. -pub(crate) const SUB_LANE_H: f32 = HIT_MIN; -/// The lane header column: wide enough for `V1`/`A1` and fixed, so both lanes -/// and the ruler above them start at the same pixel and are the same width -- -/// one x-to-time mapping for the whole timeline. `HEADER_GAP` is part of that -/// offset and is therefore shared by all three rows. -pub(crate) const HEADER_W: f32 = 40.; -pub(crate) const HEADER_GAP: f32 = 4.; /// The label row inside a clip; a waveform paints under it, never through it. pub(crate) const LABEL_H: f32 = 15.; -/// A clip narrower than this shows no name: two characters and an ellipsis say -/// nothing that the tint has not already said, and cost the picture a smear. -pub(crate) const LABEL_MIN_W: f32 = 36.; /// Peak buckets per second of source. Fixed and modest on purpose: `peaks` /// allocates one bucket per window, so a rate taken from anything the user can /// influence is an allocation bomb -- and 40 is already finer than the pixels a @@ -82,24 +58,11 @@ pub(crate) const HIT_MIN: f32 = 24.; pub(crate) const LIBRARY_FRAC: f32 = 0.2; pub(crate) const LIBRARY_MIN_W: f32 = 120.; pub(crate) const LIBRARY_MAX_W: f32 = 220.; -/// A library row: a name over its duration, two lines and a click target, so -/// `HIT_MIN` binds it like every other one. -pub(crate) const ROW_H: f32 = 32.; -/// The tint swatch down the left of a row: the same colour that source's clips -/// wear in the lanes, which is the whole of the panel<->timeline association. -pub(crate) const SWATCH_W: f32 = 4.; -/// How far the encode has come, drawn under the stop square on a library row. -/// Inside a `HIT_MIN` cell with a little air each side, so the bar never reaches -/// the edge of the target it belongs to. -pub(crate) const PROXY_BAR_W: f32 = HIT_MIN - 10.; pub(crate) const CONTROL_H: f32 = 28.; /// The volume slider beside its button: a hundred steps across it, so a pixel /// is finer than a step and the drag reads as continuous. pub(crate) const VOLUME_W: f32 = 110.; pub(crate) const RULER_HIT_H: f32 = HIT_MIN; -/// Wide enough for `HH:MM:SS:FF / HH:MM:SS:FF`, and fixed so changing digits -/// cannot push the layout around. -pub(crate) const TIME_W: f32 = 200.; /// The keybindings card: a row per action, a title and a status line, inside a /// 360 px tall window. The rows are click targets, so `HIT_MIN` binds them too. /// Wider than the export card, and for the same reason that one is wider than @@ -110,16 +73,6 @@ pub(crate) const TIME_W: f32 = 200.; /// than overprinting. Still inside the 640 px floor. pub(crate) const KEYS_W: f32 = 480.; pub(crate) const KEYS_ROW_H: f32 = HIT_MIN; -/// How much of the row list is on screen at once; past this it scrolls. What -/// keeps the card inside the smallest window no matter how many actions the -/// editor grows -- ten rows fit here, and the eleventh is a scroll away. -pub(crate) const KEYS_ROWS_H: f32 = 10. * KEYS_ROW_H; -/// The same for the export card, which carries two summary lines and a button -/// under its list and so has less room: a section header, six codecs, the -/// container, five qualities and the destination are more rows than a 360 px -/// window holds. Eight on screen, which is the whole format section and its -/// header -- what a user picks first is never behind a scroll. -pub(crate) const EXPORT_ROWS_H: f32 = 8. * KEYS_ROW_H; /// The export card is wider than the keybindings one: its rows carry a key, a /// name *and* what the choice means, and the two summary lines under them state /// the whole file. At `KEYS_W` every one of those wrapped to two lines, which is @@ -130,12 +83,6 @@ pub(crate) const EXPORT_W: f32 = 420.; /// in the export card says what picks it, so the card is drivable by keyboard /// without a legend to memorise. pub(crate) const EXPORT_KEY_W: f32 = 26.; -/// Everything in the export card that is *not* the row list: the title, the -/// status line, the head and tail of the summary, the button, the gaps between -/// them and the padding around the lot. What the list may be is the window -/// minus this -- and never less than [`EXPORT_ROWS_H`], which is the number -/// that makes the card fit the 360 px floor. -pub(crate) const EXPORT_FIXED_H: f32 = 17. + 28. + 15. + 30. + CONTROL_H + 4. + 10. + 24.; /// The menu a right-click on a clip opens: wide enough for the longest label /// beside the stroke that does the same thing, with the click targets `HIT_MIN` /// binds like every other list here. @@ -170,26 +117,10 @@ pub(crate) fn sub_bottom(bars_h: f32) -> f32 { /// the track is empty. The silence preview's marks are floored by it too -- they /// are the same kind of thing, a picture of where something is and no target. pub(crate) const SUB_CUE_MIN_W: f32 = 2.; -/// How much of the subtitle list in the library column is on screen at once, -/// past which it scrolls -- the media list above it is what keeps the height. -pub(crate) const SUB_ROWS_H: f32 = 3. * ROW_H; -/// The row naming the file a block of tracks came out of. Always drawn where -/// there is more than one file -- the list already scrolls past `SUB_ROWS_H`, -/// so a short window loses tracks under the fold rather than the name saying -/// whose they are. A click folds it, so it binds `HIT_MIN` like every other -/// target. -pub(crate) const SUB_HEAD_H: f32 = HIT_MIN; -/// How much of a subtitle row's width the file's name in front of the label may -/// take. Half: which file and which language are both worth reading, and a name -/// given the whole row is a row where the language is what gets truncated. -pub(crate) const SUB_STEM_SHARE: f32 = 0.5; /// Roughly how wide one character of an 11 px list row is. Generous on purpose: /// the element truncates for real, and a budget that overshoots would have the /// element cut the tail off after [`clip_middle`] had already kept it. pub(crate) const LIST_CHAR_W: f32 = 6.; -/// The fewest characters a clipped name is cut to, however narrow the column -/// gets: past this there is nothing on either side of the gap to read. -pub(crate) const LIST_CLIP_MIN: usize = 5; /// How long the export card's Subtitles line may get before it counts tracks /// instead of naming them ([`subtitle_plan`]). Three lines of that row's value /// box, at [`LIST_CHAR_W`] to a character: [`EXPORT_W`] less the row's padding @@ -216,70 +147,6 @@ pub(crate) fn lanes_h(lanes: usize) -> f32 { } } -/// How tall one lane row is: [`LANE_H`] for a media track, [`SUB_LANE_H`] for -/// a caption one -- the one place that answer is decided, since -/// [`lanes_h_mixed`], [`lanes_shown_mixed`] and [`rows_below_mixed`] all walk -/// off it and a track drawn at one height and measured at another is a fold -/// line that lands on the wrong row. -pub(crate) fn lane_h(kind: LaneKind) -> f32 { - match kind { - LaneKind::Subtitle => SUB_LANE_H, - LaneKind::Video | LaneKind::Audio => LANE_H, - } -} - -/// [`lanes_h`] for a real stack of lanes rather than a bare count: a project -/// with a caption track in it is shorter than that many `LANE_H` rows, and -/// the column, the fold and the affordance below it all have to agree on -/// exactly how much shorter, or "N more below" is answering a box nothing -/// draws at. -pub(crate) fn lanes_h_mixed(kinds: &[LaneKind]) -> f32 { - match kinds.len() { - 0 => 0., - n => kinds.iter().copied().map(lane_h).sum::() + (n - 1) as f32 * 8., - } -} - -/// [`lanes_shown`] for a real stack: the largest prefix of `kinds` whose -/// drawn height still fits `box_h`, on the same boundary [`lanes_shown`] -/// draws it at (`lanes_h(k) <= box_h`) -- so a uniform stack answers exactly -/// what [`lanes_shown`] already did, and a mixed one answers the row count -/// its own heights actually reach. -pub(crate) fn lanes_shown_mixed(kinds: &[LaneKind], box_h: f32) -> usize { - (0..=kinds.len()) - .rev() - .find(|&k| lanes_h_mixed(&kinds[..k]) <= box_h) - .unwrap_or(0) - .max(1) -} - -/// [`rows_below`] for a real stack: `scrolled` read against each row's own -/// top rather than a uniform `LANE_H + 8` stride, so a column with a thin -/// caption track in it still says the true count once that track has -/// scrolled by. -pub(crate) fn rows_below_mixed(kinds: &[LaneKind], box_h: f32, scrolled: f32) -> usize { - // Row `k`'s own top, in the same units `scrolled` is given in: nothing - // for the first row, and every row before it plus the gap that follows - // each one for the rest. - let top = |k: usize| -> f32 { - match k { - 0 => 0., - k => lanes_h_mixed(&kinds[..k]) + 8., - } - }; - let past = (0..=kinds.len()) - .min_by(|&a, &b| { - (scrolled - top(a)) - .abs() - .partial_cmp(&(scrolled - top(b)).abs()) - .unwrap() - }) - .unwrap_or(0); - kinds - .len() - .saturating_sub(past + lanes_shown_mixed(kinds, 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 @@ -342,14 +209,6 @@ pub(crate) const TIMELINE_SHARE: f32 = 171. / 360.; /// own padding, fixed so nothing in it can push the timeline down. pub(crate) const TOOLBAR_H: f32 = CONTROL_H + 16.; -/// The top bar: the project's name on the left, the two file actions on the -/// right. Fixed for the reason [`HEADER_H`] is. -pub(crate) const TOPBAR_H: f32 = 36.; - -/// The transport strip under the picture -- play, timecode, volume -- where a -/// player's own controls live in every consumer editor. -pub(crate) const TRANSPORT_H: f32 = CONTROL_H + 12.; - /// One press of a zoom key, or one notch of ctrl+wheel. pub(crate) const ZOOM_STEP: f32 = 1.25; diff --git a/crates/app/src/library_meta.rs b/crates/app/src/library_meta.rs index e08cd8b..6be957d 100644 --- a/crates/app/src/library_meta.rs +++ b/crates/app/src/library_meta.rs @@ -361,42 +361,6 @@ pub(crate) fn library_w(window_w: f32) -> f32 { .min(window_w / 3.) } -/// What is left of a library column this wide for a row's *words*: the panel's -/// padding on both sides, the tint bar, the gap after it and the row's own right -/// inset. Every row in the column -- media and subtitle -- is built to this -/// shape, so one number answers for both. -pub(crate) fn row_text_w(width: f32) -> f32 { - // 8 px of panel padding each side, then the bar, the gap after it and the - // row's own right inset -- the numbers the rows are built with. - width - 16. - SWATCH_W - 6. - 6. -} - -/// A name cut to what a column this wide can hold, out of the *middle*. Two -/// files off one release differ in their last characters and nowhere else -- -/// "…Episode 01" against "…02" -- so a name cut from the right is the same -/// name twice and the list stops naming anything. The width decides how much -/// survives, not a number of characters somebody guessed: a wider window spells -/// more of the file out, and the floor still keeps both ends. -/// -/// The element truncates for real; this only decides where what is lost comes -/// out of. -pub(crate) fn clip_middle(name: &str, width: f32) -> String { - let budget = ((width / LIST_CHAR_W) as usize).max(LIST_CLIP_MIN); - let chars: Vec = name.chars().collect(); - if chars.len() <= budget { - return name.to_string(); - } - // The gap costs a character, and what is left of the odd one goes to the - // tail: the tail is the half that tells two of them apart. - let head = (budget - 1) / 2; - let tail = budget - 1 - head; - format!( - "{}…{}", - chars[..head].iter().collect::(), - chars[chars.len() - tail..].iter().collect::() - ) -} - /// What the window is called: the program, and what is open in it. The name is /// what the header shows, so an empty window says the program alone rather than /// "no file open — edith". diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 975f35c..7552995 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -31,9 +31,6 @@ pub(crate) use interact::*; pub(crate) use layout::*; pub(crate) use library_meta::*; pub(crate) use menus::*; -// The tests' door to the escape rule; render.rs calls it by its own name. -#[cfg(test)] -pub(crate) use render::escape_leaves_player_fullscreen; // The Contain letterbox, shared with the subtitle picture overlay // (ui/preview.rs) so both draw the same fitted rect the same way. pub(crate) use notices::*; @@ -79,12 +76,6 @@ use gpui::{ }; struct Player { - /// DESIGN.md §12 step 2: the stance skeleton behind `EDITH_DARKROOM`, read - /// once at startup ([`main`]) and never toggled at runtime -- a mid-session - /// flip would mean every region rebuilding under the pointer, which is not - /// this flag's job. [`crate::render`] branches its one `Render::render` on - /// it; nothing else reads it. - darkroom: bool, /// The timeline, once there is one. A run with no file opens without it and /// waits: the first media import or project load is what fills it, and /// until then every action that needs a timeline says so instead of acting. @@ -225,7 +216,7 @@ struct Player { pub(crate) dock_src_active: bool, /// The Sources tab's own filter text (darkroom dock, MOCK-SPEC "Dock" §2) /// and whether it is the thing typed strokes go to right now -- the same - /// capture-flag shape `keys_search`/`keys_open` already use, so a letter + /// capture-flag shape `keys_open` already uses, so a letter /// filters the list instead of firing a spine action while the box is /// focused, and does nothing to the keymap once it is not. pub(crate) dock_filter: String, @@ -512,15 +503,10 @@ struct Player { /// list). Cleared by [`Player::close_card`], the one reset list every /// opener routes through. settings_open: bool, - /// What has been typed into the card's search box, which is the card's own - /// input exactly as the export card's digits are (nothing in it takes - /// focus, so the root's key handler is the field). Emptied every time the - /// card opens: a search is a look at the list, not a setting. - keys_search: String, - /// Where that list is scrolled to. Held here rather than left to the - /// wheel alone: forty actions are four times what a 360 px window shows, - /// and the rows past the fold have to be reachable from the keyboard that - /// is already typing in the search box. + /// Where the actions list is scrolled to. Held here rather than left to + /// the wheel alone: forty actions are four times what a 360 px window + /// shows, and the rows past the fold have to be reachable from the + /// keyboard. 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 @@ -528,7 +514,6 @@ struct Player { /// it, and a scroll that nothing reads is a scroll the affordance cannot /// follow. lanes_scroll: ScrollHandle, - inspector_scroll: ScrollHandle, /// And where the equalizer card's own body has been taken to. It is the /// tallest card in the column -- a graph with a row of numbers and a row of /// buttons under it -- and at the 360 px floor its title and its buttons @@ -744,9 +729,6 @@ struct Player { /// which is what makes the colour card's graph move as a slider is dragged: /// each live write reseeks, and the reseek's frame is the next count. histogram: [[u32; HIST_BINS]; 3], - /// The action whose row is waiting for a stroke. The next key that is - /// neither escape nor a lone modifier becomes the whole of what reaches it. - rebinding: Option, /// What the file actions have had to say, oldest first. A *queue* and not a /// slot: two imports that fail back to back used to be one message, because /// the second overwrote the first before a frame had drawn it -- the failure @@ -803,19 +785,7 @@ fn main() { // DESIGN.md §1: "the room is the film's" -- darkroom mode owns the // palette outright, so the saved pick above is overridden the moment the // flag is read, once, before the first paint. - // - // Darkroom is the default room now (user order: "make darkroom default - // no need to pass environment"). `OLD_GUI=1` (any case) is the one door - // back into the legacy four-region tree -- `EDITH_DARKROOM` opted IN to - // the new room; this opts OUT of it, which is why the sense of the read - // below is inverted rather than the flag renamed in place. - let old_gui = std::env::vars() - .find(|(k, _)| k.eq_ignore_ascii_case("OLD_GUI")) - .is_some_and(|(_, v)| v.eq_ignore_ascii_case("1")); - let darkroom = !old_gui; - if darkroom { - ui::theme::set(ui::theme::PaletteId::Darkroom); - } + ui::theme::set(ui::theme::PaletteId::Darkroom); // The subtitle style the last session picked, same silence on a missing // or unreadable file. let (sub_family, sub_text) = load_subtitle_style(); @@ -875,7 +845,6 @@ fn main() { |window, cx| { let queue = queue.clone(); let player = cx.new(|cx| Player { - darkroom, // Nothing to wait for yet: the file named on the command // line is still queued, and the repaint that carries its // poster frame to the screen is asked for when it lands @@ -977,10 +946,8 @@ fn main() { keymap: keymap.clone(), keys_open: false, settings_open: false, - keys_search: String::new(), keys_scroll: ScrollHandle::new(), lanes_scroll: ScrollHandle::new(), - inspector_scroll: ScrollHandle::new(), eq_scroll: ScrollHandle::new(), export_open: false, export_grouped: true, @@ -1048,7 +1015,6 @@ fn main() { // Picture and sound, which is what an export was before // there was anything to pick. format: Format::default(), - rebinding: None, notices: notice.clone().map(SharedString::from).into_iter().collect(), exported: None, // The whole of argv, waiting for the first repaint to start diff --git a/crates/app/src/menus.rs b/crates/app/src/menus.rs index fbd1694..e933aac 100644 --- a/crates/app/src/menus.rs +++ b/crates/app/src/menus.rs @@ -240,56 +240,6 @@ pub(crate) fn keys_rows() -> Vec { rows } -/// [`keys_rows`] with a search applied: the rows whose label or whose stroke -/// carries `needle`, and the heading each one lives under. A heading with -/// nothing left beneath it goes with them -- an empty "Playback" over a gap -/// reads as a list that lost its rows rather than as a search that found none. -/// -/// Each row keeps the index it has in the unfiltered list, so an element id is -/// the same one before and after a keystroke: filtering is a look at the list, -/// and gpui's per-element state is keyed on that id. -/// -/// Case-insensitive substring, on both columns: people look for an action by -/// what it does ("vol") and for a stroke by what they pressed ("ctrl"). -pub(crate) fn keys_filter(needle: &str, keymap: &Keymap) -> Vec<(usize, KeyRow)> { - let needle = needle.trim().to_lowercase(); - let rows = keys_rows().into_iter().enumerate(); - if needle.is_empty() { - return rows.collect(); - } - // A chord matches on whole keys, not substrings -- "f1" must not drag in - // "f11". A needle that spells a combination still matches the whole chord. - let hit = |label: &str, chord: &str| { - let chord = chord.to_lowercase(); - label.to_lowercase().contains(&needle) - || chord.split([' ', '+']).any(|part| part == needle) - || (needle.contains(['+', ' ']) && chord.contains(&needle)) - }; - let mut out: Vec<(usize, KeyRow)> = Vec::new(); - // The heading above the row being looked at, until a row under it earns it - // a place -- then it goes in once, ahead of that row. - let mut pending: Option<(usize, KeyRow)> = None; - for (i, row) in rows { - match &row { - KeyRow::Head(_) => pending = Some((i, row)), - KeyRow::Act(action) => { - if hit(action.label(), &keymap.display(*action)) { - out.extend(pending.take()); - out.push((i, row)); - } - } - KeyRow::Fixed(f) => { - let fixed = &keymap::FIXED[*f]; - if hit(fixed.label, &fixed.chord) { - out.extend(pending.take()); - out.push((i, row)); - } - } - } - } - out -} - /// The character a stroke types into the actions card's search box, if it types /// one. gpui reports a printable key as itself and the space bar by name /// (platform.rs:866), and everything else -- the arrows, the function keys -- diff --git a/crates/app/src/notices.rs b/crates/app/src/notices.rs index 560f10d..ab0ddc7 100644 --- a/crates/app/src/notices.rs +++ b/crates/app/src/notices.rs @@ -7,17 +7,6 @@ use crate::*; /// eight is more than a user will ever answer in a row. pub(crate) const NOTICES_MAX: usize = 8; -/// The narrowest a notice's *message* is allowed to be squeezed before its hint -/// gives up the line and drops below it. -/// -/// The bar is a message beside a hint, and at the 640x360 floor the picture -/// region it hangs under is narrower than the hint alone -- so the message was -/// squeezed to nothing and wrapped one character per line, which is a failure -/// rendered as a column of letters. Wide enough that a line of it is a phrase -/// rather than a word ladder, and narrow enough to still fit beside the hint in -/// any window worth putting two things on a line in. -pub(crate) const NOTICE_MIN_W: f32 = 180.; - /// The whole of the queue's policy, where it can be read at once and tested /// without a window: dedupe against the back, a ceiling, oldest out first -- /// except an export's own outcome, which jumps to the front. [`Player::notify_user`] diff --git a/crates/app/src/oracle.rs b/crates/app/src/oracle.rs index 127573d..ca29d07 100644 --- a/crates/app/src/oracle.rs +++ b/crates/app/src/oracle.rs @@ -446,9 +446,3 @@ pub(crate) fn menu_at(at: Point, viewport: Size, height: f32) -> ) } -/// Whether the Add button does anything: a row picked, a timeline to put it on, -/// and no export reading that timeline. A button that would do nothing is dimmed -/// and takes no click, like every other one here. -pub(crate) fn can_add(picked: Option<&(PathBuf, usize)>, timeline: bool, exporting: bool) -> bool { - picked.is_some() && timeline && !exporting -} diff --git a/crates/app/src/player/actions.rs b/crates/app/src/player/actions.rs index 0341bc5..84cf61a 100644 --- a/crates/app/src/player/actions.rs +++ b/crates/app/src/player/actions.rs @@ -175,9 +175,13 @@ impl Player { ActionId::FocusPanels => { self.focus_surface(crate::ui::stance::Surface::Dock, window, cx); } - // Nothing to cancel while nothing is exporting; the export guard in - // the key handler is what answers this one while there is. - ActionId::CancelExport => {} + // `^esc` (or whatever the keymap now binds it to) reaches here + // through the plain `act()` dispatch even while an export is + // running (`ui::stance`'s key handler deliberately leaves + // `exporting()` out of its modal guard so this keeps working): + // was a no-op until now, the real gap the progress card's own + // "the chord as well" doc promised. + ActionId::CancelExport => self.cancel_export(), ActionId::ShowActions => self.show_actions(cx), ActionId::Settings => self.open_settings(cx), ActionId::Screenshot => self.take_screenshot(cx), @@ -256,13 +260,11 @@ impl Player { } /// The actions card, from its key, from the panel button, or from its own - /// row: open, with an empty search box -- a card that opens showing the - /// last search would hide most of the list for a reason nobody remembers. + /// row: open, scrolled to the top -- a card that opens where the last + /// look left it would hide most of the list for a reason nobody remembers. pub(crate) fn show_actions(&mut self, cx: &mut Context) { self.keys_open = true; - self.keys_search.clear(); self.scroll_keys(None); - self.rebinding = None; // One card at a time, the rule the other cards follow. self.export_open = false; cx.notify(); @@ -433,11 +435,7 @@ impl Player { // below, which otherwise repeats nothing. if self.mbps_edit.is_some() { Repeat::Card - } else if self.rebinding.is_some() - || self.keys_open - || self.export_open - || self.exporting().is_some() - { + } else if self.keys_open || self.export_open || self.exporting().is_some() { Repeat::Nothing } else if self.eq_open.is_some() || self.color_open.is_some() @@ -629,46 +627,6 @@ impl Player { self.selected.clear(); cx.notify(); } - - /// The stroke a waiting row was after: it becomes the whole of what reaches - /// that action, which is what the row was showing. A chord another action - /// already holds is refused by the keymap and the row keeps waiting, so the - /// next stroke is another try rather than a lost one. A binding that took - /// holds either way: - /// what a failed write costs is only the next run, which is what the notice - /// is for. - pub(crate) fn capture(&mut self, action: ActionId, key: &str, ctrl: bool) { - let chord = keymap::Chord { - key: key.to_string(), - ctrl, - }; - // Only a stroke the file can spell and read back as itself: gpui reports - // "+" for shift+=, which is the chord grammar's separator, so binding it - // would write a line the next load would have to drop. Refused here, in - // front of the user, rather than silently costing that binding later. - // The row keeps waiting, as it does for a stroke already taken. - if !chord.bindable() { - let text = format!("THAT KEY CANNOT BE BOUND — {}", chord.pretty()); - eprintln!("{text}"); - self.notify_user(text.into()); - return; - } - let text = match self.keymap.rebind_action(action, chord.clone()) { - Ok(()) => { - self.rebinding = None; - match self.keymap.save() { - Ok(()) => return, - Err(e) => format!( - "KEYBINDINGS NOT SAVED — {}: {e}", - Keymap::config_path().display() - ), - } - } - Err(holder) => format!("ALREADY BOUND — {} is {}", chord.pretty(), holder.label()), - }; - eprintln!("{text}"); - self.notify_user(text.into()); - } } /// The half-open range a mark and a mark make, in either order: a person's two diff --git a/crates/app/src/player/cards.rs b/crates/app/src/player/cards.rs index 060d200..e0130a7 100644 --- a/crates/app/src/player/cards.rs +++ b/crates/app/src/player/cards.rs @@ -1313,8 +1313,6 @@ impl Player { pub(crate) fn close_card(&mut self) { self.keys_open = false; self.settings_open = false; - self.keys_search.clear(); - self.rebinding = None; self.export_open = false; // The two things typed *into* the export card go with it: a field left // open would take the next keystroke for a card that is gone. @@ -1741,6 +1739,30 @@ impl Player { } return true; } + // The export card's custom bitrate field: the mouse door is the + // steppers and the row's own click (`Player::edit_mbps`), but the + // `0–9`/backspace/enter/esc chords `keymap::FIXED` already + // advertises need a keyboard door too, or a hand with no mouse + // could open the field and never fill it in. + if self.export_open { + if let Some(edit) = &mut self.mbps_edit { + if key == ESCAPE { + self.mbps_edit = None; + } else if key == "enter" { + if let Some(mbps) = edit.commit() { + self.custom_mbps = mbps; + self.mbps_edit = None; + } + } else if key == "backspace" { + edit.backspace(); + } else if let Ok(digit) = key.parse::() { + edit.digit(digit); + } else { + return false; + } + return true; + } + } false } } diff --git a/crates/app/src/player/export.rs b/crates/app/src/player/export.rs index 0d64b31..a978a92 100644 --- a/crates/app/src/player/export.rs +++ b/crates/app/src/player/export.rs @@ -414,7 +414,6 @@ impl Player { // was waiting in. Nor may a half-typed number: the card opens on the // bitrate it will write, never on digits left behind by a closed one. self.keys_open = false; - self.rebinding = None; self.mbps_edit = None; cx.notify(); } @@ -465,34 +464,6 @@ impl Player { self.set_format(next_container(self.format)); } - /// The quality rows by keyboard, wrapping. Refused by name where the format - /// has no bitrate to pick: a key that silently does nothing is the card - /// looking broken. - pub(crate) fn cycle_quality(&mut self) { - if let Some(why) = bitrate_refusal(self.format) { - self.notify_user(why.into()); - return; - } - let at = Quality::ALL - .iter() - .position(|&q| q == self.quality) - .unwrap_or(0); - self.quality = Quality::ALL[(at + 1) % Quality::ALL.len()]; - } - - /// The sound's rate by keyboard, wrapping through the offered ones -- the - /// picture's quality row for the other half of the file. Refused by name - /// where this timeline in this format has no rate to pick, exactly as - /// [`Player::cycle_quality`] is: a key that silently does nothing is the - /// card looking broken. - pub(crate) fn cycle_audio_kbps(&mut self) { - if let Some(why) = self.audio_rate_refusal() { - self.notify_user(why.into()); - return; - } - self.audio_kbps = next_audio_kbps(self.audio_kbps); - } - /// Which encoder an export of this project would write the picture with /// ([`engine::export::EncoderSeat`]). The session's, because it is saved /// with the project -- there is no card-local copy to drift from it -- and @@ -515,22 +486,6 @@ impl Player { cx.notify(); } - /// The seat by keyboard, wrapping through the three -- the Sound row's - /// rule, for the row beside it. Refused by name with no timeline: a key - /// that silently does nothing is the card looking broken. - pub(crate) fn cycle_encoder(&mut self, cx: &mut Context) { - let Some(session) = &self.session else { - self.notify_user("no timeline to export — open a file first".into()); - cx.notify(); - return; - }; - let at = EncoderSeat::ALL - .iter() - .position(|&s| s == session.encoder_seat()) - .unwrap_or(0); - self.apply_encoder(EncoderSeat::ALL[(at + 1) % EncoderSeat::ALL.len()], cx); - } - /// Why the sound row is not a choice right now, the engine answering about /// the very project it would export. No session is the same answer as no /// sound: there is nothing to write either way. diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index 99b20a0..afd8058 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -47,16 +47,11 @@ impl Player { // notice per keystroke would turn the ledger into a firehose, // exactly what §8's "one at a time" is against; a single `s` is // not that. - // The legacy room has no ledger reading this queue and never - // notified on a split before -- gated so that room's behaviour - // stays exactly as it was. let cut = session.cut_at(f64::from(at) / self.fps); - if self.darkroom { - if cut { - self.notify_user("SPLIT".into()); - } else { - self.notify_user("NOTHING TO SPLIT — the playhead is already on a cut".into()); - } + if cut { + self.notify_user("SPLIT".into()); + } else { + self.notify_user("NOTHING TO SPLIT — the playhead is already on a cut".into()); } } self.selected.clear(); @@ -862,29 +857,6 @@ impl Player { live_idx(session.lane_clips(drag.lane), drag.idx, drag.clip) } - /// The line while the clip is still in the hand: the very answer - /// [`Player::drop_frame`] will commit, worked out on every move of the drag, - /// so what the eye was promised is where the release puts it. A pointer that - /// has wandered off the bed promises nothing. - pub(crate) fn preview_drop( - &mut self, - from: Lane, - idx: usize, - x: Pixels, - cx: &mut Context, - ) { - let cue = self.drop_frame(from, idx, x).and_then(|(_, cue)| cue); - self.set_cue(cue, x, cx); - } - - /// The same line for a library row on its way to a lane: it goes down at - /// the frame it is let go on ([`Player::place_frame`]), so that frame is - /// what snaps and what is drawn. - pub(crate) fn preview_place(&mut self, x: Pixels, cx: &mut Context) { - let cue = self.place_frame(x).1; - self.set_cue(cue, x, cx); - } - /// The shadow the clip in the hand would fill, on the lane the pointer is /// over: its head where [`Player::drop_frame`] says the release will put it /// -- the same call the drop makes, so the box drawn and the box committed @@ -1145,37 +1117,6 @@ impl Player { .unwrap_or(raw) } - /// Whether the playhead is standing exactly on one: what the timeline's own - /// line says out loud, so "a cut here is copied" is on screen before the cut - /// rather than discovered in the export card afterwards. - /// - /// Asked every repaint, so it walks the *playhead* into each clip's source - /// and looks it up in that source's own sorted grid -- where - /// [`Player::sync_frames`] builds the whole list, which is a film's worth of - /// marks to allocate and sort sixty times a second. - pub(crate) fn on_sync_point(&self) -> bool { - let Some(session) = &self.session else { - return false; - }; - let now = frame_at(session.now(), self.fps); - let sources = session.sources(); - session.lanes().into_iter().any(|lane| { - lane.kind == LaneKind::Video - && session.lane_clips(lane).iter().any(|clip| { - clip.speed.is_normal() - && (clip.start..clip.start + (clip.out_frame - clip.in_frame)) - .contains(&now) - && sources - .get(clip.source) - .and_then(|entry| self.syncs.get(&entry.path)) - .is_some_and(|keys| { - keys.binary_search(&(clip.in_frame + (now - clip.start))) - .is_ok() - }) - }) - }) - } - /// Puts the playhead on the sync point before or after it -- the keyboard's /// half of placing a cut where the export can copy it, and the only way to /// reach one exactly on a timeline zoomed out to a whole film, where one diff --git a/crates/app/src/player/view.rs b/crates/app/src/player/view.rs index d8c750f..e7df591 100644 --- a/crates/app/src/player/view.rs +++ b/crates/app/src/player/view.rs @@ -251,55 +251,6 @@ impl Player { cx.notify(); } - /// A press on the scrollbar's track: on the thumb, the drag begins from - /// wherever in it the hand landed; beside it, the view jumps so the - /// thumb's middle is at the press and the drag carries on from there -- - /// a click is a jump, and holding it is a jump that keeps going. - pub(crate) fn scroll_press(&mut self, x: Pixels, cx: &mut Context) { - let view = self.view(); - if view.bed <= 0. || view.duration <= 0. { - return; - } - let (thumb_x, thumb_w) = scroll_thumb( - view.bed, - view.duration, - view.scale.start.max(0.), - view.span(), - ); - let at = px_along(x, self.scroll_track.get()); - let grab = match (thumb_x..thumb_x + thumb_w).contains(&at) { - true => at - thumb_x, - // Beside the thumb: jump so its middle is under the pointer -- - // by the track's own proportion, the very mapping a drag sample - // is read through below, so the first move of the drag that - // follows lands exactly where the jump left the view and the - // thumb never snaps under the hand (a jump worked out in pixels - // at the view's own pps landed at span-over-duration of the - // target and the snap was the drag correcting it). The thumb is - // clamped inside the track by [`scroll_thumb`], so the grab this - // leaves is always a real place inside it -- at the thumb's floor - // width as much as anywhere else. - false => { - let start = f64::from((at - thumb_w / 2.).max(0.)) / f64::from(view.bed.max(1.)) - * view.duration; - self.scale = View { - scale: Scale { - start, - ..view.scale - }, - ..view - } - .settled(); - thumb_w / 2. - } - }; - self.scroll_drag = Some(grab); - // The wheel's own claim on the follow: a hand on the scrollbar is - // looking away from the playhead on purpose. - self.panned = true; - cx.notify(); - } - /// A sample of a thumb drag: the window starts where the thumb's grabbed /// point sits under the pointer, clamped by the same `settled` every other /// scroll answers to. No reseek, no worker -- the view is the only thing @@ -336,38 +287,6 @@ impl Player { to.clamp(0., max) } - /// A press on the lane stack's scrollbar: on the thumb, the drag begins - /// from wherever in it the hand landed; beside it, the stack jumps so the - /// thumb's middle is at the press and the drag carries on from there -- - /// the time axis's own terms ([`Self::scroll_press`]), turned through a - /// right angle. - pub(crate) fn lanes_press(&mut self, y: Pixels, cx: &mut Context) { - let track = f32::from(self.lanes_scroll.bounds().size.height); - let max = f32::from(self.lanes_scroll.max_offset().height); - if track <= 0. || max <= 0. { - return; - } - let scrolled = -f32::from(self.lanes_scroll.offset().y); - let (thumb_y, thumb_h) = lanes_thumb(track, track + max, track, scrolled); - let at = px_down(y, self.lanes_scroll.bounds()); - let grab = match (thumb_y..thumb_y + thumb_h).contains(&at) { - true => at - thumb_y, - // Beside the thumb: jump so its middle is under the pointer, at - // the press's own share of the stack. The thumb is clamped inside - // the track by [`lanes_thumb`], so the grab this leaves is always - // a real place inside it. - false => { - let to = - self.lanes_taken((at - thumb_h / 2.).max(0.) / (track - thumb_h).max(1.) * max); - self.lanes_scroll - .set_offset(point(self.lanes_scroll.offset().x, px(-to))); - thumb_h / 2. - } - }; - self.lanes_drag = Some(grab); - cx.notify(); - } - /// A sample of the lane thumb's drag: the stack is taken to where the /// thumb's grabbed point sits under the pointer, clamped by the same /// `max_offset` the column's own wheel answers to. No reseek, no repaint @@ -386,23 +305,6 @@ impl Player { cx.notify(); } - /// The wheel over the lane stack's strip, in the pixels gpui's own scroll - /// of the column would move it (`pixel_delta` -- a line a notch, not a - /// share of anything): the strip stops the wheel before the column behind - /// it sees it, so this is the notch's one path and it moves the stack - /// exactly as far as the names' own surface does. - pub(crate) fn lanes_wheel(&mut self, dy: f32, cx: &mut Context) { - let max = f32::from(self.lanes_scroll.max_offset().height); - if max <= 0. { - return; - } - let scrolled = -f32::from(self.lanes_scroll.offset().y); - let to = self.lanes_taken(scrolled - dy); - self.lanes_scroll - .set_offset(point(self.lanes_scroll.offset().x, px(-to))); - cx.notify(); - } - /// One notch of the wheel anywhere over the timeline -- the ruler or a /// lane's bed alike, since a hand aims at the clip it is working on and not /// at the strip above it. Ctrl zooms about the pointer, bare scrolls the diff --git a/crates/app/src/render.rs b/crates/app/src/render.rs index 186a913..012115e 100644 --- a/crates/app/src/render.rs +++ b/crates/app/src/render.rs @@ -3,20 +3,6 @@ use crate::*; -/// Whether a stroke leaves player fullscreen. Bare escape does, the same -/// stroke every card and menu in this window answers to -- and it is -/// answered *first*: the picture-only layout is the chrome itself missing, -/// not a card drawn over it, so it goes before a menu close or a preview -/// close gets a look at the same key. See the call site in [`Player::render`] -/// for the deliberate order this buys with a preview open underneath. -pub(crate) fn escape_leaves_player_fullscreen( - key: &str, - ctrl: bool, - player_fullscreen: bool, -) -> bool { - key == ESCAPE && !ctrl && player_fullscreen -} - /// The frame `image`, letterboxed/pillarboxed into whatever box it is given, /// filling that box on its own axis and leaving the other bare -- the bare /// strip is the box's own background (`BG_CANVAS`), never painted here, which @@ -109,7 +95,6 @@ impl Player { // After the picture, so the plate is drawn over it rather than // under. .children(self.subtitle_overlay(position, window)) - .children(self.preview_badge(cx)) // The three transient lines hang off the bottom of the picture // rather than taking a row of the column: a notice that arrives // must not push the transport, the toolbar and the timeline down @@ -126,14 +111,6 @@ impl Player { .gap(px(2.)) .children(self.import_bar(cx)) .children(self.seek_bar()) - // DESIGN §8: no full-width bar over the picture, ever. - // The darkroom stance has its own §8-conformant notice - // plate above the ledger (`ui::stance::notice_plate`) -- - // this legacy bar would otherwise paint a second, - // picture-covering copy of the same notice underneath - // it. The legacy (non-darkroom) room keeps this bar - // exactly as it was. - .children((!self.darkroom).then(|| self.notice_bar(cx)).flatten()) // How tall the lot came out, for the cue plate above to // step over ([`sub_bottom`]) -- the bars are over the // picture, and a message drawn across the line being @@ -248,471 +225,6 @@ impl Render for Player { self.panned = false; } - // DESIGN.md §12 step 2: the stance skeleton, on by default now - // (`OLD_GUI=1` opts back into the tree below). - // `.into_any_element()` on both arms is the one thing this branch - // costs the legacy tree below -- an `impl IntoElement` return can - // only be one concrete type, and the two trees are not the same one. - if self.darkroom { - return ui::stance::render(self, window, cx).into_any_element(); - } - - (div() - .track_focus(&self.focus) - .on_key_down(cx.listener(|this, event: &KeyDownEvent, window, cx| { - let key = event.keystroke.key.as_str(); - let ctrl = event.keystroke.modifiers.control; - // `is_held` is the auto-repeat, and a value is the one thing - // worth running on it: a held arrow on a card moves the slider - // it picked, and a held volume key runs the volume. Everything - // else is filtered exactly as it always was -- a repeat that - // toggled playback, or cut the timeline, many times a second is - // what this guard is for, and a row waiting for a stroke takes - // none of it either (it would bind the key, then fire what it - // just bound). See [`repeats`]. - if event.is_held - && !repeats(this.repeat_scope(), key, this.keymap.lookup(key, ctrl)) - { - return; - } - // The recovery notice is the one bar that reads a key as more - // than "answered": `enter` loads the sidecar it named, and - // every other key declines it -- the way any other key - // dismisses any other notice. Asked before the generic - // dismiss below shares the same door with it, not instead of - // it: this recovers or declines, that pops the bar. - if this.recovery_sidecar.is_some() { - if key == "enter" { - this.recover_from_sidecar(cx); - } else if let Some(sidecar) = this.recovery_sidecar.take() { - Player::discard_sidecar(&sidecar); - } - } - // Any key answers the message on the bar and brings the next of - // them up, whatever it was -- and owes - // the repaint itself: a notice no longer keeps the render loop - // alive, and the arms below that do notify are not all of them - // (an unbound key, or the copy chord, changes nothing else). - if this.dismiss_notice() { - cx.notify(); - } - // A row is waiting for a stroke, and while it is, that stroke is - // data: it means the binding and nothing else, which is why this - // answers before the export guard and before the keymap is - // consulted at all. - if let Some(action) = this.rebinding { - if key == ESCAPE { - this.rebinding = None; - } else if !is_bare_modifier(key) { - this.capture(action, key, ctrl); - } - cx.notify(); - return; - } - // On linux gpui reports the copy chord as key "c" with the - // control modifier set (the control code is mapped back), which - // is why the keymap is keyed on the pair and never on the key - // alone. - let action = this.keymap.lookup(key, ctrl); - // An export is reading the edit list every other action here - // would change, so cancelling is the only one that means - // anything until it is over. - if this.exporting().is_some() { - if cancels_export(key, ctrl, action) { - this.cancel_export(); - } - cx.notify(); - return; - } - // The overlay owns the keyboard while it is up -- but it types - // now: a printable stroke is the search box's, which is why - // nothing here reaches the keymap. A waiting row is answered - // above and still wins, so a rebind onto "v" binds the key - // rather than typing it. - if this.keys_open { - if key == ESCAPE { - // Two steps out, the way a search box anywhere gets - // out: the filter first -- the whole list back -- - // and the card only once there is no search to clear. - if this.keys_search.is_empty() { - this.keys_open = false; - } else { - this.keys_search.clear(); - this.scroll_keys(None); - } - // The rows past the fold, without a wheel: forty actions - // are four times what the viewport shows, and the hand - // typing in the search box is already on the keyboard. - } else if key == "up" { - this.scroll_keys(Some(KEYS_ROW_H)); - } else if key == "down" { - this.scroll_keys(Some(-KEYS_ROW_H)); - } else if key == "backspace" { - this.keys_search.pop(); - this.scroll_keys(None); - } else if let Some(c) = typed(key) { - this.keys_search.push(c); - this.scroll_keys(None); - } - cx.notify(); - return; - } - // The dock's Sources filter (MOCK-SPEC "Dock" §2): owns the - // keyboard only while it was clicked into, exactly the - // `keys_search` shape above -- a letter typed anywhere else in - // the room still means what the spine says it means. - if this.dock_filter_edit { - if key == "escape" || key == "enter" { - this.dock_filter_edit = false; - } else if key == "backspace" { - this.dock_filter.pop(); - } else if let Some(c) = typed(key) { - this.dock_filter.push(c); - } - cx.notify(); - return; - } - // `↵` adds the picked source at the playhead (MOCK-SPEC "Dock" - // hint paragraph, gesture 2) -- the keyboard door beside the - // legacy "Add at playhead" button's pointer one, live only - // where a row is actually picked so a bare enter elsewhere - // keeps meaning whatever it already means below. - if key == "enter" - && this.dock_src_active - && this.selected_asset.is_some() - && this.exporting().is_none() - { - if let Some((path, stream)) = this.selected_asset.clone() { - this.insert_source(&path, stream, None, None, cx); - } - cx.notify(); - return; - } - // The export card owns it the same way, and for the same - // reason. Escape closes it -- nothing has been written yet, so - // there is nothing here to cancel -- and the card's own letters - // are its input: it has no widget that takes focus (nothing in - // it does), so this listener is its keyboard, exactly as it is - // a waiting row's. - if this.export_open { - // A list open over the card is the innermost thing on - // screen, so it is what a stroke closes first -- the rule - // every menu here follows, said before the card's own keys - // so escape does not take the card out from under it. - if this.picker.take().is_some() { - cx.notify(); - return; - } - // A number being typed is the next thing in: while the - // field is open every stroke is text, which is what makes - // it a field and not a capture -- the card's letters cannot - // fire under it, and escape gives up the edit before it - // touches the card. - if let Some(edit) = &mut this.mbps_edit { - if key == ESCAPE { - this.mbps_edit = None; - } else if key == "enter" { - // Committed or refused in its own words; a refused - // one stays open on what was typed, so the number - // can be fixed rather than typed again. - if let Some(mbps) = edit.commit() { - this.custom_mbps = mbps; - this.quality = Quality::Custom; - this.mbps_edit = None; - } - } else if key == "backspace" { - edit.backspace(); - } else if key == "up" { - edit.step(1); - } else if key == "down" { - edit.step(-1); - } else if let Ok(digit) = key.parse::() { - edit.digit(digit); - } - cx.notify(); - return; - } - if key == ESCAPE { - this.export_open = false; - } else if key == "enter" { - // The card's own button, by keyboard: the one thing in - // it that writes a file must not be pointer-only either. - this.start_export(cx); - } else if let Some(format) = format_key(key, this.format) { - // The codec rows by their own letter, so the card can be - // driven without a mouse -- the same card-local input - // the typed bitrate is, and for the same reason: a - // choice reachable only by pointer is not reachable by - // everyone. Not a keymap binding: it means nothing - // outside this card, exactly like the digits. - this.set_format(format); - } else if key == "c" { - this.cycle_container(); - } else if key == "q" { - this.cycle_quality(); - } else if key == "b" { - // The sound's rate, `q`'s pair for the other half of - // the file. Not a digit: those are the picture's. - this.cycle_audio_kbps(); - } else if key == "e" { - // Which encoder writes the picture, `b`'s neighbour for - // the other thing about the file a person picks rather - // than types. Card-local like the rest of these. - this.cycle_encoder(cx); - } else if key == "d" { - // The save dialog, which was the one row here a - // keyboard could not open. - this.pick_destination(cx); - } else if let Some(preset) = ExportPreset::ALL - .into_iter() - .find(|p| p.key() == key) - // `Custom` shares `s` with Advanced below, which already - // handles that key -- reaching it here too would only - // race the same assignment against itself. - .filter(|p| *p != ExportPreset::Custom) - { - this.pick_preset(preset); - } else if key == "g" { - this.export_grouped = !this.export_grouped; - } else if key == "r" { - this.export_refusals_inline = !this.export_refusals_inline; - } else if key == "s" { - // The Advanced pane, by keyboard: the primary pane's - // own row for it opens the same way a click does. - this.export_advanced_open = !this.export_advanced_open; - } else if key == "n" { - // The custom row's field, by keyboard. The digits used - // to do this from anywhere in the card, which meant a - // stray keystroke changed the bitrate with nothing on - // screen to say it had: now a digit outside the field - // means nothing at all, and this is the way in. - this.edit_mbps(); - } - cx.notify(); - return; - } - // Every param card's own key branch, factored into - // `Player::param_card_key` (`player/cards.rs`) so this tree and - // the darkroom stance drive the same logic rather than a - // second, divergent copy. - if this.param_card_key(key, event.keystroke.modifiers.shift, cx) { - cx.notify(); - return; - } - // A clip menu names an index, and every edit below moves - // indices -- so a stroke closes it before it acts. Escape means - // that and nothing else, which is the `esc` the keys menu - // already lists (keymap.rs `FIXED`). - // Both menus, taken rather than short-circuited: the library's - // one names a row the edits below can remove, so it closes on a - // stroke exactly as the clip menu does. - // A choice list goes the same way and for the same reason: it - // names a clip index too, and escape is the way out of it. - // An open list is the innermost thing on screen, so it takes - // the keys before anything under it does: ↑↓ walk it, enter - // takes the row, and escape falls through to the close below -- - // the same three strokes every list in this editor answers. - // The picture-only layout is the outermost thing on screen -- - // it is the chrome itself that is missing, not a card drawn - // over it -- so its own escape is answered before any menu or - // preview below gets a look at the stroke. Deliberate order: - // with a preview open *and* the player fullscreen, the first - // Escape only leaves fullscreen (the preview keeps playing, - // now behind the chrome again), and it takes a second Escape - // to stop the preview -- one stroke, one effect, same as - // every other card in this chain. - if escape_leaves_player_fullscreen(key, ctrl, this.player_fullscreen) { - this.player_fullscreen = false; - window.toggle_fullscreen(); - cx.notify(); - return; - } - if let Some(mut picker) = this.picker { - let rows = this.choices(picker.of); - if !rows.is_empty() && matches!(key, "up" | "down" | "enter") { - match key { - "down" => picker.sel = (picker.sel + 1) % rows.len(), - "up" => picker.sel = (picker.sel + rows.len() - 1) % rows.len(), - _ => { - let (choice, ..) = rows[picker.sel.min(rows.len() - 1)]; - this.choose(choice, cx); - cx.notify(); - return; - } - } - this.picker = Some(picker); - cx.notify(); - return; - } - } - let clip_menu = this.context_menu.take().is_some(); - let row_menu = this.library_menu.take().is_some(); - let list = this.picker.take().is_some(); - if clip_menu || row_menu || list { - cx.notify(); - if key == ESCAPE { - return; - } - } - // The innermost thing left on screen once no menu is up: a - // preview takes the picture over the timeline's own, and - // escape is its own way out, same as every card above it. - if key == ESCAPE && !ctrl && this.preview_session.is_some() { - this.close_preview(cx); - return; - } - if let Some(action) = action { - this.act(action, window, cx); - } - })) - // The whole window is the drop target: gpui turns an external file - // drop into an `ExternalPaths` drag (window.rs:3626) delivered as a - // mouse-up to every hovered hitbox, and the root's is the only one - // that covers the picture as well as the panel. - .on_drop(cx.listener(|this, paths: &gpui::ExternalPaths, _, cx| { - // The overlay owns the pointer as well as the keyboard, and a - // drop is a click the scrim cannot swallow: gpui delivers it to - // the root's hitbox, which is under the scrim but is not a - // sibling it can stop. The export card is over the timeline for - // the same reason: importing under it would change the very - // edit list the card is about to write out. - if this.modal() { - return; - } - for path in paths.paths() { - // One queue for all of them, in arrival order: the fork -- - // a project replaces the timeline, media joins the library - // -- is made when each one's worker starts ([`arrival`]), - // and neither is read on this thread. - this.import(path, cx); - } - })) - // A drop event carries no path of its own -- gpui only tells the - // target that something landed -- so the line that promises where - // it will land is fed by the drag's own moves, which do carry the - // pointer (gpui div.rs:282). On the root, because a drag crosses - // the window: it starts on a clip or on a library row and ends over - // a lane, and only an ancestor of both hears all of it. - .on_drag_move(cx.listener(|this, event: &DragMoveEvent, _, cx| { - // The clip the payload named, wherever an edit mid-drag has - // since put it ([`Player::dragged`]): the line has to promise a - // landing for the take actually in the hand. - let drag = *event.drag(cx); - if let Some(idx) = this.dragged(&drag) { - this.preview_drop(drag.lane, idx, event.event.position.x, cx); - } - // The shadow belongs to a *lane*, and which lane the pointer is - // over is the one thing this element cannot see. Cleared here - // and drawn again by the lane the pointer is actually inside - // (`lane_row`), which gpui runs straight after this one: the - // capture phase goes parent first, so a pointer over no lane at - // all -- up in the library, say -- promises nothing. - this.set_ghost(Vec::new(), cx); - })) - .on_drag_move( - cx.listener(|this, event: &DragMoveEvent, _, cx| { - this.preview_place(event.event.position.x, cx); - this.set_ghost(Vec::new(), cx); - }), - ) - // The same pair for the two subtitle gestures, for the same reason: - // a palette row starts up in the library and a caption starts on a - // lane, and both are let go somewhere else entirely. - .on_drag_move(cx.listener(|this, event: &DragMoveEvent, _, cx| { - this.preview_place(event.event.position.x, cx); - this.set_ghost(Vec::new(), cx); - })) - .on_drag_move(cx.listener(|this, event: &DragMoveEvent, _, cx| { - // The placement gpui froze into the payload, whose *length* is - // all the line needs; which caption it is is the drop's - // question ([`Player::dragged_sub`]). - let (drag, x) = (*event.drag(cx), event.event.position.x); - let cue = this.sub_drop_frame(drag.sub, x).1; - this.set_cue(cue, x, cx); - this.set_ghost(Vec::new(), cx); - })) - // Scrubbing is tracked on the root because the pointer leaves the - // 6 px ruler on the first drag and its own listeners then stop - // firing; the root's hitbox is the whole window. - .on_mouse_move(cx.listener(Self::drag_move)) - .on_mouse_up(MouseButton::Left, cx.listener(Self::drag_release)) - .size_full() - .flex() - .flex_col() - .bg(rgb(BG_CANVAS())) - .text_color(rgb(FG_PRIMARY())) - .text_size(px(12.)) - // Four regions, the arrangement every consumer editor shares: - // library left, picture centre, inspector right, and the timeline - // full width along the bottom with its edit toolbar directly above - // it. Nothing here moves when the state changes -- the regions are - // fixed and the panels keep their room whether or not anything is - // open in them. - // Player fullscreen: the picture and nothing else -- what - // `Fullscreen` gives every consumer video player. The four-region - // layout is skipped rather than hidden under it (a hidden library - // and inspector would still lay out and take the split's own - // room), and the picture div itself is untouched either way -- - // [`Player::picture_area`] is the same call in both arms. - .when(self.player_fullscreen, |d| { - d.child(self.picture_area(position, window, cx)) - }) - .when(!self.player_fullscreen, |d| { - d.child(self.topbar(window, cx)) - .child( - div() - .flex_1() - .min_h(px(0.)) - .flex() - .child( - self.library( - self.split_px(Split::Library, window.viewport_size()), - cx, - ), - ) - // The seams, one per pair of regions: what a hand - // drags to give a panel more room and its - // neighbour less ([`divider`]). - .child(divider(Split::Library, cx)) - .child( - div() - .flex_1() - .min_w(px(0.)) - .flex() - .flex_col() - .child(self.picture_area(position, window, cx)) - .child(self.transport_bar(state, window.viewport_size(), cx)), - ) - .child(divider(Split::Inspector, cx)) - // The settings cards live in here rather than over - // the timeline: adjusting a clip must not hide the - // clip. - .child(self.inspector(window.viewport_size(), cx)), - ) - // Above the toolbar rather than under it: the toolbar is - // a fixed strip belonging to the timeline, so the pair - // moves as one and the edge the hand is pulling is the - // edge under the pointer. - .child(divider(Split::Timeline, cx)) - .child(self.toolbar(cx)) - .child(self.timeline(position, state, window.viewport_size(), cx)) - }) - // Over the region they were opened on, and under the modal cards: - // they are only ever up while none of those is (`modal`). - .children(self.context_card(window.viewport_size(), cx)) - .children(self.library_card(window.viewport_size(), cx)) - // The two that are genuinely modal -- the whole registry, and the - // card that writes a file -- are the only sheets left over the - // window. - .children(self.keys_overlay(cx)) - .children(self.export_card(window.viewport_size(), cx)) - // The same sheet once the card has been answered: the running - // export is the one state in this window where nothing may be - // edited, so it is drawn as what it is rather than as a strip. - .children(self.export_progress_card(cx)) - // Last, so it floats over whatever opened it -- an inspector row or - // a clip menu -- rather than under it. - .children(self.picker_card(window.viewport_size(), cx))) - .into_any_element() + ui::stance::render(self, window, cx) } } diff --git a/crates/app/src/tests/cards.rs b/crates/app/src/tests/cards.rs index 9389498..0dc6cf7 100644 --- a/crates/app/src/tests/cards.rs +++ b/crates/app/src/tests/cards.rs @@ -3,7 +3,7 @@ use super::*; use crate::audio_cards::EQ_GRAPH_MAX_H; -use crate::ui::inspector::transition_of; +use crate::ui::dock_stance::transition_of; use std::sync::atomic::Ordering; /// FAULT 2's general shape (not just the source dot's menu): `overlaid()` @@ -29,7 +29,7 @@ fn no_overlaid_state_in_the_stance_goes_modal_without_painting_something() { ); } let guard_at = stance - .find("if this.rebinding.is_some()\n || this.card_open()") + .find("if this.card_open()\n || this.context_menu.is_some()") .expect("the stance's modal guard"); let guard = &stance[guard_at..guard_at + 1600]; for field in [ @@ -39,7 +39,7 @@ fn no_overlaid_state_in_the_stance_goes_modal_without_painting_something() { ] { assert!( guard.contains(field), - "the overlaid()/rebinding branch no longer clears {field} on every key -- \ + "the overlaid() branch no longer clears {field} on every key -- \ a menu can go modal and unrecoverable again (FAULT 2)" ); } @@ -139,7 +139,7 @@ fn every_modal_field_has_a_mounted_surface_somewhere_in_the_darkroom() { fn the_stances_key_guard_does_not_swallow_a_bare_export_before_the_oracle_is_asked() { let stance = src_text("ui/stance.rs"); let guard_at = stance - .find("if this.rebinding.is_some()\n || this.card_open()") + .find("if this.card_open()\n || this.context_menu.is_some()") .expect("the stance's modal guard moved -- update this test's search string"); let guard_line = &stance[guard_at..guard_at + 200]; assert!( @@ -159,58 +159,6 @@ fn the_stances_key_guard_does_not_swallow_a_bare_export_before_the_oracle_is_ask ); } -#[test] -fn a_bare_escape_leaves_player_fullscreen_before_anything_under_it() { - // Fires while the picture-only layout is up, on the same bare escape - // every menu and preview close on -- and only that key: a chord, or an - // escape while not fullscreen, means nothing to it. - assert!(escape_leaves_player_fullscreen("escape", false, true)); - assert!(!escape_leaves_player_fullscreen("escape", false, false)); - assert!(!escape_leaves_player_fullscreen("escape", true, true)); - assert!(!escape_leaves_player_fullscreen("q", false, true)); -} - -#[test] -fn only_a_chord_gets_out_of_an_export() { - use keymap::ActionId; - // What this guards: bare escape is the stroke a hand throws at anything on - // screen, and while an export ran it deleted the encode. The way out is the - // same key with control on it, and the card says so. - assert!(cancels_export("escape", true, Some(ActionId::CancelExport))); - assert!(!cancels_export("escape", false, None)); - // Even if something else were ever bound to bare escape, it is not this. - assert!(!cancels_export("escape", false, Some(ActionId::Play))); - // A rebound cancel works as well -- it adds a way out, never replaces the - // chord, and the keymap is what decides whether that one carries control. - assert!(cancels_export("q", false, Some(ActionId::CancelExport))); - // Nothing else does, whatever it means outside an export. - assert!(!cancels_export("e", false, Some(ActionId::Export))); - assert!(!cancels_export("space", false, Some(ActionId::Play))); - assert!(!cancels_export("q", false, None)); - // The default keymap is what the handler feeds this: the chord reaches - // CancelExport, the bare key reaches Deselect instead -- neither of which - // this guard lets cancel a running export. - let k = keymap::Keymap::defaults(); - assert!(cancels_export("escape", true, k.lookup("escape", true))); - assert!(!cancels_export("escape", false, k.lookup("escape", false))); -} - -#[test] -fn a_capture_waits_through_a_lone_modifier() { - // gpui delivers these on their own; taking one as a binding would make - // the action fire on the way to every chord that uses it. - for key in [ - "control", "shift", "alt", "super", "platform", "function", "fn", "meta", "command", - ] { - assert!(is_bare_modifier(key), "{key}"); - } - // Everything a binding is actually made of, escape included -- the - // capture branch turns that one away itself. - for key in ["c", "x", "space", "escape", "delete", "f1", "z"] { - assert!(!is_bare_modifier(key), "{key}"); - } -} - /// The whole point of the card: there is no action a pointer cannot reach. /// It renders [`keys_rows`] and nothing else, so this reads the same list /// the card does -- add an `ActionId` and forget to surface it and this @@ -263,78 +211,10 @@ fn every_action_is_on_the_actions_card() { assert!(!action.label().is_empty(), "{action:?}"); assert_ne!(keymap.display(action), "unbound", "{action:?}"); } - // The list scrolls inside a card the smallest window holds, so a - // thirty-fourth action costs no height at all. - assert!( - rows.len() as f32 * KEYS_ROW_H > KEYS_ROWS_H, - "no cap needed?" - ); // Both halves of a row are click targets, so WCAG 2.5.8 binds them. assert!(KEYS_ROW_H >= HIT_MIN); } -/// The search box: what a typed word leaves standing. Forty actions is more -/// than a 360 px window shows at once, so this is the card's answer to -/// "where is the one I want" -- and a heading with nothing under it would -/// be worse than no filter at all. -#[test] -fn a_search_leaves_the_rows_it_names_under_their_own_headings() { - use keymap::{ActionId, Category, Keymap}; - let keymap = Keymap::defaults(); - let acts = |found: &[(usize, KeyRow)]| -> Vec { - found - .iter() - .filter_map(|(_, r)| match r { - KeyRow::Act(a) => Some(*a), - _ => None, - }) - .collect() - }; - let heads = |found: &[(usize, KeyRow)]| -> Vec { - found - .iter() - .filter_map(|(_, r)| match r { - KeyRow::Head(c) => Some(*c), - _ => None, - }) - .collect() - }; - // Nothing typed hides nothing, and every row keeps its place in the - // unfiltered list: an element id must not move under a keystroke. - let all = keys_filter("", &keymap); - assert_eq!(all.len(), keys_rows().len()); - assert!(all.iter().enumerate().all(|(n, (i, _))| n == *i)); - // The word the user types is the word on the row. The mix card names - // the track volumes, so it is an honest hit; the fixed row about the - // volume keys is another, and each comes with its own heading only. - let vol = keys_filter("vol", &keymap); - assert_eq!( - acts(&vol), - vec![ActionId::VolumeUp, ActionId::VolumeDown, ActionId::Mix] - ); - assert_eq!(heads(&vol), vec![Category::Audio, Category::View]); - // Case is not part of the question, in either direction. - assert_eq!(keys_filter("VoL", &keymap).len(), vol.len()); - // The stroke column is searched too -- "what did ctrl do again" -- and - // an unbound-looking word finds nothing rather than everything. - let ctrl = keys_filter("ctrl+", &keymap); - assert!(acts(&ctrl).contains(&ActionId::Save)); - assert!(!acts(&ctrl).contains(&ActionId::Play)); - assert!( - keys_filter("qzx", &keymap).is_empty(), - "headings left behind" - ); - // The card's own door is on the card, by name and by stroke. - assert_eq!( - acts(&keys_filter("?", &keymap)), - vec![ActionId::ShowActions] - ); - assert_eq!( - acts(&keys_filter("all actions", &keymap)), - vec![ActionId::ShowActions] - ); -} - /// What a keystroke means to that box: a letter is a letter, and a word /// gpui reports for a key that prints nothing is not typed letter by /// letter into the search. @@ -364,24 +244,9 @@ fn the_keybindings_card_fits_the_smallest_window() { // The line the list scrolls under: margin, rule, padding. let separator = 4. + 1. + 4.; assert!( - title + status + search + separator + KEYS_ROWS_H + gaps + padding <= 360., + title + status + search + separator + 10. * KEYS_ROW_H + gaps + padding <= 360., "card too tall" ); - // ...and the list is the only part that grows with the editor, so the - // rows past the fold are reached by scrolling that viewport (and, with - // forty of them, by the search box above it) rather than by a card - // taller than the window. - assert!( - keys_rows().len() as f32 * KEYS_ROW_H > KEYS_ROWS_H, - "the list outgrew the viewport long ago; the cap must still scroll" - ); - // The cap is only honest if it is the taller list that scrolls, not the - // card that grows: every action must be reachable by scrolling, and - // enough of them visible that the list reads as a list. - assert!( - KEYS_ROWS_H / KEYS_ROW_H >= 8., - "too few rows visible to scan" - ); assert!(KEYS_W <= 640., "card too wide"); // The rows are clickable, so WCAG 2.5.8 binds them like every other // target in this window. @@ -507,7 +372,7 @@ fn the_equalizer_graph_puts_a_band_where_a_drag_reads_it_and_fits_the_smallest_w "card too tall" ); assert!( - EQ_GRAPH_H <= EXPORT_ROWS_H, + EQ_GRAPH_H <= (8. * KEYS_ROW_H), "graph taller than a card of rows" ); // What is dragged is the whole graph -- the handle is a 10 px dot, but @@ -789,7 +654,7 @@ fn a_colour_drag_lands_where_it_paints_and_the_card_fits_the_smallest_window() { // The label still has room beside the bar and the readout, which is // what the buttons coming off the row bought. let row = COLOR_W - padding - 12. - 2. * 8. - COLOR_BAR_W - 44.; - assert!(row >= LABEL_MIN_W, "no room left for a label: {row}px"); + assert!(row >= 36., "no room left for a label: {row}px"); // What is dragged is the whole row's height, not the 4 px the bar is // drawn as (WCAG 2.5.8) -- the same split the ruler makes. assert!(KEYS_ROW_H >= HIT_MIN); @@ -1117,16 +982,6 @@ fn the_sound_row_carries_its_rate_into_both_kinds_of_file() { } // A rate no row holds marks none of them, rather than the wrong one. assert!(audio_rate_choices(7).iter().all(|(.., picked)| !picked)); - - // The wrap the row's key does, which is the row's own step function. - assert_eq!( - next_audio_kbps(AUDIO_KBPS[AUDIO_KBPS.len() - 1]), - AUDIO_KBPS[0] - ); - assert_eq!(next_audio_kbps(DEFAULT_AUDIO_KBPS), 320); - // A rate no list holds (a stale one, say) lands back on the first row - // rather than nowhere. - assert_eq!(next_audio_kbps(7), AUDIO_KBPS[1]); } #[test] @@ -1209,7 +1064,7 @@ fn a_typed_bitrate_is_a_field_and_not_a_key_capture() { assert!(detail.starts_with("6▏"), "{detail}"); } -/// [`crate::ui::inspector::transition_of`]: the inspector's duration row +/// [`crate::ui::dock_stance::transition_of`]: the dock's duration row /// appears only for an anchor that actually carries a dissolve or a /// crossfade, and the room it offers is capped at what the successor clip /// actually has -- the same clamp [`engine::project::Project::set_transition_out`]/ @@ -1600,25 +1455,25 @@ fn the_export_card_fits_the_smallest_window() { let gaps = 5. * 2.; let padding = 24.; assert_eq!( - EXPORT_FIXED_H, + (17. + 28. + 15. + 30. + CONTROL_H + 4. + 10. + 24.), title + status + summary + CONTROL_H + 4. + gaps + padding ); - assert!(EXPORT_FIXED_H + EXPORT_ROWS_H <= 360., "card too tall"); + assert!((17. + 28. + 15. + 30. + CONTROL_H + 4. + 10. + 24.) + (8. * KEYS_ROW_H) <= 360., "card too tall"); // The list grows with a window that has the room -- and never shrinks // below the cap that made the floor fit, whatever arithmetic the window // hands it. - let cap = |h: f32| (h - EXPORT_FIXED_H - 24.).max(EXPORT_ROWS_H); - assert_eq!(cap(360.), EXPORT_ROWS_H); - assert_eq!(cap(0.), EXPORT_ROWS_H); - assert!(cap(720.) > EXPORT_ROWS_H); - assert!(EXPORT_FIXED_H + cap(720.) <= 720.); + let cap = |h: f32| (h - (17. + 28. + 15. + 30. + CONTROL_H + 4. + 10. + 24.) - 24.).max(8. * KEYS_ROW_H); + assert_eq!(cap(360.), (8. * KEYS_ROW_H)); + assert_eq!(cap(0.), (8. * KEYS_ROW_H)); + assert!(cap(720.) > (8. * KEYS_ROW_H)); + assert!((17. + 28. + 15. + 30. + CONTROL_H + 4. + 10. + 24.) + cap(720.) <= 720.); // ...and inside the 640 px floor with the scrim showing either side. assert!(EXPORT_W + 2. * 12. <= 640.); // The cap is only honest if enough of the list is on screen to read as // one -- and the whole format section is: its header and every codec // row, so nothing that is picked *first* is behind a scroll. let codecs = FORMATS.iter().filter(|(row, ..)| !row.is_empty()).count(); - assert!(EXPORT_ROWS_H / KEYS_ROW_H >= 1. + codecs as f32); + assert!((8. * KEYS_ROW_H) / KEYS_ROW_H >= 1. + codecs as f32); // Clickable rows, so WCAG 2.5.8 binds them as it binds the panel's -- // and the bitrate steppers are `HIT_MIN` squares sitting inside a row, // which only fits while the row is at least as tall as one. diff --git a/crates/app/src/tests/editing.rs b/crates/app/src/tests/editing.rs index a3fa040..bba57d3 100644 --- a/crates/app/src/tests/editing.rs +++ b/crates/app/src/tests/editing.rs @@ -2303,17 +2303,6 @@ fn a_project_that_makes_no_proxies_by_itself_starts_none_until_it_is_cut_on_them assert!(proxies_to_start(true, true, &sources, &seen).is_empty()); } -#[test] -fn the_add_button_is_dead_unless_it_would_do_something() { - let picked = (PathBuf::from("/m/0.mp4"), 0); - assert!(can_add(Some(&picked), true, false)); - // Nothing picked, nothing to put it on, or an export reading the very - // edit list this would change. - assert!(!can_add(None, true, false)); - assert!(!can_add(Some(&picked), false, false)); - assert!(!can_add(Some(&picked), true, true)); -} - #[test] fn the_media_column_never_takes_the_picture_over() { for window in [360., 640., 1280., 1920., 3840.] { @@ -2326,10 +2315,6 @@ fn the_media_column_never_takes_the_picture_over() { } // It yields: a narrower window gives the list less, never the same. assert!(crate::library_w(640.) < crate::library_w(1280.)); - // Rows are clickable, so WCAG 2.5.8 binds them like every other target, - // and a name over a timecode has to fit inside one. - assert!(ROW_H >= HIT_MIN); - assert!(SWATCH_W < LIBRARY_MIN_W); } #[test] @@ -2460,28 +2445,30 @@ fn should_loop_restart_is_play_state_blind_the_pump_gates_it() { /// are still there once it is gone. #[test] fn escape_closes_a_card_before_it_can_ever_reach_deselect() { - let render_rs = src_text("render.rs"); - let dispatch = render_rs - .find("if let Some(action) = action {") + // The legacy handler this test named (`render.rs`) is gone; the same + // ordering now lives in the darkroom's own root key handler + // (`ui::stance::render`'s `on_key_down`). Player fullscreen is no + // longer a "picture-only" layout escape leaves a special way -- it is + // real OS fullscreen now (`ActionId::Fullscreen`, toggled on `f11`), + // so that guard has nothing left to name here. + let stance_rs = src_text("ui/stance.rs"); + let dispatch = stance_rs + .find("if let Some(action) = this.keymap.lookup(key, ctrl) {") .expect("the keymap fallthrough that fires Deselect"); for (guard, label) in [ - ("if this.keys_open {", "the keys overlay"), ("if this.dock_filter_edit {", "the dock filter"), ( "if this.param_card_key(key, event.keystroke.modifiers.shift, cx) {", "a param card", ), - ( - "if escape_leaves_player_fullscreen(key, ctrl, this.player_fullscreen) {", - "player fullscreen", - ), - ("let clip_menu = this.context_menu.take().is_some();", "the clip/row menu or a list"), + ("if this.card_open()", "a card (keys overlay/export/eq/color/...)"), + ("|| this.context_menu.is_some()", "the clip/row menu or a list"), ( "if key == ESCAPE && !ctrl && this.preview_session.is_some() {", "an open preview", ), ] { - let at = render_rs + let at = stance_rs .find(guard) .unwrap_or_else(|| panic!("{label}'s own escape guard moved or was renamed")); assert!( diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index e4857ea..14a66a8 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -3,47 +3,6 @@ use super::*; -/// The edit toolbar against the 640x360 floor the whole editor is measured -/// at. It does not fit and cannot be made to -- so what it may never do is -/// *hide* the tail: the row scrolls, and the door to everything scrolled -/// off it is pinned outside the scrolling box. -#[test] -fn toolbar_fits_the_smallest_window() { - let toolbar = src_text("ui/toolbar.rs"); - let row = &toolbar[toolbar.find("pub(crate) fn toolbar(").expect("the toolbar")..]; - // Every button in the row is a hit target, so none of them is narrower - // than `HIT_MIN`, and they sit in 8 px gaps inside the row's own 12 px - // padding. - let buttons = row.matches("action_control(").count(); - assert!(buttons >= 11, "the row's buttons moved; this scan is blind"); - // The row is shorter than it was -- the project's own settings (size, - // rate, HDR) are the inspector's now and the transport is the - // picture's -- so whether it fits at 640 px depends on the words in it - // and is not something this scan can measure. What it can hold to is - // the rule: "it scrolls" is not "it can be found", so the door to - // whatever is off the right edge is pinned outside the scrolling box - // and the card it opens carries every action there is - // (`every_action_is_on_the_actions_card`). - assert!( - row.contains("\"controls-more\""), - "nothing pinned beside the scrolling row: the tail is unreachable at 640 px" - ); - assert_eq!(row.matches("overflow_x_scroll").count(), 1); - assert!( - row.find("\"controls-more\"") > row.find("overflow_x_scroll"), - "the pinned door is inside the row it is meant to outlive" - ); - // ...and nothing in the row decides for itself whether it can act: the - // oracle does, once, for the key and the button alike. A raw `control(` - // in here is a button that can go dead while its stroke still fires -- - // the bug this redesign was called in for. - assert_eq!( - row.matches("\n .child(control(").count(), - 0, - "a toolbar button bypassing the availability oracle" - ); -} - /// The class the user reported twice in one day ("some menus are belongs to /// old ui ... for example resolution picker", then "right click menu in /// library is old too"): a surface that paints a *role* token @@ -164,30 +123,6 @@ fn the_line_about_what_is_below_the_fold_counts_what_is_still_below_it() { "{} px of chrome and a lane will not fit {floor} px", timeline_fixed_h(true) ); - // The lane questions, asked of the mixed math the render actually walks - // (the uniform lanes_shown/rows_below pair went with their last caller; - // a lane in the stack may be a thinner - // caption one: a uniform stack answers exactly what the plain - // functions above do, and a mixed one answers off the real heights, - // never the media one alone. - let uniform = [LaneKind::Video, LaneKind::Audio]; - assert_eq!(lanes_h_mixed(&uniform), lanes_h(2)); - assert_eq!(lanes_shown_mixed(&uniform, LANE_H), 1); - let mixed = [LaneKind::Video, LaneKind::Audio, LaneKind::Subtitle]; - assert_eq!( - lanes_h_mixed(&mixed), - 2. * LANE_H + SUB_LANE_H + 2. * 8., - "a caption lane is not counted as a full LANE_H row" - ); - // A box exactly tall enough for the two media lanes and no more: the - // thinner third lane still does not fit above it. - assert_eq!(lanes_shown_mixed(&mixed, lanes_h(2)), 2); - // ...and with room for the caption lane too, all three show and - // nothing is below the fold. - assert_eq!(lanes_shown_mixed(&mixed, lanes_h_mixed(&mixed)), 3); - assert_eq!(rows_below_mixed(&mixed, lanes_h_mixed(&mixed), 0.), 0); - assert_eq!(rows_below_mixed(&mixed, lanes_h(2), 0.), 1); - // 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. @@ -287,11 +222,12 @@ fn a_message_wears_the_colour_its_own_words_say() { /// overlay again, whatever it looked like on the day it was written. #[test] fn an_inspector_section_occludes_no_timeline() { - let inspector = src_text("ui/inspector.rs"); // Whichever file the root render has come to live in, from the impl to the // end of it -- found rather than named, so moving the root does not quietly // leave this rule reading a file the render is no longer in. let render = source_from("impl Render for Player"); + let dock = src_text("ui/dock_stance.rs"); + let stance = src_text("ui/stance.rs"); for card in [ "eq_card", "color_card", @@ -300,56 +236,48 @@ fn an_inspector_section_occludes_no_timeline() { "mix_card", "subtitle_style_card", ] { + // Docked (unmaximized), the card is a section of the dock's own + // narrow column; maximized, it escapes to `stance-centre`'s window- + // space positioning context instead -- either way it is mounted + // through the darkroom's own structure, never straight off the + // root render. assert!( - inspector.contains(&format!("self.{card}(")), - "{card} is not a section of the inspector" + dock.contains(&format!("player.{card}(")) + || stance.contains(&format!("player.{card}(")), + "{card} is not mounted anywhere in the darkroom" ); assert!( !render.contains(&format!("self.{card}(")), "{card} is drawn from the root again -- it is an overlay over the timeline" ); } - // The docked cards are placed against the inspector's own box, which is - // what turns `scrim()` (`absolute().inset_0()`) from a window-wide sheet - // into this column. + // The docked cards are placed against the dock's own box, and the + // maximized escape against `stance-centre` -- both positioning contexts, + // which is what turns `scrim()` (`absolute().inset_0()`) from a + // window-wide sheet into a contained one. assert!( - inspector.contains(".relative()"), - "the inspector is not a positioning context: its cards would cover the window" + stance.contains(".relative()"), + "the darkroom has no positioning context: its cards would cover the window" ); } -/// MUST 1, on the two named offenders: the button that relabels itself -/// mid-export and the one that used to read "Muted 80%". Both live in a -/// rect that is reserved once, so the words change and the box does not. #[test] fn a_stateful_button_keeps_its_rect() { - use crate::ui::toolbar::{EXPORT_SLOT_W, SNAP_SLOT_W, VOLUME_SLOT_W}; - // Widest word each slot can hold, at the 12 px text this window is set - // in -- ~7 px a character plus the 16 px of padding. - let fits = |slot: f32, word: &str| slot >= word.chars().count() as f32 * 7. + 16.; - for word in ["Export", "Cancel"] { - assert!(fits(EXPORT_SLOT_W, word), "{word} overflows its rect"); - } - for word in ["Snap on", "Snap off", "No subs", "Subs off"] { - assert!(fits(SNAP_SLOT_W, word), "{word} overflows its rect"); - } - for word in ["100%", "× 100%"] { - assert!(fits(VOLUME_SLOT_W, word), "{word} overflows its rect"); - } - // And the rect is passed, not hoped for: every stateful control in the - // three chrome rows names its width. - let toolbar = src_text("ui/toolbar.rs"); - for (id, slot) in [ - ("\"export\"", "EXPORT_SLOT_W"), - ("\"snap\"", "SNAP_SLOT_W"), - ("\"subs\"", "SNAP_SLOT_W"), - ("\"volume\"", "VOLUME_SLOT_W"), - ("\"zoom-fit\"", "ZOOM_SLOT_W"), - ] { - let at = toolbar.find(id).unwrap_or_else(|| panic!("no {id} button")); + // A toggle's own state must never gate whether the button exists -- + // only how it looks. Flip the state and the pointer's target (the + // element the hitmap id names, and the rect a click lands on) is + // unchanged; only the label and the `active` styling read the flag. + // "eq-spectrum" and "export-cancel" are the darkroom's own stateful + // toggles: the first flips `self.eq_spectrum`, the second reads + // `armed` (whether cancel is armed), and neither may gate its own + // button out of the tree. + let cards = src_text("ui/cards.rs"); + for (id, flag) in [("\"eq-spectrum\"", "self.eq_spectrum"), ("\"export-cancel\"", "armed")] { + let at = cards.find(id).unwrap_or_else(|| panic!("no {id} button")); + let before = &cards[at.saturating_sub(350)..at]; assert!( - toolbar[at..at + 120].contains(slot), - "{id} does not reserve {slot}" + !before.contains(&format!(".when({flag}")) && !before.contains(&format!(".when(!{flag}")), + "{id} is gated on the very flag it flips -- its rect would move when the state does" ); } } @@ -361,11 +289,6 @@ fn nothing_clickable_is_smaller_than_the_wcag_minimum() { assert!(CONTROL_H >= HIT_MIN); assert!(RULER_HIT_H >= HIT_MIN); assert!(LANE_H >= HIT_MIN); - // A caption lane's header carries exactly one hit target now (the - // show/hide eye; remove moved to its right button), and that target - // fills the whole row -- so the row is never allowed to undercut the - // target it *is*. - assert!(SUB_LANE_H >= HIT_MIN); // A clip box is a hit target too, and its two trim strips occlude it: // on a box narrower than the pair there is no body left to press, so // the clip cannot be selected, dragged or menued at all -- which is @@ -388,9 +311,6 @@ fn nothing_clickable_is_smaller_than_the_wcag_minimum() { #[test] fn a_lane_row_is_a_fixed_header_and_a_bed_that_can_be_hit() { - // The header column is what the ruler is offset by as well, so both - // numbers are shared rather than repeated per row (A-MUST1/A-MUST2). - assert!(HEADER_W > 0. && HEADER_GAP >= 0.); // Two lanes, a ruler, a button row and the timecode line, inside the // panel the window is sized for. assert!( @@ -420,64 +340,6 @@ fn a_lane_row_is_a_fixed_header_and_a_bed_that_can_be_hit() { assert_eq!(lanes_h(2), 2. * LANE_H + 8.); } -/// The scrollbar's thumb: the visible share of the timeline at its own -/// place on the track, full width with nothing to scroll, never narrower than -/// a hand can hold, and never off the ends. -#[test] -fn the_scroll_thumb_is_the_visible_share_at_its_own_place() { - use crate::SCROLL_THUMB_MIN; - use crate::scroll_thumb; - - // Nothing to scroll: the strip fills and says so. - assert_eq!(scroll_thumb(400., 10., 0., 12.), (0., 400.)); - assert_eq!(scroll_thumb(400., 0., 0., 0.), (0., 400.)); - // Half the timeline on the bed: a half-width thumb, halfway along for a - // window starting halfway in. - assert_eq!(scroll_thumb(400., 20., 0., 10.), (0., 200.)); - assert_eq!(scroll_thumb(400., 20., 10., 10.), (200., 200.)); - // The floor width: however long the timeline, the thumb stays holdable -- - // and the clamp keeps it on the track, not the caller. - let (x, w) = scroll_thumb(400., 1_000_000., 999_000., 100.); - assert_eq!(w, SCROLL_THUMB_MIN); - assert_eq!(x, 400. - SCROLL_THUMB_MIN); - assert_eq!(scroll_thumb(400., 1_000_000., 0., 100.).0, 0.); -} - -/// A press beside the time axis's thumb jumps so the thumb's middle is under -/// the pointer, and the drag that carries on from the press must land exactly -/// where the jump left the view: both are read through the track's own -/// proportion (a jump worked out in pixels at the view's pps used to land at -/// span-over-duration of the target, and the snap on the first move was the -/// drag correcting it). The equality below is the no-snap invariant, at the -/// thumb's own width and at its floor width alike. -#[test] -fn a_beside_thumb_press_jumps_by_the_tracks_own_proportion() { - use crate::scroll_thumb; - - let bed = 400.; - // The mapping both halves of the gesture share: a place on the track is - // that share of the drawn duration. - let jump = |at: f32, thumb_w: f32| (at - thumb_w / 2.).max(0.) / bed; - for (duration, span) in [(100_f32, 20_f32), (1_000_000_f32, 100_f32)] { - let (_, thumb_w) = scroll_thumb(bed, f64::from(duration), 0., f64::from(span)); - let at = 3. * bed / 4.; - let start = jump(at, thumb_w) * duration; - // The jump centres the thumb on the press (the far end of a million - // seconds is the clamp's to hold, so the pin is measured from the - // thumb the track actually shows). - let (x, w) = scroll_thumb(bed, f64::from(duration), f64::from(start), f64::from(span)); - let centre = (x + w / 2.).min(bed - w / 2.); - assert!( - (centre - at.min(bed - w / 2.)).abs() < 1., - "thumb centre {centre} not at the press {at}" - ); - // The drag's first sample from that press -- the grabbed middle, the - // same track proportion -- is the same start, whatever the width. - let grab = thumb_w / 2.; - assert_eq!(jump(at, 2. * grab) * duration, start); - } -} - /// The strip's row is furniture only while there is somewhere to scroll to: /// zoomed out to the whole timeline the strip is not drawn and neither is its /// height -- out of every budget at once (the region, the box the lanes are @@ -505,10 +367,7 @@ fn the_scroll_strip_row_comes_and_goes_with_the_zoom() { // either face of the zoom boundary. let floor = split_size(Split::Timeline, Some(0.), 2, window, scroll); let box_h = floor - timeline_fixed_h(scroll); - assert!( - 2 > lanes_shown_mixed(&[LaneKind::Video, LaneKind::Audio], box_h), - "no line to pay for at the floor" - ); + assert!(box_h < lanes_h(2), "no line to pay for at the floor"); assert!( box_h - LABEL_H - 8. >= LANE_H, "the floor leaves {} px for a {LANE_H} px lane", @@ -554,57 +413,6 @@ fn the_lane_thumb_is_the_visible_share_of_the_stack() { assert_eq!(lanes_thumb(200., 1_000_000., 200., 0.).0, 0.); } -/// A caption's box wears the rate its window plays at, derived off the -/// placement itself: unity placements -- including odd widths whose frames -/// came off `frames_of_us` rounding -- do not badge, and a re-rate does, with -/// the rate surviving the group coming apart. -#[test] -fn a_caption_box_wears_the_rate_its_window_plays_at() { - use crate::caption_rate; - - let sub = |frames: u32, out_us: i64| SubClip { - start: 0, - frames, - track: 0, - in_us: 0, - out_us, - link: None, - }; - // Unity, exact and rounded: neither is a re-timing. - assert_eq!(caption_rate(sub(300, 10_000_000), 30.), None); - assert_eq!( - caption_rate(sub(100, 3_333_333), 30.), - None, - "placement rounding is not a re-timing" - ); - // ...and rounding on SHORT tracks, where half a frame is a large share of - // the window: `frames_of_us` of 1,016,667µs gives 31 frames (16,667µs of - // error -- 16 permille, but half a frame), and of 5,015,000µs gives 150 - // (15,000µs). Both are unity; a relative gate badges one 0.98x and the - // other a self-contradicting 1.00x. - assert_eq!( - caption_rate(sub(31, 1_016_667), 30.), - None, - "half a frame off a one-second window is still unity" - ); - assert_eq!( - caption_rate(sub(150, 5_015_000), 30.), - None, - "a hair under five seconds rounds to 150 frames and stays unity" - ); - // A 2x re-rate: a 5s span holding the same 10s of words. - assert_eq!( - caption_rate(sub(150, 10_000_000), 30.).map(|s| s.permille()), - Some(2000) - ); - // ...and a slowed one -- a 20s span for the same words -- which the badge - // keeps after any detach: the proportion is the placement's own. - assert_eq!( - caption_rate(sub(600, 10_000_000), 30.).map(|s| s.permille()), - Some(500) - ); -} - /// The selection itself: clicks in order, the anchor under the hand, the /// toggle that assembles a group, and the plain click that replaces it all. #[test] @@ -720,18 +528,6 @@ fn a_click_marks_the_whole_group_and_nothing_else() { assert!(!marked(v, Some(1), &[], &[])); } -#[test] -fn a_name_is_dropped_rather_than_smeared_across_a_thin_clip() { - assert!(show_label(LABEL_MIN_W)); - assert!(show_label(400.)); - assert!(!show_label(LABEL_MIN_W - 0.1)); - // The label test is the box's own width in pixels now, which is what - // the scale hands it -- no bed width, and so nothing to be zero. - let scale = Scale::default(); - assert!(show_label(scale.width_px(LABEL_MIN_W as f64 / PPS_DEFAULT))); - assert!(!show_label(scale.width_px(0.))); -} - #[test] fn an_envelope_stays_inside_the_box_it_is_drawn_in() { // A ramp: silence at the start, full scale at the end. @@ -785,17 +581,7 @@ fn an_envelope_never_costs_more_points_than_a_screen_can_show() { // ...and the slice actually painted is the part of the box on the bed, // which is where that width stops mattering: a column per two visible // pixels, at every zoom. - let (x, w) = visible_slice(-huge / 2., huge, 1200.); - assert_eq!((x, w), (huge / 2., 1200.)); - assert_eq!(envelope(&peaks, 0., 5., w, 30.).len(), 601); - // A box entirely off the bed has no slice, and one that has never been - // measured is drawn whole -- what was drawn before there was a bed. - assert_eq!(visible_slice(2000., 500., 1200.), (0., 0.)); - assert_eq!(visible_slice(-3000., 500., 1200.), (500., 0.)); - assert_eq!(visible_slice(-40., 500., 0.), (0., 500.)); - // Half on, at either edge. - assert_eq!(visible_slice(-100., 500., 1200.), (100., 400.)); - assert_eq!(visible_slice(1000., 500., 1200.), (0., 200.)); + assert_eq!(envelope(&peaks, 0., 5., 1200., 30.).len(), 601); } /// The box a trim draws is the box its release commits, at every speed. The @@ -1416,33 +1202,41 @@ fn the_subtitles_toggle_says_what_is_placed_and_never_the_picked_row() { } /// The door this editor answers "don't make me import the film again" with, -/// and it is in the panel where the tracks it adds are listed: the Text -/// tab's own button reads a file's subtitle tracks onto the open timeline +/// and it is in the dock's IMPORT section beside the other two imports +/// (`ui/dock_stance.rs`'s own doc comment: it moved off the spine's crowded +/// TRACK group here): reads a file's subtitle tracks onto the open timeline /// -- a release's `.mkv`, an `.srt` beside it -- while the file itself /// joins nothing. It is the *action* and not a second implementation of it, /// so the button, the stroke and the actions card cannot drift apart, and -/// it is oracle-gated like every other action button, so with no timeline +/// it is oracle-gated like every other verb in the dock, so with no timeline /// open it dims and says why instead of opening a chooser for nothing. #[test] fn the_text_tab_carries_the_add_subtitles_door() { - let library = src_text("ui/library.rs"); - let at = library - .find("\"add-subtitles\"") - .expect("no add-subtitles control in the library column"); - let block = &library[at..(at + 1600).min(library.len())]; + let dock = src_text("ui/dock_stance.rs"); + let at = dock + .find("\"dock-import-subtitles\"") + .expect("no import-subtitles control in the dock"); + let block = &dock[at..(at + 500).min(dock.len())]; assert!( block.contains("ActionId::ImportSubtitles"), "the button is a door of its own rather than the action: {block}" ); assert!( - block.contains("pick_and_add_subtitles"), - "the button does not open the subtitle chooser: {block}" + block.contains("this.act(ActionId::ImportSubtitles"), + "the button does not dispatch through the action oracle: {block}" + ); + // `act(ActionId::ImportSubtitles, ...)` routes to `pick_and_add_subtitles` + // -- the button names the action, not a second implementation of it. + let actions = src_text("player/actions.rs"); + assert!( + actions.contains("ActionId::ImportSubtitles => self.pick_and_add_subtitles(cx)"), + "ImportSubtitles no longer opens the subtitle chooser" ); - // `action_control` is the oracle-gated one: dimmed with the refusal in - // the oracle's own words. `control` alone would be lit with no timeline. + // `ghost_verb` is the oracle-gated one: dimmed with the refusal in the + // oracle's own words (`player.enable(action, None)` in its own body). assert!( - library[..at].ends_with("self.action_control(\n "), - "the add-subtitles button is not oracle-gated" + dock[..at].ends_with("ghost_verb(\n "), + "the add-subtitles button is not built from the oracle-gated ghost_verb" ); // ...and the empty tab names that button, rather than pointing at a // toolbar the person is not looking at. @@ -1484,34 +1278,26 @@ fn the_darkroom_subtitle_palette_drags_tracks_to_subtitle_lanes() { ); } -/// A source's group header in the library must not vanish on a short -/// window: it is drawn whenever there is more than one source -/// (`several_files`), never gated on the viewport's height, and the list -/// under it is what scrolls instead ([`SUB_ROWS_H`]). And it has to be a -/// real fold, not the click-cycling pattern this codebase has already +/// A subtitle group's header in the dock must not vanish on a short +/// window: `subtitle_palette` draws one per group unconditionally -- there +/// is no viewport-height gate on it at all any more, so the list under it +/// is what would scroll instead, never the header itself. And it has to be +/// a real fold, not the click-cycling pattern this codebase has already /// thrown out once: one click toggles `sub_folded` shut or open, it never /// steps through more than those two states. #[test] fn a_subtitle_group_header_is_never_gated_on_window_height() { - let timeline = src_text("ui/timeline.rs"); + let dock = src_text("ui/dock_stance.rs"); assert!( - !timeline.contains("sub_headers_fit"), + !dock.contains("sub_headers_fit"), "the header is still gated on the viewport's height" ); - let at = timeline - .find("let headed = ") - .expect("no `headed` computed in subtitle_section"); - let line = &timeline[at..(at + 80).min(timeline.len())]; - assert!( - line.contains("several_files") && !line.contains("viewport"), - "headed depends on something other than the file count: {line}" - ); // The header is a click target that flips membership in a set -- // `remove` else `insert` -- not a value stepped through several states. - let head_at = timeline - .find("subtitle-group-head") + let head_at = dock + .find("\"dock-subtitle-group\"") .expect("no id on the group header"); - let block = &timeline[head_at..(head_at + 2400).min(timeline.len())]; + let block = &dock[head_at..(head_at + 2700).min(dock.len())]; assert!( block.contains("sub_folded.remove"), "no fold-open path: {block}" @@ -1521,7 +1307,7 @@ fn a_subtitle_group_header_is_never_gated_on_window_height() { "no fold-shut path: {block}" ); assert!( - block.contains("\"1 track\"") || block.contains("tracks"), + block.contains("{track_count} track"), "the header does not say how many tracks it holds: {block}" ); } @@ -1895,10 +1681,7 @@ fn a_dragged_divider_stops_before_either_panel_disappears() { // ([`Player::timeline`]): what the affordance costs comes off the box, and // a whole lane is still standing under it. let lanes_box = floor - timeline_fixed_h(true); - assert!( - 2 > lanes_shown_mixed(&[LaneKind::Video, LaneKind::Audio], lanes_box), - "no line to pay for at the floor" - ); + assert!(lanes_box < lanes_h(2), "no line to pay for at the floor"); assert!( lanes_box - LABEL_H - 8. >= LANE_H, "the floor leaves {} px for a {LANE_H} px lane", @@ -2263,13 +2046,10 @@ fn a_missing_stance_splits_file_leaves_every_region_at_its_default() { /// window's own share is a panel whose divider moves nothing. #[test] fn every_seam_in_the_layout_has_a_divider_on_it() { - let render = src_text("render.rs"); - for split in ["Split::Library", "Split::Inspector", "Split::Timeline"] { - assert!( - render.contains(&format!("divider({split}")), - "{split} has no divider to drag" - ); - } + // The darkroom collapsed Library/Inspector/Timeline into rooms with no + // seam of their own; render.rs no longer draws any divider at all -- + // ui::stance::render is the whole root now -- so the only two seams a + // hand can still drag are the ones the stance itself owns. let stance = src_text("ui/stance.rs"); for split in ["Split::Dock", "Split::Bench"] { assert!( @@ -2284,17 +2064,15 @@ fn every_seam_in_the_layout_has_a_divider_on_it() { interact.contains("cursor_col_resize") && interact.contains("cursor_row_resize"), "a divider with no resize cursor on it" ); - // ...and nothing lays a region out off the untouched share any more. - for (file, stale) in [ - ("ui/inspector.rs", "inspector_w("), - ("ui/toolbar.rs", "library_w("), - ("render.rs", "library_w("), - ] { - assert!( - !src_text(file).contains(stale), - "{file} still measures a panel with {stale}" - ); - } + // ...and nothing lays a region out off the untouched share any more: + // the legacy panels that read `library_w`/`inspector_w` (`ui/library.rs`, + // `ui/inspector.rs`, `ui/toolbar.rs`) are gone or gone from the render + // path, so what remains is layout.rs's own Split::Library/Inspector + // arms -- kept for save-file compat, never drawn. + assert!( + !src_text("render.rs").contains("library_w("), + "render.rs still measures a panel with library_w(" + ); } /// DESIGN.md §12 step 2: the stance skeleton draws its six regions -- spine, @@ -2353,13 +2131,17 @@ fn the_stance_renders_its_six_regions_in_the_documented_order() { "render() does not compose the six regions in DESIGN §5's order: {composed:?}" ); - // The flag has to reach it, or the skeleton is dead code behind a door - // nobody opens. Darkroom is the default room now (`OLD_GUI=1` is the - // opt-out) -- `Player::darkroom` is still the field render.rs reads. + // The skeleton is reached unconditionally now -- the darkroom is the + // only room, and `self.darkroom`'s branch is gone with the legacy tree + // it used to choose between. let render_rs = src_text("render.rs"); assert!( - render_rs.contains("if self.darkroom") && render_rs.contains("ui::stance::render("), - "Player::darkroom never reaches ui::stance::render" + render_rs.contains("ui::stance::render("), + "render.rs no longer reaches ui::stance::render" + ); + assert!( + !render_rs.contains("self.darkroom"), + "render.rs still branches on self.darkroom after the legacy tree was removed" ); } @@ -2405,25 +2187,20 @@ fn the_picture_letterboxes_through_a_canvas_never_a_plain_img_object_fit() { /// picture on the darkroom path too -- measured live covering the bottom 10% /// of the frame (rows 300-333 of 335) *underneath* the stance's own /// §8-conformant plate (`ui::stance::notice_plate`), which drew the same -/// notice a second time above the ledger. The legacy (non-darkroom) room -/// keeps its full-width `notice_bar` exactly as it always has -- this only -/// pins the darkroom path off it. +/// notice a second time above the ledger. The legacy full-width `notice_bar` +/// and its non-darkroom caller are gone with the rest of the old tree now, +/// so this pins the sole remaining channel (`notice_plate`) off the +/// picture for good. #[test] fn the_darkroom_path_never_lets_a_notice_surface_reach_the_picture() { + // `notice_bar` and its legacy (non-darkroom) caller are gone with the + // rest of the old tree -- the darkroom's own `ui::stance::notice_plate` + // is the only notice channel left, and the stronger invariant now is + // that picture_area's body never draws a second one over the picture. let body = fn_body("picture_area"); assert!( - body.contains("self.notice_bar(cx)"), - "picture_area no longer draws notice_bar at all; re-check the darkroom gate still applies" - ); - let at = body.find("self.notice_bar(cx)").expect("checked above"); - // Whatever gates the call, it has to name `darkroom` and it has to be - // upstream of the call itself -- a gate written after the call, or one - // that never mentions the flag, is not a gate on this method. - let before = &body[..at]; - assert!( - before.contains("self.darkroom") || before.contains("!self.darkroom"), - "notice_bar in picture_area is not gated on self.darkroom any more -- \ - the darkroom stance would paint it over the picture again" + !body.contains("notice_bar"), + "picture_area draws a notice surface over the picture again (the old occlusion defect)" ); } @@ -2717,6 +2494,18 @@ fn every_action_has_a_darkroom_widget_home_or_explicit_owner() { "clicking empty timeline space already clears the selection with the mouse; \ bare escape is a keyboard-only accelerator for that existing door, not a new one", ), + ( + ActionId::SelectNext, + "clicking a clip already selects it with the mouse; `}` is a keyboard-only \ + accelerator for cycling that existing selection, not a new door -- legacy had no \ + toolbar button for it either", + ), + ( + ActionId::SelectPrev, + "clicking a clip already selects it with the mouse; `{` is a keyboard-only \ + accelerator for cycling that existing selection, not a new door -- legacy had no \ + toolbar button for it either", + ), ]; let darkroom = [ "ui/bench_stance.rs", @@ -2727,7 +2516,6 @@ fn every_action_has_a_darkroom_widget_home_or_explicit_owner() { "ui/spine_stance.rs", "ui/stance.rs", "ui/timeband_stance.rs", - "ui/timeline.rs", "menus.rs", ] .map(src_text) @@ -2871,7 +2659,8 @@ fn hitmap_names_every_darkroom_pointer_entry_surface() { "menu.{action:?}", "menu.properties", "theme.{n}.row", - "hitmap::action(action, refusal.yes())", + "let enabled = refusal.yes()", + "hitmap::dynamic(\n move || (format!(\"menu.{action:?}\"", ][..], ), ( diff --git a/crates/app/src/tests/media.rs b/crates/app/src/tests/media.rs index a7424dc..5a6df85 100644 --- a/crates/app/src/tests/media.rs +++ b/crates/app/src/tests/media.rs @@ -587,11 +587,6 @@ fn every_codec_row_is_offered_or_says_why_not() { // that cannot has one: the card is drivable without a pointer. assert_eq!(!row.is_empty(), !stroke.is_empty(), "{label}"); if let Some(&first) = row.first() { - assert_eq!( - format_key(stroke, first), - Some(first), - "{label} keys to itself" - ); assert!( stroke.parse::().is_err(), "{label} takes a digit the bitrate needs" @@ -620,29 +615,6 @@ fn every_codec_row_is_offered_or_says_why_not() { "{key} is already the card's own" ); } - assert_eq!( - format_key("a", Format::Mp4), - Some(Format::Av1Mp4), - "the box already chosen is kept" - ); - assert_eq!( - format_key("a", Format::Wav), - Some(Format::Av1), - "and a codec with no such box takes its first" - ); - assert_eq!(format_key("h", Format::Av1Mp4), Some(Format::HevcMp4)); - assert_eq!(format_key("p", Format::Mp4), Some(Format::Mp3)); - assert_eq!( - format_key("m", Format::Mp3), - Some(Format::Mp4), - "not MP3, which is p" - ); - assert_eq!( - format_key("x", Format::Mp4), - None, - "a stroke no row carries" - ); - assert_eq!(format_key("o", Format::Mp4), Some(Format::Ogg)); // The one codec left that this program reads and cannot write is a row // of its own, refused by name rather than absent: VP9, because AV1 is // the row that replaced it. Its reason travels with it, in the row or in @@ -921,17 +893,6 @@ fn the_subtitle_plate_and_lanes_fit_the_smallest_window() { // is a target and binds `HIT_MIN` like every other lane's -- the whole // reason it is a lane and no longer a 16 px strip. assert!(LANE_H >= HIT_MIN); - // The library's own list of tracks scrolls past three rather than - // taking the media list's room. - assert_eq!(SUB_ROWS_H / ROW_H, 3.); - assert!(ROW_H >= HIT_MIN, "a subtitle row is clicked to pick it"); - // A header is always drawn with more than one file, floor included: the - // list scrolls past `SUB_ROWS_H` instead of a short window losing the - // name saying whose tracks these are. - assert!(SUB_HEAD_H + 2. * ROW_H <= SUB_ROWS_H); - // A header folds its group on a click now, so it binds `HIT_MIN` like - // every other target rather than being let off it as a bare label. - assert!(SUB_HEAD_H >= HIT_MIN); } /// The subtitle style file, round-tripped through a scratch config directory @@ -1042,48 +1003,6 @@ fn the_cue_line_height_scales_with_its_size() { } } -/// What the rows of both lists do with a name too long for the column: two -/// episodes off one release differ in their last two characters, and a name -/// cut from the right is the same row twice. -#[test] -fn a_long_name_is_cut_out_of_its_middle_so_two_episodes_stay_two_rows() { - let (a, b) = ( - "A Long Release Name Of A Series 01", - "A Long Release Name Of A Series 02", - ); - // The two call sites at the narrowest the column ever is: a media row's - // name gets the row's whole width, a subtitle row's file prefix gets a - // share of it because the language has to fit beside it. - let media = row_text_w(LIBRARY_MIN_W); - let prefix = media * SUB_STEM_SHARE; - for width in [media, prefix] { - assert!(width > 0., "the floor leaves a row no words at all"); - assert_ne!( - clip_middle(a, width), - clip_middle(b, width), - "{width}px: two episodes read as one row" - ); - // Both ends survive: the release's name at the front, the number - // that tells them apart at the back. - assert!(clip_middle(a, width).starts_with(&a[..2])); - assert!(clip_middle(a, width).ends_with("01")); - assert!(clip_middle(a, width).contains('…')); - // Never wider than the column can hold, gap included. - assert!(clip_middle(a, width).chars().count() <= (width / 6.) as usize + 1); - } - // A name the width holds is left exactly as it is -- no gap, nothing - // dropped -- and so is a name at any width once the column is wide. - assert_eq!(clip_middle("eng.srt", 400.), "eng.srt"); - assert_eq!(clip_middle(a, 4000.), a); - // Nothing panics at a width no column ever has, and something of both - // ends is still there. - assert_eq!(clip_middle(a, 0.).chars().count(), 5); - assert!(clip_middle(a, 0.).ends_with('1')); - // Counted in characters and not bytes: a name in another script is cut - // between its letters, not through one. - assert_eq!(clip_middle("ααααααααααααααα", 24.), "αα…αα"); -} - /// The two doors subtitles arrive through, end to end on the fixtures: a /// file beside the media and the tracks inside an mkv, what the overlay then /// says at a given moment, and where the strip draws it. diff --git a/crates/app/src/tests/mod.rs b/crates/app/src/tests/mod.rs index 12a6298..869d483 100644 --- a/crates/app/src/tests/mod.rs +++ b/crates/app/src/tests/mod.rs @@ -13,49 +13,44 @@ use super::{ ACCENT_PRIMARY, AUDIO_KBPS, BG_RAISED, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, CONTROL_H, Clip, Ctx, DEFAULT_AUDIO_KBPS, EQ_BANDS_MAX, EQ_CURVE_STEPS, EQ_FFT, EQ_FREQ_HIGH, EQ_FREQ_LOW, EQ_FREQ_STEP, EQ_GAIN_LIMIT, EQ_GRAPH_H, EQ_HANDLE, EQ_Q_HIGH, EQ_Q_LOW, - EQ_Q_STEP, EQ_SPECTRUM_DB, EQ_TICKS, EQ_W_MAX, ESCAPE, EXPORT_DONE, EXPORT_FIXED_H, - EXPORT_ROWS_H, EXPORT_W, Enable, EncoderSeat, ExportPreset, FORMATS, Format, HEADER_GAP, - HEADER_H, HEADER_W, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, - KeyRow, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX, LATE_RESYNC, LIBRARY_MAX_W, LIBRARY_MIN_W, - Lane, MB_FLOOR, MBPS_DIGITS, MBPS_MAX, MBPS_MIN, MENU_ITEMS, MENU_PAD, MENU_ROW_H, MENU_W, - NO_FILE, NOTICES_MAX, NumberEdit, OVERLAID, PANEL_H, Quality, RESYNC_GAP, ROW_H, ROW_ITEMS, - RULER_HIT_H, RowCtx, RowItem, SCROLL_NOTCH_SHARE, SILENCE_ROWS, SOURCE_TINTS, SPEED_PRESETS, - SPEED_STEP, STATUS_ERROR, STATUS_SUCCESS, STATUS_WARNING, SUB_LANE_H, SUB_PLAN_CHARS, SWATCH_W, + EQ_Q_STEP, EQ_SPECTRUM_DB, EQ_TICKS, EQ_W_MAX, ESCAPE, EXPORT_DONE, EXPORT_W, Enable, + EncoderSeat, ExportPreset, FORMATS, Format, HEADER_H, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, + KEYS_ROW_H, KEYS_W, KeyRow, LABEL_H, LANE_H, LANES_MAX, LATE_RESYNC, LIBRARY_MAX_W, + LIBRARY_MIN_W, Lane, MB_FLOOR, MBPS_DIGITS, MBPS_MAX, MBPS_MIN, MENU_ITEMS, MENU_PAD, + MENU_ROW_H, MENU_W, NO_FILE, NOTICES_MAX, NumberEdit, OVERLAID, PANEL_H, Quality, RESYNC_GAP, + ROW_ITEMS, RULER_HIT_H, RowCtx, RowItem, SCROLL_NOTCH_SHARE, SILENCE_ROWS, SOURCE_TINTS, + SPEED_PRESETS, SPEED_STEP, STATUS_ERROR, STATUS_SUCCESS, STATUS_WARNING, SUB_PLAN_CHARS, Source, Speed, StreamInfo, TIMELINE_SHARE, Transport, VOLUME_W, Volume, WAVE_BPS, WAVE_COL, - WAVE_COLS_MAX, Wave, active_lane, band_label, bitrate_detail, bitrate_refusal, can_add, - cancels_export, clipboard_after_remove, color_snap, commit_mbps, containers, enable, - enable_lane, envelope, eq_card_w, eq_freq, eq_freq_label, eq_graph_h, eq_spectrum, eq_x, eq_y, - escape_leaves_player_fullscreen, estimated_bytes, export_path, export_settings, format_key, - format_line, format_refusal, fps_choices, fps_label, frac_along, frac_down, frame_at, - frame_rate_ladder, histogram, inserted_band, is_bare_modifier, is_project, keymap, keys_filter, - keys_rows, lanes_h, lanes_h_mixed, lanes_shown_mixed, marked, menu_at, menu_items, menu_rows_h, - next_audio_kbps, next_container, normalise, nothing_to_play, notice_tone, panel_h, - project_path, proxies_to_start, push_notice, px_below, retarget, row_enable, row_items, - rows_below_mixed, scrub_due, secs_label, should_resync, show_label, silence_rate, size_label, - snap_cue, snap_marks, snapped, source_tint, span_partner, speed_at, sub_pick_after_removal, - subtitle_plan, summary_head, summary_tail, timecode, timeline_fixed_h, tip_may_paint, - transport, typed, unseen_paths, unseen_sources, whole_take, window_title, + WAVE_COLS_MAX, Wave, ZOOM_MIN_FRAMES, active_lane, band_label, bitrate_detail, bitrate_refusal, + clipboard_after_remove, color_snap, commit_mbps, containers, enable, enable_lane, envelope, + eq_card_w, eq_freq, eq_freq_label, eq_graph_h, eq_spectrum, eq_x, eq_y, estimated_bytes, + export_path, export_settings, format_line, format_refusal, fps_choices, fps_label, frac_along, + frac_down, frame_at, frame_rate_ladder, histogram, inserted_band, is_project, keymap, + keys_rows, lanes_h, marked, menu_at, menu_items, menu_rows_h, next_container, normalise, + nothing_to_play, notice_tone, panel_h, project_path, proxies_to_start, push_notice, px_below, + retarget, row_enable, row_items, scrub_due, secs_label, should_resync, silence_rate, + size_label, snap_cue, snap_marks, snapped, source_tint, span_partner, speed_at, + sub_pick_after_removal, subtitle_plan, summary_head, summary_tail, timecode, timeline_fixed_h, + tip_may_paint, transport, typed, unseen_paths, unseen_sources, whole_take, window_title, }; use super::{ ActionId, Choice, EDGE_W, ETA_SPAN, Edge, FITS, FRAME_RATES, IMPORT_STALL, Import, ImportStage, Landing, LaneKind, PPS_DEFAULT, PPS_MIN, Preset, RESOLUTIONS, Repeat, SAMPLE_RATES, SEEK_STALL, - Scale, ScanKey, ScanPlan, SilenceScan, SubClip, View, ZOOM_MIN_FRAMES, ZOOM_OUT_MARGIN, - ZOOM_STEP, arrival, audio_rate_choices, av1_hw_warning, clip_width, clock, encoder_choices, - encoder_label, eta_secs, file_name, file_uri, fit_choices, frames_of_us, full_scan_key, - import_line, landing, lane_refuses, launch_queue, library_rows, live_idx, next_fit, - next_resolution, note_progress, pending_fps_choices, pending_resolution_choices, px_along, - read_ahead, repeats, resolution_choices, resolution_ladder, sample_rate_choices, scan_plan, - seek_line, silence_cached, silence_line, slice_whole_levels, source_secs, span_label, - stash_or_write, tone_choices, tone_label, trimmed_clip, trimmed_sub, trims, unscannable, - unusable, visible_slice, + Scale, ScanKey, ScanPlan, SilenceScan, SubClip, View, ZOOM_OUT_MARGIN, ZOOM_STEP, arrival, + audio_rate_choices, av1_hw_warning, clip_width, clock, encoder_choices, encoder_label, + eta_secs, file_name, file_uri, fit_choices, frames_of_us, full_scan_key, import_line, landing, + lane_refuses, launch_queue, library_rows, live_idx, next_fit, next_resolution, note_progress, + pending_fps_choices, pending_resolution_choices, px_along, read_ahead, repeats, + resolution_choices, resolution_ladder, sample_rate_choices, scan_plan, seek_line, + silence_cached, silence_line, slice_whole_levels, source_secs, stash_or_write, tone_choices, + tone_label, trimmed_clip, trimmed_sub, trims, unscannable, unusable, }; use super::{ - SUB_BOTTOM, SUB_CUE_MIN_W, SUB_HEAD_H, SUB_LINE_H, SUB_ROWS_H, SUB_STEM_SHARE, SUB_TEXT, Subs, - carries_subtitles, clip_middle, cue_box, cues_at, file_tint, is_subtitle, lang_human, - row_text_w, sub_bottom, sub_pick_name, subtitle_detail, subtitle_notice, subtitle_rows, - subtitle_tail, subtitle_toggle_notice, walk_subtitles, + SUB_BOTTOM, SUB_CUE_MIN_W, SUB_LINE_H, SUB_TEXT, Subs, carries_subtitles, cue_box, cues_at, + file_tint, is_subtitle, lang_human, sub_bottom, sub_pick_name, subtitle_detail, + subtitle_notice, subtitle_rows, subtitle_tail, subtitle_toggle_notice, walk_subtitles, }; use engine::PlaybackSession; diff --git a/crates/app/src/tests/view.rs b/crates/app/src/tests/view.rs index 3c771f0..a70857f 100644 --- a/crates/app/src/tests/view.rs +++ b/crates/app/src/tests/view.rs @@ -869,24 +869,6 @@ fn a_clip_is_drawn_the_same_width_whatever_else_is_on_the_timeline() { /// that tells two zooms apart. #[test] fn the_zoom_button_says_how_much_is_on_the_bed() { - assert_eq!(span_label(4.5), "4.5s"); - assert_eq!(span_label(22.5), "22s"); - assert_eq!(span_label(90.), "1.5m"); - assert_eq!(span_label(3600.), "1.0h"); - // The span a five hour timeline is zoomed all the way out to. - assert_eq!(span_label(5. * 3600. * 1.05), "5.2h"); - // Before the first paint there is no bed and so no answer to give. - assert_eq!(span_label(0.), "—"); - assert_eq!(span_label(f64::NAN), "—"); - // A span under a second is a span: the tightest zoom is - // `ZOOM_MIN_FRAMES` across the bed, which on 240 fps slow-motion is - // 0.03s, and "0.0s" would be the pill saying nothing is on the bed. - for fps in [60., 120., 240., 1000.] { - let label = span_label(ZOOM_MIN_FRAMES / fps); - assert_ne!(label, "0.0s", "{fps} fps"); - assert_ne!(label, "0.00s", "{fps} fps"); - } - assert_eq!(span_label(ZOOM_MIN_FRAMES / 240.), "0.03s"); // A frame of quiet at 60 fps, which the silence card says out loud. assert_eq!(secs_label(1. / 60.), "0.02s"); assert_eq!(secs_label(4.5), "4.5s"); diff --git a/crates/app/src/timeline_math.rs b/crates/app/src/timeline_math.rs index 636ef04..aa27805 100644 --- a/crates/app/src/timeline_math.rs +++ b/crates/app/src/timeline_math.rs @@ -166,59 +166,10 @@ impl Selection { } } -/// The rate a caption's box plays its window at, read off the placement -/// itself: how long the words are, against how much timeline they cross. A -/// clip's badge comes from its own `speed`; a caption has none, so its box -/// derives one -- and keeps it even after the group that re-timed it comes -/// apart, because the proportion is the placement's own. `None` at unity: -/// placement rounding leaves an odd-width window a frame or so off real time, -/// and a badge is for a box that was *re-timed*, not one that rounds. -pub(crate) fn caption_rate(sub: SubClip, fps: f64) -> Option { - if !(fps.is_finite() && fps > 0.0) || sub.window_us() <= 0 { - return None; - } - let (span_us, window_us) = (f64::from(sub.frames) / fps * 1e6, sub.window_us() as f64); - // The unity gate is absolute, in frames of the timeline: placement - // rounding (`frames_of_us`) leaves a short track up to half a frame off - // real time, which against a one-second window is fifteen permille -- a - // relative gate would badge most palette drops under two and a half - // seconds. Unity is "the window lands within a frame and a half of the - // span"; the permille is only ever the rate the badge shows. - if (span_us - window_us).abs() <= 1.5 / fps * 1e6 { - return None; - } - // The rate is the window over the span -- content per timeline, a clip's - // own `speed` in the same spelling: 10s of words crossing 5s of timeline - // is 2.00x. - let permille = (window_us / span_us * 1000.).round(); - Some(Speed::from_permille(permille.clamp( - f64::from(Speed::MIN.permille()), - f64::from(Speed::MAX.permille()), - ) as u16)) -} - -/// The scrollbar's thumb over a track `w` px wide: `(x, width)` of the box -/// standing for the visible share of a timeline `duration` long whose window -/// starts at `start` and spans `span`. Full width when nothing is off-screen -/// (there is nothing to scroll and the strip says so by filling), never -/// narrower than [`SCROLL_THUMB_MIN`] when there is (a thumb a pixel wide is a -/// thumb no hand can hold), and never off the track either way -- the clamp, -/// not the caller, owns that, because a drag's samples arrive raw. -pub(crate) fn scroll_thumb(w: f32, duration: f64, start: f64, span: f64) -> (f32, f32) { - if w <= 0. || duration <= 0. || span >= duration { - return (0., w.max(0.)); - } - let share = f64::from(w); - let width = ((span / duration) * share).clamp(f64::from(SCROLL_THUMB_MIN), f64::from(w)); - let x = (start / duration * share).clamp(0., f64::from(w) - width); - (x as f32, width as f32) -} - /// The lane stack's thumb over a track `h` px tall: `(y, height)` of the box /// standing for the visible share of a stack `content` px tall in a box -/// `box_h` px tall, taken down by `scrolled` px -- the time axis's -/// [`scroll_thumb`] turned through a right angle, and on the same terms: -/// full track when the whole stack is on screen, never shorter than +/// `box_h` px tall, taken down by `scrolled` px. Full track when the whole +/// stack is on screen, never shorter than /// [`SCROLL_THUMB_MIN`] when it is not, and never off the track either way. pub(crate) fn lanes_thumb(track: f32, content: f32, box_h: f32, scrolled: f32) -> (f32, f32) { if track <= 0. || content <= 0. || box_h >= content { @@ -257,11 +208,6 @@ pub(crate) fn marked( picks.contains(&here) || (link.is_some() && pick_links.contains(&link)) } -/// Whether a clip is wide enough to be worth naming. -pub(crate) fn show_label(w: f32) -> bool { - w >= LABEL_MIN_W -} - /// The clip a trim is *showing*, worked out the way `Project::trim` will write /// it: the timeline room the edge leaves is turned into source frames by the one /// conversion that exists for it ([`Speed::fit`]), and the box is drawn from @@ -481,22 +427,6 @@ pub(crate) fn sub_mark(subs: &[SubClip], start: u32) -> Option { subs.iter().position(|s| s.start == start) } -/// The part of a clip's box that is on the bed, in the box's own pixels: -/// `(left, width)` of its intersection with the visible strip. Everything drawn -/// *inside* a box -- its waveform, its name, its speed badge -- is placed in -/// here rather than at the box's own edges, which at a deep zoom sit thousands -/// of pixels off either side of the screen: a label out there is a label nobody -/// can read, and a waveform out there is a path with a point per two pixels of a -/// width nobody can see. A bed that has not been measured yet answers with the -/// whole box, which is what was drawn before there was a bed to clip to. -pub(crate) fn visible_slice(left: f32, width: f32, bed: f32) -> (f32, f32) { - if bed <= 0. { - return (0., width); - } - let from = (-left).clamp(0., width); - let to = (bed - left).clamp(from, width); - (from, to - from) -} /// Scales an envelope to its own loudest sample, so a quietly mastered source /// still draws as a shape. The fixtures peak around an eighth of full scale, and diff --git a/crates/app/src/ui/cards.rs b/crates/app/src/ui/cards.rs index 58b8e16..7e7873b 100644 --- a/crates/app/src/ui/cards.rs +++ b/crates/app/src/ui/cards.rs @@ -7,9 +7,8 @@ use crate::*; /// DESIGN §3/§4 atoms shared by every param/setting card below (colour, /// transform, speed, EQ, silence, mix, subtitle style): what a row's label -/// and value paint as once `self.darkroom` is on, so the seven card bodies -/// each pick tokens rather than reimplement the same font/colour swap seven -/// times (`export_card`'s own `dark`-branch technique, one level up). +/// and value paint in the darkroom, so the seven card bodies each pick +/// tokens rather than reimplement the same font/colour swap seven times. /// /// A row label is what the room says about the control -- Archivo, §3's /// label-row size, `ink2` at rest / `ink1` picked (no permanent pill: the @@ -68,7 +67,7 @@ fn dark_row_value(text: impl Into) -> Div { /// ([`Player::toggle_maximize`]) -- mouse and key reach the same switch. // `+ use<>` (edition 2024 precise capturing): without it, the elided // lifetime on `cx` would be captured into the returned opaque type by -// default, so a hoisted `let head = dark.then(|| dark_card_head(..., cx));` +// default, so a hoisted `let head = true.then(|| dark_card_head(..., cx));` // would keep `cx` borrowed until `head` is finally consumed -- fighting // every other `cx.listener(...)` call built in between, which is exactly // the E0500/E0501 chain this card's own hoist is here to avoid. @@ -288,34 +287,22 @@ impl Player { // The cap is what keeps the card inside the smallest window; a taller // one gets a taller list rather than a scroll past empty space, and the // card is still only as tall as the rows it has. - // DEFECT 1 (MOCK-SPEC.md / DESIGN §4): the darkroom draws this same - // card in its own language -- plate surface, mono for what the film - // says, ghost rows, one bordered chip for the commit action -- while - // the legacy tree (`OLD_GUI=1`) keeps the rounded sheet verbatim. - // Branched here rather than in a second function so the ~350 lines - // of row-building *logic* below (which preset is picked, which - // format is refused, what a click does) stay written once; only the - // few tokens a paint reads differ. - let dark = self.darkroom; - let rows_h = match dark { - // The corner plate sits over the bench+ledger footprint (§11 - // check 6), which is a fraction of the window a centred modal - // was sized against -- a fixed, smaller cap rather than - // `viewport.height`-derived room the plate does not have. - true => (EXPORT_ROWS_H / 2.).max(4. * KEYS_ROW_H), - false => (f32::from(viewport.height) - EXPORT_FIXED_H - 24.).max(EXPORT_ROWS_H), - }; - let ink_secondary = if dark { INK3() } else { FG_SECONDARY() }; - let ink_primary = if dark { INK1() } else { FG_PRIMARY() }; - let bg_hover = if dark { DARK_RAISED() } else { BG_HOVER() }; - let bg_selected = if dark { DARK_RAISED() } else { BG_SELECTED() }; + // DESIGN §4: plate surface, mono for what the film says, ghost rows, + // one bordered chip for the commit action. + let ink_secondary = INK3(); + let bg_hover = DARK_RAISED(); + let bg_selected = DARK_RAISED(); // Archivo for what the row *says as a verb* (its label), mono for // what the film says through it (its detail/key) -- DESIGN §3. - let label_style = - dark.then(|| type_scale::label(type_scale::LABEL_ROW_PX, gpui::FontWeight::MEDIUM)); - let mono_style = dark - .then(|| type_scale::mono(type_scale::CHORD_METADATA_MAX_PX, gpui::FontWeight::MEDIUM)); - let head_style = dark.then(type_scale::head); + let label_style = Some(type_scale::label( + type_scale::LABEL_ROW_PX, + gpui::FontWeight::MEDIUM, + )); + let mono_style = Some(type_scale::mono( + type_scale::CHORD_METADATA_MAX_PX, + gpui::FontWeight::MEDIUM, + )); + let head_style = Some(type_scale::head()); let row = |id: (&'static str, usize)| { div() .id(id) @@ -370,19 +357,12 @@ impl Player { // picked, `ink2` resting), detail follows one step behind // (`ink2` picked, `ink2` resting -- never `ink3`, which stays // for the key column and the summary's small print). - let ink = match (dark, picked) { - (true, true) => INK2(), - (true, false) => INK2(), - (false, true) => ink_primary, - (false, false) => ink_secondary, + let ink = INK2(); + let label_ink = match picked { + true => INK1(), + false => INK2(), }; - let label_ink = match (dark, picked) { - (true, true) => INK1(), - (true, false) => INK2(), - (false, true) => ink_primary, - (false, false) => ink_secondary, - }; - let key_ink = if dark { INK3() } else { ink_secondary }; + let key_ink = INK3(); live(row(id), enabled) .when(picked, |d| d.bg(rgb(bg_selected))) .child( @@ -412,9 +392,7 @@ impl Player { // every row and a wrapped line reads as if it // began left of the label it belongs to. div() - .when(dark, |d| { - d.w(px(92.)).flex_none().text_color(rgb(label_ink)) - }) + .map(|d| d.w(px(92.)).flex_none().text_color(rgb(label_ink))) .when_some(label_style.clone(), |d, style| { d.font(style.font).text_size(style.size) }) @@ -927,225 +905,60 @@ impl Player { false => "↵ exports · esc closes · s Advanced".into(), }, }; - if dark { - // DEFECT 1: the darkroom's own language, not the legacy sheet -- - // a plate (canvas-on-panel, §4), positioned over the bench+ - // ledger footprint it can sit over rather than centred over the - // whole window (§11 check 6: the picture stays uncovered). The - // click-catcher behind it is `size_full` so a click anywhere - // still closes the card exactly as the legacy scrim's does, but - // paints nothing (`SCRIM()` is deliberately not applied here) -- - // an invisible catcher changes zero picture pixels while a - // dimming one would still tint the screen it must never cover. - // The plate is the room's below-picture footprint, not a 340px - // corner card (user 2026-08-21: "export section is not aligning - // with our design"). Measured at 1280x720 the corner card's own - // max-height was ~9px taller than the footprint it had to fit - // in, so its scrolling row list collapsed to a single visible - // row: the presets, Advanced and every codec row under them were - // unreachable by pointer, and the long status sentence wrapped to - // three lines over the top of them. Two columns instead -- rows - // left, what-it-adds-up-to and the one bordered chip right -- - // inside the same bench+ledger footprint every menu already - // hangs in, so the picture stays uncovered (§11 check 6) and the - // list gets the whole height rather than a fraction of it. - let floor = crate::ui::stance::below_picture_floor( - f32::from(viewport.height), - self.split_px(Split::Bench, viewport), - ); - let summary = |text: SharedString, ink: u32| { - div() - .flex_none() - .px(px(6.)) - .type_style(type_scale::mono( - type_scale::CHORD_METADATA_MAX_PX, - gpui::FontWeight::MEDIUM, - )) - .text_color(rgb(ink)) - .child(text) - }; - return Some( - div() - .id("export-click-catcher") - .absolute() - .top_0() - .bottom_0() - .left_0() - .right_0() - .flex() - // Below the time band, not merely below the picture: the - // transport and the Export chip that opened this card are - // on that band, and a sheet drawn over them hides the - // control the editor just pressed. The bench and the - // ledger are what this plate is allowed to cover. - .pt(px(floor + crate::ui::stance::TIME_BAND_H + 6.)) - .pb(px(6.)) - .px(px(6.)) - .on_mouse_down( - MouseButton::Left, - cx.listener(|this, _: &MouseDownEvent, _, cx| { - this.close_card(); - cx.notify(); - cx.stop_propagation(); - }), - ) - .child( - div() - .id("export-plate") - .flex_1() - .min_w(px(0.)) - .on_mouse_down(MouseButton::Left, swallow) - .flex() - .flex_col() - .gap(px(4.)) - .p(px(10.)) - .rounded(px(4.)) - .bg(rgb(DARK_PANEL())) - .border_1() - .border_color(rgba(DARK_SEAM())) - .child( - div() - .flex_none() - .flex() - .items_baseline() - .justify_between() - .gap(px(12.)) - .px(px(6.)) - .child( - div() - .type_style(type_scale::head()) - .text_color(rgb(INK3())) - .child("EXPORT"), - ) - .child( - div() - .min_w(px(0.)) - .truncate() - .type_style(type_scale::mono( - type_scale::CHORD_METADATA_MAX_PX, - gpui::FontWeight::MEDIUM, - )) - .text_color(rgb(INK2())) - .child(status_line), - ), - ) - .child( - div() - .flex_1() - .min_h(px(0.)) - .flex() - .gap(px(10.)) - .child( - div() - .id("export-rows") - .flex_1() - .min_w(px(0.)) - .h_full() - .flex() - .flex_col() - .gap(px(2.)) - .overflow_y_scroll() - .children(list), - ) - .child( - div() - .flex_none() - .w(px(300.)) - .h_full() - .flex() - .flex_col() - .justify_end() - .gap(px(4.)) - .border_l_1() - .border_color(rgb(DARK_HAIRLINE())) - .pl(px(8.)) - .child(summary(head.into(), INK2())) - .children(self.range.map(|(start, end)| { - summary( - format!( - "RANGE {}\u{2013}{} ({})", - timecode( - f64::from(start) / self.fps, - self.fps - ), - timecode(f64::from(end) / self.fps, self.fps), - frames_timecode(end - start, self.fps), - ) - .into(), - INK3(), - ) - })) - .child(summary(tail.into(), INK3())) - // §4: "the single bordered chip in - // the whole room" -- ghosts - // everywhere else in this card, one - // border here, wearing its chord - // live off the keymap so a rebind - // cannot leave it stale. - .child( - div() - .id("export-confirm") - .mt(px(4.)) - .flex() - .items_center() - .justify_center() - .gap(px(6.)) - .h(px(CONTROL_H)) - .px(px(10.)) - .rounded(px(3.)) - .border_1() - .border_color(rgb(match blocked.is_some() { - true => INK4(), - false => INK2(), - })) - .when(blocked.is_none(), |d| d.cursor_pointer()) - .when(blocked.is_some(), |d| { - d.cursor_not_allowed() - }) - .hover(|s| s.bg(rgb(DARK_RAISED()))) - .on_click(cx.listener( - |this, _: &ClickEvent, _, cx| { - this.start_export(cx) - }, - )) - .type_style(type_scale::label( - type_scale::LABEL_ROW_PX, - gpui::FontWeight::MEDIUM, - )) - .text_color(rgb(match blocked.is_some() { - true => INK4(), - false => INK1(), - })) - .child(action) - .when(blocked.is_none(), |d| { - d.child( - div() - .type_style(type_scale::mono( - type_scale::CHORD_METADATA_MIN_PX, - gpui::FontWeight::MEDIUM, - )) - .text_color(rgb(INK3())) - .child( - self.keymap - .chord(ActionId::Export), - ), - ) - }), - ), - ), - ) - .into_any_element(), - ) - .into_any_element(), - ); - } + // The darkroom's own language, not the corner-card sheet the legacy + // tree drew before it was removed -- + // a plate (canvas-on-panel, §4), positioned over the bench+ + // ledger footprint it can sit over rather than centred over the + // whole window (§11 check 6: the picture stays uncovered). The + // click-catcher behind it is `size_full` so a click anywhere + // still closes the card exactly as the legacy scrim's does, but + // paints nothing (`SCRIM()` is deliberately not applied here) -- + // an invisible catcher changes zero picture pixels while a + // dimming one would still tint the screen it must never cover. + // The plate is the room's below-picture footprint, not a 340px + // corner card (user 2026-08-21: "export section is not aligning + // with our design"). Measured at 1280x720 the corner card's own + // max-height was ~9px taller than the footprint it had to fit + // in, so its scrolling row list collapsed to a single visible + // row: the presets, Advanced and every codec row under them were + // unreachable by pointer, and the long status sentence wrapped to + // three lines over the top of them. Two columns instead -- rows + // left, what-it-adds-up-to and the one bordered chip right -- + // inside the same bench+ledger footprint every menu already + // hangs in, so the picture stays uncovered (§11 check 6) and the + // list gets the whole height rather than a fraction of it. + let floor = crate::ui::stance::below_picture_floor( + f32::from(viewport.height), + self.split_px(Split::Bench, viewport), + ); + let summary = |text: SharedString, ink: u32| { + div() + .flex_none() + .px(px(6.)) + .type_style(type_scale::mono( + type_scale::CHORD_METADATA_MAX_PX, + gpui::FontWeight::MEDIUM, + )) + .text_color(rgb(ink)) + .child(text) + }; Some( - scrim() + div() + .id("export-click-catcher") + .absolute() + .top_0() + .bottom_0() + .left_0() + .right_0() .flex() - .justify_center() - .items_center() - .bg(rgba(SCRIM())) - // Click away closes it, as on every card here. + // Below the time band, not merely below the picture: the + // transport and the Export chip that opened this card are + // on that band, and a sheet drawn over them hides the + // control the editor just pressed. The bench and the + // ledger are what this plate is allowed to cover. + .pt(px(floor + crate::ui::stance::TIME_BAND_H + 6.)) + .pb(px(6.)) + .px(px(6.)) .on_mouse_down( MouseButton::Left, cx.listener(|this, _: &MouseDownEvent, _, cx| { @@ -1156,89 +969,144 @@ impl Player { ) .child( div() - .w(px(EXPORT_W)) + .id("export-plate") + .flex_1() + .min_w(px(0.)) .on_mouse_down(MouseButton::Left, swallow) .flex() .flex_col() - .gap(px(2.)) - .p(px(12.)) - .rounded(px(6.)) - .bg(rgb(BG_RAISED())) - .child(div().flex_none().px(px(6.)).child("Export")) - // The status line, where a refusal from the save dialog - // lands: the notice bar it would otherwise take is under - // the scrim. The keys are on the rows, so this says how - // the card as a whole is answered rather than listing - // them a second time. + .gap(px(4.)) + .p(px(10.)) + .rounded(px(4.)) + .bg(rgb(DARK_PANEL())) + .border_1() + .border_color(rgba(DARK_SEAM())) .child( div() .flex_none() - .px(px(6.)) - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - .child(status_line), - ) - // Capped and scrolling like the keybindings list: the - // rows are more than a 360 px window has room for, and - // it is the list that scrolls, never the card that - // grows -- the summary and the button below stay put. - .child( - div() - .id("export-rows") .flex() - .flex_col() - .gap(px(2.)) - .max_h(px(rows_h)) - .overflow_y_scroll() - .children(list), - ) - .child(div().flex_none().px(px(6.)).text_size(px(11.)).child(head)) - // The mark, in and out and how long that is -- only - // when there is one: an unmarked export writes the - // whole timeline, the summary it always had. - .children(self.range.map(|(start, end)| { - div() - .flex_none() - .px(px(6.)) - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - .child(format!( - "RANGE {}\u{2013}{} ({})", - timecode(f64::from(start) / self.fps, self.fps), - timecode(f64::from(end) / self.fps, self.fps), - frames_timecode(end - start, self.fps), - )) - })) - .child( - div() - .flex_none() + .items_baseline() + .justify_between() + .gap(px(12.)) .px(px(6.)) - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - .child(tail), + .child( + div() + .type_style(type_scale::head()) + .text_color(rgb(INK3())) + .child("EXPORT"), + ) + .child( + div() + .min_w(px(0.)) + .truncate() + .type_style(type_scale::mono( + type_scale::CHORD_METADATA_MAX_PX, + gpui::FontWeight::MEDIUM, + )) + .text_color(rgb(INK2())) + .child(status_line), + ), ) .child( div() - .id("export-confirm") - .mt(px(4.)) + .flex_1() + .min_h(px(0.)) .flex() - .h(px(CONTROL_H)) - .items_center() - .justify_center() - .rounded(px(3.)) - .bg(rgb(match blocked.is_some() { - true => BG_PANEL(), - false => BG_SELECTED(), - })) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .on_click( - cx.listener(|this, _: &ClickEvent, _, cx| { - this.start_export(cx) - }), + .gap(px(10.)) + .child( + div() + .id("export-rows") + .flex_1() + .min_w(px(0.)) + .h_full() + .flex() + .flex_col() + .gap(px(2.)) + .overflow_y_scroll() + .children(list), ) - .child(action), - ), + .child( + div() + .flex_none() + .w(px(300.)) + .h_full() + .flex() + .flex_col() + .justify_end() + .gap(px(4.)) + .border_l_1() + .border_color(rgb(DARK_HAIRLINE())) + .pl(px(8.)) + .child(summary(head.into(), INK2())) + .children(self.range.map(|(start, end)| { + summary( + format!( + "RANGE {}\u{2013}{} ({})", + timecode(f64::from(start) / self.fps, self.fps), + timecode(f64::from(end) / self.fps, self.fps), + frames_timecode(end - start, self.fps), + ) + .into(), + INK3(), + ) + })) + .child(summary(tail.into(), INK3())) + // §4: "the single bordered chip in + // the whole room" -- ghosts + // everywhere else in this card, one + // border here, wearing its chord + // live off the keymap so a rebind + // cannot leave it stale. + .child( + div() + .id("export-confirm") + .mt(px(4.)) + .flex() + .items_center() + .justify_center() + .gap(px(6.)) + .h(px(CONTROL_H)) + .px(px(10.)) + .rounded(px(3.)) + .border_1() + .border_color(rgb(match blocked.is_some() { + true => INK4(), + false => INK2(), + })) + .when(blocked.is_none(), |d| d.cursor_pointer()) + .when(blocked.is_some(), |d| d.cursor_not_allowed()) + .hover(|s| s.bg(rgb(DARK_RAISED()))) + .on_click(cx.listener( + |this, _: &ClickEvent, _, cx| { + this.start_export(cx) + }, + )) + .type_style(type_scale::label( + type_scale::LABEL_ROW_PX, + gpui::FontWeight::MEDIUM, + )) + .text_color(rgb(match blocked.is_some() { + true => INK4(), + false => INK1(), + })) + .child(action) + .when(blocked.is_none(), |d| { + d.child( + div() + .type_style(type_scale::mono( + type_scale::CHORD_METADATA_MIN_PX, + gpui::FontWeight::MEDIUM, + )) + .text_color(rgb(INK3())) + .child( + self.keymap.chord(ActionId::Export), + ), + ) + }), + ), + ), + ) + .into_any_element(), ) .into_any_element(), ) @@ -1258,7 +1126,6 @@ impl Player { /// chord as well ([`cancels_export`]). pub(crate) fn export_progress_card(&self, cx: &mut Context) -> Option { let export = self.exporting()?; - let dark = self.darkroom; let progress = export.progress().clamp(0., 1.); let elapsed = self .export_started @@ -1276,16 +1143,7 @@ impl Player { [one] => file_name(&one.path), [first, rest @ ..] => format!("{} +{} more", file_name(&first.path), rest.len()), }; - let note = |text: SharedString| match dark { - true => dark_help(text).into_any_element(), - false => div() - .flex_none() - .px(px(6.)) - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - .child(text) - .into_any_element(), - }; + let note = |text: SharedString| dark_help(text).into_any_element(); let armed = self.cancel_armed; let percent_line: SharedString = format!( "{}% · {} elapsed · {left}", @@ -1312,14 +1170,9 @@ impl Player { .gap(px(6.)) .p(px(12.)) .rounded(px(6.)) - .bg(rgb(if dark { DARK_PANEL() } else { BG_RAISED() })) - .when(dark, |d| d.border_1().border_color(rgba(DARK_SEAM()))) - .when(dark, |d| { - d.child(dark_card_head("Exporting", None, None, None, cx)) - }) - .when(!dark, |d| { - d.child(div().flex_none().px(px(6.)).child("Exporting")) - }) + .bg(rgb(DARK_PANEL())) + .map(|d| d.border_1().border_color(rgba(DARK_SEAM()))) + .map(|d| d.child(dark_card_head("Exporting", None, None, None, cx))) // The bar itself: the same number as the percentage // below it, and it only ever moves forward -- the // worker's progress is a monotone `fetch_max`. @@ -1329,7 +1182,7 @@ impl Player { .mx(px(6.)) .h(px(6.)) .rounded(px(3.)) - .bg(rgb(if dark { DARK_HAIRLINE() } else { BG_PANEL() })) + .bg(rgb(DARK_HAIRLINE())) .child( div() .h_full() @@ -1338,16 +1191,7 @@ impl Player { .bg(rgb(STATUS_PROGRESS())), ), ) - .when(dark, |d| d.child(dark_row_value(percent_line.clone()))) - .when(!dark, |d| { - d.child( - div() - .flex_none() - .px(px(6.)) - .text_size(px(11.)) - .child(percent_line.clone()), - ) - }) + .map(|d| d.child(dark_row_value(percent_line.clone()))) // The row that was picked, then the seats the worker // actually opened -- so a fallback to the software // encoder shows here rather than being invisible. @@ -1386,7 +1230,7 @@ impl Player { .flex() .gap(px(6.)) .justify_end() - .when(armed && dark, |d| { + .when(armed, |d| { d.child(dark_ghost_button( "export-keep", "Keep exporting", @@ -1398,22 +1242,7 @@ impl Player { }), )) }) - .when(armed && !dark, |d| { - d.child(control( - "export-keep", - 140., - ACCENT_PRIMARY(), - None, - "Keep exporting", - "leaves the export running".to_string(), - true, - cx.listener(|this, _: &ClickEvent, _, cx| { - this.cancel_armed = false; - cx.notify(); - }), - )) - }) - .when(dark, |d| { + .map(|d| { d.child(dark_ghost_button( "export-cancel", "Cancel export", @@ -1427,31 +1256,6 @@ impl Player { cx.notify(); }), )) - }) - .when(!dark, |d| { - d.child(control( - "export-cancel", - 140., - BG_RAISED(), - None, - "Cancel export", - match armed { - true => "stops the worker and deletes the part file" - .to_string(), - false => { - "asks first -- one press only offers the choice" - .to_string() - } - }, - true, - cx.listener(move |this, _: &ClickEvent, _, cx| { - match this.cancel_armed { - true => this.cancel_export(), - false => this.cancel_armed = true, - } - cx.notify(); - }), - )) }), ), ), @@ -1512,7 +1316,6 @@ impl Player { cx: &mut Context, ) -> Option { let (lane, idx) = self.eq_open?; - let dark = self.darkroom; // The rate the engine filters this timeline at, so the drawn curve is // the one those coefficients make -- near the top of the axis a 44.1 kHz // clip and a 48 kHz one are not the same shape. @@ -1547,12 +1350,7 @@ impl Player { .w(px(EQ_HANDLE)) .h(px(EQ_HANDLE)) .rounded(px(EQ_HANDLE / 2.)) - .bg(rgb(match (dark, i == self.eq_band) { - (true, true) => INK1(), - (true, false) => INK3(), - (false, true) => ACCENT_PRIMARY(), - (false, false) => FG_SECONDARY(), - })) + .bg(rgb(if i == self.eq_band { INK1() } else { INK3() })) }) .collect(); // Maximized used to claim a fixed 320 px slice for the graph @@ -1564,7 +1362,7 @@ impl Player { // rows below it claim their own natural height first, the same // leftover-space idiom `dock_stance::dock_sources` already uses for // its own scroll region. - let graph_maximized = dark && self.card_maximized; + let graph_maximized = self.card_maximized; let graph = div() // Ided like the band rows it replaces: what the pointer presses on // is one element with its own hitbox, which is what a drag is @@ -1576,11 +1374,7 @@ impl Player { }) .when(!graph_maximized, |d| d.flex_none().h(px(eq_graph_h(false)))) .rounded(px(3.)) - .bg(rgb(if dark { - DARK_HAIRLINE() - } else { - BG_HOVER_DIM() - })) + .bg(rgb(DARK_HAIRLINE())) .cursor_pointer() // The press picks the band under it *and* is already the first // sample of the drag, so a plain click sets a value. A second click @@ -1615,7 +1409,7 @@ impl Player { .left(relative(eq_x(*freq))) .w(px(1.)) .h_full() - .bg(rgb(if dark { DARK_HAIRLINE() } else { EQ_GRID() })) + .bg(rgb(DARK_HAIRLINE())) }) .collect::>(), ) @@ -1627,22 +1421,19 @@ impl Player { .top(relative(eq_y(db))) .w_full() .h(px(1.)) - .bg(rgb(if dark { DARK_HAIRLINE() } else { EQ_GRID() })) + .bg(rgb(DARK_HAIRLINE())) .child( div() .absolute() .left(px(4.)) .top(px(-11.)) - .when(dark, |d| { + .map(|d| { d.type_style(type_scale::mono( type_scale::CHORD_METADATA_MIN_PX, gpui::FontWeight::MEDIUM, )) .text_color(rgb(INK3())) }) - .when(!dark, |d| { - d.text_size(px(9.)).text_color(rgb(FG_SECONDARY())) - }) .child(format!("{db:+.0}")), ) })) @@ -1653,7 +1444,7 @@ impl Player { .top(relative(0.5)) .w_full() .h(px(1.)) - .bg(rgb(if dark { DARK_HAIRLINE() } else { BG_HOVER() })), + .bg(rgb(DARK_HAIRLINE())), ) .child(eq_curve(self.eq_params.clone(), sample_rate)) .children(handles) @@ -1672,11 +1463,7 @@ impl Player { // a box narrower than the text. `.whitespace_nowrap()` is // the platform's own backstop, so a mis-measured box clips // or overhangs instead of silently wrapping again. - let end_px = if dark { - type_scale::CHORD_METADATA_MIN_PX - } else { - 9. - }; + let end_px = type_scale::CHORD_METADATA_MIN_PX; let div = div().absolute().bottom(px(1.)).whitespace_nowrap(); let div = if i == 0 { div.w(px(eq_tick_end_w(label, end_px))) @@ -1692,16 +1479,13 @@ impl Player { .ml(px(-12.)) .text_align(TextAlign::Center) }; - div.when(dark, |d| { + div.map(|d| { d.type_style(type_scale::mono( type_scale::CHORD_METADATA_MIN_PX, gpui::FontWeight::MEDIUM, )) .text_color(rgb(INK3())) }) - .when(!dark, |d| { - d.text_size(px(9.)).text_color(rgb(FG_SECONDARY())) - }) .child(*label) })) .child( @@ -1709,16 +1493,13 @@ impl Player { .absolute() .top(px(2.)) .left(px(4.)) - .when(dark, |d| { + .map(|d| { d.type_style(type_scale::mono( type_scale::CHORD_METADATA_MIN_PX, gpui::FontWeight::MEDIUM, )) .text_color(rgb(INK3())) }) - .when(!dark, |d| { - d.text_size(px(9.)).text_color(rgb(FG_SECONDARY())) - }) .child(format!("+{EQ_GAIN_LIMIT:.0} dB")), ); // The bottom of the axis is not named: -12 dB would land in the same @@ -1782,8 +1563,8 @@ impl Player { .gap(px(2.)) .p(px(12.)) .rounded(px(6.)) - .bg(rgb(if dark { DARK_PANEL() } else { BG_RAISED() })) - .when(dark, |d| d.border_1().border_color(rgba(DARK_SEAM()))) + .bg(rgb(DARK_PANEL())) + .map(|d| d.border_1().border_color(rgba(DARK_SEAM()))) .child( div() .id("eq-card-rows") @@ -1798,7 +1579,7 @@ impl Player { .gap(px(2.)) // Which clip, because the card is modal and the lane it // was opened from is behind a scrim by the time it is up. - .when(dark, |d| { + .map(|d| { d.child(dark_card_head( "Equalizer", Some(format!("{} clip {}", lane.label(), idx + 1).into()), @@ -1807,28 +1588,11 @@ impl Player { cx, )) }) - .when(!dark, |d| { - d.child(div().flex_none().px(px(6.)).child(format!( - "Equalizer — {} clip {}", - lane.label(), - idx + 1 - ))) - }) - .when(dark && self.notices.front().is_some(), |d| { + + .when(self.notices.front().is_some(), |d| { d.child(dark_help(self.notices.front().cloned().unwrap_or_default())) }) - .when(!dark, |d| { - d.child( - div() - .flex_none() - .px(px(6.)) - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - .child(self.notices.front().cloned().unwrap_or_else(|| { - "drag a handle, or a digit picks a band — ←→ moves it, ↑↓ its gain, shift+←→ its width; a adds, x removes, f flattens it, r all, s spectrum; a click away or esc closes".into() - })), - ) - }) + .child(graph) // Which band the keyboard is holding and every number it // is set to, each with the pair of buttons that moves it: @@ -1847,7 +1611,7 @@ impl Player { // by its key alone. .flex_wrap() .gap(px(4.)) - .when(dark, |d| { + .map(|d| { d.child(dark_ghost_button( "eq-reset", "Flatten all", @@ -1861,33 +1625,12 @@ impl Player { }), )) }) - .when(!dark, |d| { - d.child( - div() - .id("eq-reset") - .flex() - .flex_1() - .h(px(CONTROL_H)) - .items_center() - .justify_center() - .rounded(px(3.)) - .bg(rgb(BG_SELECTED())) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { - for band in &mut this.eq_params.bands { - band.gain_db = 0.; - } - this.commit_eq(cx); - })) - .child("Flatten all"), - ) - }) + // The two that change how many bands there are. // The engine takes any cascade -- the count was // only ever fixed because this card had no way // to say otherwise. - .when(dark, |d| { + .map(|d| { d.child(dark_ghost_button( "eq-add", "Add band", @@ -1898,26 +1641,8 @@ impl Player { }), )) }) - .when(!dark, |d| { - d.child( - div() - .id("eq-add") - .flex() - .flex_1() - .h(px(CONTROL_H)) - .items_center() - .justify_center() - .rounded(px(3.)) - .bg(rgb(BG_PANEL())) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { - this.add_band(cx) - })) - .child("Add band"), - ) - }) - .when(dark, |d| { + + .map(|d| { d.child(dark_ghost_button( "eq-remove", "Remove band", @@ -1928,30 +1653,12 @@ impl Player { }), )) }) - .when(!dark, |d| { - d.child( - div() - .id("eq-remove") - .flex() - .flex_1() - .h(px(CONTROL_H)) - .items_center() - .justify_center() - .rounded(px(3.)) - .bg(rgb(BG_PANEL())) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { - this.remove_band(cx) - })) - .child("Remove band"), - ) - }) + // The analyser's switch, next to the one other // button the card has: `s` does the same, and a // toggle only a keystroke can reach is one most // people never find. - .when(dark, |d| { + .map(|d| { d.child(dark_ghost_button( "eq-spectrum", match self.eq_spectrum { @@ -1966,63 +1673,19 @@ impl Player { }), )) }) - .when(!dark, |d| { - d.child( - div() - .id("eq-spectrum") - .flex() - .flex_1() - .h(px(CONTROL_H)) - .items_center() - .justify_center() - .rounded(px(3.)) - .bg(rgb(match self.eq_spectrum { - true => BG_SELECTED(), - false => BG_HOVER_DIM(), - })) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { - this.eq_spectrum = !this.eq_spectrum; - cx.notify(); - })) - .child(match self.eq_spectrum { - true => "Spectrum on", - false => "Spectrum off", - }), - ) - }), + , ), ) // The column's own line, on the card that needs it for // the column's reason: a row nobody knows is under the // fold is a row that is not there. - .when(can_scroll && dark, |d| { + .when(can_scroll, |d| { d.child(dark_help(match below > 1. { true => "more below — scroll the card", false => "the end — scroll up for the rest", })) }) - .when(can_scroll && !dark, |d| { - d.child( - div() - .flex_none() - .h(px(LABEL_H)) - .flex() - .items_center() - .justify_end() - .px(px(6.)) - .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 card", - false => "the end — scroll up for the rest", - }), - ) - }), + , ), ) } @@ -2037,7 +1700,6 @@ impl Player { picked: Option<&Band>, cx: &mut Context, ) -> impl IntoElement { - let dark = self.darkroom; let row = div() .flex_none() .flex() @@ -2047,13 +1709,9 @@ impl Player { .flex_wrap() .items_center() .gap(px(10.)) - .px(px(6.)) - .when(!dark, |d| d.text_size(px(11.))); + .px(px(6.)); let Some(band) = picked.copied() else { - return match dark { - true => row.child(dark_help("no bands — a adds one")), - false => row.child("no bands — a adds one"), - }; + return row.child(dark_help("no bands — a adds one")); }; let step = |id: &'static str, label: &'static str, @@ -2061,23 +1719,7 @@ impl Player { cx: &mut Context| { let on_click = cx.listener(move |this, _: &ClickEvent, _, cx| this.nudge_band(change, cx)); - match dark { - true => dark_step_glyph(id, label == "+", on_click).into_any_element(), - false => div() - .id(id) - .flex() - .w(px(HIT_MIN)) - .h(px(HIT_MIN)) - .items_center() - .justify_center() - .rounded(px(3.)) - .bg(rgb(BG_PANEL())) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .on_click(on_click) - .child(label) - .into_any_element(), - } + dark_step_glyph(id, label == "+", on_click).into_any_element() }; let number = |value: String, ids: (&'static str, &'static str), @@ -2087,27 +1729,18 @@ impl Player { .flex() .items_center() .gap(px(4.)) - .child(match dark { - true => dark_row_value(value).into_any_element(), - false => div().child(value).into_any_element(), - }) + .child(dark_row_value(value).into_any_element()) .child(step(ids.0, "−", by.0, cx)) .child(step(ids.1, "+", by.1, cx)) }; - row.child(match dark { - true => dark_help(format!( + row.child( + dark_help(format!( "Band {} of {}", self.eq_band + 1, self.eq_params.bands.len() )) .into_any_element(), - false => format!( - "Band {} of {}", - self.eq_band + 1, - self.eq_params.bands.len() - ) - .into_any_element(), - }) + ) .child(number( band_label(&band), ("eq-freq-down", "eq-freq-up"), @@ -2165,7 +1798,6 @@ impl Player { ) -> Option { let (lane, idx) = self.color_open?; let params = self.color_params(); - let dark = self.darkroom; let rows: Vec<_> = COLOR_BANDS .iter() .enumerate() @@ -2186,9 +1818,8 @@ impl Player { // Darkroom: no permanent pill under a label -- the picked // row is a 1px `ink1` rule (§4's focus ring), never a fill. // Hover is the one fill step §4 allows. - .when(dark && picked, |d| d.border_l_2().border_color(rgb(INK1()))) - .when(!dark && picked, |d| d.bg(rgb(BG_SELECTED()))) - .hover(|s| s.bg(rgb(if dark { DARK_RAISED() } else { BG_HOVER() }))) + .when(picked, |d| d.border_l_2().border_color(rgb(INK1()))) + .hover(|s| s.bg(rgb(DARK_RAISED()))) .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { this.color_band = i; cx.notify(); @@ -2198,8 +1829,7 @@ impl Player { .flex_1() .min_w(px(0.)) .truncate() - .when(dark, |d| d.child(dark_row_label(label, picked))) - .when(!dark, |d| d.child(label)), + .map(|d| d.child(dark_row_label(label, picked))), ) .child( // The bar is 4 px to look at and a whole row to hit @@ -2230,7 +1860,7 @@ impl Player { .w_full() .h(px(4.)) .rounded(px(2.)) - .bg(rgb(if dark { DARK_PANEL() } else { BG_PANEL() })) + .bg(rgb(DARK_PANEL())) .child( div() .h_full() @@ -2243,14 +1873,7 @@ impl Player { .child( div() .w(px(44.)) - .when(dark, |d| { - d.child(dark_row_value(format!("{:.0}%", value * 100.))) - }) - .when(!dark, |d| { - d.text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - .child(format!("{:.0}%", value * 100.)) - }), + .map(|d| d.child(dark_row_value(format!("{:.0}%", value * 100.)))), ) }) .collect(); @@ -2292,9 +1915,9 @@ impl Player { .gap(px(2.)) .p(px(12.)) .rounded(px(6.)) - .bg(rgb(if dark { DARK_PANEL() } else { BG_RAISED() })) - .when(dark, |d| d.border_1().border_color(rgba(DARK_SEAM()))) - .when(dark, |d| { + .bg(rgb(DARK_PANEL())) + .map(|d| d.border_1().border_color(rgba(DARK_SEAM()))) + .map(|d| { d.child(dark_card_head( "Colour", Some(head_meta.clone()), @@ -2303,23 +1926,6 @@ impl Player { cx, )) }) - .when(!dark, |d| { - d.child(div().flex_none().px(px(6.)).child(format!( - "Colour — {} clip {}", - lane.label(), - idx + 1 - ))) - }) - .when(!dark, |d| { - d.child( - div() - .flex_none() - .px(px(6.)) - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - .child(help_text), - ) - }) // The frame as it is being graded, over the controls // grading it: the three lines are what the picture is // made of, and every sample of a drag reseeks, so they @@ -2329,16 +1935,12 @@ impl Player { .flex_none() .h(px(HIST_H)) .rounded(px(3.)) - .bg(rgb(if dark { - DARK_HAIRLINE() - } else { - BG_HOVER_DIM() - })) + .bg(rgb(DARK_HAIRLINE())) .relative() .child(hist_curves(self.histogram)), ) .children(rows) - .when(dark, |d| { + .map(|d| { d.child(dark_ghost_button( "color-reset", "Reset", @@ -2348,25 +1950,6 @@ impl Player { this.set_color(ColorParams::default(), cx); }), )) - }) - .when(!dark, |d| { - d.child( - div() - .id("color-reset") - .mt(px(4.)) - .flex() - .h(px(CONTROL_H)) - .items_center() - .justify_center() - .rounded(px(3.)) - .bg(rgb(BG_SELECTED())) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { - this.set_color(ColorParams::default(), cx); - })) - .child("Reset"), - ) }), ), ) @@ -2382,7 +1965,6 @@ impl Player { ) -> Option { let (lane, idx) = self.transform_open?; let params = self.transform_params(); - let dark = self.darkroom; let rows: Vec<_> = TRANSFORM_BANDS .iter() .enumerate() @@ -2400,9 +1982,8 @@ impl Player { .px(px(6.)) .rounded(px(3.)) .cursor_pointer() - .when(dark && picked, |d| d.border_l_2().border_color(rgb(INK1()))) - .when(!dark && picked, |d| d.bg(rgb(BG_SELECTED()))) - .hover(|s| s.bg(rgb(if dark { DARK_RAISED() } else { BG_HOVER() }))) + .when(picked, |d| d.border_l_2().border_color(rgb(INK1()))) + .hover(|s| s.bg(rgb(DARK_RAISED()))) .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { this.transform_band = i; cx.notify(); @@ -2412,8 +1993,7 @@ impl Player { .flex_1() .min_w(px(0.)) .truncate() - .when(dark, |d| d.child(dark_row_label(label, picked))) - .when(!dark, |d| d.child(label)), + .map(|d| d.child(dark_row_label(label, picked))), ) .child( div() @@ -2439,7 +2019,7 @@ impl Player { .w_full() .h(px(4.)) .rounded(px(2.)) - .bg(rgb(if dark { DARK_PANEL() } else { BG_PANEL() })) + .bg(rgb(DARK_PANEL())) .child( div() .h_full() @@ -2452,14 +2032,7 @@ impl Player { .child( div() .w(px(44.)) - .when(dark, |d| { - d.child(dark_row_value(transform_row_value(i, value))) - }) - .when(!dark, |d| { - d.text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - .child(transform_row_value(i, value)) - }), + .map(|d| d.child(dark_row_value(transform_row_value(i, value)))), ) }) .collect(); @@ -2500,9 +2073,9 @@ impl Player { .gap(px(2.)) .p(px(12.)) .rounded(px(6.)) - .bg(rgb(if dark { DARK_PANEL() } else { BG_RAISED() })) - .when(dark, |d| d.border_1().border_color(rgba(DARK_SEAM()))) - .when(dark, |d| { + .bg(rgb(DARK_PANEL())) + .map(|d| d.border_1().border_color(rgba(DARK_SEAM()))) + .map(|d| { d.child(dark_card_head( "Transform", Some(head_meta.clone()), @@ -2511,25 +2084,8 @@ impl Player { cx, )) }) - .when(!dark, |d| { - d.child(div().flex_none().px(px(6.)).child(format!( - "Transform — {} clip {}", - lane.label(), - idx + 1 - ))) - }) - .when(!dark, |d| { - d.child( - div() - .flex_none() - .px(px(6.)) - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - .child(help_text), - ) - }) .children(rows) - .when(dark, |d| { + .map(|d| { d.child(dark_ghost_button( "transform-reset", "Reset", @@ -2539,25 +2095,6 @@ impl Player { this.set_transform(TransformParams::default(), cx); }), )) - }) - .when(!dark, |d| { - d.child( - div() - .id("transform-reset") - .mt(px(4.)) - .flex() - .h(px(CONTROL_H)) - .items_center() - .justify_center() - .rounded(px(3.)) - .bg(rgb(BG_SELECTED())) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { - this.set_transform(TransformParams::default(), cx); - })) - .child("Reset"), - ) }), ), ) @@ -2581,7 +2118,6 @@ impl Player { let speed = self.card_speed(); let session = self.session.as_ref()?; let clip = session.lane_clips(lane).get(idx).copied()?; - let dark = self.darkroom; let lo = f32::from(Speed::MIN.permille()); let hi = f32::from(Speed::MAX.permille()); let frac = ((f32::from(speed.permille()) - lo) / (hi - lo)).clamp(0., 1.); @@ -2598,20 +2134,13 @@ impl Player { .items_center() .justify_center() .rounded(px(3.)) - .when(dark && picked, |d| d.bg(rgb(DARK_RAISED()))) - .when(!dark, |d| { - d.bg(rgb(match picked { - true => BG_SELECTED(), - false => BG_PANEL(), - })) - }) + .when(picked, |d| d.bg(rgb(DARK_RAISED()))) .cursor_pointer() - .hover(|s| s.bg(rgb(if dark { DARK_RAISED() } else { BG_HOVER() }))) + .hover(|s| s.bg(rgb(DARK_RAISED()))) .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { this.set_speed(at, cx); })) - .when(dark, |d| d.child(dark_row_value(format!("{at}")))) - .when(!dark, |d| d.child(format!("{at}"))) + .map(|d| d.child(dark_row_value(format!("{at}")))) }) .collect(); let head_meta: SharedString = format!("{} clip {}", lane.label(), idx + 1).into(); @@ -2658,9 +2187,9 @@ impl Player { .gap(px(6.)) .p(px(12.)) .rounded(px(6.)) - .bg(rgb(if dark { DARK_PANEL() } else { BG_RAISED() })) - .when(dark, |d| d.border_1().border_color(rgba(DARK_SEAM()))) - .when(dark, |d| { + .bg(rgb(DARK_PANEL())) + .map(|d| d.border_1().border_color(rgba(DARK_SEAM()))) + .map(|d| { d.child(dark_card_head( "Speed (tape)", Some(head_meta.clone()), @@ -2669,23 +2198,6 @@ impl Player { cx, )) }) - .when(!dark, |d| { - d.child(div().flex_none().px(px(6.)).child(format!( - "Speed (tape) — {} clip {}", - lane.label(), - idx + 1 - ))) - }) - .when(!dark, |d| { - d.child( - div() - .flex_none() - .px(px(6.)) - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - .child(help_text), - ) - }) .child( // 4 px to look at and a whole row to hit (WCAG // 2.5.8), the split the colour sliders and the ruler @@ -2711,7 +2223,7 @@ impl Player { .w_full() .h(px(4.)) .rounded(px(2.)) - .bg(rgb(if dark { DARK_PANEL() } else { BG_PANEL() })) + .bg(rgb(DARK_PANEL())) .child( div() .h_full() @@ -2722,20 +2234,7 @@ impl Player { ), ) .child(div().flex().gap(px(4.)).children(presets)) - .when(dark, |d| d.child(dark_help(tail_text.clone()))) - .when(!dark, |d| { - d.child( - div() - .flex_none() - .px(px(6.)) - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - // What the choice *is*, in the numbers the - // timeline is measured in: the source range - // never moves, the room it takes does. - .child(tail_text), - ) - }), + .map(|d| d.child(dark_help(tail_text.clone()))), ), ) } @@ -2764,7 +2263,6 @@ impl Player { if !self.mix_open { return None; } - let dark = self.darkroom; let session = self.session.as_ref(); let lanes = self.mix_lanes(); let limiter = session.map_or_else(Limiter::default, PlaybackSession::limiter); @@ -2802,70 +2300,31 @@ impl Player { .justify_between() .px(px(6.)) .rounded(px(3.)) - .when(dark && picked, |d| d.border_l_2().border_color(rgb(INK1()))) - .when(!dark, |d| { - d.bg(rgb(match picked { - true => BG_SELECTED(), - false => BG_PANEL(), - })) - }) + .when(picked, |d| d.border_l_2().border_color(rgb(INK1()))) .cursor_pointer() - .hover(|s| s.bg(rgb(if dark { DARK_RAISED() } else { BG_HOVER() }))) + .hover(|s| s.bg(rgb(DARK_RAISED()))) .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { this.mix_field = n; cx.notify(); })) - .child( - div() - .when(dark, |d| d.child(dark_row_label(label.clone(), picked))) - .when(!dark, |d| d.text_color(rgb(FG_SECONDARY())).child(label)), - ) + .child(div().map(|d| d.child(dark_row_label(label.clone(), picked)))) .child( div() .flex() .items_center() .gap(px(4.)) - .when(dark, |d| d.child(dark_row_value(value.clone()))) - .when(!dark, |d| d.child(value)) + .map(|d| d.child(dark_row_value(value.clone()))) .children([-1, 1].map(|steps: i32| { let id = ("mix-step", n * 2 + usize::from(steps > 0)); - match dark { - true => dark_step_glyph( - id, - steps > 0, - cx.listener(move |this, _: &ClickEvent, _, cx| { - this.mix_field = n; - this.nudge_mix(steps, cx); - }), - ) - .into_any_element(), - false => div() - .id(id) - .flex_none() - .w(px(HIT_MIN)) - .h(px(KEYS_ROW_H)) - .flex() - .items_center() - .justify_center() - .rounded(px(3.)) - .bg(rgb(BG_PANEL())) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .on_click(cx.listener( - move |this, _: &ClickEvent, _, cx| { - // Picked as well as moved, the silence - // card's rule: the row a press lands on - // is the row the arrows carry on from. - this.mix_field = n; - this.nudge_mix(steps, cx); - }, - )) - .child(match steps > 0 { - true => "+", - false => "−", - }) - .into_any_element(), - } + dark_step_glyph( + id, + steps > 0, + cx.listener(move |this, _: &ClickEvent, _, cx| { + this.mix_field = n; + this.nudge_mix(steps, cx); + }), + ) + .into_any_element() })), ) }) @@ -2914,9 +2373,9 @@ impl Player { .gap(px(6.)) .p(px(12.)) .rounded(px(6.)) - .bg(rgb(if dark { DARK_PANEL() } else { BG_RAISED() })) - .when(dark, |d| d.border_1().border_color(rgba(DARK_SEAM()))) - .when(dark, |d| { + .bg(rgb(DARK_PANEL())) + .map(|d| d.border_1().border_color(rgba(DARK_SEAM()))) + .map(|d| { d.child(dark_card_head( "Mix", None, @@ -2925,24 +2384,6 @@ impl Player { cx, )) }) - .when(!dark, |d| { - d.child( - div() - .flex_none() - .px(px(6.)) - .child("Mix — track volumes and the master limiter"), - ) - }) - .when(!dark, |d| { - d.child( - div() - .flex_none() - .px(px(6.)) - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - .child(help_text), - ) - }) .child( div() .id("mix-rows") @@ -2952,20 +2393,7 @@ impl Player { .overflow_y_scroll() .children(rows), ) - .when(dark, |d| d.child(dark_help(tail_text.clone()))) - .when(!dark, |d| { - d.child( - div() - .flex_none() - .px(px(6.)) - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - // What the choice *is*: the limiter's own line, - // because "on" alone says nothing about what it - // does to a mix that never reaches the ceiling. - .child(tail_text), - ) - }), + .map(|d| d.child(dark_help(tail_text.clone()))), ), ) } @@ -2985,17 +2413,14 @@ impl Player { if !self.subtitle_style_open { return None; } - let dark = self.darkroom; let help_text = "− and + move the size, or ↑↓ picks a row and ←→ moves it (held or pressed); a family row picks it outright — a click away or esc closes"; - let head = dark.then(|| { - dark_card_head( - "Subtitle style", - None, - Some(help_text.into()), - Some(self.card_maximized), - cx, - ) - }); + let head = Some(dark_card_head( + "Subtitle style", + None, + Some(help_text.into()), + Some(self.card_maximized), + cx, + )); let size_picked = self.subtitle_style_field == 0; let size_row = div() .id("subtitle-size-row") @@ -3006,63 +2431,25 @@ impl Player { .justify_between() .px(px(6.)) .rounded(px(3.)) - .when(dark && size_picked, |d| { - d.border_l_2().border_color(rgb(INK1())) - }) - .when(!dark, |d| { - d.bg(rgb(match size_picked { - true => BG_SELECTED(), - false => BG_PANEL(), - })) - }) - .child( - div() - .when(dark, |d| d.child(dark_row_label("Size", size_picked))) - .when(!dark, |d| d.text_color(rgb(FG_SECONDARY())).child("Size")), - ) + .when(size_picked, |d| d.border_l_2().border_color(rgb(INK1()))) + .child(div().map(|d| d.child(dark_row_label("Size", size_picked)))) .child( div() .flex() .items_center() .gap(px(4.)) - .when(dark, |d| { - d.child(dark_row_value(format!("{:.0}px", self.sub_text))) - }) - .when(!dark, |d| d.child(format!("{:.0}px", self.sub_text))) + .map(|d| d.child(dark_row_value(format!("{:.0}px", self.sub_text)))) .children([-1, 1].map(|steps: i32| { let id = ("subtitle-size-step", usize::from(steps > 0)); - match dark { - true => dark_step_glyph( - id, - steps > 0, - cx.listener(move |this, _: &ClickEvent, _, cx| { - this.subtitle_style_field = 0; - this.nudge_sub_size(steps, cx); - }), - ) - .into_any_element(), - false => div() - .id(id) - .flex_none() - .w(px(HIT_MIN)) - .h(px(KEYS_ROW_H)) - .flex() - .items_center() - .justify_center() - .rounded(px(3.)) - .bg(rgb(BG_PANEL())) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { - this.subtitle_style_field = 0; - this.nudge_sub_size(steps, cx); - })) - .child(match steps > 0 { - true => "+", - false => "−", - }) - .into_any_element(), - } + dark_step_glyph( + id, + steps > 0, + cx.listener(move |this, _: &ClickEvent, _, cx| { + this.subtitle_style_field = 0; + this.nudge_sub_size(steps, cx); + }), + ) + .into_any_element() })), ); let default_picked = self.subtitle_style_field == 1; @@ -3074,24 +2461,13 @@ impl Player { .items_center() .px(px(6.)) .rounded(px(3.)) - .when(dark && default_picked, |d| { - d.border_l_2().border_color(rgb(INK1())) - }) - .when(!dark, |d| { - d.bg(rgb(match default_picked { - true => BG_SELECTED(), - false => BG_PANEL(), - })) - }) + .when(default_picked, |d| d.border_l_2().border_color(rgb(INK1()))) .cursor_pointer() - .hover(|s| s.bg(rgb(if dark { DARK_RAISED() } else { BG_HOVER() }))) + .hover(|s| s.bg(rgb(DARK_RAISED()))) .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { this.set_sub_family(None, cx); })) - .when(dark, |d| { - d.child(dark_row_label("System default", default_picked)) - }) - .when(!dark, |d| d.child("System default")); + .map(|d| d.child(dark_row_label("System default", default_picked))); let family_rows = self.subtitle_fonts.iter().enumerate().map(|(n, name)| { let picked = self.subtitle_style_field == n + 2 || self.sub_family.as_deref() == Some(name.as_str()); @@ -3103,23 +2479,16 @@ impl Player { .items_center() .px(px(6.)) .rounded(px(3.)) - .when(dark && picked, |d| d.border_l_2().border_color(rgb(INK1()))) - .when(!dark, |d| { - d.bg(rgb(match picked { - true => BG_SELECTED(), - false => BG_PANEL(), - })) - }) + .when(picked, |d| d.border_l_2().border_color(rgb(INK1()))) .cursor_pointer() - .hover(|s| s.bg(rgb(if dark { DARK_RAISED() } else { BG_HOVER() }))) + .hover(|s| s.bg(rgb(DARK_RAISED()))) .on_click(cx.listener({ let name = name.clone(); move |this, _: &ClickEvent, _, cx| { this.set_sub_family(Some(name.clone()), cx); } })) - .when(dark, |d| d.child(dark_row_label(name.clone(), picked))) - .when(!dark, |d| d.child(name.clone())) + .map(|d| d.child(dark_row_label(name.clone(), picked))) }); Some( scrim() @@ -3156,27 +2525,9 @@ impl Player { .gap(px(6.)) .p(px(12.)) .rounded(px(6.)) - .bg(rgb(if dark { DARK_PANEL() } else { BG_RAISED() })) - .when(dark, |d| d.border_1().border_color(rgba(DARK_SEAM()))) - .when(dark, move |d| d.child(head.unwrap())) - .when(!dark, |d| { - d.child( - div() - .flex_none() - .px(px(6.)) - .child("Subtitle style — font and size of the cue plate"), - ) - }) - .when(!dark, |d| { - d.child( - div() - .flex_none() - .px(px(6.)) - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - .child(help_text), - ) - }) + .bg(rgb(DARK_PANEL())) + .map(|d| d.border_1().border_color(rgba(DARK_SEAM()))) + .map(move |d| d.child(head.unwrap())) .child(size_row) .child( div() @@ -3205,18 +2556,15 @@ impl Player { cx: &mut Context, ) -> Option { let (lane, idx) = self.silence_open?; - let dark = self.darkroom; let head_meta: SharedString = format!("{} clip {}", lane.label(), idx + 1).into(); let help_text = "− and + move a setting, or ↑↓ picks one and ←→ moves it (hold to run it) — the marks on the lane are what would go; a click away or esc closes"; - let head = dark.then(|| { - dark_card_head( - "Silences", - Some(head_meta.clone()), - Some(help_text.into()), - Some(self.card_maximized), - cx, - ) - }); + let head = Some(dark_card_head( + "Silences", + Some(head_meta.clone()), + Some(help_text.into()), + Some(self.card_maximized), + cx, + )); let cfg = self.silence; // The unit is a label, never a conversion: the threshold is a level // below full scale whichever of the two the row says (`silence_dbfs`). @@ -3280,24 +2628,14 @@ impl Player { .justify_between() .px(px(6.)) .rounded(px(3.)) - .when(dark && picked, |d| d.border_l_2().border_color(rgb(INK1()))) - .when(!dark, |d| { - d.bg(rgb(match picked { - true => BG_SELECTED(), - false => BG_PANEL(), - })) - }) + .when(picked, |d| d.border_l_2().border_color(rgb(INK1()))) .cursor_pointer() - .hover(|s| s.bg(rgb(if dark { DARK_RAISED() } else { BG_HOVER() }))) + .hover(|s| s.bg(rgb(DARK_RAISED()))) .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { this.silence_field = n; cx.notify(); })) - .child( - div() - .when(dark, |d| d.child(dark_row_label(label, picked))) - .when(!dark, |d| d.text_color(rgb(FG_SECONDARY())).child(label)), - ) + .child(div().map(|d| d.child(dark_row_label(label, picked)))) // The value and the two steps that move it. Every other // card has something to drag or press; this one had the // arrow keys and nothing else, so a row was a setting a @@ -3309,49 +2647,19 @@ impl Player { .flex() .items_center() .gap(px(4.)) - .when(dark, |d| d.child(dark_row_value(value.clone()))) - .when(!dark, |d| d.child(value)) + .map(|d| d.child(dark_row_value(value.clone()))) .children([-1, 1].map(|steps: i32| { let id = ("silence-step", n * 2 + usize::from(steps > 0)); - match dark { - true => dark_step_glyph( - id, - steps > 0, - cx.listener(move |this, _: &ClickEvent, _, cx| { - this.silence_field = n; - this.nudge_silence(steps); - cx.notify(); - }), - ) - .into_any_element(), - false => div() - .id(id) - .flex_none() - .w(px(HIT_MIN)) - .h(px(KEYS_ROW_H)) - .flex() - .items_center() - .justify_center() - .rounded(px(3.)) - .bg(rgb(BG_PANEL())) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .on_click(cx.listener( - move |this, _: &ClickEvent, _, cx| { - // Picked as well as moved: the row a - // press lands on is the row the arrows - // carry on from. - this.silence_field = n; - this.nudge_silence(steps); - cx.notify(); - }, - )) - .child(match steps > 0 { - true => "+", - false => "−", - }) - .into_any_element(), - } + dark_step_glyph( + id, + steps > 0, + cx.listener(move |this, _: &ClickEvent, _, cx| { + this.silence_field = n; + this.nudge_silence(steps); + cx.notify(); + }), + ) + .into_any_element() })), ) }) @@ -3360,33 +2668,14 @@ impl Player { // one of them behind the other, and there are only two. let button = |n: usize, text: String, act: fn(&mut Self, &mut Context)| { let enabled = found != 0; - match dark { - true => dark_ghost_button( - ("silence-apply", n), - text, - "", - enabled, - cx.listener(move |this, _: &ClickEvent, _, cx| act(this, cx)), - ) - .into_any_element(), - false => div() - .id(("silence-apply", n)) - .flex_1() - .flex() - .min_h(px(KEYS_ROW_H)) - .items_center() - .justify_center() - .rounded(px(3.)) - .bg(rgb(match found { - 0 => BG_PANEL(), - _ => BG_SELECTED(), - })) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| act(this, cx))) - .child(text) - .into_any_element(), - } + dark_ghost_button( + ("silence-apply", n), + text, + "", + enabled, + cx.listener(move |this, _: &ClickEvent, _, cx| act(this, cx)), + ) + .into_any_element() }; Some( scrim() @@ -3427,40 +2716,11 @@ impl Player { .gap(px(6.)) .p(px(12.)) .rounded(px(6.)) - .bg(rgb(if dark { DARK_PANEL() } else { BG_RAISED() })) - .when(dark, |d| d.border_1().border_color(rgba(DARK_SEAM()))) - .when(dark, move |d| d.child(head.unwrap())) - .when(!dark, |d| { - d.child(div().flex_none().px(px(6.)).child(format!( - "Silences — {} clip {}", - lane.label(), - idx + 1 - ))) - }) - .when(!dark, |d| { - d.child( - div() - .flex_none() - .px(px(6.)) - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - .child(help_text), - ) - }) + .bg(rgb(DARK_PANEL())) + .map(|d| d.border_1().border_color(rgba(DARK_SEAM()))) + .map(move |d| d.child(head.unwrap())) .children(rows) - .when(dark, |d| d.child(dark_help(status.clone()))) - .when(!dark, |d| { - d.child( - div() - .flex_none() - .px(px(6.)) - .text_color(rgb(match (&self.silence_scan, found) { - (None, 1..) => ACCENT_PRIMARY(), - _ => FG_SECONDARY(), - })) - .child(status), - ) - }) + .map(|d| d.child(dark_help(status.clone()))) .child(div().flex().gap(px(4.)).children([ button(0, "Cut them out (enter)".into(), Self::cut_silences), button( diff --git a/crates/app/src/ui/dock_stance.rs b/crates/app/src/ui/dock_stance.rs index 12ab1dd..fcfb737 100644 --- a/crates/app/src/ui/dock_stance.rs +++ b/crates/app/src/ui/dock_stance.rs @@ -1077,20 +1077,40 @@ fn sources_tab( }) } -/// The transition duration row, in the darkroom's own idiom: the darkroom is -/// the default surface (`main.rs`'s `OLD_GUI` gate), so a row that only ever -/// drew in the legacy inspector (`ui::inspector::transition_duration_row`) -/// was a control a shipped user could never reach after a dissolve -/// (ctrl+x) or crossfade (ctrl+f). Same facts as that row -- -/// [`ui::inspector::transition_of`] picks the anchor's transition and its cap, -/// [`Player::nudge_transition`] does the clamped step -- only the paint is -/// this tab's own (`ghost_verb`'s row height and ink tokens, not legacy grey). +/// The transition a clip carries into its immediate successor, if any -- a +/// dissolve on a video lane ([`Clip::transition_out`]) or a crossfade on an +/// audio lane, told apart from a plain one-sided fade drag by +/// [`Project::crossfade`]'s own signature: both ends of the join set +/// together, not just this clip's tail. `cap` is what the pair actually +/// offers -- the shorter of the two clips' own lengths -- the same ceiling +/// [`Project::set_transition_out`]/[`Project::crossfade`] clamp to, so the +/// row this feeds never claims more room than a step could land in. +pub(crate) fn transition_of( + lane_kind: LaneKind, + clip: &Clip, + next: Option<&Clip>, +) -> Option<(&'static str, u32, u32)> { + let next = next.filter(|n| n.start == clip.end())?; + let cap = clip.frames().min(next.frames()); + match lane_kind { + LaneKind::Video if clip.transition_out > 0 => Some(("Dissolve", clip.transition_out, cap)), + LaneKind::Audio if clip.fade_out > 0 && next.fade_in > 0 => { + Some(("Crossfade", clip.fade_out, cap)) + } + _ => None, + } +} + +/// The transition duration row: `transition_of` picks the anchor's +/// transition and its cap, [`Player::nudge_transition`] does the clamped +/// step -- only the paint is this tab's own (`ghost_verb`'s row height and +/// ink tokens). fn transition_row(player: &Player, cx: &mut Context) -> Option { let (lane, idx) = player.selected.anchor()?; let session = player.session.as_ref()?; let clips = session.lane_clips(lane); let (label_text, frames, cap) = - crate::ui::inspector::transition_of(lane.kind, clips.get(idx)?, clips.get(idx + 1))?; + transition_of(lane.kind, clips.get(idx)?, clips.get(idx + 1))?; let label_style = label(type_scale::LABEL_ROW_PX, FontWeight::MEDIUM); let step = |id: &'static str, label: &'static str, glyph: &'static str, by: i32, cx: &mut Context| { div() diff --git a/crates/app/src/ui/inspector.rs b/crates/app/src/ui/inspector.rs deleted file mode 100644 index 97fa15c..0000000 --- a/crates/app/src/ui/inspector.rs +++ /dev/null @@ -1,536 +0,0 @@ -//! The right-hand region: what is selected, and what can be done to it. -//! -//! Every consumer editor has this column, and edith's settings used to be -//! floating cards *over the timeline* instead -- so adjusting a clip hid the -//! very clip being adjusted. The cards are docked in here now: the equalizer, -//! the grade, the speed, the silence scan and the mix are children of this -//! panel, and opening one occludes zero timeline pixels -//! (`an_inspector_section_occludes_no_timeline`). - -use crate::ui::toolbar::{TONE_SLOT_W, ZOOM_SLOT_W}; -use crate::*; - -impl Player { - /// The inspector column. Two sections that are always there -- the - /// selection's and the project's -- and, over them, whichever settings card - /// is open, which is a section of this panel rather than a sheet over the - /// window. - pub(crate) fn inspector( - &self, - viewport: Size, - cx: &mut Context, - ) -> impl IntoElement { - let width = self.split_px(Split::Inspector, viewport); - // 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() - .w(px(width)) - .h_full() - // The bed the docked cards are placed against: `scrim()` is - // `absolute().inset_0()`, so it covers this panel and nothing else. - .relative() - .flex() - .flex_col() - .bg(rgb(BG_PANEL())) - .border_l_1() - .border_color(rgb(STROKE_DIVIDER())) - .child(section_head("Inspector")) - .child( - div() - .id("inspector-rows") - .flex_1() - .min_h(px(0.)) - .overflow_y_scroll() - .track_scroll(&self.inspector_scroll) - .flex() - .flex_col() - .gap(px(8.)) - .p(px(8.)) - .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(room, cx)) - .children(self.transform_card(room, cx)) - .children(self.speed_card(room, cx)) - .children(self.silence_card(room, cx)) - .children(self.mix_card(room, cx)) - .children(self.subtitle_style_card(room, cx)) - } - - /// What is marked, and the settings that belong to *it*. A dump of every - /// property regardless of what is selected is the anti-pattern this avoids: - /// with nothing marked the section says how to get one, and each button is - /// dimmed with the oracle's reason rather than missing. - fn selection_section(&self, cx: &mut Context) -> impl IntoElement { - let picked = self.selected.anchor().and_then(|(lane, idx)| { - let session = self.session.as_ref()?; - let clip = session.lane_clips(lane).get(idx).copied()?; - let source = session.sources().get(clip.source); - let image = source.is_some_and(|s| engine::is_image(&s.path)); - Some(( - lane, - clip, - source.map_or_else(|| lane.label().to_string(), |s| file_name(&s.path)), - image, - )) - }); - // A subtitle lane holds no `Clip`, so the read above answers `None` on a - // marked caption -- while the bed draws that caption in the selection's - // own colours and this panel's Delete lifts it. The panel says what is - // marked or it is telling the user the opposite of what they can see. - let caption = self - .selected - .anchor() - .filter(|_| picked.is_none()) - .and_then(|(lane, idx)| { - let sub = self.session.as_ref()?.sub_lane(lane).get(idx).copied()?; - Some((lane, sub)) - }); - // The transition the anchor's clip carries into its successor, if - // any -- a dissolve on a video lane ([`Clip::transition_out`]) or a - // crossfade on an audio lane, told apart from a plain one-sided fade - // by [`Project::crossfade`]'s own signature: both ends of the join - // set together. `cap` is what the pair actually offers, the same - // ceiling the engine's own setters clamp to, so the row never claims - // more room than a step could land in. - let transition = self.selected.anchor().and_then(|(lane, idx)| { - let session = self.session.as_ref()?; - let clips = session.lane_clips(lane); - let (label, frames, cap) = transition_of(lane.kind, clips.get(idx)?, clips.get(idx + 1))?; - Some((lane, idx, label, frames, cap)) - }); - // A multi-selection is named for its anchor and counted: what the - // panel shows is the anchor's settings, and the count says there is - // more in hand than the panel is showing. - let more = self.selected.len().saturating_sub(1); - let head = match (&picked, &caption) { - (Some((lane, _, name, _)), _) => format!("{} · {}", lane.label(), name), - (None, Some((lane, _))) => format!("{} · caption", lane.label()), - (None, None) => "Nothing selected".to_string(), - }; - let head = match more { - 0 => head, - n => format!("{head} · and {n} more picked"), - }; - let detail = match &picked { - Some((_, clip, _, _)) => format!( - "{} → {} · {} · {}", - timecode(f64::from(clip.start) / self.fps, self.fps), - timecode(f64::from(clip.start + clip.frames()) / self.fps, self.fps), - span_label(f64::from(clip.frames()) / self.fps), - clip.speed, - ), - // The words' own span, in the same shape a clip's is written in -- - // and no speed, because a caption has none to change. - None => match &caption { - Some((_, sub)) => format!( - "{} → {} · {} · words", - timecode(f64::from(sub.start) / self.fps, self.fps), - timecode(f64::from(sub.end()) / self.fps, self.fps), - span_label(f64::from(sub.frames) / self.fps), - ), - None => "Click a clip on the timeline to see its settings".to_string(), - }, - }; - div() - .flex() - .flex_col() - .gap(px(6.)) - .p(px(8.)) - .rounded(px(4.)) - .bg(rgb(BG_HOVER_DIM())) - .child( - div() - .flex_none() - .truncate() - .text_color(rgb(match picked.is_some() || caption.is_some() { - true => FG_PRIMARY(), - false => FG_SECONDARY(), - })) - // The kind's own colour, the same one its clip wears on the - // timeline: the panel and the box are about the same thing. - .when_some(picked.as_ref(), |d, (lane, _, _, image)| { - d.border_l_2() - .border_color(rgb(clip_kind(lane.kind, *image))) - .pl(px(6.)) - }) - .when_some(caption.as_ref(), |d, (lane, _)| { - d.border_l_2() - .border_color(rgb(clip_kind(lane.kind, false))) - .pl(px(6.)) - }) - .child(head), - ) - .child( - div() - .flex_none() - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - .child(detail), - ) - // The duration field: a value and its own two steppers, the - // shape `mbps_steppers` already draws for the export card's - // bitrate -- present only while the anchor carries a transition, - // since a row for a number that means nothing is a row lying - // about what is selected. - .when_some(transition, |d, (lane, idx, label, frames, cap)| { - d.child(self.transition_duration_row(lane, idx, label, frames, cap, cx)) - }) - .child( - div() - .flex() - .flex_wrap() - .gap(px(6.)) - .child(self.action_control( - "inspect-speed", - 0., - BG_RAISED(), - None, - "Speed", - "how fast this clip and its group play", - ActionId::Speed, - cx.listener(|this, _: &ClickEvent, _, cx| this.open_speed(cx)), - )) - .child(self.action_control( - "inspect-color", - 0., - BG_RAISED(), - None, - "Colour", - "exposure, contrast, saturation and temperature", - ActionId::Color, - cx.listener(|this, _: &ClickEvent, _, cx| this.open_color(cx)), - )) - .child(self.action_control( - "inspect-transform", - 0., - BG_RAISED(), - None, - "Transform", - "position, scale, rotation and crop for this clip", - ActionId::Transform, - cx.listener(|this, _: &ClickEvent, _, cx| this.open_transform(cx)), - )) - .child(self.action_control( - "inspect-eq", - 0., - BG_RAISED(), - None, - "Equalizer", - "the bands this clip's sound is filtered through", - ActionId::Equalizer, - cx.listener(|this, _: &ClickEvent, _, cx| this.open_eq(cx)), - )) - .child(self.action_control( - "inspect-silence", - 0., - BG_RAISED(), - None, - "Silence", - "finds the quiet stretches and cuts or speeds them", - ActionId::Silence, - cx.listener(|this, _: &ClickEvent, _, cx| this.open_silence(cx)), - )) - .child(self.action_control( - "inspect-fit", - 0., - BG_RAISED(), - None, - "Fit", - "how this picture is placed on the project canvas", - ActionId::Fit, - cx.listener(|this, _: &ClickEvent, _, cx| this.cycle_fit(cx)), - )) - .child(self.action_control( - "inspect-delete", - 0., - BG_RAISED(), - None, - "Delete", - "takes this clip off the timeline", - ActionId::Delete, - cx.listener(|this, _: &ClickEvent, _, cx| this.delete_selected(cx)), - )), - ) - } - - /// The duration row a transition-carrying anchor grows under - /// `selection_section`'s detail line: `frames` as the engine counts it, - /// flanked by the −/+ steppers [`Player::mbps_steppers`] already draws - /// for the export card's bitrate row -- a field, not the drag handle - /// `659770a` deliberately shrank the join's hit target away from. Each - /// press nudges by one frame ([`Player::nudge_transition`]); the engine's - /// own setters clamp to `cap`, so a run of presses past what the - /// successor offers stops there rather than erroring. - fn transition_duration_row( - &self, - lane: Lane, - idx: usize, - label: &'static str, - frames: u32, - cap: u32, - cx: &mut Context, - ) -> impl IntoElement { - let step = |id: &'static str, glyph: &'static str, by: i32, cx: &mut Context| { - div() - .id(id) - .flex() - .w(px(HIT_MIN)) - .h(px(HIT_MIN)) - .items_center() - .justify_center() - .rounded(px(3.)) - .bg(rgb(BG_RAISED())) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { - this.nudge_transition(lane, idx, by, cx); - })) - .child(glyph) - }; - div() - .flex_none() - .flex() - .items_center() - .gap(px(6.)) - .child( - div() - .flex_1() - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - .child(format!("{label} {frames}f (of {cap}f offered)")), - ) - .child(step("transition-down", "−", -1, cx)) - .child(step("transition-up", "+", 1, cx)) - } - - /// The settings that are the *project's* rather than any clip's: the canvas - /// every clip is composed onto, the rate it is cut at, the HDR rendition it - /// is watched in, and the mix everything sums into. They used to be four - /// more buttons in a toolbar row that already did not fit the floor. - fn project_section(&self, cx: &mut Context) -> impl IntoElement { - let resolution = self.session.as_ref().map(PlaybackSession::resolution); - div() - .flex() - .flex_col() - .gap(px(6.)) - .p(px(8.)) - .rounded(px(4.)) - .bg(rgb(BG_HOVER_DIM())) - .child( - div() - .flex_none() - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - .child("PROJECT"), - ) - .child( - div() - .flex() - .flex_wrap() - .gap(px(6.)) - .child(self.action_control( - "resolution", - ZOOM_SLOT_W, - BG_RAISED(), - None, - match resolution.or(self.pending_settings.0) { - Some((_, h)) => format!("{h}p"), - None => "Size".to_string(), - }, - "the canvas every clip is composed onto, and the size the export comes out at", - ActionId::Resolution, - cx.listener(|this, event: &ClickEvent, _, cx| { - this.open_picker(Pick::Resolution, event.position(), cx) - }), - )) - .child(self.action_control( - "fps", - ZOOM_SLOT_W, - BG_RAISED(), - None, - match (self.session.is_some(), self.pending_settings.1) { - (true, _) => format!("{} fps", fps_label(self.fps)), - (false, Some(fps)) => format!("{} fps", fps_label(fps)), - (false, None) => "Rate".to_string(), - }, - "the rate the whole timeline is cut and written at", - ActionId::Resolution, - cx.listener(|this, event: &ClickEvent, _, cx| { - this.open_picker(Pick::Fps, event.position(), cx) - }), - )) - .child(self.action_control( - "sample-rate", - ZOOM_SLOT_W, - BG_RAISED(), - None, - match self.session.as_ref().map_or(self.pending_settings.2, |s| s.sample_rate()) { - Some(rate) => format!("{rate} Hz"), - None => "Source".to_string(), - }, - "the rate the project's own sound mix is run at; source derives it from \ - the first audio source", - ActionId::Resolution, - cx.listener(|this, event: &ClickEvent, _, cx| { - this.open_picker(Pick::SampleRate, event.position(), cx) - }), - )) - .child(self.action_control( - "tonemap", - TONE_SLOT_W, - BG_RAISED(), - None, - match &self.session { - Some(session) => format!("HDR {}", tone_label(session.tone())), - None => "HDR".to_string(), - }, - "which rendition HDR media is watched in; SDR media is untouched", - ActionId::Resolution, - cx.listener(|this, event: &ClickEvent, _, cx| { - this.open_picker(Pick::Tone, event.position(), cx) - }), - )) - // Its own rect and a label that *is* the state, the rule - // the snap toggle writes down: a button that resized itself - // on every press made the row shuffle under the pointer. - .child(self.action_control( - "proxies", - TONE_SLOT_W, - BG_RAISED(), - None, - // The window's own switch and not the session's: it is - // answerable with nothing open, so a label that read - // "Proxies" there would be a control whose state was a - // secret until a file arrived. - match self.proxies_on { - true => format!("Proxies on{}", self.proxy_tail()), - false => format!("Proxies off{}", self.proxy_tail()), - }, - "cuts on small stand-ins of the big films; the sound and every export \ - stay the film's own", - ActionId::ToggleProxies, - cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_proxies(cx)), - )) - // Beside it, because the two are one subject: that one is - // what the picture is decoded from, this one is whether the - // stand-in is ever made. Two states and no cycle, the rule - // the switch beside it keeps. - .child(self.action_control( - "auto-proxies", - TONE_SLOT_W, - BG_RAISED(), - None, - match self.auto_proxies_on { - true => "Auto proxies on", - false => "Auto proxies off", - }, - "makes a stand-in for every big film as it is imported; with it off, \ - turning Proxies on is what asks for them", - ActionId::ToggleAutoProxies, - cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_auto_proxies(cx)), - )) - .child(self.action_control( - "inspect-mix", - 0., - BG_RAISED(), - None, - "Mix", - "a fader per track and the limiter over the sum of them", - ActionId::Mix, - cx.listener(|this, _: &ClickEvent, _, cx| this.open_mix(None, cx)), - )) - .child(self.action_control( - "inspect-subtitle-style", - 0., - BG_RAISED(), - None, - "Font", - "the cue plate's own font and size", - ActionId::SubtitleStyle, - cx.listener(|this, _: &ClickEvent, _, cx| this.open_subtitle_style(cx)), - )), - ) - } -} - -/// The transition a clip carries into its immediate successor, if any -- a -/// dissolve on a video lane ([`Clip::transition_out`]) or a crossfade on an -/// audio lane, told apart from a plain one-sided fade drag by -/// [`Project::crossfade`]'s own signature: both ends of the join set -/// together, not just this clip's tail. `cap` is what the pair actually -/// offers -- the shorter of the two clips' own lengths -- the same ceiling -/// [`Project::set_transition_out`]/[`Project::crossfade`] clamp to, so the -/// row this feeds never claims more room than a step could land in. -/// -/// Free of `Context` and of [`PlaybackSession`] alike, so it is testable -/// without either -- this test binary has neither a `TestAppContext` nor -/// real media to open one with (`split_drag_owes_save`'s own reason for -/// being pulled out the same way). -pub(crate) fn transition_of( - lane_kind: LaneKind, - clip: &Clip, - next: Option<&Clip>, -) -> Option<(&'static str, u32, u32)> { - let next = next.filter(|n| n.start == clip.end())?; - let cap = clip.frames().min(next.frames()); - match lane_kind { - LaneKind::Video if clip.transition_out > 0 => Some(("Dissolve", clip.transition_out, cap)), - LaneKind::Audio if clip.fade_out > 0 && next.fade_in > 0 => { - Some(("Crossfade", clip.fade_out, cap)) - } - _ => None, - } -} - -/// A region's own title bar: the same 24 px strip in the library and the -/// inspector, so the two columns read as the pair they are. -pub(crate) fn section_head(title: &'static str) -> impl IntoElement { - div() - .flex_none() - .h(px(24.)) - .flex() - .items_center() - .px(px(8.)) - .bg(rgb(BG_PANEL())) - .border_b_1() - .border_color(rgb(STROKE_DIVIDER())) - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - .child(title) -} diff --git a/crates/app/src/ui/library.rs b/crates/app/src/ui/library.rs index 4e1005d..ae02ced 100644 --- a/crates/app/src/ui/library.rs +++ b/crates/app/src/ui/library.rs @@ -6,538 +6,6 @@ use crate::ui::widgets::*; use crate::*; impl Player { - /// The media library: a row per source the timeline knows, in the order - /// they arrived, each wearing the tint its clips wear in the lanes -- the - /// swatch *is* what says which boxes down there came from this file. A - /// click picks a row, the button under the list drops that source in at the - /// playhead, and a row dragged onto either lane does the same thing through - /// the same call. - /// - /// Import lives here, because this is the list it adds to. Plain divs like - /// the rest of this window: nothing in it takes focus, so the root keeps - /// the keyboard and the play key still works after a row is clicked - /// (ledger:182). - pub(crate) fn library(&self, width: f32, cx: &mut Context) -> impl IntoElement { - let exporting = self.exporting().is_some(); - let sources = self - .session - .as_ref() - .map_or(&[][..], PlaybackSession::sources); - // Every source matches the first in size and rate or it was refused at - // the door (the import policy, ledger:436), so the session's own meta - // describes every row and nothing has to be probed to say so. - let meta = self.session.as_ref().map(PlaybackSession::meta); - // Its own length, not one derived from what is on the lanes: a row - // imported and never placed is a row with a length, and it is the - // length a drag would put down. - let rows: Vec<_> = library_rows( - sources, - &self.streams, - &self.decoders, - self.timeline_audio(), - |path| { - self.session - .as_ref() - .map_or(0, |session| session.file_frames(path)) - }, - ) - .into_iter() - // The tab is the one filter: `enumerate` stays *before* it, so a row's - // index is still its index in the whole library and the tints, the - // menus and the drags all keep naming the same file whichever tab is - // open. - .enumerate() - .filter(|(_, row)| self.library_tab.holds(&row.path)) - .map(|(i, row)| { - let picked = self - .selected_asset - .as_ref() - .is_some_and(|p| *p == (row.path.clone(), row.stream)); - let name: SharedString = row.name.clone().into(); - let says: String = match (&row.unusable, meta) { - // A greyed row says why in full, where its length would be: - // the list is the one place the file's own tracks are named. - (Some(why), _) => format!("{} — {why}", row.path.display()), - // A file with no picture has no size and no frame rate to - // report, and only one lane it can go on: saying so is the - // difference between a hint and a lie. - (None, _) if engine::is_audio(&row.path) => format!( - "{} — audio only · drag onto the audio lane, or Add at playhead", - row.path.display() - ), - // A still is the mirror: its own size (the timeline's meta - // describes video, and a picture placed on that canvas is not - // the same shape), no frame rate, and one kind of lane. - (None, _) if engine::is_image(&row.path) => format!( - "{} — still image{} · drag onto a video lane, or Add at playhead", - row.path.display(), - match self.sizes.get(&row.path).copied().flatten() { - Some((w, h)) => format!(" · {w}x{h}"), - None => String::new(), - } - ), - // The file's *own* frame rate, not the timeline's: a clip shot - // at another rate plays at the speed it was shot at, and the - // row that says where it came from has to say which rate that - // was. - (None, Some(meta)) => format!( - "{} — {}x{} @ {:.2} fps · drag it where you want it, or Add at playhead", - row.path.display(), - meta.width, - meta.height, - self.session - .as_ref() - .map_or(meta.frame_rate, |session| session.file_fps(&row.path)) - ), - (None, None) => row.path.display().to_string(), - }; - // The menu is the third way into a row, after the click and the - // drag, and a right-click nothing advertises is one nobody finds. - let tip: SharedString = format!("{says} · right-click for more").into(); - let ghost = name.clone(); - // What the second line says: the stream, then either its length or - // the reason it cannot be used. - let under = match &row.unusable { - Some(why) => join_detail(&row.detail, why), - // A still has no length to report -- the ten minutes it is - // *held* to is a wall, not a duration -- so the line says what - // it is and how big it is instead. - None if engine::is_image(&row.path) => join_detail( - &row.detail, - &match self.sizes.get(&row.path).copied().flatten() { - Some((w, h)) => format!("still image · {w}x{h}"), - None => "still image".to_string(), - }, - ), - None => join_detail( - &row.detail, - &timecode(f64::from(row.frames) / self.fps, self.fps), - ), - }; - // ...and what this file's stand-in is up to, after its length: a - // percentage while one is being made, the word while there is one, - // and nothing at all for a film that wants none ([`Proxy::detail`]). - let under = join_detail( - &under, - &self - .proxies - .get(&row.path) - .map_or_else(String::new, Proxy::detail), - ); - // A stand-in being made is minutes of this machine, and the row - // that says how far it has got is where the way out of it belongs. - // Gone the moment the worker settles, like the percentage beside - // it: there is nothing left to stop. - // The switch, and what it is showing. One control for the whole - // life of a stand-in ([`Player::toggle_proxy`]): a filled dot for - // one that exists, a stop square while one is being made -- with - // how far it has got drawn under it -- and a hollow dot for a row - // that has none. Never an ×: that shape means the file leaves the - // library, and taking a *stand-in* off a row is not that. - let (glyph, proxy_on, progress, waiting) = match self.proxies.get(&row.path) { - Some(Proxy::Ready) => ("●", true, None, false), - Some(Proxy::Making(job)) => ("■", true, Some(job.progress()), false), - // Asked for and already winding down: the same square, dimmed, - // so a second click does not look like the first one missed. - Some(Proxy::Cancelling(_)) => ("■", true, None, true), - Some(Proxy::Asked) => ("○", false, None, true), - _ => ("○", false, None, false), - }; - // What the row is drawing right now, carried into the click: a - // stand-in that finishes between this paint and the pointer going - // down must not turn a stop into a deletion - // ([`Player::toggle_proxy`]). - let showed_stop = glyph == "■"; - let stop_path = row.path.clone(); - let stop_tip: SharedString = match self.proxies.get(&row.path) { - Some(Proxy::Making(_)) => format!( - "Stop making the stand-in for {} — nothing of it is kept, and the film itself \ - is what plays", - row.name - ), - Some(Proxy::Cancelling(_)) => { - format!("Stopping the stand-in for {}…", row.name) - } - Some(Proxy::Ready) => format!( - "Stand-in ON for {} — click to delete it; the film itself is what plays after \ - that, and nothing of the film is touched", - row.name - ), - _ => format!("Stand-in OFF for {} — click to make one", row.name), - } - .into(); - let usable = row.unusable.is_none(); - // What is left of the row for words: the switch and the gap before - // it, on the rows that carry one. Both lines are held to it -- the - // name alone was, and the detail line under it ran on under the - // switch and was cut mid-word -- and an unusable row draws no switch - // and so pays nothing for one. - // Two switches now sit at the end of a usable row -- the preview - // play button beside the stand-in toggle -- so the text gives up - // twice the room it gave up for one. - let text_w = row_text_w(width) - - match usable { - true => 2. * (HIT_MIN + 6.), - false => 0., - }; - let (path, stream) = (row.path.clone(), row.stream); - let dragged = (path.clone(), stream); - let menu_path = path.clone(); - let preview_path = path.clone(); - let preview_tip: SharedString = format!( - "Preview {} — plays it without touching the timeline", - row.name - ) - .into(); - div() - .id(("asset", i)) - .flex_none() - .h(px(ROW_H)) - .flex() - .items_center() - .gap(px(6.)) - .pr(px(6.)) - .rounded(px(3.)) - // A row that cannot be placed takes no click and no drag, and - // reads as unavailable rather than merely unlucky. - .when(!usable, |d| d.text_color(rgb(FG_SECONDARY())).opacity(0.55)) - .when(usable, |d| { - d.cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { - this.selected_asset = Some((path.clone(), stream)); - cx.notify(); - })) - // The drag carries the row's file and stream and the - // row's name: one for the drop to insert, one for the - // pointer to carry, so what is being dragged is legible - // on the way down. - .on_drag(AssetDrag(dragged.0, dragged.1), move |_, _, _, cx| { - cx.new(|_| Tip(ghost.clone())) - }) - }) - // The right button hangs the row's own menu at the pointer. - // Every row takes it, greyed ones included: a file that cannot - // join this timeline can still be revealed, described and taken - // out of the list, and Add is the one item that then refuses -- - // in the engine's words, where the row's grey already says why. - .on_mouse_down( - MouseButton::Right, - cx.listener(move |this, event: &MouseDownEvent, _, cx| { - if this.modal() { - return; - } - // Picked as a left-click would pick it, so the row the - // menu is about is the row that reads as chosen -- but - // only a row that *can* be picked, which is what keeps - // the Add button under the list honest. - if usable { - this.selected_asset = Some((menu_path.clone(), stream)); - } - this.library_menu = Some(LibraryMenu { - path: menu_path.clone(), - stream, - at: event.position, - details: false, - }); - cx.notify(); - }), - ) - .when(picked, |d| d.bg(rgb(BG_SELECTED())).border_1()) - .tooltip(move |_, cx| cx.new(|_| Tip(tip.clone())).into()) - // Full height and hard against the edge: the tint reads as - // the lane's colour continuing into the list, not as a chip - // that happens to be near it. - .child( - div() - .flex_none() - .w(px(SWATCH_W)) - .h_full() - .rounded(px(2.)) - .bg(rgb(source_tint(row.tint))), - ) - .child( - div() - .flex_1() - .min_w(px(0.)) - .flex() - .flex_col() - // Two lines rather than two columns: at the width - // this panel yields to, a name and a timecode side - // by side leave room for neither. - // Cut out of the middle, not the end: two episodes off - // one release are the same words up to the number, and - // the number is at the end. - .child( - div() - .truncate() - .text_size(px(11.)) - // Less the stand-in switch and the gap before - // it: a media row carries one where a subtitle - // row -- built to the same `row_text_w` -- does - // not, so the difference is taken here. - .child(clip_middle(&name, text_w)), - ) - .child( - div() - .truncate() - .text_size(px(10.)) - .text_color(rgb(FG_SECONDARY())) - .child(clip_middle(&under, text_w)), - ), - ) - // The stand-in switch, on every row that can carry one. A - // `HIT_MIN` target that stops the click there: the row under it - // picks the file, and turning a stand-in on or off is not a way - // of choosing what to place. The selection language the rest of - // the window speaks says which way it is set -- lit like a - // picked row when there is one, dimmed like an unusable one - // when there is not. - .when(usable, |d| { - d.child( - div() - .id(("preview-play", i)) - .flex_none() - .w(px(HIT_MIN)) - .h_full() - .flex() - .items_center() - .justify_center() - .rounded(px(3.)) - .text_size(px(11.)) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .tooltip(move |_, cx| cx.new(|_| Tip(preview_tip.clone())).into()) - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { - cx.stop_propagation(); - this.open_preview(&preview_path, stream, cx); - })) - .child("▶"), - ) - }) - .when(usable, |d| { - d.child( - div() - .id(("proxy-toggle", i)) - .flex_none() - .w(px(HIT_MIN)) - .h_full() - .flex() - .flex_col() - .items_center() - .justify_center() - .gap(px(2.)) - .rounded(px(3.)) - .text_size(px(10.)) - .when(proxy_on, |d| d.bg(rgb(BG_SELECTED()))) - .when(!proxy_on, |d| d.text_color(rgb(FG_SECONDARY()))) - .when(waiting, |d| d.opacity(0.55)) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .tooltip(move |_, cx| cx.new(|_| Tip(stop_tip.clone())).into()) - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { - cx.stop_propagation(); - this.toggle_proxy(&stop_path, showed_stop, cx); - })) - .child(glyph) - // How far the encode has come, under the stop it is - // stopped with: a bar rather than only the row's - // "proxy 37%", so the control reads as a job that is - // running and not as a thing that removes something. - .children(progress.map(|p| { - div() - .flex_none() - .w(px(PROXY_BAR_W)) - .h(px(2.)) - .rounded(px(1.)) - .bg(rgb(BG_RAISED())) - .child( - div() - .h_full() - .w(px(PROXY_BAR_W * p.clamp(0., 1.))) - .rounded(px(1.)) - .bg(rgb(ACCENT_PRIMARY())), - ) - })), - ) - }) - }) - .collect(); - div() - .id("library") - .flex_none() - .w(px(width)) - .h_full() - .flex() - .flex_col() - .gap(px(6.)) - .p(px(8.)) - .bg(rgb(BG_PANEL())) - // The column itself scrolls at a short window. Its five stacked - // things want 140 px and the 640x360 floor gives the region 136, so - // the list -- the only child that may shrink -- was being squeezed to - // nothing: tabs, an Import button, a way to add at the playhead, and - // no sight of what had been imported. Everything keeps its own size - // and the column carries the remainder, which is the same answer the - // lanes and the inspector give. - .overflow_y_scroll() - .child( - div().flex_none().flex().items_center().gap(px(6.)).child( - div() - .flex_1() - .min_w(px(0.)) - .flex() - // Wraps rather than clipping: at the 640 px floor - // this column is 128 px wide and the third tab - // would hang off its edge, which is a control the - // pointer cannot reach. - .flex_wrap() - .gap(px(2.)) - .children(LIBRARY_TABS.map(|tab| { - let on = tab == self.library_tab; - div() - .id(("library-tab", tab as usize)) - .flex_none() - .h(px(HIT_MIN)) - .px(px(6.)) - .flex() - .items_center() - .rounded(px(3.)) - .text_size(px(11.)) - .text_color(rgb(match on { - true => FG_PRIMARY(), - false => FG_SECONDARY(), - })) - // One selection language everywhere: the - // same stroke a picked clip and a picked - // row wear. - .when(on, |d| { - d.bg(rgb(BG_SELECTED())) - .border_b_2() - .border_color(rgb(STROKE_SELECTED())) - }) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { - this.library_tab = tab; - cx.notify(); - })) - .child(tab.label()) - })), - ), - ) - // The tab says what the one full-width control is for. Text holds - // no rows of its own ([`LibraryTab::holds`]) -- it is the tracks - // under it -- and what a person opens it to do is put subtitles on - // this timeline: off a release's `.mkv`, off an `.srt` beside it, - // without the file itself joining the library or a lane. So that is - // the button there, where the tracks it adds are listed; media goes - // on getting in from the other two tabs, from a drop, and from the - // actions card. - .when(self.library_tab == LibraryTab::Text, |d| { - d.child(div().flex_none().child(self.action_control( - "add-subtitles", - width - 16., - match self.session.as_ref().is_some_and(|s| !s.subtitles().is_empty()) { - // The primary action of this tab while it has nothing: - // the same rule the Import button follows one tab over. - false => ACCENT_PRIMARY(), - true => BG_RAISED(), - }, - None, - // The column is 128 px at the 640x360 floor and the whole - // name does not fit it: a centred label wider than its - // button is clipped at *both* ends ("d subtitles from a - // fil"), which is a button that says nothing. The short - // form there; the full name is what the tooltip, the - // actions card and the stroke go on saying either way. - match (width - 16.) / LIST_CHAR_W >= 26. { - true => "Add subtitles from a file…", - false => "Add subtitles", - }, - "reads a file's subtitle tracks into the palette below — drag one onto an S \ - track to place it; the file itself joins nothing", - ActionId::ImportSubtitles, - cx.listener(|this, _: &ClickEvent, _, cx| this.pick_and_add_subtitles(cx)), - ))) - }) - .when(self.library_tab != LibraryTab::Text, |d| { - d.child(div().flex_none().child(control( - "import", - // Full width of the column: the way media gets in is - // the one affordance of the tabs that hold media, - // however narrow the window is. - width - 16., - // Filled with the accent while there is nothing to work - // on, because with an empty library this *is* the - // primary action -- and Export, which wears the accent - // the rest of the time, is dimmed until something is - // imported. One live accent in the window either way. - match rows.is_empty() { - true => ACCENT_PRIMARY(), - false => BG_RAISED(), - }, - None, - "Import", - "adds a file to this list — or drop one on the window".to_string(), - !exporting, - cx.listener(|this, _: &ClickEvent, _, cx| this.pick_and_import(cx)), - ))) - }) - .child( - div() - .id("library-rows") - .flex_1() - // Never nothing: a media list with no room left is a library - // column that has stopped being a library column. - .min_h(px(ROW_H)) - .flex() - .flex_col() - .gap(px(2.)) - .overflow_y_scroll() - // Never a blank column: with nothing imported the list is - // where the way in is said. - .when(rows.is_empty(), |d| { - d.child( - div() - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - .child(self.library_tab.empty()), - ) - }) - .children(rows), - ) - // Under the media it belongs to: a subtitle track is not a source -- - // it goes on no lane and is dragged nowhere -- but it is a thing the - // timeline holds, and this is the list of those. - .when(self.library_tab == LibraryTab::Text, |d| { - d.children(self.subtitle_section(width, cx)) - }) - .child(control( - "add-asset", - 0., - BG_RAISED(), - None, - "Add at playhead", - match self.selected_asset { - Some(_) => "inserts the picked file at the playhead".to_string(), - None => "click a file above first — or drag one where you want it".to_string(), - }, - can_add( - self.selected_asset.as_ref(), - self.session.is_some(), - exporting, - ), - cx.listener(|this, _: &ClickEvent, _, cx| { - if let Some((path, stream)) = this.selected_asset.clone() { - // No lane: the button means "wherever this belongs", - // which for a file with no picture is the audio lane. - this.insert_source(&path, stream, None, None, cx); - } - }), - )) - } - /// The menu a right-click on a library row opens: what can be done with the /// *file* rather than with a clip of it, and a turn-over side saying what /// that file is. Built like [`Player::context_card`] down to the scrim, the @@ -552,8 +20,7 @@ impl Player { let path = menu.path.clone(); // DESIGN §9: the same plate row treatment `Player::context_card` // draws with -- one function, so a copy-paste sibling menu cannot - // drift from it (darkroom only; `OLD_GUI=1` is unchanged). - let darkroom = self.darkroom; + // drift from it. let row = move |n: usize| { div() .id(("library-menu", n)) @@ -564,7 +31,7 @@ impl Player { .gap(px(12.)) .px(px(6.)) .rounded(px(3.)) - .when(darkroom, |d| { + .map(|d| { d.type_style(crate::ui::type_scale::label( crate::ui::type_scale::LABEL_ROW_PX, gpui::FontWeight::MEDIUM, @@ -573,7 +40,7 @@ impl Player { }) }; let chord_style = |d: Div| -> Div { - d.when(darkroom, |d| { + d.map(|d| { d.type_style(crate::ui::type_scale::mono( crate::ui::type_scale::CHORD_METADATA_MIN_PX, gpui::FontWeight::MEDIUM, @@ -659,7 +126,7 @@ impl Player { // DESIGN §9: destructive verbs sit below a rule line. One // hairline, drawn once, above whichever of the two removes // this row context offers. - if matches!(item, RowItem::Remove | RowItem::RemoveWithClips) && darkroom { + if matches!(item, RowItem::Remove | RowItem::RemoveWithClips) { rows.push( div() .flex_none() @@ -700,12 +167,7 @@ impl Player { // floor clamp and the room the list sizes against are `menu_floor`'s, // so a menu taller than the footprint scrolls instead of climbing // back over the picture. - let (at, room) = menu_floor( - menu.at, - viewport, - darkroom, - self.split_px(Split::Bench, viewport), - ); + let (at, room) = menu_floor(menu.at, viewport, self.split_px(Split::Bench, viewport)); let list_h = menu_rows_h(rows.len(), room); let (x, y) = menu_at(at, viewport, MENU_PAD * 2. + list_h); let full: SharedString = path.display().to_string().into(); @@ -728,7 +190,7 @@ impl Player { }), ) .child( - menu_plate("library-menu-card", x, y, darkroom) + menu_plate("library-menu-card", x, y) // Painted after the scrim, so this listener runs first // and a press meant for an item never closes the menu // out from under its own click (`context_card`). diff --git a/crates/app/src/ui/mod.rs b/crates/app/src/ui/mod.rs index 7386d6d..ae75f1d 100644 --- a/crates/app/src/ui/mod.rs +++ b/crates/app/src/ui/mod.rs @@ -7,7 +7,6 @@ pub mod bench_stance; pub mod cards; pub mod dock_stance; pub mod hitmap; -pub mod inspector; pub mod library; pub mod overlays; pub mod preview; @@ -16,7 +15,5 @@ pub mod spine_stance; pub mod stance; pub mod theme; pub mod timeband_stance; -pub mod timeline; -pub mod toolbar; pub mod type_scale; pub mod widgets; diff --git a/crates/app/src/ui/overlays.rs b/crates/app/src/ui/overlays.rs index bb77f06..fb42290 100644 --- a/crates/app/src/ui/overlays.rs +++ b/crates/app/src/ui/overlays.rs @@ -107,352 +107,6 @@ impl Player { ) } - /// A notice holds its own bar, full width, until it is answered: any key - /// retires it (the key handler) and so does a click on it. Its own surface - /// because the message is the point -- a failure cut to the timecode's slot - /// is a failure nobody read. - /// - /// The export's own line is more than a message: it names a file that is - /// now on disk, so the same click that retires it shows that file in the - /// desktop's file manager. - pub(crate) fn notice_bar(&self, cx: &mut Context) -> Option { - let notice = self.notices.front().cloned()?; - // The path travels with the text it was written for: a later notice - // holds the bar and the click is a plain dismissal again. - let exported = self - .exported - .clone() - .filter(|_| notice.starts_with(EXPORT_DONE)); - // How many are waiting behind this one, said out loud: a queue nobody is - // told about is a queue whose second message reads as the first one - // failing to go away. - let behind = self.notices.len() - 1; - let hint = match (exported.is_some(), behind) { - (true, _) => "click — open file location".to_string(), - (false, 0) => "click or press any key to dismiss".to_string(), - (false, 1) => "click or press any key — 1 more message behind this".to_string(), - (false, n) => format!("click or press any key — {n} more messages behind this"), - }; - // What the message *is*, by colour, before it is read: the words the - // editor shouts a failure in are the ones it opens with, so the bar can - // colour itself off the same text every one of them already carries. - let tone = notice_tone(¬ice); - Some( - div() - .id("notice") - .when(exported.is_some(), |d| { - d.tooltip(|_, cx| { - cx.new(|_| { - Tip("Open file location — shows the export in the file manager".into()) - }) - .into() - }) - }) - .flex_none() - .flex() - // The hint keeps its own width, and at the 640x360 floor the - // picture region is narrower than the hint alone: with both on - // one line the message was squeezed to nothing and wrapped a - // character per line -- a notice rendered as a column of - // letters. Wrapping puts the hint on its own line instead, so - // the message keeps the whole width and the queue counter - // stays on screen under it. - .flex_wrap() - .items_start() - .gap(px(12.)) - .px(px(12.)) - .py(px(6.)) - .bg(rgb(BG_RAISED())) - // The tone is a stripe down the leading edge rather than the - // whole bar's colour: a full red bar at every refusal is an - // alarm, and most of these are answers. - .border_l(px(3.)) - .border_color(rgb(tone)) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { - // Another process starting: off the UI thread, and it - // outlives the notice it was asked from. - if let Some(path) = exported.clone() { - cx.background_executor() - .spawn(async move { show_in_file_manager(&path) }) - .detach(); - } - this.dismiss_notice(); - cx.notify(); - })) - // Shrinkable, because a gpui text element measures its - // min-content as the *whole line* (`TextLayout::layout` only - // wraps against a definite width) -- without a `min_w` the - // message would refuse to shrink at all and run off the region - // instead. With a floor under it, it shrinks to that floor, - // which pushes the hint onto its own line and leaves the - // message the width it needs to wrap like a sentence. - .child(div().flex_1().min_w(px(NOTICE_MIN_W)).child(notice)) - .child( - div() - .flex_none() - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - .child(hint), - ), - ) - } - - /// Every binding, and the way to change one: a row per entry, click it and - /// the next stroke becomes its chord. Over the whole window, because while - /// it is up nothing under it may answer -- the scrim stops the clicks - /// (gpui dispatches mouse listeners topmost-first, window.rs:3705) and the - /// key handler's own branch stops the strokes. - /// - /// Plain divs, like every control here: nothing in it takes focus, so the - /// root is still the one reading the keyboard -- which is exactly what a - /// waiting row depends on. - pub(crate) fn keys_overlay(&self, cx: &mut Context) -> Option { - if !self.keys_open { - return None; - } - // The way out, spelled the way the rows spell a chord. - let out = keymap::Chord { - key: ESCAPE.to_string(), - ctrl: false, - } - .pretty(); - // Every action there is, under its heading, and the strokes the modal - // cards answer to beside them -- `keys_rows` is the whole of the order - // and every word in it comes off the registry. - // - // A row is two targets, not one: its label *does* the action, which is - // the pointer's way to the ones no button carries, and its stroke - // changes that stroke. An action with two strokes reads as one line - // ("x or delete") and a rebind replaces that whole set. - let mut rows: Vec = Vec::new(); - let row = || { - div() - .flex() - // The floor, not the height: a row that needed two lines - // would otherwise paint over the one under it -- which it did - // anyway until this said `flex_none`, a row inside a capped - // scrolling list being shrunk to fit by default (the export - // card's rows had the same shape and the same overlap). - .flex_none() - .min_h(px(KEYS_ROW_H)) - .items_center() - .justify_between() - .gap(px(12.)) - .px(px(6.)) - .rounded(px(3.)) - }; - let found = keys_filter(&self.keys_search, &self.keymap); - // What the search box says: the typed text, and how much of the list is - // left under it -- a filter that found nothing has to say so, or the - // card reads as a list that lost its rows. - let search = if self.keys_search.is_empty() { - "search: type to filter · ↑ ↓ scroll the list · a click away closes".to_string() - } else { - let rows = found - .iter() - .filter(|(_, r)| !matches!(r, KeyRow::Head(_))) - .count(); - match rows { - 0 => format!( - "search: {} — nothing matches · {out} clears", - self.keys_search - ), - n => format!("search: {} — {n} shown · {out} clears", self.keys_search), - } - }; - for (i, key_row) in found { - rows.push(match key_row { - KeyRow::Head(category) => div() - .flex_none() - .px(px(6.)) - .pt(px(4.)) - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - .child(category.label()) - .into_any_element(), - KeyRow::Act(action) => { - let capturing = self.rebinding == Some(action); - // Why the label half will not answer, if it will not: the - // registry's one answer, the same the clip menu dims by. - let refusal = self.enable(action, None); - let out = out.clone(); - row() - .when(capturing, |d| d.bg(rgb(BG_SELECTED()))) - .child( - div() - .id(("do", i)) - .flex_1() - .min_w(px(0.)) - .flex() - .min_h(px(KEYS_ROW_H)) - .items_center() - // One line, cut where the stroke's column - // starts: a label longer than the room it has - // printed straight over the stroke beside it, - // and two overprinted words are less readable - // than one truncated one. - .truncate() - .child(action.label()) - .children(hitmap::action(action, refusal.yes())) - // The reason rides on the label rather than in - // the stroke column, which the rebind half - // needs whatever the editor's state is: an - // action nobody can ask for right now is still - // one whose key may be changed. - .when_some(refusal.why(), |d, why| { - let why: SharedString = why.into(); - d.tooltip(move |_, cx| cx.new(|_| Tip(why.clone())).into()) - }) - .when(!refusal.yes(), |d| d.opacity(0.4).cursor_not_allowed()) - .when(refusal.yes(), |d| { - d.cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .on_click(cx.listener( - move |this, _: &ClickEvent, window, cx| { - // The card goes first: several of - // these open a card of their own, - // and every edit moves the indices - // the menus are holding. - this.keys_open = false; - this.rebinding = None; - this.act(action, window, cx); - cx.notify(); - }, - )) - }), - ) - .child( - // corner-cut: the column is as wide as the stroke it - // prints, so a one-character chord gives this half a - // hit area under the 24px WCAG 2.5.8 floor -- tall - // enough, narrow. Upgrade: a min_w of HIT_MIN here. - div() - .id(("bind", i)) - .flex_none() - .flex() - .min_h(px(KEYS_ROW_H)) - .items_center() - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { - this.rebinding = Some(action); - cx.notify(); - })) - .child(if capturing { - div() - .text_color(rgb(FG_SECONDARY())) - .child(format!("press a key — {out} cancels")) - } else { - div().child(self.keymap.display(action)) - }), - ) - .into_any_element() - } - KeyRow::Fixed(f) => { - let f = &keymap::FIXED[f]; - row() - .child(f.label) - // Dim, and no hover: this one is not a row you can click. - .child(div().text_color(rgb(FG_SECONDARY())).child(f.chord.clone())) - .into_any_element() - } - }); - } - Some( - scrim() - .flex() - .justify_center() - .items_center() - // The picture behind is out of reach, and looks it. The press is - // swallowed here so a button under the scrim cannot take it -- - // and it closes the card on the way, which is the pointer's exit - // from every card here ([`Player::close_card`]). - .bg(rgba(SCRIM())) - .on_mouse_down( - MouseButton::Left, - cx.listener(|this, _: &MouseDownEvent, _, cx| { - this.close_card(); - cx.notify(); - cx.stop_propagation(); - }), - ) - .child( - div() - .w(px(KEYS_W)) - .on_mouse_down(MouseButton::Left, swallow) - .flex() - .flex_col() - .gap(px(2.)) - .p(px(12.)) - .rounded(px(6.)) - .bg(rgb(BG_RAISED())) - // Title and instruction are two children, never one - // wrapping line: a fixed-height slot whose text wrapped - // painted its second line over the first row. - .child(div().flex_none().px(px(6.)).child("Actions & keys")) - // One status line, under the title where the eye starts. - // A refusal takes it over -- it is the more urgent of the - // two, and the notice bar it would otherwise appear in is - // under the scrim. - // - // The row list below is capped and scrolls, so neither a - // wrapped refusal here nor another action added to `ALL` - // can push the card past a 360 px window any more. - .child( - div() - .flex_none() - .px(px(6.)) - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - .child(self.notices.front().cloned().unwrap_or_else(|| { - "click an action to do it · click its key to change it".into() - })), - ) - // The search box: no focus and no text field -- the - // card's key handler is the field, exactly as the - // export card's bitrate is typed into it. Its own line - // above the list, so the rows below it are always the - // answer to what it says. - .child( - div() - .flex_none() - .px(px(6.)) - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - .child(search), - ) - // Capped and scrolling rather than as tall as the action - // list happens to be: the list grows with the editor, - // the smallest window does not. - .child( - div() - .id("keys-rows") - .flex() - .flex_col() - .gap(px(2.)) - .max_h(px(KEYS_ROWS_H)) - // The line the list scrolls under: a row half - // out of the viewport sat against the search - // line with nothing between them, and read as a - // row painted over the heading rather than as a - // list with more above it. - .mt(px(4.)) - .border_t_1() - .border_color(rgb(BG_PANEL())) - .pt(px(4.)) - .overflow_y_scroll() - // The wheel's offset and the arrow keys' are - // the same one, so the two cannot disagree - // about where the list is. - .track_scroll(&self.keys_scroll) - .children(rows), - ), - ), - ) - } - /// The menu a right-click on a clip opens: what that clip can be given, /// each item beside the stroke that does the very same thing, and a /// turn-over side that says what the clip *is*. An item that would do @@ -484,10 +138,7 @@ impl Player { let secs = |frames: u32| timecode(f64::from(frames) / self.fps, self.fps); // DESIGN §9/§3: a menu row is a plate row, Archivo at the room's // 10.5px row size -- `ink2`, dimmed to `ink3` on the disabled ones - // below by the same `.opacity` every row already carried. Gated on - // `self.darkroom` so `OLD_GUI=1` keeps its own unstyled rows exactly - // as they draw today. - let darkroom = self.darkroom; + // below by the same `.opacity` every row already carried. let row = move |n: usize| { div() .id(("menu", n)) @@ -500,7 +151,7 @@ impl Player { .gap(px(12.)) .px(px(6.)) .rounded(px(3.)) - .when(darkroom, |d| { + .map(|d| { d.type_style(type_scale::label( type_scale::LABEL_ROW_PX, gpui::FontWeight::MEDIUM, @@ -513,7 +164,7 @@ impl Player { // than a room verb goes through this rather than the row's ambient // Archivo. let chord_style = |d: Div| -> Div { - d.when(darkroom, |d| { + d.map(|d| { d.type_style(type_scale::mono( type_scale::CHORD_METADATA_MIN_PX, gpui::FontWeight::MEDIUM, @@ -731,17 +382,11 @@ impl Player { // §5/§11 check 6: the picture is never covered. A right-click high on // the window would otherwise hang the menu at the pointer, straight // over the screen -- clamped below it into the bench/ledger/dock - // footprint instead, darkroom only (the legacy tree has no such - // fixed split to clamp against). The list is sized against that same + // footprint instead. The list is sized against that same // footprint (`room`), not the whole window, so a menu taller than // the footprint scrolls inside its own plate instead of walking its // clamped top edge back up over the picture ([`menu_floor`]). - let (at, room) = menu_floor( - menu.at, - viewport, - self.darkroom, - self.split_px(Split::Bench, viewport), - ); + let (at, room) = menu_floor(menu.at, viewport, self.split_px(Split::Bench, viewport)); let list_h = menu_rows_h(rows.len(), room); let (x, y) = menu_at(at, viewport, MENU_PAD * 2. + list_h); let full: SharedString = source @@ -774,7 +419,7 @@ impl Player { // One plate shape for all three hanging menus // ([`menu_plate`]) -- the id is still this menu's own, so // the details side keeps its tooltip. - menu_plate("menu-card", x, y, darkroom) + menu_plate("menu-card", x, y) // Painted after the scrim, so this listener runs first // (gpui bubbles mouse events in reverse, window.rs:3705) // and a press meant for an item never closes the menu @@ -818,7 +463,6 @@ impl Player { cx: &mut Context, ) -> Option { let picker = self.picker?; - let darkroom = self.darkroom; let theme_picker = picker.of == Pick::Theme; let rows: Vec = self .choices(picker.of) @@ -842,7 +486,7 @@ impl Player { .gap(px(12.)) .px(px(6.)) .rounded(px(3.)) - .when(darkroom, |d| { + .map(|d| { d.type_style(type_scale::label( type_scale::LABEL_ROW_PX, gpui::FontWeight::MEDIUM, @@ -859,27 +503,19 @@ impl Player { // plate grammar `context_card`/`library_card` already // draw: one `raised` fill step for hover, `ink1` for the // row in force, no second grey. - .hover(|s| s.bg(rgb(if darkroom { DARK_RAISED() } else { BG_HOVER() }))) + .hover(|s| s.bg(rgb(DARK_RAISED()))) // The mark is a glyph as well as a highlight, like the // export card's rows: a background alone is gone under a // hover and invisible to anyone who cannot tell the two // greys apart (WCAG 1.4.1). .when(picked, |d| { - d.bg(rgb(if darkroom { - DARK_RAISED() - } else { - BG_SELECTED() - })) - .when(darkroom, |d| d.text_color(rgb(INK1()))) + d.bg(rgb(DARK_RAISED())).map(|d| d.text_color(rgb(INK1()))) }) // Where the keyboard is, said after the mark so the cursor // is visible on the picked row too -- and as a border in // the darkroom (DESIGN §4's 1px `ink1` focus ring) rather // than a second grey nobody can tell from the first. - .when(n == picker.sel, |d| match darkroom { - true => d.border_1().border_color(rgb(INK1())), - false => d.bg(rgb(BG_HOVER())), - }) + .when(n == picker.sel, |d| d.border_1().border_color(rgb(INK1()))) .child( div() .flex() @@ -899,13 +535,8 @@ impl Player { .text_size(px(11.)) // On the picked row the dim ink sits on the // highlight, where it is only 3.3:1 (WCAG 1.4.3). - .text_color(rgb(match (darkroom, picked) { - (true, true) => INK2(), - (true, false) => INK3(), - (false, true) => FG_PRIMARY(), - (false, false) => FG_SECONDARY(), - })) - .when(darkroom, |d| { + .text_color(rgb(if picked { INK2() } else { INK3() })) + .map(|d| { d.type_style(type_scale::mono( type_scale::CHORD_METADATA_MIN_PX, gpui::FontWeight::MEDIUM, @@ -925,12 +556,7 @@ impl Player { .collect(); // The window's own room, and the list scrolls only where the window has // none -- the clip menu's rule, one function for both. - let (at, room) = menu_floor( - picker.at, - viewport, - darkroom, - self.split_px(Split::Bench, viewport), - ); + let (at, room) = menu_floor(picker.at, viewport, self.split_px(Split::Bench, viewport)); let list_h = menu_rows_h(rows.len(), room); let (x, y) = menu_at(at, viewport, MENU_PAD * 2. + list_h); Some( @@ -954,7 +580,7 @@ impl Player { }), ) .child( - menu_plate("picker-card", x, y, darkroom) + menu_plate("picker-card", x, y) // Painted after the scrim, so this listener runs first // and a press meant for a row never closes the list out // from under its own click (`context_card`). diff --git a/crates/app/src/ui/preview.rs b/crates/app/src/ui/preview.rs index 0508f54..e650557 100644 --- a/crates/app/src/ui/preview.rs +++ b/crates/app/src/ui/preview.rs @@ -6,64 +6,17 @@ use crate::*; use std::path::{Path, PathBuf}; impl Player { - /// The one thing that says a preview is up rather than the timeline: a - /// banner over the top of the picture, and a click of its own -- the - /// keyboard has `esc`, and a hand with only a mouse needs a way out too. + /// The darkroom's own preview indicator (MOCK-SPEC.md): a plate + /// (canvas-on-panel, §4), mono for what the film says, and a ghost + /// `Stop` wearing its `esc` chord rather than a bordered button -- no + /// fill, no border, hover lifts one step like every other ghost in the + /// room. /// - /// Legacy-only now (DEFECT 2, MOCK-SPEC.md): this is a full-width band - /// drawn *on* the frame, which DESIGN §5 forbids for the darkroom - /// ("nothing else over the picture, ever"). [`Player::preview_plate`] is - /// the darkroom's own restyle of the same information, built as a flex - /// sibling so the picture's own box shrinks for it rather than being - /// painted over -- the same fix `two_up`'s doc comment describes for the - /// OUT|IN plates. `OLD_GUI=1` keeps drawing this banner unchanged. - pub(crate) fn preview_badge(&self, cx: &mut Context) -> Option { - (!self.darkroom && self.preview_session.is_some()).then(|| { - div() - .absolute() - .top_0() - .left_0() - .right_0() - .flex() - .items_center() - .justify_center() - .gap(px(8.)) - .p(px(4.)) - .bg(rgba(SUB_SHADE())) - .text_size(px(11.)) - .text_color(rgb(FG_PRIMARY())) - .child("PREVIEW — not on the timeline") - .child( - div() - .id("preview-stop") - .px(px(6.)) - .rounded(px(3.)) - .cursor_pointer() - .bg(rgb(BG_RAISED())) - .hover(|s| s.bg(rgb(BG_HOVER()))) - .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.close_preview(cx))) - .children(hitmap::control("preview.stop", "Stop preview", true)) - .child("Stop (esc)"), - ) - }) - } - - /// The darkroom's own preview indicator (DEFECT 2, MOCK-SPEC.md): a - /// plate (canvas-on-panel, §4), mono for what the film says, and a ghost - /// `Stop` wearing its `esc` chord rather than the legacy bordered - /// button -- no fill, no border, hover lifts one step like every other - /// ghost in the room. - /// - /// corner-cut: built and unit-shaped but **not yet mounted** -- it needs - /// to sit as a flex sibling of the picture inside `ui::stance::screen` - /// (the box `two_up`'s own doc comment already fixed this exact way for - /// the OUT|IN plates), which is `stance.rs`, out of this task's file - /// ownership while another builder has it open concurrently. `#[allow - /// It is mounted in `ui::stance::screen` as a flex sibling below the - /// picture's own child, the way `two_up` is, so the frame's box shrinks to - /// make room rather than being drawn over. + /// Mounted in `ui::stance::screen` as a flex sibling below the picture's + /// own child, the way `two_up` is, so the frame's box shrinks to make + /// room rather than being drawn over. pub(crate) fn preview_plate(&self, cx: &mut Context) -> Option { - (self.darkroom && self.preview_session.is_some()).then(|| { + self.preview_session.is_some().then(|| { div() .id("preview-plate") .flex_none() @@ -414,13 +367,10 @@ impl Player { /// the layout box is not) keeps the strip's room reserved instead of /// collapsing it, which is what let the picture's own `flex_1` above it /// resize on every cut walk (404px resting on a cut, 335px a frame off - /// one, springing back on the very next). Only `!self.darkroom` still - /// returns `None`: the legacy tree never reserved this room and does not - /// start now. + /// one, springing back on the very next). The darkroom is the only room + /// now, so the sole remaining `None` cases are off a cut or with + /// nothing marked. pub(crate) fn two_up(&self) -> Option { - if !self.darkroom { - return None; - } let resting = (|| { let (lane, idx) = self.selected.anchor()?; let session = self.session.as_ref()?; @@ -494,30 +444,6 @@ impl Player { .child(plate("IN", in_label)), ) } - - /// What is decoding the picture right now, for the transport line: the - /// backend is the running worker's own (it is written where a hardware - /// session falls back to software, so this follows reality), and the codec - /// comes from the clip under the playhead. Empty when nothing is playing -- - /// the question is about what is happening, not about what would. - pub(crate) fn live_decode(&self, position: f64, playing: bool) -> String { - let Some(session) = self.session.as_ref().filter(|_| playing) else { - return String::new(); - }; - let backend = session.decode_backend(); - let codec = session - .video_clip_at(position) - .and_then(|(lane, idx)| session.lane_clips(lane).get(idx).map(|clip| clip.source)) - .and_then(|source| session.sources().get(source)) - .and_then(|source| self.decoders.get(&source.path).copied().flatten()) - .and_then(|(codec, _)| codec); - match backend { - // Neither is a decode, and saying "SW" of them would be a lie. - Backend::Gap => "gap · nothing to decode".to_string(), - Backend::Still => "still · one decode, held".to_string(), - _ => format!("{} decode", decode_label(codec, backend)), - } - } } /// `~/Pictures/edith`, or `.` with no `HOME` -- [`keymap::config_path_in`]'s diff --git a/crates/app/src/ui/spine_stance.rs b/crates/app/src/ui/spine_stance.rs index 2786dc1..57d4871 100644 --- a/crates/app/src/ui/spine_stance.rs +++ b/crates/app/src/ui/spine_stance.rs @@ -311,20 +311,6 @@ pub(crate) fn render(player: &Player, cx: &mut Context) -> impl IntoElem player, cx, )) - // ToggleSnap (homeless per this task's audit): editing-adjacent -- - // it decides where a drag lands (keymap.rs's own category puts it - // under Editing, not View) -- so it earns the CUT group beside the - // trim/loop-trim it changes the feel of, not the quiet ROOM cluster - // below. Active fill mirrors loop-trim's own on/off convention. - .child(glyph( - "spine-toggle-snap", - "Sn", - ActionId::ToggleSnap, - player.snap, - false, - player, - cx, - )) // VIEW group, added this task: ZoomIn/ZoomOut/ZoomFit (keymap.rs) had // real, already-working handlers (`Player::zoom`/`zoom_fit`, wired // into the legacy `ui/toolbar.rs`) but no home anywhere in the @@ -363,6 +349,20 @@ pub(crate) fn render(player: &Player, cx: &mut Context) -> impl IntoElem player, cx, )) + // ToggleSnap: decides where a drag lands, which is what the eye + // reads the zoom scale against -- placed as the VIEW group's last + // row, beside the zoom controls above it, rather than off in CUT + // where nothing else answers "what scale/behaviour am I looking + // at". Active fill mirrors loop-trim's own on/off convention. + .child(glyph( + "snap", + "Sn", + ActionId::ToggleSnap, + player.snap, + false, + player, + cx, + )) .child(group_head("track")) .child(pair( glyph( diff --git a/crates/app/src/ui/stance.rs b/crates/app/src/ui/stance.rs index 0b71f75..0a7eecc 100644 --- a/crates/app/src/ui/stance.rs +++ b/crates/app/src/ui/stance.rs @@ -1,7 +1,7 @@ -//! DESIGN.md §5 -- the stance: fixed geography, drawn by default now -//! (`OLD_GUI=1` opts back into the legacy four-region tree), whole here -//! rather than folded into that tree so the two can be told apart, and -//! swapped, with a single `if` in `render.rs`. +//! DESIGN.md §5 -- the stance: fixed geography, the only room now the +//! legacy four-region tree is gone (`self.darkroom` no longer branches +//! anything in `render.rs`), whole here as its own module rather than +//! folded into that tree. //! //! This step lays out the six regions and nothing else: correct geometry, //! correct surfaces, a section-head label per region. No content, no @@ -99,22 +99,12 @@ impl Player { /// exactly as the tab's own click does (`dock_stance::dock_tab`'s /// `on_click`), so the ring and a mouse click can't disagree about /// which tab was last chosen. - /// - /// The ring is darkroom-only UI -- the legacy tree never mounts - /// `focus_dock`/`focus_bench`/`focus_inspector` (only `track_focus` - /// sites live in this module and `dock_stance.rs`), so under - /// `OLD_GUI=1` a `window.focus` here would land on an unmounted - /// handle and kill the root key listener (`main.rs`'s fallback focus) - /// until the next mouse click. No-op there instead. pub(crate) fn focus_surface( &mut self, surface: Surface, window: &mut Window, cx: &mut Context, ) { - if !self.darkroom { - return; - } if let Some(src_active) = surface_wants_src_active(surface) { self.dock_src_active = src_active; crate::ui::dock_stance::save(src_active); @@ -202,16 +192,11 @@ pub(crate) fn maximized_card_top(viewport_h: f32, bench_h: f32) -> f32 { /// room *below the floor* instead means it never needs more than that room, /// so `menu_at` never has a reason to walk it back up; a list still taller /// than the room scrolls inside its own plate, same as the keys overlay. -/// Darkroom only -- the legacy tree has no fixed split to clamp against. pub(crate) fn menu_floor( at: Point, viewport: Size, - darkroom: bool, bench_h: f32, ) -> (Point, Size) { - if !darkroom { - return (at, viewport); - } let floor = below_picture_floor(f32::from(viewport.height), bench_h); let at = point(at.x, px(f32::from(at.y).max(floor))); let room = size(viewport.width, px(f32::from(viewport.height) - floor)); @@ -233,7 +218,7 @@ mod menu_floor_tests { fn a_menu_taller_than_the_footprint_stays_pinned_to_the_floor_not_walked_back_over_it() { let viewport = size(px(1280.), px(720.)); let floor = below_picture_floor(f32::from(viewport.height), BENCH_H); - let (at, room) = menu_floor(point(px(300.), px(20.)), viewport, true, BENCH_H); + let (at, room) = menu_floor(point(px(300.), px(20.)), viewport, BENCH_H); assert_eq!(f32::from(at.y), floor); // 396px of rows (the charter's measured menu height) does not fit in // the 316px footprint room, so it must be capped to it, not the @@ -394,8 +379,14 @@ fn section_head(label: &str) -> impl IntoElement { /// A ghost command (DESIGN §4): borderless glyph (`ink2`) + dim chord /// (`ink3`), read live off the keymap so a rebind can never leave the spine /// showing a stroke that no longer fires it. -fn ghost(player: &Player, glyph: &str, action: ActionId) -> impl IntoElement { +fn ghost( + player: &Player, + glyph: &str, + action: ActionId, + cx: &mut Context, +) -> impl IntoElement { div() + .id("keys") .flex_none() .flex() .flex_col() @@ -403,6 +394,11 @@ fn ghost(player: &Player, glyph: &str, action: ActionId) -> impl IntoElement { .gap(px(2.)) .py(px(6.)) .rounded(px(3.)) + .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) + })) .type_style(type_scale::label( type_scale::LABEL_ROW_PX, gpui::FontWeight::MEDIUM, @@ -434,8 +430,11 @@ fn ghost(player: &Player, glyph: &str, action: ActionId) -> impl IntoElement { /// on the press (bypassing the modal `overlaid()` guard, which would /// otherwise swallow the second `?` down while the first is still up) and /// its `on_key_up` closes it on release, so this is the room dimming one -/// fill step for as long as the key is held, never a latch (DESIGN §9: "no -/// modal cheat-sheet"). +/// fill step for as long as the key is held, never a latch (DESIGN §9: +/// hold-to-peek, click also dismisses). The scrim also closes on a press, +/// same contract every other card's scrim answers, so a hand that lets go +/// of `?` before reading the list still has a door out without touching the +/// keyboard again. /// /// corner-cut, named explicitly in DESIGN §9's own 2026-08-20 amendment /// rather than silently shipped against the section's original text: it @@ -445,7 +444,7 @@ fn ghost(player: &Player, glyph: &str, action: ActionId) -> impl IntoElement { /// Ceiling: DESIGN §12 step 7's full geographic pass (each region draws its /// own rows while held) -- §9's amendment names the 56 actions still /// without a home. -fn keys_overlay(player: &Player) -> impl IntoElement { +fn keys_overlay(player: &Player, cx: &mut Context) -> impl IntoElement { div() .id("stance-keys-overlay") .absolute() @@ -455,6 +454,18 @@ fn keys_overlay(player: &Player) -> impl IntoElement { .h(px(BENCH_H + LEDGER_H)) .bg(rgba(SCRIM())) .flex() + // Click also dismisses (DESIGN §9): the hold-`?`-release above is + // the fast door, this is the same scrim-press-closes contract every + // other card's scrim answers, so a hand that let go of `?` before + // reading the list still has a way to shut it without the keyboard. + .on_mouse_down( + MouseButton::Left, + cx.listener(|this, _: &MouseDownEvent, _, cx| { + this.close_card(); + cx.notify(); + cx.stop_propagation(); + }), + ) .child( div() .id("stance-keys-list") @@ -467,6 +478,7 @@ fn keys_overlay(player: &Player) -> impl IntoElement { .bg(rgb(DARK_PANEL())) .border_1() .border_color(rgba(DARK_SEAM())) + .on_mouse_down(MouseButton::Left, swallow) .flex() .flex_col() .gap(px(3.)) @@ -558,7 +570,7 @@ fn spine(player: &Player, cx: &mut Context) -> impl IntoElement { .gap(px(4.)) .child(section_head("spine")) .child(spine_stance::render(player, cx)) - .child(ghost(player, "?", ActionId::ShowActions)) + .child(ghost(player, "?", ActionId::ShowActions, cx)) } /// The picture region: top of the centre column, takes the remaining space, @@ -1017,14 +1029,13 @@ pub(crate) fn render( cx.notify(); return; } - // Same modal guard the legacy handler's rebinding/keys_open/ - // export_open/colour/transform/speed/EQ/silence/mix/ - // subtitle-style/menu chain (`render.rs`) amounts to, read as - // one bool instead of re-copied field by field: while a card, a - // rebind capture, or a menu owns the keyboard, the darkroom - // stance yields to it exactly as the legacy tree does. This is - // the fix for the stance's `Home`-inside-the-Colour-card - // misfire. + // Same modal guard the legacy handler's keys_open/export_open/ + // colour/transform/speed/EQ/silence/mix/subtitle-style/menu + // chain (`render.rs`) amounts to, read as one bool instead of + // re-copied field by field: while a card or a menu owns the + // keyboard, the darkroom stance yields to it exactly as the + // legacy tree does. This is the fix for the stance's + // `Home`-inside-the-Colour-card misfire. // // `exporting()` alone is deliberately left out of this list // (`Player::card_open` is `modal()` minus it): a running export @@ -1038,8 +1049,7 @@ pub(crate) fn render( // branch, and the six it leaves live (Theme, Fullscreen, // SubtitleStyle, CancelExport, ...) are exactly the ones meant // to keep working. - if this.rebinding.is_some() - || this.card_open() + if this.card_open() || this.context_menu.is_some() || this.library_menu.is_some() || this.picker.is_some() @@ -1048,7 +1058,6 @@ pub(crate) fn render( // the same list `overlaid`/`modal` read) -- blocking every // key while a card is open must not also lock the card open. if key == ESCAPE { - this.rebinding = None; this.close_card(); } // FAULT 2, general shape: `context_menu`/`library_menu`/ @@ -1125,7 +1134,7 @@ pub(crate) fn render( .when_some(player.notices.back().cloned(), |el, n| { el.child(notice_plate(n, bench_h)) }) - .when(player.keys_open, |el| el.child(keys_overlay(player))) + .when(player.keys_open, |el| el.child(keys_overlay(player, cx))) .when(player.settings_open, |el| { el.child(settings_stance::render(player, window_size, cx)) }) diff --git a/crates/app/src/ui/theme.rs b/crates/app/src/ui/theme.rs index c5360ac..284a99a 100644 --- a/crates/app/src/ui/theme.rs +++ b/crates/app/src/ui/theme.rs @@ -40,7 +40,6 @@ //! ([`BG_PANEL()`]): one relaxed load and one field read off a `'static` //! table, which is what "the palette can be swapped whole" costs at paint time. -use engine::project::LaneKind; use std::path::PathBuf; use std::sync::atomic::{AtomicUsize, Ordering::Relaxed}; @@ -1444,20 +1443,6 @@ pub const GLYPH_SLOT: f32 = 14.; /// families share it. pub const GHOST_ALPHA: u32 = 0x66; -/// What a clip on `kind` is painted: the timeline's whole colour language in -/// one call, so a lane added later cannot invent a shade of its own. -pub fn clip_kind(kind: LaneKind, image: bool) -> u32 { - match kind { - LaneKind::Audio => CLIP_AUDIO(), - LaneKind::Video if image => CLIP_IMAGE(), - LaneKind::Video => CLIP_VIDEO(), - // The purple every editor paints a title track, and the one clip colour - // this palette already carried and nothing drew: a caption's box is now - // that box. - LaneKind::Subtitle => CLIP_TEXT(), - } -} - /// Which of the feedback colours a message wears. Read off the words rather /// than carried alongside them: every message in this editor already opens with /// what it is ("EXPORT DONE", "SCAN FAILED", "NOTHING DETACHED"), and a second diff --git a/crates/app/src/ui/timeline.rs b/crates/app/src/ui/timeline.rs deleted file mode 100644 index bce841a..0000000 --- a/crates/app/src/ui/timeline.rs +++ /dev/null @@ -1,2018 +0,0 @@ -//! The bottom region: the ruler, the lanes and the subtitle strip. - -use crate::ui::widgets::*; -use crate::*; - -impl Player { - /// The bottom region, full width under everything else: the timecode and - /// what is decoding, the ruler, the lanes and the subtitle strip. The edit - /// buttons are the row directly above it ([`Player::toolbar`]) -- the - /// arrangement every consumer editor shares, and the reason this is no - /// longer one "panel" that owned both. - pub(crate) fn timeline( - &self, - position: f64, - state: Transport, - viewport: Size, - cx: &mut Context, - ) -> impl IntoElement { - // Where the playhead is *on the bed*, in pixels from its left edge. - // Clamped to the bed because it is drawn as a width as well as an - // offset, and the view follows the playhead anyway, so it is never off - // the bed for long. - let bed_w = f32::from(self.ruler.get().size.width); - let filled = self.scale.px_at(position).clamp(0., bed_w); - let key = |action| self.keymap.display(action); - // The lanes the project has, or the pair a fresh one starts with so the - // panel reads the same before a file is open as after. - let lanes = self - .session - .as_ref() - .map_or_else(|| vec![Lane::V1, Lane::A1], PlaybackSession::lanes); - // A loop rather than a `map`: each row takes `cx` in turn, where a - // closure would hold it for as long as the iterator lives. - let mut rows = Vec::new(); - for &lane in &lanes { - rows.push(self.lane_row(lane, filled, cx)); - } - let (hint, filled) = if let Some(export) = self.exporting() { - // The words are the card's now ([`Player::export_progress_card`]): - // the export is modal, so this line is under its scrim and a second - // copy of the clocks there is one that can only be read dimmed. The - // ruler keeps the number -- it is the one part of the progress the - // card does not cover, and it costs nothing. - (String::new(), export.progress()) - } else { - // The strokes no button carries; the rest ride on the buttons' - // tooltips. Keys first: at a 640 px window the tail is what a - // truncation eats, and the two hints at the end are also on the - // ruler's and Import's tooltips. - // While it plays, what is decoding it goes first: it is the - // answer that changes as the playhead crosses a cut, and the tail - // of this line is what a narrow window truncates. - // ...and ahead of even that, where the playhead is standing when - // that is a frame a cut is free at: it decides whether an export of - // this film is minutes of copying or hours of encoding, which is - // the one thing on this line worth interrupting the hints for. - let sync = match self.on_sync_point() { - true => "SYNC POINT — a cut here is copied, not re-encoded", - false => "", - }; - ( - join_detail( - sync, - &join_detail( - &self.live_decode(position, state.is_playing()), - &format!( - "{} copy · {} paste · {} undo · {} redo · click the bar to seek · \ - drop a file to import", - key(ActionId::Copy), - key(ActionId::Paste), - key(ActionId::Undo), - key(ActionId::Redo) - ), - ), - ), - 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. - // What the lane count asks for against its share of the window -- or - // what a hand dragged the seam above to, which wins both - // ([`Player::split_px`]). - // - // The scrollbar's geometry comes off the very view the wheel and the - // zoom write: `settled` is what those paths clamp to, so the thumb - // never disagrees with where the panel actually is. And with the whole - // timeline on the bed there is no strip at all -- nor a row reserved - // for one: the region, this box and the seam's floor all carry the - // strip's pixels or none of them do ([`timeline_fixed_h`]), so the - // lanes keep exactly the room they had at either side of the zoom - // that crosses the line. - let view = self.view(); - let scrollable = view.duration > view.span(); - let kinds: Vec = lanes.iter().map(|lane| lane.kind).collect(); - let region_h = self.split_px(Split::Timeline, viewport); - let lanes_box = (region_h - timeline_fixed_h(scrollable)).max(LANE_H); - let overflows = lanes.len() > lanes_shown_mixed(&kinds, lanes_box); - let lanes_box = match overflows { - true => (lanes_box - LABEL_H - 8.).max(LANE_H), - false => lanes_box, - }; - let (thumb_x, thumb_w) = scroll_thumb( - view.bed, - view.duration, - view.scale.start.max(0.), - view.span(), - ); - // 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. The stack's own - // strip below reads the same number, so a thumb dragged there and a - // count the affordance lets go of cannot disagree. - let scrolled = -f32::from(self.lanes_scroll.offset().y); - let below = rows_below_mixed(&kinds, lanes_box, scrolled); - // The stack's own scrollbar: the thumb is the visible share of the - // lane rows, read straight off the column's own scroll state -- the - // box, the fold and how far down it has been taken are all the - // handle's to know, so nothing here is a second truth about any of - // them. - let stack = self.lanes_scroll.bounds(); - let track_h = f32::from(stack.size.height); - let stack_max = f32::from(self.lanes_scroll.max_offset().height); - let (stack_y, stack_thumb_h) = lanes_thumb(track_h, track_h + stack_max, track_h, 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(region_h)) - .flex() - .flex_col() - .gap(px(8.)) - .px(px(12.)) - .py(px(8.)) - .bg(rgb(BG_TIMELINE())) - .border_t_1() - .border_color(rgb(STROKE_DIVIDER())) - .child( - div() - .flex_none() - .flex() - .items_center() - .gap(px(12.)) - // Fixed width and one line: changing digits must not push - // the row around, nor wrap and change its height. - // The timeline's own length, never the drawn one: a tail - // being dragged inflates the bed to the room that edge has - // ([`Player::drawn_duration`]), and for a still that room is - // ten minutes -- a total that jumped to 10:00:00 the moment - // a picture's edge was pressed, and back on release. - .child(div().flex_none().w(px(TIME_W)).truncate().child(format!( - "{} / {}", - timecode(position, self.fps), - timecode( - self.session - .as_ref() - .map_or(0., PlaybackSession::timeline_duration), - self.fps - ) - ))) - .child( - div() - .flex_1() - .min_w(px(0.)) - .truncate() - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - .child(hint), - ), - ) - // Press to seek, drag to scrub: the move and release halves live on - // the root, since the pointer leaves the bar immediately. The bar - // stays 6 px to look at; the strip that takes the click is 24, so - // it can be hit without aiming (WCAG 2.5.8). - .child( - div() - .flex_none() - .flex() - .gap(px(HEADER_GAP)) - // The lanes' header column, empty here: the ruler's own bar - // has to start where their beds start, or the playhead - // would point at a different moment in each row. - .child(div().flex_none().w(px(HEADER_W))) - .child( - div() - .id("ruler") - .flex_1() - .min_w(px(0.)) - .h(px(RULER_HIT_H)) - .flex() - .flex_col() - .justify_center() - .rounded(px(3.)) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER_DIM()))) - // The strip carries no text, so the tooltip is the only - // place it can say what it is. - .tooltip(|_, cx| { - cx.new(|_| { - Tip("Seek — click or drag; wheel scrolls, ctrl+wheel zooms" - .into()) - }) - .into() - }) - // Ctrl+wheel zooms about the pointer and a bare one - // scrolls the view along -- [`Player::timeline_wheel`], - // the same answer the lanes below give, because a - // hand does not aim at a strip to zoom a timeline. - .on_scroll_wheel(cx.listener( - |this, event: &ScrollWheelEvent, _, cx| { - this.timeline_wheel(event, cx); - }, - )) - .on_mouse_down( - MouseButton::Left, - cx.listener(|this, event: &MouseDownEvent, _, cx| { - this.scrubbing = true; - this.scrub_to(event.position.x, true, cx); - }), - ) - .child( - div() - .w_full() - .h(px(6.)) - .rounded(px(3.)) - .bg(rgb(BG_RAISED())) - .child(bounds_probe(self.ruler.clone())) - .child( - div() - .h_full() - .w(px(filled)) - .rounded(px(3.)) - .bg(rgb(ACCENT_PRIMARY())), - ) - // The export's own mark, in and out: drawn - // over the played fill rather than under it, - // so a range that starts behind the playhead - // still shows -- translucent, the same wash - // the silence marks use, so the ruler under - // it stays readable. - .children(self.range.map(|(start, end)| { - let left = self.scale.px_at(f64::from(start) / self.fps); - let right = self.scale.px_at(f64::from(end) / self.fps); - // The wash alone is the played fill's own - // color at lower alpha, so once the - // playhead has passed the whole band the - // two blend to one flat color and the mark - // vanishes. A tick at each boundary, in - // the theme's foreground rather than its - // accent, reads over either background. - div() - .absolute() - .top_0() - .h_full() - .left(px(left)) - .w(px((right - left).max(1.))) - .rounded(px(3.)) - .bg(rgba(ACCENT_WASH())) - .border_l(px(2.)) - .border_r(px(2.)) - .border_color(rgb(FG_PRIMARY())) - })), - ), - ), - ) - // Every lane the project has, in its own order -- and its own - // column, so a project with more lanes than the panel is tall - // scrolls its tracks instead of pushing the picture off the window. - // The gap is the panel's own, so two lanes lay out exactly as they - // did when they were two children of it. The column sits in a - // relative box so the stack's own scrollbar can lie *over* the - // beds' right edge: a gutter beside them would take its width off - // the bed, and the ruler above would stop pointing at the moment - // the lanes are drawn at. - .child( - div() - .flex_1() - .min_h(px(0.)) - .max_h(px(lanes_h(LANES_MAX))) - .relative() - .flex() - .flex_col() - .child( - div() - .id("lanes") - // Takes whatever the region has left and scrolls - // inside it: at the 640x360 floor the region is - // capped ([`TIMELINE_SHARE`]) and a fixed column - // would be clipped by it rather than scrolled. - .flex_1() - .min_h(px(0.)) - .w_full() - .flex() - .flex_col() - .gap(px(8.)) - .overflow_y_scroll() - .track_scroll(&self.lanes_scroll) - .children(rows), - ) - // The lane stack's own scrollbar, drawn only while the - // stack overflows -- the same state the affordance below - // announces -- and never while the whole stack is on - // screen, where a full-height thumb would say nothing the - // lanes themselves do not. It costs the lanes nothing, - // being over the bed rather than out of it, and it is its - // own mouse region: a press there never reaches a clip. - .when(overflows, |d| { - d.child( - div() - .id("lanes-scroll") - .absolute() - .top_0() - .right_0() - .bottom_0() - .w(px(SCROLL_HIT)) - .rounded(px(3.)) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER_DIM()))) - .tooltip(|_, cx| { - cx.new(|_| { - Tip("Scroll the tracks — drag the thumb or click to \ - jump; the wheel scrolls them" - .into()) - }) - .into() - }) - // The strip is its own mouse region, and it - // says so with an occluder: gpui's hit test - // stops here, so the clip a press lands on - // top of -- and the column's own native - // scroll, and the bed's time wheel behind - // that -- never hear anything through it. - // Occluding is also why the two drag - // listeners ride here and not only on the - // root: an occluder deafens the root to - // everything under it ([`drag_scrim`]'s - // lesson), and this thumb's drag runs along - // the strip's own 14 px -- the pointer never - // leaves the one place the root cannot hear. - // A drag that does leave it is picked up by - // the root's own copies, without a seam. - .occlude() - .on_scroll_wheel(cx.listener( - |this, event: &ScrollWheelEvent, window, cx| { - cx.stop_propagation(); - let line = window.line_height(); - let dy = f32::from(event.delta.pixel_delta(line).y); - this.lanes_wheel(dy, cx); - }, - )) - .on_mouse_down( - MouseButton::Left, - cx.listener(|this, event: &MouseDownEvent, _, cx| { - cx.stop_propagation(); - this.lanes_press(event.position.y, cx); - }), - ) - // A right press is a clip's menu anywhere - // else on the bed; over the strip it is - // nothing, and the clip beneath must not - // answer it through the strip. - .on_mouse_down(MouseButton::Right, |_: &MouseDownEvent, _, cx| { - cx.stop_propagation() - }) - .on_mouse_move(cx.listener(Player::drag_move)) - .on_mouse_up(MouseButton::Left, cx.listener(Player::drag_release)) - .child( - div() - .absolute() - .top_0() - .bottom_0() - .left(px((SCROLL_HIT - 6.) / 2.)) - .w(px(6.)) - .rounded(px(3.)) - .bg(rgb(BG_RAISED())) - .child( - div() - .absolute() - .top(px(stack_y)) - .h(px(stack_thumb_h)) - .w_full() - .rounded(px(3.)) - .bg(rgb(ACCENT_PRIMARY())), - ), - ), - ) - }), - ) - // The timeline's own scrollbar: the time axis is the one dimension - // the panel scrolls with no bar of its own, and until f69ba33 only - // the wheel and the keys reached it. The thumb is the visible share - // of the drawn duration and sits where that share is -- read off - // the very `Scale` every box is drawn through, so a wheel notch, a - // zoom about the pointer and the follow of the playhead all move - // it, because they all move the one state. The row exists only - // while there is somewhere to scroll to: zoomed out to the whole - // timeline the strip is not drawn and no pixels are held for it - // ([`timeline_fixed_h`]) -- a bar for a view that cannot move is a - // bar teaching nothing. - .when(scrollable, |d| { - d.child( - div() - .flex_none() - .flex() - .gap(px(HEADER_GAP)) - // Under the lane headers like the ruler is above them, so - // the thumb and the bed it stands for line up. - .child(div().flex_none().w(px(HEADER_W))) - .child( - div() - .id("timeline-scroll") - .flex_1() - .min_w(px(0.)) - .h(px(SCROLL_HIT)) - .flex() - .flex_col() - .justify_center() - .rounded(px(3.)) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER_DIM()))) - .tooltip(|_, cx| { - cx.new(|_| { - Tip("Scroll the timeline — drag the thumb or click to \ - jump; wheel scrolls, ctrl+wheel zooms" - .into()) - }) - .into() - }) - // Both consumed here for the vertical strip's - // reason: the row sits over nothing today, but - // a press or a notch that fell through it - // would be a gesture the strip drew and the - // panel answered. - .on_scroll_wheel(cx.listener( - |this, event: &ScrollWheelEvent, _, cx| { - cx.stop_propagation(); - this.timeline_wheel(event, cx); - }, - )) - .on_mouse_down( - MouseButton::Left, - cx.listener(|this, event: &MouseDownEvent, _, cx| { - cx.stop_propagation(); - this.scroll_press(event.position.x, cx); - }), - ) - .child( - div() - .w_full() - .h(px(6.)) - .rounded(px(3.)) - .bg(rgb(BG_RAISED())) - .child(bounds_probe(self.scroll_track.clone())) - .child( - div() - .h_full() - .rounded(px(3.)) - .left(px(thumb_x)) - .absolute() - .top_0() - .w(px(thumb_w)) - .bg(rgb(ACCENT_PRIMARY())), - ), - ), - ), - ) - }) - // "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 { - // Over the track names, not over the beds: a wheel - // on a bed moves the *view* along the timeline now, - // so the column names its own scroll surface. - 0 => "the last track — scroll the names for the rest".to_string(), - 1 => "1 more track below — scroll the track names".to_string(), - n => format!("{n} more tracks below — scroll the track names"), - }), - ) - }) - } - - /// The subtitle tracks this timeline holds, under the media list: one row - /// each, the picked one marked, and a click makes another one the picked one - /// -- which is the whole of choosing between the two tracks of a film. A row - /// per track and no cycle: three of them is an ordinary number for a remux, - /// and a key that steps through three is a key nobody can aim. - /// - /// A track that could not be read is *here*, greyed and saying why, exactly - /// as a media row the timeline cannot take is: PGS subtitles are pictures, - /// and a film carrying four of them says so instead of listing nothing. - /// - /// Every row names the file it came out of itself, in words and in the tint - /// that file's clips wear on the lanes -- but only where there is more than - /// one file to tell apart, the way [`row_name`] numbers audio streams only - /// where a file gave several. There, each file's block is headed by its - /// name as well, its swatch and its track count -- always, whatever the - /// window's height, since the list under it scrolls (`SUB_ROWS_H`) rather - /// than the header being the thing a short window drops. A click on a - /// header folds its rows shut (`Player::sub_folded`) and a second one opens - /// them back -- a fold and not a cycle, so what a click does never depends - /// on what the last one did. - /// - /// `None` when there are none -- an empty heading is a section about - /// nothing. - pub(crate) fn subtitle_section( - &self, - width: f32, - cx: &mut Context, - ) -> Option { - let tracks = self.session.as_ref()?.subtitles(); - if tracks.is_empty() { - return None; - } - let groups = subtitle_rows(tracks); - // What the row's × says the way back is, in the stroke this keymap - // actually binds: a file's subtitles go on without the file. - let add_key = self.keymap.display(ActionId::ImportSubtitles); - // One file's tracks need no prefix saying which file: it is the only - // one, and every row would carry the same word. - let several_files = groups.len() > 1; - let headed = several_files; - let text_w = row_text_w(width); - let rows: Vec<_> = groups - .into_iter() - .enumerate() - .map(|(group_ord, SubGroup { name, path, rows })| { - // The file's own colour, the one its media rows and its clips - // wear -- and none at all for a standalone `.srt`, which came - // off no file on this timeline. - let tint = file_tint(self.sources(), &path); - let track_count = rows.len(); - let numbered = rows.len() > 1; - let folded = self.sub_folded.contains(&path); - let fold_path = path.clone(); - // The name twice over: all of it the header can hold, and the - // share of a row a prefix may take in front of the label. - let head = clip_middle(&name, text_w); - let prefix = clip_middle(&name, text_w * SUB_STEM_SHARE); - let rows: Vec<_> = rows - .into_iter() - .map(|row| { - let track = row.track; - let picked = track == self.sub_track; - let usable = row.refused.is_none(); - // Two tracks off one remux that both say "eng" are told - // apart by their number and by nothing else -- the same - // count [`sub_pick_name`] echoes. - let title = match numbered { - true => format!("{} {}", row.label, row.number), - false => row.label, - }; - // A standalone `.srt` is named after its own file, so - // the file in front of it says the same word twice - // ("Legend.of.… · Legend.of.…"). [`sub_pick_name`]'s - // rule, on the row it is about. - let owned = several_files && !title.starts_with(name.as_str()); - // The whole path, never clipped: the row says which - // file, and the tooltip says which one on disk. - let tip: SharedString = match &row.refused { - Some(why) => format!("{} — {why}", path.display()), - None => format!( - "{} — drag it onto a subtitle track to place it; nothing is over \ - the picture until it is placed", - path.display() - ), - } - .into(); - // What the pointer carries onto a lane: the row's own - // name, the ghost a library row makes. - let carried: SharedString = title.clone().into(); - // Named, because a × is the same glyph on every row and - // the tooltip is what says which track it takes off. - let remove_tip: SharedString = format!( - "Remove {title} from the palette — {} puts a file's subtitles \ - back in it", - add_key - ) - .into(); - div() - // The *flat* index into the session's add-order - // list, which is what a pick is and what a save - // writes: the grouping moved the row on screen and - // never the track it stands for. - .id(("subtitle-track", track)) - .flex_none() - .h(px(ROW_H)) - .flex() - .items_center() - .gap(px(6.)) - .pr(px(6.)) - .rounded(px(3.)) - .when(!usable, |d| d.text_color(rgb(FG_SECONDARY())).opacity(0.55)) - .when(usable, |d| { - d.cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - // Dragged, the whole track goes down on the - // subtitle lane it is let go over -- the - // gesture a media row already answers to, - // on the list beside it. A track that could - // not be read carries nothing: there is - // nothing of it to place. - .on_drag(SubPick(track), move |_, _, _, cx| { - cx.new(|_| Tip(carried.clone())) - }) - // Selects the row and shows nothing: a - // subtitle track reaches the picture by - // being placed on a subtitle lane, the way - // a film reaches it by being placed on a - // video one. What the selection is for is - // the × and the mark on the row. - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { - this.sub_track = track; - cx.notify(); - })) - }) - .when(picked, |d| d.bg(rgb(BG_SELECTED()))) - .tooltip(move |_, cx| cx.new(|_| Tip(tip.clone())).into()) - // The media rows' bar, same width and hard against - // the same edge: one association across the panel - // and the lanes. Kept as room rather than dropped - // where there is no tint, so a standalone `.srt` - // still lines its words up with the rest. - .child( - div() - .flex_none() - .w(px(SWATCH_W)) - .h_full() - .rounded(px(2.)) - .when_some(tint, |d, tint| d.bg(rgb(tint))), - ) - .child( - div() - .flex_1() - .min_w(px(0.)) - .flex() - .flex_col() - .child( - div() - .flex() - .text_size(px(11.)) - // In front, because the column - // truncates from the right: an - // ownership word at the end is a - // word the floor never shows. - .when(owned, |d| { - d.child( - div() - .flex_none() - // Said twice where a - // header says it above: - // still there, out of - // the way. - .when(headed, |d| { - d.text_color(rgb(FG_SECONDARY())) - }) - .child(format!("{prefix} · ")), - ) - }) - .child( - div() - .flex_1() - .min_w(px(0.)) - .truncate() - .child(title), - ), - ) - .child( - div() - .truncate() - .text_size(px(10.)) - .text_color(rgb(FG_SECONDARY())) - .child(row.detail), - ), - ) - // The way back off the timeline, on every row and on - // the last one too -- a list of subtitles is allowed - // to be empty, unlike a lane. A `HIT_MIN` target and - // never hidden, the lane header's ×, and it stops - // the click there: the row under it picks a track, - // and picking the track that has just gone would - // leave the pick naming nothing. - .child( - div() - .id(("subtitle-remove", track)) - .flex_none() - .w(px(HIT_MIN)) - .h_full() - .flex() - .items_center() - .justify_center() - .rounded(px(3.)) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .tooltip(move |_, cx| { - cx.new(|_| Tip(remove_tip.clone())).into() - }) - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { - cx.stop_propagation(); - this.remove_subtitle_track(track, cx); - })) - .child("×"), - ) - }) - .collect(); - div() - .flex_none() - .flex() - .flex_col() - .gap(px(2.)) - // The header: which film these came out of, in words and not - // in colour alone -- a click folds its rows shut and a - // second click opens them, so it is its own `HIT_MIN` - // target rather than a bare label. - .when(headed, |d| { - d.child( - div() - .id(("subtitle-group-head", group_ord)) - .flex_none() - .h(px(SUB_HEAD_H)) - .flex() - .items_center() - .gap(px(6.)) - .text_size(px(10.)) - .text_color(rgb(FG_SECONDARY())) - .rounded(px(3.)) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { - match this.sub_folded.remove(&fold_path) { - true => {} - false => { - this.sub_folded.insert(fold_path.clone()); - } - } - cx.notify(); - })) - // Folded / open, in the same glyph a fold uses - // everywhere else on this row list. - .child(match folded { - true => "▸", - false => "▾", - }) - .when_some(tint, |d, tint| { - d.child( - div() - .flex_none() - .w(px(SWATCH_W)) - .h_full() - .rounded(px(2.)) - .bg(rgb(tint)), - ) - }) - .child(div().flex_1().min_w(px(0.)).truncate().child(head)) - .child(match track_count { - 1 => "1 track".to_string(), - n => format!("{n} tracks"), - }), - ) - }) - .when(!(headed && folded), |d| d.children(rows)) - }) - .collect(); - Some( - div() - .flex_none() - .flex() - .flex_col() - .gap(px(2.)) - .child( - div() - .truncate() - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - .child(match self.subs_on { - // A palette and not a picker: none of these rows is - // "the one on screen" any more, so the heading names - // no track. What is on screen is on the subtitle - // lanes, each with its own eye. - true => "Subtitles", - // The mute's state where the tracks are listed: with - // it off no lane draws, however many are placed. - false => "Subtitles — hidden", - }), - ) - .child( - div() - .id("subtitle-rows") - .flex() - .flex_col() - .gap(px(2.)) - .max_h(px(SUB_ROWS_H)) - .overflow_y_scroll() - .children(rows), - ), - ) - } - - /// One lane of the edit list made visible: a fixed header saying which lane - /// it is, then a bed with a box per clip, placed and sized by its share of - /// the timeline. A cut adds a box without moving anything, a delete closes - /// the hole, a lift leaves one. A clip too narrow for its name says what it - /// is by its tint, and the tooltip is where every box says what clicking it - /// does. Never focusable, so the root keeps focus and the play binding still - /// works after a click (ledger:182). - pub(crate) fn lane_row( - &self, - lane: Lane, - // Where the playhead is on the bed, in pixels: worked out once by the - // panel so the ruler's line and every lane's draw the same one. - filled: f32, - cx: &mut Context, - // Borrows nothing it was given (`use<>`): the rows are built one after - // another into a list, and a row still holding `cx` would be the only - // one that could be built. - ) -> impl IntoElement + use<> { - // The mapping, copied out once: every box in the row is placed through - // it, so all of them move together when it does. No bed width is needed - // to place them any more -- a second is so many pixels wherever it is. - let scale = self.scale; - // How much bed there is to be seen on, measured off the ruler's own - // probe like every other question about it: what a box draws *inside* - // itself is clipped to this ([`visible_slice`]), because a box at a deep - // zoom is far wider than the strip it is being watched through. - let bed = f32::from(self.ruler.get().size.width); - // Where the snap line stands, in the same pixels every box is placed - // through -- and only while a gesture is actually live: gpui drops a - // drag without telling anyone, so this asks whether one is in flight - // (`App::has_active_drag`) rather than remembering that one was. - let cue = self - .snap_cue - .filter(|_| self.trim.is_some() || cx.has_active_drag()) - .map(|frame| scale.px_at(f64::from(frame) / self.fps)); - // The shadow (or shadows, on a set-drag -- [`Player::preview_ghost`]), - // on the one lane each names -- and, like the line, only while the - // drag that asked for it is still in flight. - let ghost: Vec = self - .ghost - .iter() - .copied() - .filter(|g| g.lane == lane && cx.has_active_drag()) - .collect(); - let clips = self - .session - .as_ref() - .map_or(&[][..], |session| session.lane_clips(lane)); - // The group ids some *other* lane carries: a clip whose id is in here - // has a half elsewhere, and one whose is not is a detached half however - // many lanes there are. - // The group ids some *other* lane carries, on either of its lists: a - // placement whose id is in here has a half elsewhere -- a clip on - // another track, or a caption pinned to this clip -- and one whose is - // not is detached however many lanes there are. - let others: Vec = self.session.as_ref().map_or_else(Vec::new, |session| { - session - .lanes() - .into_iter() - .filter(|&other| other != lane) - .flat_map(|other| { - let clips = session.lane_clips(other).iter().filter_map(|c| c.link); - let subs = session.sub_lane(other).iter().filter_map(|s| s.link); - clips.chain(subs) - }) - .collect() - }); - let name = lane.label(); - let row_id: SharedString = format!("{name}-clip").into(); - let remove_id: SharedString = format!("{name}-remove").into(); - let header_id: SharedString = format!("{name}-header").into(); - let header_tip: SharedString = - format!("{name} — drag this header onto another to reorder the tracks").into(); - // The header ghost, the same shape a clip's is: the track's own name - // under the pointer, so what is in the hand is legible while it moves. - let header_ghost: SharedString = name.clone().into(); - // The line this row draws between itself and its neighbour while a - // header is being carried -- and, like every other drag cue here, only - // while the gesture is still in flight. - let drop = self - .lane_drop - .filter(|d| d.lane == lane && cx.has_active_drag()); - let remove_tip: SharedString = format!( - "Remove {name} — it must be empty first, and {} brings it back", - self.keymap.display(ActionId::Undo) - ) - .into(); - let sources = self - .session - .as_ref() - .map_or(&[][..], PlaybackSession::sources); - let (picks, pick_links) = self.marks(); - let audio = lane.kind == LaneKind::Audio; - // A subtitle lane holds no `Clip` and every other lane holds no - // `SubClip`, so the two lists below are never both full and the bed - // draws whichever it was given -- one row, and no second kind of row to - // keep in step with this one. - let sub = lane.kind == LaneKind::Subtitle; - let shown = self.sub_lane_on(lane); - let subs: Vec = match (sub, &self.session) { - (true, Some(session)) => session.sub_lane(lane).to_vec(), - _ => Vec::new(), - }; - // Where this lane's words actually are on this timeline - // ([`PlaybackSession::sub_lane_cues`], the same map an export and the - // plate over the picture go through): the marks inside the placements' - // boxes, so a caption's box says where in it anybody speaks. - let cues: Vec<(f32, f32)> = match (sub, &self.session) { - (true, Some(session)) => session - .sub_lane_cues(lane) - .iter() - .map(|cue| cue_box(scale, cue)) - .collect(), - _ => Vec::new(), - }; - // Thinner than a media lane's ([`SUB_LANE_H`]), so its header has room - // for one `HIT_MIN` target and not the two a stacked eye-and-remove - // pair would need -- the right button carries the remove instead, the - // same door a caption's own box already answers to (`sub_tip`), so a - // track that used to have its own × still has one, just not a second - // row to draw it in. - let eye_tip: SharedString = match shown { - true => format!( - "{name} is the track shown over the picture — the right button removes it, empty \ - first, and {} brings it back", - self.keymap.display(ActionId::Undo) - ), - false => format!( - "Click to show {name} over the picture instead — one subtitle track is drawn at a \ - time, and an export carries every one of them; the right button removes it, empty \ - first, and {} brings it back", - self.keymap.display(ActionId::Undo) - ), - } - .into(); - // What a caption's box says clicking it does; the media boxes' tooltip - // names edits a placement has none of (no group, no speed, no ripple). - let sub_tip: SharedString = - "Drag it along the lane or onto another subtitle track, an end to trim it, x or the \ - right button takes it off" - .into(); - // What this track plays at, on the header it belongs to: shown only - // when it is not unity, because a column 40 px wide has room for a - // number or for a name, and the name is what a header is for. The - // press opens the mix card on this very track. - let gain_db = self - .session - .as_ref() - .map_or(0., |session| session.lane_gain_db(lane)); - let gain_tip: SharedString = format!( - "{name} plays at {gain_db:+.0} dB — opens the mix ({}); the whole track, every frequency, unlike the equalizer", - self.keymap.display(ActionId::Mix) - ) - .into(); - let tip: SharedString = format!( - "Select (or {} under the playhead, {}/{} along the lane) — drag it to move it, an end to trim, {} removes the take, {} leaves a gap, {} rejoins a cut", - self.keymap.display(ActionId::Select), - self.keymap.display(ActionId::SelectPrev), - self.keymap.display(ActionId::SelectNext), - self.keymap.display(ActionId::Delete), - self.keymap.display(ActionId::Lift), - self.keymap.display(ActionId::Regroup) - ) - .into(); - div() - .flex_none() - .h(px(lane_h(lane.kind))) - .flex() - .gap(px(HEADER_GAP)) - // A header let go anywhere along this row lands the track in the - // hand in this row's place: the whole width is the target, not the - // 40 px column, because a slot is what is being aimed at. The bed's - // own drops carry other payloads and never see this one. - .relative() - .on_drop(cx.listener(move |this, drag: &LaneDrag, _, cx| { - this.reorder_lane(drag.0, lane, cx); - })) - .on_drag_move( - cx.listener(move |this, event: &DragMoveEvent, _, cx| { - // Carried off this row, the line it was promising goes with - // it: a cue left painted over a slot a release out here does - // not commit is the drag saying one thing and the drop - // doing another. Its *own* promise only -- gpui runs this on - // every painted row, not just the one under the pointer, so - // a row that cleared the cue outright would rub out the line - // the hovered row had just drawn. - if !event.bounds.contains(&event.event.position) { - return this.forget_lane_drop(lane, cx); - } - this.preview_lane_drop(event.drag(cx).0, lane, cx); - }), - ) - // The fixed column the ruler above is offset by as well. Full lane - // height, so it reads as the bed continuing rather than as a chip. - .child( - div() - // Dragged, the whole track moves in the stack -- the - // gesture every editor reorders tracks with, and the reason - // the column is a handle rather than a caption. - .id(header_id) - .cursor(CursorStyle::OpenHand) - .tooltip(move |_, cx| cx.new(|_| Tip(header_tip.clone())).into()) - .on_drag(LaneDrag(lane), move |_, _, _, cx| { - cx.new(|_| Tip(header_ghost.clone())) - }) - .flex_none() - .w(px(HEADER_W)) - .h_full() - .flex() - .flex_col() - .items_center() - .justify_center() - .rounded(px(3.)) - .bg(rgb(BG_RAISED())) - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY())) - .child(match audio { - // A button, not a label: the one setting a track has of - // its own used to be reachable from nowhere. - true => div() - .id(("mix-lane", lane.ord)) - .flex_1() - .w_full() - .flex() - .items_center() - .justify_center() - .rounded(px(3.)) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .tooltip(move |_, cx| cx.new(|_| Tip(gain_tip.clone())).into()) - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { - this.open_mix(Some(lane), cx) - })) - .child(match gain_db == 0. { - true => name.clone(), - false => format!("{name} {gain_db:+.0}"), - }) - .into_any_element(), - // A subtitle track's own one setting, in the same - // place and for the same reason: whether *this* lane is - // the one drawn over the picture. A radio and not an - // eye -- one track shows at a time, so a click here - // takes the picture off whichever lane had it -- and - // `HIT_MIN` tall like the mix button it sits where. - // The lit dot and the accent tell the shown lane from - // the rest of a stack of them at a glance. - // One line, not name-over-dot: at `SUB_LANE_H` the - // whole header is one `HIT_MIN` target, and the - // shown/hidden state is already the colour, the - // background and the border below -- a second line - // saying the same thing again is a line this row no - // longer has the height to spare. - false if sub => div() - .id(("show-lane", lane.ord)) - .flex_1() - .w_full() - .flex() - .items_center() - .justify_center() - .rounded(px(3.)) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .when(!shown, |d| d.text_color(rgb(FG_DISABLED()))) - .when(shown, |d| { - d.text_color(rgb(ACCENT_PRIMARY())) - .bg(rgb(BG_HOVER())) - .border_1() - .border_color(rgb(ACCENT_PRIMARY())) - }) - .tooltip(move |_, cx| cx.new(|_| Tip(eye_tip.clone())).into()) - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { - this.show_sub_lane(lane, cx) - })) - // The remove door a stacked second row used to be, - // on the same button now: the right button is - // already how a caption's own box takes itself - // off the lane (`sub_tip`), so the header answers - // to it too rather than spending a second - // `HIT_MIN` row on a thin lane that has none to - // spare. - .on_mouse_down( - MouseButton::Right, - cx.listener(move |this, _: &MouseDownEvent, _, cx| { - this.remove_lane(lane, cx) - }), - ) - .child(name.clone()) - .into_any_element(), - false => div() - .flex_1() - .flex() - .items_center() - .child(name.clone()) - .into_any_element(), - }) - // The one thing a media header does: take this track away - // again. A `HIT_MIN` target rather than a glyph-sized one, - // and it stays put on a track holding clips instead of - // hiding -- the refusal names them, and a control that - // vanishes teaches nothing. A subtitle lane's remove lives - // on the eye button instead ([`eye_tip`]) -- this row is - // thin enough for one `HIT_MIN` target, not two. - .when(!sub, |d| { - d.child( - div() - .id(remove_id) - .flex_none() - .w_full() - .h(px(HIT_MIN)) - .flex() - .items_center() - .justify_center() - .rounded(px(3.)) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .tooltip(move |_, cx| cx.new(|_| Tip(remove_tip.clone())).into()) - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { - this.remove_lane(lane, cx) - })) - .child("×"), - ) - }), - ) - .child( - // Clips are placed at their own start rather than queued edge - // to edge: a lift leaves a hole in the lane, and the bare bed - // showing through it *is* how a gap looks. - div() - .relative() - .flex_1() - .min_w(px(0.)) - .h_full() - .rounded(px(3.)) - .bg(rgb(BG_TIMELINE())) - .overflow_hidden() - // The wheel over the clips themselves, which is where a - // hand already is: ctrl zooms about the pointer, bare - // scrolls the view along ([`Player::timeline_wheel`]). - // Stopped here, because gpui runs the lane *column's* own - // overflow scroll on the same notch (div.rs:2403) and a - // gesture that slid the view sideways and the tracks upward - // at once is two answers to one notch. The track headers - // beside this bed are still the column's scroll surface. - .on_scroll_wheel(cx.listener(|this, event: &ScrollWheelEvent, _, cx| { - cx.stop_propagation(); - this.timeline_wheel(event, cx); - })) - // A library row let go over a lane is the same insert the - // Add button makes, through the same call -- but where the - // pointer let it go, not at the playhead: a hand that - // carried a file to a place on the bed named that place. - // gpui hands a drop no event, so the pointer is read off - // the window, which took it from the release that fired - // this (gpui window.rs:3602). - .on_drop(cx.listener(move |this, drag: &AssetDrag, window, cx| { - // Onto the edges near it, exactly as a clip carried by - // hand lands: the line drawn while it was in flight is - // the frame it goes down on. - let at = this.place_frame(window.mouse_position().x).0; - this.insert_source(&drag.0.clone(), drag.1, Some(lane), Some(at), cx) - })) - .drag_over::(|s, _, _, _| s.bg(rgb(BG_HOVER_DIM()))) - // The shadow of the row in flight, drawn by the lane the - // pointer is inside: `on_drag_move` fires on every painted - // element while a drag of its type is live, wherever the - // pointer is, and hands each one its own box -- which is how - // a lane knows the pointer is over *it* (gpui div.rs:282). - // The root cleared it a moment ago, so exactly one lane - // draws one. - .on_drag_move(cx.listener( - move |this, event: &DragMoveEvent, _, cx| { - if !event.bounds.contains(&event.event.position) { - return; - } - let path = event.drag(cx).0.clone(); - this.preview_ghost_asset(&path, lane, event.event.position.x, cx); - }, - )) - // ...and a clip let go over a lane lands the same way: on - // the track it was dropped on, at the frame it was carried - // to -- its own included, which is the drag that moves a - // take along its track. - .on_drop(cx.listener(move |this, drag: &ClipDrag, window, cx| { - // Against the lane as it is *now* ([`Player::dragged`]), - // and then snapped by `move_clip` like any other drop: - // which clip is being moved and where it lands are two - // questions, and this is the first one. - let Some(idx) = this.dragged(drag) else { - return; - }; - this.move_clip(drag.lane, idx, lane, window.mouse_position().x, cx) - })) - .drag_over::(|s, _, _, _| s.bg(rgb(BG_HOVER_DIM()))) - // ...and the same shadow for the clip in the hand, seated on - // this lane when the pointer is inside it. - .on_drag_move(cx.listener( - move |this, event: &DragMoveEvent, _, cx| { - if !event.bounds.contains(&event.event.position) { - return; - } - let drag = *event.drag(cx); - this.preview_ghost(&drag, lane, event.event.position.x, cx); - }, - )) - // A palette row let go over a lane places that whole - // subtitle track where the hand left it -- and over a lane - // that is not a subtitle one, `place_sub` refuses it in - // words, which is why the listener is on every bed rather - // than on the subtitle beds alone. - .on_drop(cx.listener(move |this, drag: &SubPick, window, cx| { - this.place_sub(drag.0, lane, window.mouse_position().x, cx); - })) - .drag_over::(|s, _, _, _| s.bg(rgb(BG_HOVER_DIM()))) - .on_drag_move(cx.listener( - move |this, event: &DragMoveEvent, _, cx| { - if !event.bounds.contains(&event.event.position) { - return; - } - let track = event.drag(cx).0; - this.preview_ghost_pick(track, lane, event.event.position.x, cx); - }, - )) - // ...and a caption already on a lane moves along it, or onto - // another subtitle track, exactly as a clip does. - .on_drop(cx.listener(move |this, drag: &SubDrag, window, cx| { - this.move_sub(drag, lane, window.mouse_position().x, cx); - })) - .drag_over::(|s, _, _, _| s.bg(rgb(BG_HOVER_DIM()))) - .on_drag_move(cx.listener( - move |this, event: &DragMoveEvent, _, cx| { - if !event.bounds.contains(&event.event.position) { - return; - } - let drag = *event.drag(cx); - this.preview_ghost_sub(&drag, lane, event.event.position.x, cx); - }, - )) - .children(clips.iter().enumerate().map(|(i, clip)| { - // The clip as the lane holds it, for the drag payload: - // what a drop looks itself up by has to be the placed - // clip, never the preview an edge drag is drawing. - let placed = *clip; - // What a drag on an edge is showing, which is the clip - // itself while nothing is being dragged. - let clip = &self.trimmed(lane, i, *clip); - // Its *timeline* length, which a speed halves or - // quadruples: the box is as wide as the clip is long - // where it sits, not as long as the source it reads. - let (start, len) = ( - f64::from(clip.start) / self.fps, - f64::from(clip.frames()) / self.fps, - ); - let on = marked((lane, i), clip.link, &picks, &pick_links); - // A group with a half in the other lane wears its tint; - // one without is outlined, so a detached half is visible - // as detached before anyone clicks it. - let grouped = clip.link.is_some_and(|link| others.contains(&link)); - // Tinted by *file*, not by source entry: two audio - // streams of one file are two sources, and the library - // gives them one swatch because they are one file. - let tint = self.clip_tint(clip.source); - // ...and painted by *kind*, which is the one thing a - // glance down a timeline has to answer: video blue, - // audio green, a still teal, the cues purple, the way - // every editor with more than one track colours them. - // The source tint stays the identity of the file and is - // the border and the library swatch. - let kind = clip_kind( - lane.kind, - sources - .get(clip.source) - .is_some_and(|s| engine::is_image(&s.path)), - ); - // What the clip is worth in pixels, and how wide its box - // is drawn -- the two part company on a take too short - // to be hit at this zoom ([`clip_width`]). - let span = scale.width_px(len); - let width = clip_width(span); - let left = scale.px_at(start); - // The slice of this box that is on the bed: where its - // name, its badge and its waveform go, so none of the - // three is drawn out at a zoomed-in box's own edges. - let (vis_x, vis_w) = visible_slice(left, width, bed); - let label = sources.get(clip.source).map(|s| file_name(&s.path)); - let wave = sources - .get(clip.source) - .and_then(|s| self.waves.get(&(s.path.clone(), s.audio_stream))) - .cloned(); - // The source seconds that slice plays -- not the clip's - // whole range: the envelope is drawn for the part of the - // box that can be seen, at the resolution of the pixels - // it actually has, and never one column per two pixels - // of a box millions of pixels wide. - let along = |x: f32| match width > 0. { - true => { - f64::from(clip.in_frame) - + f64::from(clip.out_frame - clip.in_frame) - * f64::from(x / width) - } - false => f64::from(clip.in_frame), - }; - let (from, to) = (along(vis_x) / self.fps, along(vis_x + vis_w) / self.fps); - let tip = tip.clone(); - // What the pointer carries on the way to another lane: - // the file the box is showing, the same ghost a library - // row makes. A box too narrow for its own label still - // says what is moving. - let ghost: SharedString = - label.clone().unwrap_or_else(|| lane.label()).into(); - // Its head in frames, for the press below: the `start` - // above is the same moment in seconds, which is what - // the box is *drawn* from. - let head = clip.start; - div() - // Named per lane: two rows numbering their clips - // from zero would hand gpui the same id twice. - .id((row_id.clone(), i)) - .absolute() - .top_0() - .h_full() - // Negative once the clip's head has been scrolled - // off the left edge: the bed clips what hangs out - // of it, so a half-visible clip is drawn as the - // half of itself that is on screen. - .left(px(left)) - .w(px(width)) - .overflow_hidden() - .rounded(px(3.)) - .border_1() - .border_color(rgb(if on { - STROKE_SELECTED() - } else if grouped { - tint - } else { - FG_SECONDARY() - })) - .bg(rgb(if on { BG_SELECTED() } else { kind })) - .cursor_pointer() - .hover(|s| s.border_color(rgb(ACCENT_PRIMARY()))) - .tooltip(move |_, cx| cx.new(|_| Tip(tip.clone())).into()) - // Dragged, it *moves*: to the frame it was let go on - // and to the lane it was let go over. The click that - // starts the drag still selects, so picking a clip - // up and putting it back down where it was is - // exactly a click. - .on_drag( - ClipDrag { - lane, - idx: i, - clip: placed, - }, - move |_, _, _, cx| cx.new(|_| Tip(ghost.clone())), - ) - .on_mouse_down( - MouseButton::Left, - cx.listener(move |this, event: &MouseDownEvent, _, cx| { - // Where in the box the hand took hold of it, - // for the drag this press may become: the - // clip has to move with the pointer rather - // than jump its head under it. - this.grab = - this.frame_under(event.position.x).saturating_sub(head); - // Ctrl held, the pick joins the selection - // instead of replacing it -- the toggle a - // group is assembled by hand with. - this.pick((lane, i), event.modifiers.control, cx); - }), - ) - // A plain click collapses a multi-pick to this one - // clip -- `pick` above deliberately keeps the whole - // set on the press so a set-drag has something to - // move; gpui drops the pending click once a drag - // starts, so this only fires on a press-release - // with no drag between. - .on_click(cx.listener(move |this, event: &ClickEvent, _, cx| { - if !press_modifiers(event).control { - this.select((lane, i), cx); - } - })) - // The right button selects exactly as the left one - // does -- the menu acts on the clip it names, so - // opening one has to pick it -- and then hangs the - // menu at the pointer. - .on_mouse_down( - MouseButton::Right, - cx.listener(move |this, event: &MouseDownEvent, _, cx| { - this.open_menu(lane, i, event.position, cx); - }), - ) - // The two strips a drag *lengthens* the clip by, - // one at each end. They occlude the box behind - // them, which is what keeps one gesture one thing: - // a press here trims, a press anywhere else on the - // box still starts the move to another lane. - // - // Asked of the clip's own width and not of the box's - // floor: a take drawn at `HIT_MIN` because it is - // shorter than that has no *pixels* to trim by -- one - // would move it by seconds -- so it keeps all of its - // padded box as a body to select and drag by, and is - // trimmed after zooming in, exactly as [`trims`] says. - .children( - [Edge::Start, Edge::End] - .into_iter() - .filter(|_| trims(span)) - .map(|edge| { - let mut zone = div() - .absolute() - .top_0() - .h_full() - .w(px(EDGE_W)) - .occlude() - .cursor(CursorStyle::ResizeLeftRight) - .hover(|s| s.bg(rgb(ACCENT_PRIMARY()))) - .on_mouse_down( - MouseButton::Left, - cx.listener( - move |this, event: &MouseDownEvent, _, cx| { - this.start_trim( - lane, - i, - edge, - event.modifiers.control, - cx, - ); - }, - ), - ) - // ...and occluding takes the *wheel* off - // the lane's bed with it (gpui stops the - // hit test at an occluder, ancestors - // included), so a notch aimed at a cut -- - // the one place a hand aims when it wants - // to see a cut closer -- would be a dead - // strip. The same answer as the bed's. - .on_scroll_wheel(cx.listener( - |this, event: &ScrollWheelEvent, _, cx| { - cx.stop_propagation(); - this.timeline_wheel(event, cx); - }, - )) - // Occluded, so the box's own right-button - // listener never fires here: the menu is - // the same menu, opened by the same call. - .on_mouse_down( - MouseButton::Right, - cx.listener( - move |this, event: &MouseDownEvent, _, cx| { - this.open_menu(lane, i, event.position, cx); - }, - ), - ); - zone = match edge { - Edge::Start => zone.left_0(), - Edge::End => zone.right_0(), - }; - zone - }), - ) - // Under the label row, never through it. - .children(wave.filter(|_| audio && vis_w > 0.).and_then(|wave| { - let inner: AnyElement = match wave { - Wave::Peaks(peaks) => { - waveform(peaks, from, to).into_any_element() - } - // A bed while the decode runs, and dimmer - // than any waveform is drawn: a flat - // `FG_SECONDARY` line here would be the shape a - // silent file makes, which this file is not - // known to be yet. - Wave::Loading => div() - .h_full() - .flex() - .items_center() - .child(div().w_full().h(px(1.)).bg(rgb(BG_HOVER()))) - .into_any_element(), - // No audio track: nothing, never a fake. - Wave::Silent => return None, - // Could not be read: a band that says so in - // words, because the empty band a silent - // file draws would claim this file has no - // sound. The reason itself went to the log. - Wave::Failed => div() - .h_full() - .flex() - .items_center() - .justify_center() - .truncate() - .text_size(px(9.)) - .text_color(rgb(FG_SECONDARY())) - .child("audio unreadable") - .into_any_element(), - }; - Some( - div() - .absolute() - .left(px(vis_x)) - .w(px(vis_w)) - .top(px(LABEL_H)) - .bottom_0() - .child(inner), - ) - })) - // The fades: a translucent wedge at each end an - // audio clip ramps, drawn over the waveform the way - // every editor shades a fade. Width comes straight - // off the clip's own frames, never off the visible - // slice -- unlike the waveform a wedge that starts - // off the left edge of the bed still shades the - // clip's own corner once scrolled back into view, - // because `overflow_hidden` on the box already - // clips it, and clamped to the box's own width so a - // fade longer than a zoomed-in clip never draws - // past its neighbour. - .when(audio, |d| { - let fade_in = self.shown_fade_in(lane, i, clip); - let fade_out = self.shown_fade_out(lane, i, clip); - d.children( - [ - (fade_in > 0).then(|| { - div() - .absolute() - .left_0() - .top_0() - .h_full() - .w(px(scale - .width_px(f64::from(fade_in) / self.fps) - .min(width))) - .child(fade_wedge(true)) - }), - (fade_out > 0).then(|| { - div() - .absolute() - .right_0() - .top_0() - .h_full() - .w(px(scale - .width_px(f64::from(fade_out) / self.fps) - .min(width))) - .child(fade_wedge(false)) - }), - ] - .into_iter() - .flatten(), - ) - }) - // The dissolve: a small X astride the join, drawn - // over the last `transition_out` frames of this - // clip's own box, whenever the next clip on the - // lane actually abuts it -- the engine already - // refuses `transition_out` on anything else - // ([`Project::set_transition_out`]), but a moved - // neighbour can leave a stale value behind, so - // this checks the join itself rather than trust - // the field alone. - .when( - lane.kind == LaneKind::Video - && clip.transition_out > 0 - && clips.get(i + 1).is_some_and(|n| n.start == clip.end()), - |d| { - d.child( - div() - .absolute() - .right_0() - .top_0() - .h_full() - .w(px(scale - .width_px(f64::from(clip.transition_out) / self.fps) - .min(width))) - .child(dissolve_glyph()), - ) - }, - ) - // The fade handles: a small grab corner at each - // *top* of an audio clip's box, sitting just - // inside the [`EDGE_W`] trim strip rather than on - // top of it -- [`FADE_HANDLE_H`] never reaches - // past the label row, so a trim's own strip (the - // box's *full* height) is still the whole of what - // a press below the label starts. Gated on - // [`trims`] like the trim strips themselves: a box - // too small for an edge to trim by is too small - // for a fade handle either. - .when(audio && trims(span), |d| { - d.children([Edge::Start, Edge::End].into_iter().map(|edge| { - let is_in = edge == Edge::Start; - let mut handle = div() - .absolute() - .top_0() - .w(px(FADE_HANDLE_W)) - .h(px(FADE_HANDLE_H)) - .occlude() - .cursor(CursorStyle::ResizeLeftRight) - .hover(|s| s.bg(rgb(ACCENT_PRIMARY()))) - .on_mouse_down( - MouseButton::Left, - cx.listener( - move |this, event: &MouseDownEvent, _, cx| { - this.start_fade_drag( - lane, - i, - is_in, - event.position.x, - cx, - ); - }, - ), - ); - handle = match edge { - Edge::Start => handle.left(px(EDGE_W)), - Edge::End => handle.right(px(EDGE_W)), - }; - handle - })) - }) - // A speeded clip says so on the box, in the corner - // the label does not reach: the box's width alone - // cannot say whether a short clip is a trim or a - // clip at 4x, and that is the difference between a - // cut and a re-time. - // Against the right edge of what is *visible* of the - // box, not of the box: zoomed in, the box's own - // right edge is off the screen and the badge with - // it, which is a clip that stops saying it is - // speeded exactly when it is being looked at - // closely. - .when(!clip.speed.is_normal() && vis_w > 0., |d| { - d.child( - div() - .absolute() - .top_0() - .left(px(vis_x)) - .w(px(vis_w)) - .flex() - .justify_end() - .overflow_hidden() - .child( - div() - .flex_none() - .px(px(3.)) - .rounded(px(3.)) - .bg(rgb(ACCENT_PRIMARY())) - .text_size(px(9.)) - .text_color(rgb(BG_RAISED())) - .child(format!("{}", clip.speed)), - ), - ) - }) - // ...and the name sits at the left edge of the same - // slice, for the same reason: a box scrolled half - // off names itself on the half that is on screen. - .when_some(label.filter(|_| show_label(vis_w)), |d, label| { - d.child( - div() - .absolute() - .top_0() - .left(px(vis_x)) - .w(px(vis_w)) - .h(px(LABEL_H)) - .px(px(4.)) - .truncate() - .text_size(px(10.)) - .child(label), - ) - }) - })) - // The same bed's other kind of box: a stretch of a palette - // track placed on this lane, dragged along it, dragged onto - // another subtitle lane, trimmed at either end, marked by a - // click and lifted off by the Delete row of its own menu or - // the stroke that row names -- the doors every other box on - // the bed has. Empty on every lane that is not a - // subtitle one, which is why there is one row and not two. - .children(subs.iter().enumerate().map(|(i, placed)| { - // What the drag payload names, and what an edge drag is - // *showing* -- the box moves under the pointer and the - // engine hears once, at the release. - let (placed, shown_sub) = (*placed, self.trimmed_sub(lane, i, *placed)); - let (start, len) = ( - f64::from(shown_sub.start) / self.fps, - f64::from(shown_sub.frames) / self.fps, - ); - let span = scale.width_px(len); - let width = clip_width(span); - let left = scale.px_at(start); - let (vis_x, vis_w) = visible_slice(left, width, bed); - // Which track's words these are, film and all: two - // "eng" tracks off two files read alike otherwise. - let label = self - .session - .as_ref() - .and_then(|session| sub_pick_name(session.subtitles(), placed.track)); - let ghost: SharedString = - label.clone().unwrap_or_else(|| lane.label()).into(); - let tip = sub_tip.clone(); - let head = shown_sub.start; - // Marked the way every other box on this bed is marked, - // in this lane's own index space -- and a caption in a - // group lights with the clips it was pinned to, exactly - // as a clip lights with its halves. - let on = marked((lane, i), placed.link, &picks, &pick_links); - // ...and wears the group's border rather than a lone - // box's, so what travels together reads together. - let grouped = placed.link.is_some_and(|link| others.contains(&link)); - div() - .id((row_id.clone(), i)) - .absolute() - .top_0() - .h_full() - .left(px(left)) - .w(px(width)) - .overflow_hidden() - .rounded(px(3.)) - .border_1() - .border_color(rgb(if on { - STROKE_SELECTED() - } else if grouped { - ACCENT_PRIMARY() - } else { - FG_SECONDARY() - })) - // A letterbox ground rather than the captions' own - // colour: the box itself is where a sentence starts - // and ends on the bed, and that is drawn by the cue - // blocks below, not by the box's own fill. Marked, - // it still takes the selection's colour, the same - // pair a marked clip takes -- what Delete will act - // on has one look on this bed and not two. - .bg(rgb(if on { BG_SELECTED() } else { BG_PANEL() })) - .when(!shown, |d| d.opacity(0.55)) - .cursor_pointer() - .hover(|s| s.border_color(rgb(ACCENT_PRIMARY()))) - .tooltip(move |_, cx| cx.new(|_| Tip(tip.clone())).into()) - .on_drag( - SubDrag { - lane, - idx: i, - sub: placed, - }, - move |_, _, _, cx| cx.new(|_| Tip(ghost.clone())), - ) - .on_mouse_down( - MouseButton::Left, - cx.listener(move |this, event: &MouseDownEvent, _, cx| { - // Where in the box the hand took hold, so - // the caption moves with the pointer rather - // than jumping its head under it. - this.grab = - this.frame_under(event.position.x).saturating_sub(head); - // ...and it marks the caption, exactly as - // the press that may become a clip's drag - // marks the clip: picking a caption up and - // putting it back down is a click. Ctrl - // toggles it into the selection like a clip. - this.pick((lane, i), event.modifiers.control, cx); - }), - ) - // A plain click collapses a multi-pick to this one - // caption, exactly as a clip's own box does above. - .on_click(cx.listener(move |this, event: &ClickEvent, _, cx| { - if !press_modifiers(event).control { - this.select((lane, i), cx); - } - })) - // The right button marks it and hangs the menu at - // the pointer, the clip menu opened on the clip - // box's own rule -- the Delete row of it is this - // caption's, and the rows a caption has no use for - // are not drawn ([`oracle::enable`]). - .on_mouse_down( - MouseButton::Right, - cx.listener(move |this, event: &MouseDownEvent, _, cx| { - this.open_menu(lane, i, event.position, cx); - }), - ) - // The rate the caption's own window plays at, off - // the placement itself: a re-timed group leaves it - // on the box even after the group comes apart, and - // the badge is the clip's badge -- same place, same - // look -- on the visible slice, for the clip's - // reason (zoomed in, the box's own edge is off the - // screen and a badge at it with it). - .when_some( - caption_rate(shown_sub, self.fps).filter(|_| vis_w > 0.), - |d, rate| { - d.child( - div() - .absolute() - .top_0() - .left(px(vis_x)) - .w(px(vis_w)) - .flex() - .justify_end() - .overflow_hidden() - .child( - div() - .flex_none() - .px(px(3.)) - .rounded(px(3.)) - .bg(rgb(ACCENT_PRIMARY())) - .text_size(px(9.)) - .text_color(rgb(BG_RAISED())) - .child(format!("{rate}")), - ), - ) - }, - ) - // The two strips a drag lengthens it by, on the same - // rule a clip's are drawn by ([`trims`]). - .children( - [Edge::Start, Edge::End] - .into_iter() - .filter(|_| trims(span)) - .map(|edge| { - let mut zone = div() - .absolute() - .top_0() - .h_full() - .w(px(EDGE_W)) - .occlude() - .cursor(CursorStyle::ResizeLeftRight) - .hover(|s| s.bg(rgb(ACCENT_PRIMARY()))) - .on_mouse_down( - MouseButton::Left, - cx.listener( - move |this, event: &MouseDownEvent, _, cx| { - this.start_trim( - lane, - i, - edge, - event.modifiers.control, - cx, - ); - }, - ), - ) - .on_scroll_wheel(cx.listener( - |this, event: &ScrollWheelEvent, _, cx| { - cx.stop_propagation(); - this.timeline_wheel(event, cx); - }, - )) - // Occluded, so the box's own - // right-button listener never fires - // here: the same menu, opened by the - // same call, exactly as a clip's - // edge strip does it. - .on_mouse_down( - MouseButton::Right, - cx.listener( - move |this, event: &MouseDownEvent, _, cx| { - this.open_menu(lane, i, event.position, cx); - }, - ), - ); - zone = match edge { - Edge::Start => zone.left_0(), - Edge::End => zone.right_0(), - }; - zone - }), - ) - // No name drawn on the box itself: the cue blocks - // now fill its full height, and a label sitting - // over them fights the very thing this box exists - // to show. The tooltip still carries the words - // (`sub_tip`), and the ghost while dragging still - // names the track (`ghost`, above). - // The way back off the lane is the way every other - // box takes: the Delete stroke on the marked caption - // and the Delete row of its own menu - // ([`Player::lift_sub`]). The × that used to sit - // here is gone with them -- it was drawn only where - // the box was wide enough to hold it, so the one - // removal a caption had was the one a zoomed-out - // caption did not have. - })) - // ...and where the words actually are inside those boxes: - // the cues this lane shows on *this* timeline, each its own - // full-height block over the letterbox ground, inset a - // pixel so the gap between two sentences is visible even - // when they sit back to back. A placement is a window of a - // track, so a box is not full of speech -- and a lane whose - // marks are all in its first half is a caption dragged too - // far, which is exactly what this shows. - .children(cues.into_iter().map(|(left, width)| { - div() - .absolute() - .top(px(1.)) - .bottom(px(1.)) - .left(px(left)) - .w(px(width)) - .rounded(px(2.)) - .bg(rgb(CLIP_TEXT())) - })) - // What the silence card found, over the clips it found them - // in and over the waveform band that shows why: on the lane - // the scan ran on and no other, because that is the only - // lane whose sound was read. Drawn before anything is cut, - // and replaced -- never stacked -- by every re-run. - .children( - self.silence_marks - .iter() - .filter(|_| self.silence_open.is_some_and(|(on, _)| on == lane)) - .map(|&(at, len)| { - div() - .absolute() - .top_0() - .h_full() - .left(px(scale.px_at(f64::from(at) / self.fps))) - // Floored like a cue's mark and for the same - // reason: a half-second silence on a zoomed- - // out bed rounds to nothing, and a preview - // that draws nothing reads as a scan that - // found nothing. - .w(px(scale - .width_px(f64::from(len) / self.fps) - .max(SUB_CUE_MIN_W))) - .bg(rgba(ACCENT_WASH())) - }), - ) - // Where the thing in the hand would come to rest, at the size - // it would come to rest at: the shadow a proper editor draws - // under a drag. Over the clips (it is translucent, so what - // it would cover shows through) and under the line, which - // marks the frame this box merely fills. - .children(ghost.into_iter().map(|g| { - div() - .absolute() - .top_0() - .h_full() - .left(px(scale.px_at(f64::from(g.start) / self.fps))) - // A row whose length the engine has not measured - // draws a head marker rather than nothing: where it - // lands is known, how long it is is not. - .w(px(scale - .width_px(f64::from(g.frames) / self.fps) - .max(GHOST_MIN))) - .rounded(px(3.)) - .border_1() - .border_color(rgb(if g.refused { - DROP_REFUSE() - } else { - FG_PRIMARY() - })) - // The file's own swatch at a third of its weight, so - // the box beneath is still legible through it -- and - // the refusal red instead, for a lane that will not - // take this drop at all. - .bg(rgba( - ((if g.refused { DROP_REFUSE() } else { g.tint }) << 8) - | GHOST_ALPHA, - )) - })) - // What the gesture in flight is about to land on, drawn on - // every lane so a clip lining up with a take one track over - // can be seen to line up with it. Under the playhead's line - // and in another colour, since the two mean different - // things and often stand on the same pixel. - .children(cue.map(|x| { - div() - .absolute() - .top_0() - .h_full() - .left(px(x)) - .w(px(1.)) - .bg(rgb(FG_PRIMARY())) - })) - // Last, so it is over the clips: the same fraction in both - // lanes, which is the playhead being one line. - .child( - div() - .absolute() - .top_0() - .h_full() - .left(px(filled)) - .w(px(2.)) - .bg(rgb(ACCENT_PLAYHEAD())), - ), - ) - // The drop indicator, last of all so it is over the header and the - // bed both: a line along the edge the track in the hand comes in - // at, which is the slot the release commits to. *Inside* the row - // rather than in the gutter between two, because the lane column - // scrolls ([`Player::lanes_scroll`]) and anything drawn past the - // first row's top edge is clipped away by it -- an indicator that - // vanished on exactly the drop everybody tries first. - .children(drop.map(|d| { - let line = div() - .absolute() - .left_0() - .w_full() - .h(px(3.)) - .bg(rgb(ACCENT_PRIMARY())); - match d.above { - true => line.top_0(), - false => line.bottom_0(), - } - })) - } -} diff --git a/crates/app/src/ui/toolbar.rs b/crates/app/src/ui/toolbar.rs deleted file mode 100644 index c9fbbcd..0000000 --- a/crates/app/src/ui/toolbar.rs +++ /dev/null @@ -1,539 +0,0 @@ -//! The three rows of chrome: the top bar over everything, the transport strip -//! under the picture, and the edit toolbar directly above the timeline. -//! -//! Every button in all three comes out of [`Player::action_control`], which -//! asks the one availability oracle whether the action can happen at all. That -//! is the whole point of this module existing: the toolbar used to decide with -//! ad-hoc booleans (`live && self.selected.is_some()`) while the keyboard asked -//! nobody, so with no file open Snap and `+ V` were dimmed *and dead* to the -//! pointer while the very same actions still fired from the keys. One oracle, -//! two doors -- if the key fires, the button fires. - -use crate::ui::widgets::*; -use crate::*; - -impl Player { - /// A toolbar button for `action`: enabled exactly when [`enable`] says the - /// action can happen, dimmed with the oracle's own reason in its tooltip - /// when it cannot, and firing the same call the key fires when it can. - /// - /// `w` is the rect the label lives in. It is reserved once and never - /// changes with state, so Play/Pause, Snap/No snap and Export/Cancel swap - /// their words and their colour inside a box that does not move -- the - /// complaint that started this redesign ("even button positions are - /// changing according to its state"). - pub(crate) fn action_control( - &self, - id: &'static str, - w: f32, - bg: u32, - glyph: Option, - label: impl Into, - hint: &str, - action: ActionId, - on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static, - ) -> impl IntoElement { - let enabled = self.enable(action, None); - let key = self.keymap.display(action); - // The dimmed button says *why* in the oracle's own words -- the same - // string the key answers with, so the tooltip and the notice cannot - // come to differ. - let say = match enabled.why() { - Some(why) => format!("{key} — {why}"), - None => format!("{key} — {hint}"), - }; - control(id, w, bg, glyph, label, say, enabled.yes(), on_click) - } - - /// The bar over everything: what is open on the left, the two actions that - /// write a file on the right. Export is the one accented button in the - /// window -- the primary action of an editor, where every consumer editor - /// puts it -- and it keeps its rect while it is a Cancel. - pub(crate) fn topbar(&self, _window: &mut Window, cx: &mut Context) -> impl IntoElement { - let exporting = self.exporting().is_some(); - // This button's own row is part of the chrome player fullscreen - // hides, so once it reads true the button is already off screen -- - // F11 or Escape is what a person actually leaves by, which is why the - // hint below names both. - let fullscreen = self.player_fullscreen; - div() - .flex_none() - .h(px(TOPBAR_H)) - .flex() - .items_center() - .gap(px(8.)) - .px(px(12.)) - .bg(rgb(BG_PANEL())) - .border_b_1() - .border_color(rgb(STROKE_DIVIDER())) - .child( - div() - .flex_none() - .w(px(10.)) - .h(px(10.)) - .rounded(px(2.)) - .bg(rgb(ACCENT_PRIMARY())), - ) - .child( - div() - .flex_1() - .min_w(px(0.)) - .truncate() - .child(self.name.clone()), - ) - // The window's own control, in the fixed rect the mute button uses - // for the same reason (toolbar.rs:194-203): fullscreen swaps the - // word and the colour, never the box. - .child(self.action_control( - "fullscreen", - 0., - BG_RAISED(), - None, - match fullscreen { - true => "Exit fullscreen", - false => "Fullscreen", - }, - "fills the screen with the picture; F11 or Escape gives it back", - ActionId::Fullscreen, - cx.listener(|this, _: &ClickEvent, window, cx| { - this.act(ActionId::Fullscreen, window, cx) - }), - )) - .child(self.action_control( - "save", - 0., - BG_RAISED(), - None, - "Save", - "writes the project file", - ActionId::Save, - cx.listener(|this, _: &ClickEvent, _, cx| this.save_project(cx)), - )) - // One rect, two states: exporting swaps the word and the colour, - // never the box. `the_export_button_never_moves` is the guard. - .child( - div() - .flex_none() - .w(px(EXPORT_SLOT_W)) - .child(self.action_control( - "export", - EXPORT_SLOT_W, - // The one accented button in the window: the primary - // action of an editor, where every consumer editor puts - // it. Cancel keeps the rect and the accent both. - ACCENT_PRIMARY(), - None, - if exporting { "Cancel" } else { "Export" }, - if exporting { - "stops the export; the part-written file goes" - } else { - "quality and destination, then writes the timeline out" - }, - if exporting { - ActionId::CancelExport - } else { - ActionId::Export - }, - cx.listener(|this, _: &ClickEvent, _, cx| { - if this.exporting().is_some() { - this.cancel_export(); - cx.notify(); - } else { - this.open_export(cx); - } - }), - )), - ) - } - - /// The player's own strip, under the picture and over the timeline: the - /// transport, the clock, and the level. Where a consumer editor puts them, - /// and the reason the edit toolbar below is nothing but edit tools. - pub(crate) fn transport_bar( - &self, - state: Transport, - viewport: Size, - cx: &mut Context, - ) -> impl IntoElement { - let muted = self.volume.muted; - // The room this strip actually has: the window less the two side - // panels. At the 640 px floor that is ~300 px, which the clock and the - // level together do not fit -- so the level's *bar* stands down (its - // button, its keys and its row on the actions card all remain), and - // the clock keeps a narrower rect rather than being pushed off. - // The two panels as they are *now*, dividers and all: a room worked out - // from the window's own shares would go stale the moment a seam moved, - // and the clock would be sized for a column that is no longer there. - let room = f32::from(viewport.width) - - self.split_px(Split::Library, viewport) - - self.split_px(Split::Inspector, viewport) - - 2. * SPLIT_W; - let clock_w = TIME_W.min(room - 140.).max(96.); - let slider = room >= TRANSPORT_ROOMY; - // Which window the loop button actually restarts, in the same - // priority [`active_loop_window`] picks it in: the marked i/o range - // once something is armed, the subject-cut trim next, the whole - // timeline last. - let armed = self.loop_on || self.loop_trim.is_some(); - let loop_hint = if armed && self.range.is_some() { - "restarts from the marked in point on reaching the marked out point, instead of stopping" - } else if self.loop_trim.is_some() { - "restarts from the subject cut's own start on reaching its end, instead of stopping" - } else { - "restarts from the top on reaching the end, instead of stopping" - }; - div() - .flex_none() - .h(px(TRANSPORT_H)) - .flex() - .items_center() - .gap(px(8.)) - .px(px(12.)) - .bg(rgb(BG_PANEL())) - .border_t_1() - .border_color(rgb(STROKE_DIVIDER())) - .child(self.action_control( - "screenshot", - 0., - BG_RAISED(), - None, - "Shot", - "saves the frame on screen as a PNG in ~/Pictures/edith", - ActionId::Screenshot, - cx.listener(|this, _: &ClickEvent, _, cx| this.take_screenshot(cx)), - )) - .child(self.action_control( - "transport", - 40., - BG_RAISED(), - Some(transport_glyph(state).into_any_element()), - "", - "plays and pauses the timeline", - ActionId::Play, - cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_or_restart(cx)), - )) - // Accented while on, the box the export button and the mute glyph - // both use for a state rather than a click: the pump reads - // `loop_on` itself at the one place it already knows the end was - // reached ([`Player::pump`]). - .child(self.action_control( - "loop", - 0., - match self.loop_on { - true => ACCENT_PRIMARY(), - false => BG_RAISED(), - }, - None, - "Loop", - loop_hint, - ActionId::Loop, - cx.listener(|this, _: &ClickEvent, window, cx| { - this.act(ActionId::Loop, window, cx) - }), - )) - // One line, one fixed width: changing digits must not push the - // strip around, and the clock is the one number that changes - // sixty times a second. - .child( - div() - .flex_none() - .w(px(clock_w)) - .truncate() - .text_color(rgb(FG_PRIMARY())) - .child(format!( - "{} / {}", - timecode( - self.active_session().map_or(0., PlaybackSession::now), - self.active_fps() - ), - timecode( - self.active_session() - .map_or(0., PlaybackSession::timeline_duration), - self.active_fps() - ) - )), - ) - .child(div().flex_1().min_w(px(0.))) - // The level as a number in its own rect, so muting swaps a glyph - // and a colour rather than relabelling the button "Muted 80%" and - // shoving the slider beside it along. - .child(self.action_control( - "volume", - VOLUME_SLOT_W, - BG_RAISED(), - None, - // The level is the label either way and it lives in a fixed - // rect: muting adds a mark and changes the colour, where it - // used to relabel the button "Muted 80%" and shove the slider - // beside it along the row. - match muted { - true => format!("× {}%", self.volume.percent()), - false => format!("{}%", self.volume.percent()), - }, - "mutes and unmutes; the level is what it comes back to", - ActionId::ToggleMute, - cx.listener(|this, _: &ClickEvent, _, cx| { - this.set_volume(|volume| volume.muted = !volume.muted, cx) - }), - )) - .text_color(rgb(match muted { - true => STATUS_WARNING(), - false => FG_PRIMARY(), - })) - .when(slider, |d| { - d.child(volume_slider( - self.volume, - self.volume_bar.clone(), - self.enable(ActionId::ToggleMute, None).yes(), - cx, - )) - }) - } - - /// The edit toolbar, directly above the timeline it acts on: split, delete, - /// undo, the tracks, the magnet and the zoom -- the arrangement Movavi and - /// CapCut share, and nothing in it that is not an edit or a way of looking - /// at one. - /// - /// The row scrolls rather than losing its tail at the 640 px floor, and the - /// door to everything scrolled off it is pinned outside the scrolling box: - /// "it scrolls" is not "it can be found" (`toolbar_fits_the_smallest_window`). - pub(crate) fn toolbar(&self, cx: &mut Context) -> impl IntoElement { - let exporting = self.exporting().is_some(); - div() - .flex_none() - .h(px(TOOLBAR_H)) - .flex() - .items_center() - .gap(px(8.)) - .px(px(12.)) - .bg(rgb(BG_PANEL())) - .border_t_1() - .border_color(rgb(STROKE_DIVIDER())) - .child( - div() - .id("controls") - .flex_1() - .min_w(px(0.)) - .flex() - .items_center() - .gap(px(8.)) - .overflow_x_scroll() - .child(group_label("Edit")) - .child(self.action_control( - "cut", - 0., - BG_RAISED(), - Some(cut_glyph().into_any_element()), - "Split", - "splits the clip under the playhead", - ActionId::Cut, - cx.listener(|this, _: &ClickEvent, _, cx| this.cut(cx)), - )) - .child(self.action_control( - "delete", - 0., - BG_RAISED(), - Some(delete_glyph().into_any_element()), - "Delete", - "takes the marked clip off the timeline", - ActionId::Delete, - cx.listener(|this, _: &ClickEvent, _, cx| this.delete_selected(cx)), - )) - .child(self.action_control( - "undo", - 0., - BG_RAISED(), - None, - "Undo", - "takes the last edit back", - ActionId::Undo, - cx.listener(|this, _: &ClickEvent, _, cx| this.undo(cx)), - )) - .child(self.action_control( - "redo", - 0., - BG_RAISED(), - None, - "Redo", - "brings the undone edit back", - ActionId::Redo, - cx.listener(|this, _: &ClickEvent, _, cx| this.redo(cx)), - )) - .child(separator()) - .child(group_label("Track")) - .child(self.action_control( - "add-video-lane", - 0., - BG_RAISED(), - None, - "+ V", - "adds a video track under the ones there", - ActionId::AddVideoLane, - cx.listener(|this, _: &ClickEvent, _, cx| { - this.add_lane(LaneKind::Video, cx) - }), - )) - .child(self.action_control( - "add-audio-lane", - 0., - BG_RAISED(), - None, - "+ A", - "adds an audio track under the ones there", - ActionId::AddAudioLane, - cx.listener(|this, _: &ClickEvent, _, cx| { - this.add_lane(LaneKind::Audio, cx) - }), - )) - .child(self.action_control( - "add-subtitle-lane", - 0., - BG_RAISED(), - None, - "+ C", - "adds a subtitle track under the ones there", - ActionId::AddSubtitleLane, - cx.listener(|this, _: &ClickEvent, _, cx| { - this.add_lane(LaneKind::Subtitle, cx) - }), - )) - .child(separator()) - .child(group_label("View")) - // Both toggles keep a rect of their own: the label is the - // state, and a state that resized its own button is what - // made the row shuffle every time it was pressed. - .child(self.action_control( - "snap", - SNAP_SLOT_W, - BG_RAISED(), - None, - if self.snap { "Snap on" } else { "Snap off" }, - match self.snap { - true => { - "drags and trims land on clip edges, the playhead and the start" - } - false => "drags and trims land exactly where the hand leaves them", - }, - ActionId::ToggleSnap, - cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_snap(cx)), - )) - .child(self.action_control( - "subs", - SNAP_SLOT_W, - BG_RAISED(), - None, - match (self.placed_captions() > 0, self.subs_on) { - (false, _) => "No subs", - (true, true) => "Subs on", - (true, false) => "Subs off", - }, - "draws the cue under the playhead over the picture", - ActionId::ToggleSubtitles, - cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_subtitles(cx)), - )) - .child(self.action_control( - "theme", - THEME_SLOT_W, - BG_RAISED(), - None, - format!("Theme: {}", crate::ui::theme::active().label()), - "the colours this window is painted in; kept in ~/.config/edith/theme", - ActionId::Theme, - cx.listener(|this, event: &ClickEvent, _, cx| { - this.open_picker(Pick::Theme, event.position(), cx) - }), - )) - .child(separator()) - .child(self.action_control( - "zoom-out", - CONTROL_H, - BG_RAISED(), - None, - "−", - "show more of the timeline; stops with all of it on the bed", - ActionId::ZoomOut, - cx.listener(|this, _: &ClickEvent, _, cx| { - this.zoom(1. / ZOOM_STEP, None, cx) - }), - )) - .child(self.action_control( - "zoom-fit", - ZOOM_SLOT_W, - BG_RAISED(), - None, - span_label(self.view().span()), - "fit the whole timeline on the bed", - ActionId::ZoomFit, - cx.listener(|this, _: &ClickEvent, _, cx| this.zoom_fit(cx)), - )) - .child(self.action_control( - "zoom-in", - CONTROL_H, - BG_RAISED(), - None, - "+", - "magnify around the playhead; ctrl+wheel over the timeline zooms at the \ - pointer, and a bare wheel scrolls it", - ActionId::ZoomIn, - cx.listener(|this, _: &ClickEvent, _, cx| this.zoom(ZOOM_STEP, None, cx)), - )) - .child(self.action_control( - "keys", - 0., - BG_RAISED(), - None, - "Actions", - "do any action, or change the key that does it", - ActionId::ShowActions, - cx.listener(|this, _: &ClickEvent, _, cx| match this.keys_open { - true => { - this.keys_open = false; - this.rebinding = None; - cx.notify(); - } - false => this.show_actions(cx), - }), - )), - ) - // The door to everything the row cannot show at this window, pinned - // where a scroll cannot take it. - .child(control( - "controls-more", - CONTROL_H, - BG_RAISED(), - None, - "⋯", - format!( - "{} — every action, including the ones scrolled off this row", - self.keymap.display(ActionId::ShowActions) - ), - !exporting, - cx.listener(|this, _: &ClickEvent, _, cx| match this.keys_open { - true => { - this.keys_open = false; - this.rebinding = None; - cx.notify(); - } - false => this.show_actions(cx), - }), - )) - } -} - -/// The rects the stateful buttons live in. Wide enough for the longest word -/// each of them can say, so the swap happens inside the box. -pub(crate) const EXPORT_SLOT_W: f32 = 76.; -pub(crate) const SNAP_SLOT_W: f32 = 76.; -pub(crate) const ZOOM_SLOT_W: f32 = 76.; -pub(crate) const VOLUME_SLOT_W: f32 = 76.; -/// The HDR rendition's names are the longest words on any button here. -pub(crate) const TONE_SLOT_W: f32 = 148.; -/// "Theme: " and the longest palette name: a fixed rect like the two toggles -/// beside it, so picking a palette repaints the button without moving the ones -/// after it. -pub(crate) const THEME_SLOT_W: f32 = 96.; - -/// The width the transport strip needs before the level's bar fits beside the -/// clock: play + clock + the mute button + the bar, in their gaps. -pub(crate) const TRANSPORT_ROOMY: f32 = 460.; diff --git a/crates/app/src/ui/widgets.rs b/crates/app/src/ui/widgets.rs index e5f16f8..9010cf4 100644 --- a/crates/app/src/ui/widgets.rs +++ b/crates/app/src/ui/widgets.rs @@ -2,13 +2,6 @@ use crate::*; -/// One clip's audio, drawn as a filled min/max envelope inside whatever box it -/// is given. Peaks are the source's whole envelope; `from`/`to` are the source -/// seconds this clip plays, so a cut clip shows its own stretch of the file. -pub(crate) fn waveform(peaks: Arc>, from: f64, to: f64) -> impl IntoElement { - waveform_ink(peaks, from, to, FG_SECONDARY()) -} - /// `ClickEvent::modifiers()` answers the mouse-*up* modifiers (gpui-0.2.2 /// `interactive.rs`), so releasing ctrl before the button lands undoes a /// ctrl-held toggle decided on mouse-down. This reads the *press* modifiers @@ -203,79 +196,6 @@ pub(crate) fn control( /// colour sliders both make. Only the level -- mute is the button beside it, so /// a muted slider still shows what unmuting comes back to, drawn dim. /// -/// Dimmed and inert without a timeline, like every other control that would -/// have nothing to act on. -pub(crate) fn volume_slider( - volume: Volume, - bar: Rc>>, - enabled: bool, - cx: &mut Context, -) -> impl IntoElement { - div() - .id("volume-bar") - .relative() - .flex_none() - .w(px(VOLUME_W)) - .h(px(CONTROL_H)) - .flex() - .items_center() - .tooltip(|_, cx| { - cx.new(|_| Tip("Volume — drag to set the level; the button mutes".into())) - .into() - }) - .when(!enabled, |d| d.opacity(0.4).cursor_not_allowed()) - .when(enabled, |d| { - d.cursor_pointer() - .on_mouse_down( - MouseButton::Left, - cx.listener(|this, event: &MouseDownEvent, _, cx| { - this.volume_dragging = true; - this.drag_volume(event.position.x, cx); - }), - ) - .child(bounds_probe(bar)) - }) - .child( - div() - .w_full() - .h(px(4.)) - .rounded(px(2.)) - .bg(rgb(BG_RAISED())) - .child( - div() - .h_full() - .w(relative(volume.along())) - .rounded(px(2.)) - .bg(rgb(if volume.muted { - FG_SECONDARY() - } else { - ACCENT_PRIMARY() - })), - ), - ) -} - -/// The line between two groups of buttons. -/// What a group of buttons is *for*, printed in front of it. A toolbar of -/// twelve unlabelled boxes is a toolbar nobody reads twice; three named groups -/// are three things to skip. -pub(crate) fn group_label(name: &'static str) -> impl IntoElement { - div() - .flex_none() - .text_size(px(10.)) - .text_color(rgb(FG_SECONDARY())) - .child(name) -} - -pub(crate) fn separator() -> impl IntoElement { - div() - .flex_none() - .mx(px(4.)) - .w(px(1.)) - .h(px(18.)) - .bg(rgb(BG_HOVER())) -} - /// Whether a card or a menu is drawn over the window, as the hover labels see /// it: written once a frame by [`Player::render`], read by every [`Tip`] before /// it paints. @@ -352,39 +272,6 @@ impl Render for OverlayTip { } } -/// Scissors: two blades crossed. Drawn this way and not as a split clip because -/// two bars is what the transport wears when it is playing -- the one glyph a -/// cut must never be mistaken for. -pub(crate) fn cut_glyph() -> impl IntoElement { - canvas( - |_, _, _| (), - |bounds, _, window, _| { - let (o, s) = (bounds.origin, bounds.size); - let mut path = PathBuilder::stroke(px(1.5)); - path.move_to(point(o.x + s.width * 0.15, o.y + s.height)); - path.line_to(point(o.x + s.width * 0.9, o.y + s.height * 0.1)); - path.move_to(point(o.x + s.width * 0.85, o.y + s.height)); - path.line_to(point(o.x + s.width * 0.1, o.y + s.height * 0.1)); - if let Ok(path) = path.build() { - window.paint_path(path, rgb(FG_PRIMARY())); - } - }, - ) - .w(px(13.)) - .h(px(13.)) -} - -/// A lid over a bin. -pub(crate) fn delete_glyph() -> impl IntoElement { - div() - .flex() - .flex_col() - .items_center() - .gap(px(2.)) - .child(div().w(px(13.)).h(px(2.)).bg(rgb(FG_PRIMARY()))) - .child(div().w(px(9.)).h(px(9.)).bg(rgb(FG_PRIMARY()))) -} - /// What a window with no file open is waiting for. Both ways in are already /// built -- the whole window is the drop target and the Import chooser takes a /// project as readily as media -- so this only has to say so. @@ -402,39 +289,3 @@ pub(crate) fn empty_hint() -> impl IntoElement { .child("or click Import in the media list"), ) } - -/// Two bars while playing, a triangle in every other state -- paused, nothing -/// open, and played out, where the button's next act is to start over rather -/// than to stop something. Drawn, so there is no icon font and no glyph -/// coverage to depend on. -pub(crate) fn transport_glyph(state: Transport) -> impl IntoElement { - let playing = state.is_playing(); - div() - .flex() - .items_center() - .gap(px(4.)) - .when(playing, |d| { - d.child(div().w(px(3.)).h(px(12.)).bg(rgb(FG_PRIMARY()))) - .child(div().w(px(3.)).h(px(12.)).bg(rgb(FG_PRIMARY()))) - }) - .when(!playing, |d| { - d.child( - canvas( - |_, _, _| (), - |bounds, _, window, _| { - let (o, s) = (bounds.origin, bounds.size); - let mut path = PathBuilder::fill(); - path.move_to(o); - path.line_to(point(o.x + s.width, o.y + s.height / 2.)); - path.line_to(point(o.x, o.y + s.height)); - path.close(); - if let Ok(path) = path.build() { - window.paint_path(path, rgb(FG_PRIMARY())); - } - }, - ) - .w(px(11.)) - .h(px(13.)), - ) - }) -} diff --git a/crates/app/src/viewport.rs b/crates/app/src/viewport.rs index effcf39..db7b5e9 100644 --- a/crates/app/src/viewport.rs +++ b/crates/app/src/viewport.rs @@ -2,21 +2,6 @@ use crate::*; -/// What the zoom button says it is showing: how much timeline fits on the bed, -/// in the coarsest unit that still tells two zooms apart. -pub(crate) fn span_label(span: f64) -> String { - match span { - s if !s.is_finite() || s <= 0. => "—".to_string(), - // Hours once a timeline is long enough to be measured in them: the far - // stop follows the content now, so "315m" is a span a user can be sat - // at, and no one reads a pill in minutes past sixty. - s if s >= 3600. => format!("{:.1}h", s / 3600.), - s if s >= 600. => format!("{:.0}m", s / 60.), - s if s >= 60. => format!("{:.1}m", s / 60.), - s if s >= 10. => format!("{s:.0}s"), - s => secs_label(s), - } -} /// A span of seconds as a person reads it: one decimal above a second, two /// below -- [`scaled`]'s rule, for its reason. The tightest zoom is