From 2ae5c26e6a988d0248af73025accb6a8bf8fca2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 12 Aug 2026 20:44:18 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(ui):=20four=20regions,=20one?= =?UTF-8?q?=20oracle,=20one=20token=20table?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Library left, picture centre with its own transport strip, inspector right, timeline full width along the bottom with the edit toolbar directly above it -- the arrangement Movavi and CapCut share. The settings cards are docked in the inspector, so adjusting a clip no longer hides the clip. Every button asks the one availability oracle, and so does act(): with no file open the toolbar used to be dim and dead to the pointer while the very same actions still fired from the keyboard. Snap, mute and the volume keys answer with nothing open, in both doors, and everything else dims with the oracle's own reason in its tooltip. Clips are painted by kind (video blue, audio green, still teal, cues purple) on a near-black ground with one cyan accent, and every stateful button keeps a rect that does not change with its state. --- crates/app/src/main.rs | 334 +++++++++++++++-------- crates/app/src/ui/cards.rs | 16 +- crates/app/src/ui/inspector.rs | 273 +++++++++++++++++++ crates/app/src/ui/library.rs | 2 + crates/app/src/ui/overlays.rs | 3 + crates/app/src/ui/theme.rs | 2 +- crates/app/src/ui/timeline.rs | 475 +++------------------------------ crates/app/src/ui/toolbar.rs | 392 +++++++++++++++++++++++++++ crates/app/src/ui/widgets.rs | 9 +- 9 files changed, 949 insertions(+), 557 deletions(-) diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index fe14af0..230dca9 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -1,7 +1,9 @@ mod keymap; mod ui; +use ui::inspector::section_head; use ui::theme::*; +use ui::toolbar::{EXPORT_SLOT_W, SNAP_SLOT_W, VOLUME_SLOT_W, ZOOM_SLOT_W}; use ui::widgets::*; use keymap::{ActionId, Keymap}; @@ -277,6 +279,12 @@ impl Volume { f32::from(self.steps) / f32::from(Self::MAX_STEPS) } + /// The level as a whole number, for the button's fixed rect: muting swaps + /// the glyph beside it, never the width of the box. + fn percent(self) -> u32 { + u32::from(self.steps) * 100 / u32::from(Self::MAX_STEPS) + } + /// What the button reads. The level shows while muted too: it is what the /// next press of the mute key brings back. fn label(self) -> String { @@ -1559,6 +1567,18 @@ impl Player { /// menu item that names the same action. One table, so the two can never /// come to mean different things. fn act(&mut self, action: ActionId, cx: &mut Context) { + // Two doors, one oracle. This used to be the asymmetry the whole + // toolbar was built on: the buttons dimmed themselves off + // [`enable`] while the keyboard walked straight past it, so with no + // file open `s` toggled the snap and `v` added a track while the very + // same controls sat dim and *dead* to the pointer. Whatever refuses the + // button refuses the key, in the oracle's own words -- and a refusal + // that is silent from the keyboard is a bug the same size. + if let Some(why) = self.enable(action, None).why() { + self.notice = Some(format!("{} — {why}", action.label()).into()); + cx.notify(); + return; + } match action { ActionId::Play => self.toggle_or_restart(cx), ActionId::StepBack => self.step(-1, cx), @@ -1726,6 +1746,7 @@ impl Player { timeline: true, clipboard: self.clipboard.is_some(), subtitles: !session.subtitles().is_empty(), + playable: !nothing_to_play(Some(session)), exporting: self.exporting().is_some(), } } @@ -5716,21 +5737,14 @@ impl Render for Player { .flex_col() .bg(rgb(BG_CANVAS)) .text_color(rgb(FG_PRIMARY)) - .text_size(px(13.)) - .child( - div() - .flex_none() - .h(px(HEADER_H)) - .flex() - .items_center() - .px(px(12.)) - .bg(rgb(BG_PANEL)) - .child(self.name.clone()), - ) - // The library beside the picture rather than under it: a media pool - // is a column in every editor that has one, and the timeline below - // already owns the full width. `library_w` is what keeps the - // picture the majority of the row at every window size. + .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. + .child(self.topbar(cx)) .child( div() .flex_1() @@ -5745,40 +5759,54 @@ impl Render for Player { div() .flex_1() .min_w(px(0.)) - .overflow_hidden() - // The bed the cue plate is placed against: it hangs - // off the bottom of the picture region, which is the - // one box that is the picture and nothing else. - .relative() .flex() - .justify_center() - .items_center() - .children( - self.image - .clone() - .map(|i| { - img(i) - .size_full() - .object_fit(gpui::ObjectFit::Contain) - .into_any_element() - }) - // With no file open the letterbox is the - // whole window, and a black rectangle says - // only that something is broken -- so it - // says what it wants instead. The window is - // already the drop target. - .or_else(|| { - self.session - .is_none() - .then(|| empty_hint().into_any_element()) - }), + .flex_col() + .child( + div() + .flex_1() + .min_h(px(0.)) + .overflow_hidden() + // The bed the cue plate is placed against: + // it hangs off the bottom of the picture + // region, which is the one box that is the + // picture and nothing else. + .relative() + .flex() + .justify_center() + .items_center() + .bg(rgb(BG_CANVAS)) + .children( + self.image + .clone() + .map(|i| { + img(i) + .size_full() + .object_fit(gpui::ObjectFit::Contain) + .into_any_element() + }) + // With no file open the letterbox + // is the whole region, and a black + // rectangle says only that + // something is broken -- so it says + // what it wants instead. The window + // is already the drop target. + .or_else(|| { + self.session + .is_none() + .then(|| empty_hint().into_any_element()) + }), + ) + // After the picture, so the plate is drawn + // over it rather than under. + .children(self.subtitle_overlay(position, window)), ) - // After the picture, so the plate is drawn over it - // rather than under: siblings paint in order. - .children(self.subtitle_overlay(position, window)), - ), + .child(self.transport_bar(position, state, 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 panel and only when there is one to show, so it costs + // Above the toolbar and only when there is one to show, so it costs // the picture nothing the rest of the time. The import's line sits // over the notice's: a notice is about something that has already // happened, and this is about something still happening. @@ -5787,25 +5815,19 @@ impl Render for Player { // loud because a still picture is the only other evidence of it. .children(self.seek_bar()) .children(self.notice_bar(cx)) - .child(self.panel(position, duration, state, cx)) - // Over the panel it was opened on, and under the cards: it is only - // ever up while neither of them is (`modal`). + .child(self.toolbar(cx)) + .child(self.timeline(position, duration, state, 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)) - // The library's own menu, the same way and for the same reason: - // over the panel it was opened on, under the cards, and never up - // while one of them is. .children(self.library_card(window.viewport_size(), cx)) - // Last, so they are over everything -- they take no room in the - // column, and only one of the two is ever up. + // 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)) - .children(self.eq_card(window.viewport_size(), cx)) - .children(self.color_card(cx)) - .children(self.speed_card(cx)) - .children(self.silence_card(cx)) - .children(self.mix_card(cx)) - // Last, so it floats over whatever opened it -- the panel's button - // or a clip menu -- rather than under it. + // 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)) } } @@ -6719,6 +6741,10 @@ struct Ctx { /// This timeline has at least one subtitle track: a toggle with nothing to /// show is a switch that does nothing, and it says so rather than flipping. subtitles: bool, + /// There is something on the lanes to play. A transport with nothing under + /// it is the one refusal that is about the timeline's contents rather than + /// about a clip. + playable: bool, exporting: bool, } @@ -6739,6 +6765,18 @@ fn enable(action: ActionId, ctx: Ctx) -> Enable { false => Enable::Yes, }; } + // The four that are about the *editor* and its monitoring rather than + // about the edit list: they work with nothing open, the keyboard has + // always fired them there, and so their buttons are live there too. + if matches!( + action, + ActionId::ToggleSnap | ActionId::ToggleMute | ActionId::VolumeUp | ActionId::VolumeDown + ) { + return match ctx.exporting { + true => Enable::No("an export is running"), + false => Enable::Yes, + }; + } if !ctx.timeline { return Enable::No("no timeline open"); } @@ -6819,6 +6857,10 @@ fn enable(action: ActionId, ctx: Ctx) -> Enable { Enable::No("no subtitles yet") } ActionId::CancelExport => Enable::No("nothing is exporting"), + // A clock started against an empty timeline is a clock counting + // nothing: the transport says so by being dim, which is what its own + // ad-hoc boolean used to say before the oracle knew the question. + ActionId::Play if !ctx.playable => Enable::No("put a clip on a lane first"), // A rate applies to a clip of either kind and to its whole group, so // there is no lane it means nothing on, and the engine words the one // refusal there is (no room). Everything else is the editor's own and @@ -8191,6 +8233,25 @@ fn panel_h(lanes: usize) -> f32 { PANEL_H + lanes_h(lanes.clamp(2, LANES_MAX)) - lanes_h(2) } +/// ...and how tall the timeline region alone is: the panel without the button +/// row that used to sit inside it, which is now its own region above +/// ([`Player::toolbar`], [`TOOLBAR_H`]). +fn timeline_h(lanes: usize) -> f32 { + panel_h(lanes) - TOOLBAR_H +} + +/// The edit toolbar directly above the timeline: one control's height in its +/// own padding, fixed so nothing in it can push the timeline down. +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. +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. +const TRANSPORT_H: f32 = CONTROL_H + 12.; + /// One press of a zoom key, or one notch of ctrl+wheel. const ZOOM_STEP: f32 = 1.25; @@ -9405,6 +9466,26 @@ mod tests { use std::path::{Path, PathBuf}; use std::time::{Duration, Instant}; + /// Every line of UI source there is, as one string: the window used to be + /// one file and the scans below read it with `include_str!`. The regions + /// are modules now (`ui/`), so the scans read all of them -- a rule that + /// stopped at `main.rs` would pass by simply not looking where the pixels + /// moved to. + fn ui_source() -> String { + [ + include_str!("main.rs").split("#[cfg(test)]").next().unwrap(), + include_str!("ui/toolbar.rs"), + include_str!("ui/inspector.rs"), + include_str!("ui/timeline.rs"), + include_str!("ui/library.rs"), + include_str!("ui/preview.rs"), + include_str!("ui/cards.rs"), + include_str!("ui/overlays.rs"), + include_str!("ui/widgets.rs"), + ] + .concat() + } + fn asset(name: &str) -> PathBuf { Path::new(env!("CARGO_MANIFEST_DIR")) .join("../../assets") @@ -9870,9 +9951,37 @@ mod tests { ); let live = Ctx { timeline: true, + playable: true, ..Ctx::default() }; assert!(whole(ActionId::Play, live).yes()); + // ...and an open timeline with nothing on its lanes refuses the + // transport in the oracle rather than in the button, which is what + // makes the key and the button say the same thing. + assert_eq!( + whole( + ActionId::Play, + Ctx { + playable: false, + ..live + } + ), + Enable::No("put a clip on a lane first") + ); + // The magnet and the monitoring level are the editor's own and answer + // with no timeline at all -- the keyboard always fired them there, and + // now so does the toolbar. + for editor_wide in [ + ActionId::ToggleSnap, + ActionId::ToggleMute, + ActionId::VolumeUp, + ActionId::VolumeDown, + ] { + assert!( + whole(editor_wide, Ctx::default()).yes(), + "{editor_wide:?} is dead with no file open while its key still fires" + ); + } assert!(!whole(ActionId::Delete, live).yes()); assert!(!whole(ActionId::Paste, live).yes()); assert!( @@ -10103,10 +10212,8 @@ mod tests { #[test] fn every_action_is_reachable_without_the_keyboard() { use keymap::ActionId; - let source = include_str!("main.rs") - .split("#[cfg(test)]") - .next() - .unwrap(); + let source = ui_source(); + let source = source.as_str(); let element = |id: &str| source.contains(&format!("\"{id}\"")); let listed: Vec = keys_rows() .iter() @@ -10181,10 +10288,8 @@ mod tests { /// the day it is added, which is the only way the two stay in step. #[test] fn every_card_closes_without_the_keyboard() { - let source = include_str!("main.rs") - .split("#[cfg(test)]") - .next() - .unwrap(); + let source = ui_source(); + let source = source.as_str(); // A fn's source, up to the next one: enough of a body to scan. let body = |name: &str| -> &str { let at = source @@ -12916,12 +13021,15 @@ mod tests { "refusal ink {:.2}", contrast(FG_SECONDARY, BG_RAISED) ); - // On the picked row that ink would only be 3.3:1 against the highlight, - // so the row it lands on lifts its key and detail to `FG_PRIMARY`. + // ...and on the picked row, where the highlight is the accent at + // surface brightness. Both inks clear 4.5:1 on it now -- the row still + // lifts its key and detail to `FG_PRIMARY`, as emphasis rather than as + // the rescue it used to be. assert!(contrast(FG_PRIMARY, BG_SELECTED) >= 4.5); assert!( - contrast(FG_SECONDARY, BG_SELECTED) < 4.5, - "the lift is still needed" + contrast(FG_SECONDARY, BG_SELECTED) >= 4.5, + "refusal ink on the picked row {:.2}", + contrast(FG_SECONDARY, BG_SELECTED) ); } @@ -14025,43 +14133,45 @@ mod tests { assert_eq!(cue_box(scale, &mapped[1]), (80., 40.)); } - /// The panel's button row 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. + /// 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 source = include_str!("main.rs") - .split("#[cfg(test)]") - .next() - .unwrap(); - let panel = &source[source.find(" fn panel(").expect("the panel") - ..source.find(" fn import_bar(").expect("the panel's end")]; + let toolbar = include_str!("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 panel's own - // 12 px padding. The level slider is the one fixed width among them. - let buttons = panel.matches("control(").count(); - assert!(buttons >= 15, "the row's buttons moved; this scan is blind"); - let row_w = buttons as f32 * (HIT_MIN + 8.) + VOLUME_W + 24.; - assert!( - row_w > 640., - "{row_w} px of buttons now fits the floor -- the pinned door may go" - ); - // So Export, Save and Actions are off the right edge at that width, and - // "it scrolls" is not "it can be found": this is the button that never - // scrolls, and the card it opens carries every action there is + // 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!( - panel.contains("\"controls-more\""), + row.contains("\"controls-more\""), "nothing pinned beside the scrolling row: the tail is unreachable at 640 px" ); - // ...and it is outside the scrolling box, which is the whole point of - // it: one `overflow_x_scroll`, and the door is written after it closes. - assert_eq!(panel.matches("overflow_x_scroll").count(), 1); + assert_eq!(row.matches("overflow_x_scroll").count(), 1); assert!( - panel.find("\"controls-more\"") > panel.find("overflow_x_scroll"), + 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" + ); } #[test] @@ -14392,7 +14502,19 @@ mod tests { #[test] fn every_mark_on_a_clip_is_legible_on_it() { - for (i, tint) in SOURCE_TINTS.iter().enumerate() { + // The body a name and a waveform are drawn on is the clip's kind + // ([`clip_kind`]); the source tint is the border and the library + // swatch, and is measured for telling itself apart rather than for + // carrying text. + for (i, tint) in [ + crate::ui::theme::CLIP_VIDEO, + crate::ui::theme::CLIP_AUDIO, + crate::ui::theme::CLIP_IMAGE, + crate::ui::theme::CLIP_TEXT, + ] + .iter() + .enumerate() + { // WCAG 1.4.3: the clip's name is body text on its tint. assert!( contrast(FG_PRIMARY, *tint) >= 4.5, @@ -14409,10 +14531,12 @@ mod tests { // A selected clip's bed is the same two marks on a different colour. assert!(contrast(FG_PRIMARY, BG_SELECTED) >= 4.5); assert!(contrast(FG_SECONDARY, BG_SELECTED) >= 3.); - // The bed a gap shows through has to read as a hole in the lane, and - // the accent playhead has to be findable on it. - assert!(contrast(BG_CANVAS, BG_RAISED) >= 1.5); - assert!(contrast(ACCENT_PRIMARY, BG_CANVAS) >= 3.); + // The bed a gap shows through has to read as a hole in the lane -- the + // clip is the object, the bed is the hole -- and the playhead has to be + // findable on both. + assert!(contrast(crate::ui::theme::CLIP_VIDEO, crate::ui::theme::BG_TIMELINE) >= 1.5); + assert!(contrast(crate::ui::theme::ACCENT_PLAYHEAD, crate::ui::theme::BG_TIMELINE) >= 3.); + assert!(contrast(crate::ui::theme::ACCENT_PLAYHEAD, crate::ui::theme::CLIP_VIDEO) >= 3.); // The sanity check on the ratio itself: black on white is 21:1. assert!((contrast(0xffffff, 0x000000) - 21.).abs() < 0.01); } diff --git a/crates/app/src/ui/cards.rs b/crates/app/src/ui/cards.rs index e7dd933..8809cfc 100644 --- a/crates/app/src/ui/cards.rs +++ b/crates/app/src/ui/cards.rs @@ -1025,7 +1025,9 @@ impl Player { div() .id(("color-bar", i)) .relative() - .w(px(COLOR_BAR_W)) + .flex_1() + .min_w(px(0.)) + .max_w(px(COLOR_BAR_W)) .h(px(KEYS_ROW_H)) .flex() .items_center() @@ -1079,7 +1081,8 @@ impl Player { ) .child( div() - .w(px(COLOR_W)) + .w_full() + .max_w(px(COLOR_W)) .on_mouse_down(MouseButton::Left, swallow) .flex() .flex_col() @@ -1195,7 +1198,8 @@ impl Player { ) .child( div() - .w(px(COLOR_W)) + .w_full() + .max_w(px(COLOR_W)) .on_mouse_down(MouseButton::Left, swallow) .flex() .flex_col() @@ -1392,7 +1396,8 @@ impl Player { ) .child( div() - .w(px(COLOR_W)) + .w_full() + .max_w(px(COLOR_W)) .on_mouse_down(MouseButton::Left, swallow) .max_h(px(360. - 24.)) .flex() @@ -1609,7 +1614,8 @@ impl Player { ) .child( div() - .w(px(COLOR_W)) + .w_full() + .max_w(px(COLOR_W)) .on_mouse_down(MouseButton::Left, swallow) .flex() .flex_col() diff --git a/crates/app/src/ui/inspector.rs b/crates/app/src/ui/inspector.rs index e69de29..e8a3cee 100644 --- a/crates/app/src/ui/inspector.rs +++ b/crates/app/src/ui/inspector.rs @@ -0,0 +1,273 @@ +//! 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::*; +use crate::ui::widgets::*; + +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 = inspector_w(f32::from(viewport.width)); + // 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); + 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() + .flex() + .flex_col() + .gap(px(8.)) + .p(px(8.)) + .child(self.selection_section(cx)) + .child(self.project_section(cx)), + ) + .children(self.eq_card(room, cx)) + .children(self.color_card(cx)) + .children(self.speed_card(cx)) + .children(self.silence_card(cx)) + .children(self.mix_card(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.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, + )) + }); + let head = match &picked { + Some((lane, _, name, _)) => format!("{} · {}", lane.label(), name), + None => "Nothing selected".to_string(), + }; + 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, + ), + 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() { + 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.)) + }) + .child(head), + ) + .child( + div() + .flex_none() + .text_size(px(11.)) + .text_color(rgb(FG_SECONDARY)) + .child(detail), + ) + .child( + div() + .flex() + .flex_wrap() + .gap(px(6.)) + .child(self.action_control( + "inspect-speed", + 0., + 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., + None, + "Colour", + "exposure, contrast, saturation and temperature", + ActionId::Color, + cx.listener(|this, _: &ClickEvent, _, cx| this.open_color(cx)), + )) + .child(self.action_control( + "inspect-eq", + 0., + 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., + 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., + 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., + None, + "Delete", + "takes this clip off the timeline", + ActionId::Delete, + cx.listener(|this, _: &ClickEvent, _, cx| this.delete_selected(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, + None, + resolution.map_or_else(|| "Size".to_string(), |(_, h)| format!("{h}p")), + "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, + None, + match self.session.is_some() { + true => format!("{} fps", fps_label(self.fps)), + false => "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( + "tonemap", + ZOOM_SLOT_W, + 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) + }), + )) + .child(self.action_control( + "inspect-mix", + 0., + 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)), + )), + ) + } +} + +/// 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 4c569f4..220c8c6 100644 --- a/crates/app/src/ui/library.rs +++ b/crates/app/src/ui/library.rs @@ -232,6 +232,7 @@ impl Player { ) .child(control( "import", + 0., None, "Import", "adds a file to this list — or drop one on the window".to_string(), @@ -266,6 +267,7 @@ impl Player { .children(self.subtitle_section(width, viewport_h, cx)) .child(control( "add-asset", + 0., None, "Add at playhead", match self.selected_asset { diff --git a/crates/app/src/ui/overlays.rs b/crates/app/src/ui/overlays.rs index deeeed8..8ae9597 100644 --- a/crates/app/src/ui/overlays.rs +++ b/crates/app/src/ui/overlays.rs @@ -50,6 +50,9 @@ impl Player { .child(div().flex_1().min_w(px(0.)).child(line)) .child(control( "cancel-import", + // Hugs its label: the bar's own line is what wants + // the width, and this button never relabels. + 0., None, "Cancel", "stops this file and anything queued behind it; the read already \ diff --git a/crates/app/src/ui/theme.rs b/crates/app/src/ui/theme.rs index 087e60a..86d1fe6 100644 --- a/crates/app/src/ui/theme.rs +++ b/crates/app/src/ui/theme.rs @@ -53,7 +53,7 @@ pub const FG_DISABLED: u32 = 0x6c7a8b; pub const ACCENT_PRIMARY: u32 = 0x22d3ee; /// Not the accent: the playhead crosses every clip colour there is and has to /// stay the one line that is none of them. -pub const ACCENT_PLAYHEAD: u32 = 0xff4d6d; +pub const ACCENT_PLAYHEAD: u32 = 0xff9db0; /// The accent as a translucent wash, for the marks drawn over a clip body. pub const ACCENT_WASH: u32 = 0x22d3eeaa; diff --git a/crates/app/src/ui/timeline.rs b/crates/app/src/ui/timeline.rs index 990bb9d..e8411ec 100644 --- a/crates/app/src/ui/timeline.rs +++ b/crates/app/src/ui/timeline.rs @@ -4,8 +4,12 @@ use crate::*; use crate::ui::widgets::*; impl Player { - /// Transport, edit and file buttons, timecode, playhead, clips lane. - pub(crate) fn panel( + /// 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, duration: f64, @@ -22,13 +26,6 @@ impl Player { // percentage and the accent bar are the same number, so the playhead // fill doubles as the progress bar for free. let exporting = self.exporting().is_some(); - // Everything but Import and Keys needs a timeline to act on: with none - // open they are dimmed rather than silently doing nothing. - let live = state != Transport::Stopped && !exporting; - // The project's own picture size, for the button that cycles it: read - // per render like everything else here, so a cycle shows on the button - // that made it. - let resolution = self.session.as_ref().map(PlaybackSession::resolution); 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. @@ -103,439 +100,15 @@ impl Player { }; div() .flex_none() - .h(px(panel_h(lanes.len()) + strip_h)) + .h(px(timeline_h(lanes.len()) + strip_h)) .flex() .flex_col() .gap(px(8.)) .px(px(12.)) .py(px(8.)) - .bg(rgb(BG_PANEL)) - // Transport | edit | file: three groups, so the eye can skip two of - // them. Every button says what it does; the tooltip adds its key. - // - // The row scrolls rather than losing its tail: at the 640 px floor - // this window is sized for it is wider than the panel, and a button - // off the right edge is a button a pointer cannot press. A plain - // wheel moves it -- gpui puts a vertical delta on the x axis when - // that is the only one scrolling (div.rs:2424). - // - // ...and "it scrolls" is not "it can be found": the button beside - // the row is pinned outside it and never scrolls away, so Export, - // Save and the rest are one press from the smallest window even - // when the row's tail is off the edge. - // `toolbar_fits_the_smallest_window` is the guard. - .child( - div() - .flex_none() - .flex() - .items_center() - .gap(px(8.)) - .child( - div() - .id("controls") - .flex_1() - .min_w(px(0.)) - .flex() - .items_center() - .gap(px(8.)) - .overflow_x_scroll() - .child(control( - "transport", - Some(transport_glyph(state).into_any_element()), - if state.is_playing() { "Pause" } else { "Play" }, - if nothing_to_play(self.session.as_ref()) && !state.is_playing() { - format!("{} — put a clip on a lane first", key(ActionId::Play)) - } else { - key(ActionId::Play) - }, - // An empty timeline has nothing to play, so the button - // says so by being dim rather than by starting a clock - // against nothing (the key press answers with the - // notice). Still live while it *is* playing: a delete - // can empty the timeline mid-play and that has to stop. - live && (state.is_playing() || !nothing_to_play(self.session.as_ref())), - cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_or_restart(cx)), - )) - .child(separator()) - .child(control( - "cut", - Some(cut_glyph().into_any_element()), - "Cut", - format!( - "{} — splits the clip under the playhead", - key(ActionId::Cut) - ), - live, - cx.listener(|this, _: &ClickEvent, _, cx| this.cut(cx)), - )) - .child(control( - "delete", - Some(delete_glyph().into_any_element()), - "Delete", - if self.selected.is_some() { - key(ActionId::Delete) - } else { - format!("{} — click a clip below first", key(ActionId::Delete)) - }, - live && self.selected.is_some(), - cx.listener(|this, _: &ClickEvent, _, cx| this.delete_selected(cx)), - )) - // The way back from every one of them. It was a stroke and - // nothing else, which made the whole edit group a one-way - // door for anyone working with a pointer. - .child(control( - "undo", - None, - "Undo", - format!("{} — takes the last edit back", key(ActionId::Undo)), - live, - cx.listener(|this, _: &ClickEvent, _, cx| this.undo(cx)), - )) - // With the edit group, beside the buttons that change the - // edit list: a track is a row of it, and adding one is an - // undoable edit like the rest. Two buttons rather than one - // with a choice, because the choice is the whole action. - .child(control( - "add-video-lane", - None, - "+ V", - format!( - "{} — adds a video track under the ones there", - key(ActionId::AddVideoLane) - ), - live, - cx.listener(|this, _: &ClickEvent, _, cx| { - this.add_lane(LaneKind::Video, cx) - }), - )) - .child(control( - "add-audio-lane", - None, - "+ A", - format!( - "{} — adds an audio track under the ones there", - key(ActionId::AddAudioLane) - ), - live, - cx.listener(|this, _: &ClickEvent, _, cx| { - this.add_lane(LaneKind::Audio, cx) - }), - )) - // The third kind of track this timeline carries, and - // the only one that arrived through a drop alone: a - // subtitle file nobody thought to drag was a track - // the editor could not be asked for. What it opens is - // a chooser rather than an empty row -- a subtitle - // track is its file, and there is nothing to add - // before one is named. - .child(control( - "add-subtitle-track", - None, - "+ S", - // Dim, and saying why it is dim, out of the one - // oracle -- the very words the key answers with - // (`Player::pick_and_add_subtitles`), so the - // tooltip and the notice cannot come to differ. - match self.enable(ActionId::AddSubtitleTrack, None).why() { - Some(why) => { - format!("{} — {why}", key(ActionId::AddSubtitleTrack)) - } - None => format!( - "{} — adds every subtitle track in a file you pick", - key(ActionId::AddSubtitleTrack) - ), - }, - live, - cx.listener(|this, _: &ClickEvent, _, cx| { - this.pick_and_add_subtitles(cx) - }), - )) - // With the transport, not the edit group: it changes what - // the file sounds like, never what it is. Reads as its own - // state, so muted is legible without a tooltip. - .child(control( - "volume", - None, - self.volume.label(), - format!( - "{} mutes · {} louder · {} quieter", - key(ActionId::ToggleMute), - key(ActionId::VolumeUp), - key(ActionId::VolumeDown) - ), - live, - cx.listener(|this, _: &ClickEvent, _, cx| { - this.set_volume(|volume| volume.muted = !volume.muted, cx) - }), - )) - // The level itself, to drag. The button beside it stays the - // mute -- one gesture each -- and the label above is what - // this writes, live, so the number follows the hand. - .child(volume_slider( - self.volume, - self.volume_bar.clone(), - live, - cx, - )) - .child(separator()) - // The size every clip is composed onto, which is also the - // size the export comes out at. Five sizes, so a click opens - // the list of them with this one marked and picks whichever - // was meant: a button that stepped one on per press made the - // user click round the ladder to get back to where they - // were. The stroke still steps, for the hand already on it. - .child(control( - "resolution", - None, - resolution.map_or_else(|| "Size".to_string(), |(_, h)| format!("{h}p")), - match resolution { - Some((w, h)) => format!( - "click to pick a size — the project is {w}x{h}; {} steps to the next", - key(ActionId::Resolution) - ), - None => format!("{} — open a file first", key(ActionId::Resolution)), - }, - live, - cx.listener(|this, event: &ClickEvent, _, cx| { - this.open_picker(Pick::Resolution, event.position(), cx) - }), - )) - // The rate every clip is counted in, which is also the rate - // the export is written at -- the other half of "the project - // is not the media", and the one the panel could only ever - // read out before. A click opens the rates with this one - // marked; picking one conforms the whole timeline to it. - .child(control( - "fps", - None, - match self.session.is_some() { - true => format!("{} fps", fps_label(self.fps)), - false => "Rate".to_string(), - }, - match self.session.is_some() { - true => format!( - "click to pick a frame rate — the project is cut at {} fps", - fps_label(self.fps) - ), - false => "the project's frame rate — open a file first".to_string(), - }, - live, - cx.listener(|this, event: &ClickEvent, _, cx| { - this.open_picker(Pick::Fps, event.position(), cx) - }), - )) - // ...and which rendition its HDR media is watched in, the - // third thing that is the project's rather than the media's. - // Listed whatever is on the timeline, and the tooltip says - // who it acts on: a control that came and went with the - // media would be one nobody could find when they wanted it. - .child(control( - "tonemap", - None, - match &self.session { - Some(session) => format!("HDR {}", tone_label(session.tone())), - None => "HDR".to_string(), - }, - match &self.session { - Some(session) => format!( - "click to pick the HDR rendition — the project is {}; SDR media is untouched", - tone_label(session.tone()) - ), - None => "the HDR rendition — open a file first".to_string(), - }, - live, - cx.listener(|this, event: &ClickEvent, _, cx| { - this.open_picker(Pick::Tone, event.position(), cx) - }), - )) - // How much of the timeline the panel below is showing -- - // beside the resolution, since neither of them edits - // anything: they are both what is being looked at. The - // middle one says how much of it is on the bed, and is the - // way back to the whole of it. - .child(control( - "zoom-out", - None, - "−", - format!( - "{} — show more of the timeline; stops with all of it on the bed", - key(ActionId::ZoomOut) - ), - live, - cx.listener(|this, _: &ClickEvent, _, cx| { - this.zoom(1. / ZOOM_STEP, None, cx) - }), - )) - .child(control( - "zoom-fit", - None, - // How much timeline is on the bed, not a multiple of - // "the whole of it": the scale no longer knows what the - // whole of it is, and a number that changed on every - // import was a number that lied. - span_label(self.view().span()), - format!( - "{} — fit the whole timeline; showing {} to {}", - key(ActionId::ZoomFit), - timecode(self.scale.start, self.fps), - timecode( - (self.scale.start + self.view().span()).min(duration), - self.fps - ) - ), - live, - cx.listener(|this, _: &ClickEvent, _, cx| this.zoom_fit(cx)), - )) - .child(control( - "zoom-in", - None, - "+", - format!( - "{} — magnify around the playhead; ctrl+wheel on the bar zooms at the pointer", - key(ActionId::ZoomIn) - ), - live, - cx.listener(|this, _: &ClickEvent, _, cx| this.zoom(ZOOM_STEP, None, cx)), - )) - // The magnet, beside the zoom for the zoom's own reason: it - // changes nothing on the timeline, it changes how the hand - // meets it. The label is the state, as the volume's is -- - // a toggle that looks the same either way says nothing. - .child(control( - "snap", - None, - if self.snap { "Snap" } else { "No snap" }, - format!( - "{} — {}", - key(ActionId::ToggleSnap), - 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", - } - ), - live, - cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_snap(cx)), - )) - // The cues over the picture, off and on -- beside the zoom - // and the snap, since like both of them it changes what is - // being looked at and nothing about the edit. The label is - // the state, as the snap's is, and it says what there is to - // toggle when there is nothing. - .child(control( - "subs", - None, - match (self.subtitle_track().is_some(), self.subs_on) { - (false, _) => "No subs", - (true, true) => "Subs", - (true, false) => "Subs off", - }, - match self.enable(ActionId::ToggleSubtitles, None).why() { - Some(why) => format!( - "{} — {why}; drop a .srt on the window, or open an mkv that carries them", - key(ActionId::ToggleSubtitles) - ), - None => format!( - "{} — {}", - key(ActionId::ToggleSubtitles), - match self.subs_on { - true => "the cue under the playhead is drawn over the picture", - false => "the cues are on the timeline and off the picture", - } - ), - }, - live && self.enable(ActionId::ToggleSubtitles, None).yes(), - cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_subtitles(cx)), - )) - // Import is not here: it belongs to the media list it adds - // to, and two doors into one action is a question about - // which one is the real one. - // - // While one runs, this button is the way out of it: the - // progress line promised esc and nothing else, which left a - // pointer no way to stop an export it had started. - .child(control( - "export", - None, - if exporting { "Cancel" } else { "Export" }, - if exporting { - format!( - "{} — stops the export; the part-written file goes", - key(ActionId::CancelExport) - ) - } else { - format!( - "{} — quality and destination, then writes the timeline out", - key(ActionId::Export) - ) - }, - if exporting { - true - } else { - live && self.export.is_none() - }, - cx.listener(|this, _: &ClickEvent, _, cx| { - if this.exporting().is_some() { - this.cancel_export(); - cx.notify(); - } else { - this.open_export(cx); - } - }), - )) - .child(control( - "save", - None, - "Save", - format!("{} — writes the project file", key(ActionId::Save)), - live, - cx.listener(|this, _: &ClickEvent, _, cx| this.save_project(cx)), - )) - // Closed while an export runs, which is what keeps a waiting - // row from swallowing the escape the progress line promises - // cancels the export. - .child(control( - "keys", - None, - "Actions", - // The pointer's way to every action there is, including - // the ones no button here has room for. - format!( - "{} — do any action, or change the key that does it", - key(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 door to everything the row cannot show at this - // window: the same card the Actions button opens, by the - // same call, pinned where a scroll cannot take it. - .child(control( - "controls-more", - None, - "⋯", - format!( - "{} — every action, including the ones scrolled off this row", - key(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), - }), - )), - ) + .bg(rgb(BG_TIMELINE)) + .border_t_1() + .border_color(rgb(STROKE_DIVIDER)) .child( div() .flex_none() @@ -1033,7 +606,7 @@ impl Player { .min_w(px(0.)) .h_full() .rounded(px(3.)) - .bg(rgb(BG_CANVAS)) + .bg(rgb(BG_TIMELINE)) .overflow_hidden() .children(cues.into_iter().map(|(left, width)| { div() @@ -1054,8 +627,8 @@ impl Player { .top_0() .h_full() .left(px(filled)) - .w(px(1.)) - .bg(rgb(ACCENT_PRIMARY)), + .w(px(2.)) + .bg(rgb(ACCENT_PLAYHEAD)), ), ), ) @@ -1230,7 +803,7 @@ impl Player { .min_w(px(0.)) .h_full() .rounded(px(3.)) - .bg(rgb(BG_CANVAS)) + .bg(rgb(BG_TIMELINE)) .overflow_hidden() // A library row let go over a lane is the same insert the // Add button makes, through the same call -- but where the @@ -1313,6 +886,18 @@ impl Player { // 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`]). @@ -1370,13 +955,13 @@ impl Player { .rounded(px(3.)) .border_1() .border_color(rgb(if on { - ACCENT_PRIMARY + STROKE_SELECTED } else if grouped { tint } else { FG_SECONDARY })) - .bg(rgb(if on { BG_SELECTED } else { tint })) + .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()) @@ -1637,8 +1222,8 @@ impl Player { .top_0() .h_full() .left(px(filled)) - .w(px(1.)) - .bg(rgb(ACCENT_PRIMARY)), + .w(px(2.)) + .bg(rgb(ACCENT_PLAYHEAD)), ), ) } diff --git a/crates/app/src/ui/toolbar.rs b/crates/app/src/ui/toolbar.rs index e69de29..6c79727 100644 --- a/crates/app/src/ui/toolbar.rs +++ b/crates/app/src/ui/toolbar.rs @@ -0,0 +1,392 @@ +//! 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::*; +use crate::ui::widgets::*; + +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, + 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, 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, cx: &mut Context) -> impl IntoElement { + let exporting = self.exporting().is_some(); + 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()), + ) + .child(self.action_control( + "save", + 0., + 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, + 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); + } + }), + )) + .when(!exporting, |d| d.text_color(rgb(BG_CANVAS))) + .when(exporting, |d| d.text_color(rgb(FG_PRIMARY))), + ) + } + + /// 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, + position: f64, + state: Transport, + cx: &mut Context, + ) -> impl IntoElement { + let muted = self.volume.muted; + 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( + "transport", + 40., + Some(transport_glyph(state).into_any_element()), + "", + "plays and pauses the timeline", + ActionId::Play, + cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_or_restart(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(TIME_W)) + .truncate() + .text_color(rgb(FG_PRIMARY)) + .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.))) + // 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, + None, + 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) + }), + )) + .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(self.action_control( + "cut", + 0., + 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., + 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., + None, + "Undo", + "takes the last edit back", + ActionId::Undo, + cx.listener(|this, _: &ClickEvent, _, cx| this.undo(cx)), + )) + .child(separator()) + .child(self.action_control( + "add-video-lane", + 0., + 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., + 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-track", + 0., + None, + "+ S", + "adds every subtitle track in a file you pick", + ActionId::AddSubtitleTrack, + cx.listener(|this, _: &ClickEvent, _, cx| { + this.pick_and_add_subtitles(cx) + }), + )) + .child(separator()) + // 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, + 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, + None, + match (self.subtitle_track().is_some(), 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(separator()) + .child(self.action_control( + "zoom-out", + CONTROL_H, + 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, + 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, + None, + "+", + "magnify around the playhead; ctrl+wheel on the ruler zooms at the pointer", + ActionId::ZoomIn, + cx.listener(|this, _: &ClickEvent, _, cx| this.zoom(ZOOM_STEP, None, cx)), + )) + .child(self.action_control( + "keys", + 0., + 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, + 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.; diff --git a/crates/app/src/ui/widgets.rs b/crates/app/src/ui/widgets.rs index 8735c51..48ca344 100644 --- a/crates/app/src/ui/widgets.rs +++ b/crates/app/src/ui/widgets.rs @@ -43,6 +43,11 @@ pub(crate) fn waveform(peaks: Arc>, from: f64, to: f64) -> impl /// A button that would do nothing says so: dimmed, no pointer, no listener. pub(crate) fn control( id: &'static str, + // The rect the label is allowed to change inside: 0 hugs the text, anything + // else is reserved once and never moves again, which is what keeps a button + // that relabels itself ("Export"/"Cancel") from shoving its neighbours + // along the row every time its state changes. + w: f32, glyph: Option, // Not `&'static str`: the volume button's label is its state. label: impl Into, @@ -58,9 +63,11 @@ pub(crate) fn control( .h(px(CONTROL_H)) .flex() .items_center() + .justify_center() .gap(px(6.)) .px(px(8.)) - .rounded(px(3.)) + .when(w > 0., |d| d.w(px(w)).overflow_hidden()) + .rounded(px(4.)) .bg(rgb(BG_RAISED)) .children(glyph) .child(label)