diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 230dca9..3e59d13 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -306,6 +306,48 @@ impl Default for Volume { } } +/// The library's three categories, in the order the giants list them: the +/// pictures, the sound, and the words. A file is in exactly one of them, so a +/// tab is a question with an answer rather than a filter with a guess. +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +enum LibraryTab { + Media, + Audio, + Text, +} + +const LIBRARY_TABS: [LibraryTab; 3] = [LibraryTab::Media, LibraryTab::Audio, LibraryTab::Text]; + +impl LibraryTab { + fn label(self) -> &'static str { + match self { + LibraryTab::Media => "Media", + LibraryTab::Audio => "Audio", + LibraryTab::Text => "Text", + } + } + + /// Whether a source belongs on this tab. Subtitles are not sources at all + /// -- they are the [`Player::subtitle_section`] under the list -- so the + /// Text tab holds no rows of its own and says so. + fn holds(self, path: &Path) -> bool { + match self { + LibraryTab::Media => !engine::is_audio(path), + LibraryTab::Audio => engine::is_audio(path), + LibraryTab::Text => false, + } + } + + /// What an empty tab says instead of being a blank column. + fn empty(self) -> &'static str { + match self { + LibraryTab::Media => "No video or stills yet — Import, or drop a file on the window", + LibraryTab::Audio => "No sound yet — Import, or drop a file on the window", + LibraryTab::Text => "No subtitles yet — drop an .srt on the window, or + S in the toolbar", + } + } +} + /// What is known about a source's audio. Three states and not two, because a /// file whose peaks have not come back yet must not be drawn as one that has no /// audio at all: the first shows a bed, the second shows nothing. @@ -1121,6 +1163,10 @@ struct Player { /// rebuilt. Its own selection and not the timeline's: Delete keeps acting /// on the clip that was clicked in a lane, whatever the library is showing. selected_asset: Option<(PathBuf, usize)>, + /// Which category of the library is being looked at. A tab and not a + /// filter box: the categories are what the media *is*, and every editor + /// this one is measured against splits its pool the same way. + library_tab: LibraryTab, /// What is known about each source's audio, taken once and kept. Keyed on /// the path *and stream* -- two streams of one file are two envelopes -- and /// the key is inserted the moment the decode is *started*: presence means @@ -8233,13 +8279,20 @@ 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`]). +/// How tall the timeline region is: its own padding, the timecode line, the +/// ruler and the gaps between them, plus a row per lane. Measured from its +/// parts rather than taken off [`PANEL_H`] -- the button row moved out of it +/// ([`Player::toolbar`]), and a height still carrying that row's pixels is a +/// height that cuts the last lane off the bottom of the window. fn timeline_h(lanes: usize) -> f32 { - panel_h(lanes) - TOOLBAR_H + TIMELINE_FIXED_H + lanes_h(lanes.clamp(2, LANES_MAX)) } +/// 8+8 padding, the timecode line, the 24 px ruler strip and the two 8 px gaps +/// between the three rows, with a couple of px of slack so a taller text line +/// cannot push a lane off the bottom. +const TIMELINE_FIXED_H: f32 = 16. + 18. + 8. + RULER_HIT_H + 8. + 4.; + /// 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.; @@ -14174,6 +14227,85 @@ mod tests { ); } + /// The whole reason `ui/theme.rs` exists: a colour written anywhere else is + /// a colour the next palette sweep will miss, which is exactly how 186 grey + /// calls survived every previous attempt at this. + #[test] + fn no_colour_is_written_outside_the_theme() { + let source = ui_source(); + let stray: Vec<&str> = source + .lines() + .filter(|l| l.contains("rgb(0x") || l.contains("rgba(0x")) + .collect(); + assert!(stray.is_empty(), "colour written outside the theme: {stray:?}"); + } + + /// The cards are sections of the inspector, not sheets over the timeline: + /// adjusting a clip must never hide the clip. Structural, because that is + /// where the rule lives -- a card rendered from the root again would be an + /// overlay again, whatever it looked like on the day it was written. + #[test] + fn an_inspector_section_occludes_no_timeline() { + let inspector = include_str!("ui/inspector.rs"); + let root = include_str!("main.rs").split("#[cfg(test)]").next().unwrap(); + let render = &root[root.find("impl Render for Player").expect("the root render")..]; + for card in [ + "eq_card", "color_card", "speed_card", "silence_card", "mix_card", + ] { + assert!( + inspector.contains(&format!("self.{card}(")), + "{card} is not a section of the inspector" + ); + 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. + assert!( + inspector.contains(".relative()"), + "the inspector is not a 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 = include_str!("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")); + assert!( + toolbar[at..at + 120].contains(slot), + "{id} does not reserve {slot}" + ); + } + } + #[test] fn nothing_clickable_is_smaller_than_the_wcag_minimum() { // Every hit target in the panel, including the scrub strip -- whose bar @@ -15128,6 +15260,7 @@ fn main() { picker: None, library_menu: None, selected_asset: None, + library_tab: LibraryTab::Media, waves: HashMap::new(), streams: HashMap::new(), bitrates: HashMap::new(), diff --git a/crates/app/src/ui/inspector.rs b/crates/app/src/ui/inspector.rs index e8a3cee..0d10372 100644 --- a/crates/app/src/ui/inspector.rs +++ b/crates/app/src/ui/inspector.rs @@ -8,6 +8,7 @@ //! (`an_inspector_section_occludes_no_timeline`). use crate::*; +use crate::ui::toolbar::{TONE_SLOT_W, ZOOM_SLOT_W}; use crate::ui::widgets::*; impl Player { @@ -124,6 +125,7 @@ impl Player { .child(self.action_control( "inspect-speed", 0., + BG_RAISED, None, "Speed", "how fast this clip and its group play", @@ -133,6 +135,7 @@ impl Player { .child(self.action_control( "inspect-color", 0., + BG_RAISED, None, "Colour", "exposure, contrast, saturation and temperature", @@ -142,6 +145,7 @@ impl Player { .child(self.action_control( "inspect-eq", 0., + BG_RAISED, None, "Equalizer", "the bands this clip's sound is filtered through", @@ -151,6 +155,7 @@ impl Player { .child(self.action_control( "inspect-silence", 0., + BG_RAISED, None, "Silence", "finds the quiet stretches and cuts or speeds them", @@ -160,6 +165,7 @@ impl Player { .child(self.action_control( "inspect-fit", 0., + BG_RAISED, None, "Fit", "how this picture is placed on the project canvas", @@ -169,6 +175,7 @@ impl Player { .child(self.action_control( "inspect-delete", 0., + BG_RAISED, None, "Delete", "takes this clip off the timeline", @@ -206,6 +213,7 @@ impl Player { .child(self.action_control( "resolution", ZOOM_SLOT_W, + BG_RAISED, 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", @@ -217,6 +225,7 @@ impl Player { .child(self.action_control( "fps", ZOOM_SLOT_W, + BG_RAISED, None, match self.session.is_some() { true => format!("{} fps", fps_label(self.fps)), @@ -230,7 +239,8 @@ impl Player { )) .child(self.action_control( "tonemap", - ZOOM_SLOT_W, + TONE_SLOT_W, + BG_RAISED, None, match &self.session { Some(session) => format!("HDR {}", tone_label(session.tone())), @@ -245,6 +255,7 @@ impl Player { .child(self.action_control( "inspect-mix", 0., + BG_RAISED, None, "Mix", "a fader per track and the limiter over the sum of them", diff --git a/crates/app/src/ui/library.rs b/crates/app/src/ui/library.rs index 220c8c6..5d34529 100644 --- a/crates/app/src/ui/library.rs +++ b/crates/app/src/ui/library.rs @@ -40,7 +40,12 @@ impl Player { }, ) .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 @@ -225,14 +230,44 @@ impl Player { div() .flex_1() .min_w(px(0.)) - .truncate() - .text_size(px(11.)) - .text_color(rgb(FG_SECONDARY)) - .child("Media"), + .flex() + .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()) + })), ) .child(control( "import", 0., + BG_RAISED, None, "Import", "adds a file to this list — or drop one on the window".to_string(), @@ -256,7 +291,7 @@ impl Player { div() .text_size(px(11.)) .text_color(rgb(FG_SECONDARY)) - .child("No media yet — Import, or drop a file on the window"), + .child(self.library_tab.empty()), ) }) .children(rows), @@ -264,10 +299,13 @@ impl Player { // 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. - .children(self.subtitle_section(width, viewport_h, cx)) + .when(self.library_tab == LibraryTab::Text, |d| { + d.children(self.subtitle_section(width, viewport_h, cx)) + }) .child(control( "add-asset", 0., + BG_RAISED, None, "Add at playhead", match self.selected_asset { diff --git a/crates/app/src/ui/toolbar.rs b/crates/app/src/ui/toolbar.rs index 6c79727..05535f8 100644 --- a/crates/app/src/ui/toolbar.rs +++ b/crates/app/src/ui/toolbar.rs @@ -26,6 +26,7 @@ impl Player { &self, id: &'static str, w: f32, + bg: u32, glyph: Option, label: impl Into, hint: &str, @@ -41,7 +42,7 @@ impl Player { Some(why) => format!("{key} — {why}"), None => format!("{key} — {hint}"), }; - control(id, w, glyph, label, say, enabled.yes(), on_click) + 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 @@ -78,6 +79,7 @@ impl Player { .child(self.action_control( "save", 0., + BG_RAISED, None, "Save", "writes the project file", @@ -93,6 +95,10 @@ impl Player { .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 { @@ -114,8 +120,7 @@ impl Player { } }), )) - .when(!exporting, |d| d.text_color(rgb(BG_CANVAS))) - .when(exporting, |d| d.text_color(rgb(FG_PRIMARY))), + , ) } @@ -142,6 +147,7 @@ impl Player { .child(self.action_control( "transport", 40., + BG_RAISED, Some(transport_glyph(state).into_any_element()), "", "plays and pauses the timeline", @@ -175,10 +181,15 @@ impl Player { .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()), + true => format!("× {}%", self.volume.percent()), + false => format!("{}%", self.volume.percent()), }, "mutes and unmutes; the level is what it comes back to", ActionId::ToggleMute, @@ -186,6 +197,10 @@ impl Player { this.set_volume(|volume| volume.muted = !volume.muted, cx) }), )) + .text_color(rgb(match muted { + true => STATUS_WARNING, + false => FG_PRIMARY, + })) .child(volume_slider( self.volume, self.volume_bar.clone(), @@ -226,6 +241,7 @@ impl Player { .child(self.action_control( "cut", 0., + BG_RAISED, Some(cut_glyph().into_any_element()), "Split", "splits the clip under the playhead", @@ -235,6 +251,7 @@ impl Player { .child(self.action_control( "delete", 0., + BG_RAISED, Some(delete_glyph().into_any_element()), "Delete", "takes the marked clip off the timeline", @@ -244,6 +261,7 @@ impl Player { .child(self.action_control( "undo", 0., + BG_RAISED, None, "Undo", "takes the last edit back", @@ -254,6 +272,7 @@ impl Player { .child(self.action_control( "add-video-lane", 0., + BG_RAISED, None, "+ V", "adds a video track under the ones there", @@ -265,6 +284,7 @@ impl Player { .child(self.action_control( "add-audio-lane", 0., + BG_RAISED, None, "+ A", "adds an audio track under the ones there", @@ -276,6 +296,7 @@ impl Player { .child(self.action_control( "add-subtitle-track", 0., + BG_RAISED, None, "+ S", "adds every subtitle track in a file you pick", @@ -291,6 +312,7 @@ impl Player { .child(self.action_control( "snap", SNAP_SLOT_W, + BG_RAISED, None, if self.snap { "Snap on" } else { "Snap off" }, match self.snap { @@ -303,6 +325,7 @@ impl Player { .child(self.action_control( "subs", SNAP_SLOT_W, + BG_RAISED, None, match (self.subtitle_track().is_some(), self.subs_on) { (false, _) => "No subs", @@ -317,6 +340,7 @@ impl Player { .child(self.action_control( "zoom-out", CONTROL_H, + BG_RAISED, None, "−", "show more of the timeline; stops with all of it on the bed", @@ -328,6 +352,7 @@ impl Player { .child(self.action_control( "zoom-fit", ZOOM_SLOT_W, + BG_RAISED, None, span_label(self.view().span()), "fit the whole timeline on the bed", @@ -337,6 +362,7 @@ impl Player { .child(self.action_control( "zoom-in", CONTROL_H, + BG_RAISED, None, "+", "magnify around the playhead; ctrl+wheel on the ruler zooms at the pointer", @@ -346,6 +372,7 @@ impl Player { .child(self.action_control( "keys", 0., + BG_RAISED, None, "Actions", "do any action, or change the key that does it", @@ -365,6 +392,7 @@ impl Player { .child(control( "controls-more", CONTROL_H, + BG_RAISED, None, "⋯", format!( @@ -390,3 +418,5 @@ 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.; diff --git a/crates/app/src/ui/widgets.rs b/crates/app/src/ui/widgets.rs index 48ca344..de3fd6c 100644 --- a/crates/app/src/ui/widgets.rs +++ b/crates/app/src/ui/widgets.rs @@ -48,6 +48,9 @@ pub(crate) fn control( // that relabels itself ("Export"/"Cancel") from shoving its neighbours // along the row every time its state changes. w: f32, + // The plane the button stands on. One button in the window is the accent + // (Export, the primary action); everything else is `BG_RAISED`. + bg: u32, glyph: Option, // Not `&'static str`: the volume button's label is its state. label: impl Into, @@ -68,7 +71,8 @@ pub(crate) fn control( .px(px(8.)) .when(w > 0., |d| d.w(px(w)).overflow_hidden()) .rounded(px(4.)) - .bg(rgb(BG_RAISED)) + .bg(rgb(bg)) + .when(bg == ACCENT_PRIMARY, |d| d.text_color(rgb(BG_CANVAS))) .children(glyph) .child(label) .tooltip(move |_, cx| cx.new(|_| Tip(tip.clone())).into())