Four regions, one oracle, one token table
Browse files at this commit2ae5c26e6a988d0248af73025accb6a8bf8fca2aParent: d8bffff- feat
- four regions, one oracle, one token table
9 changed files +949 -557
- crates/app/src/main.rs +229 -105
- crates/app/src/ui/cards.rs +11 -5
- crates/app/src/ui/inspector.rs +273 -0
- crates/app/src/ui/library.rs +2 -0
- crates/app/src/ui/overlays.rs +3 -0
- crates/app/src/ui/theme.rs +1 -1
- crates/app/src/ui/timeline.rs +30 -445
- crates/app/src/ui/toolbar.rs +392 -0
- crates/app/src/ui/widgets.rs +8 -1
crates/app/src/main.rsmodified+229 -105
| @@ -1,7 +1,9 @@ | |||
| 1 | mod keymap; | 1 | mod keymap; |
| 2 | mod ui; | 2 | mod ui; |
| 3 | 3 | ||
| 4 | +use ui::inspector::section_head; | ||
| 4 | use ui::theme::*; | 5 | use ui::theme::*; |
| 6 | +use ui::toolbar::{EXPORT_SLOT_W, SNAP_SLOT_W, VOLUME_SLOT_W, ZOOM_SLOT_W}; | ||
| 5 | use ui::widgets::*; | 7 | use ui::widgets::*; |
| 6 | 8 | ||
| 7 | use keymap::{ActionId, Keymap}; | 9 | use keymap::{ActionId, Keymap}; |
| @@ -277,6 +279,12 @@ impl Volume { | |||
| 277 | f32::from(self.steps) / f32::from(Self::MAX_STEPS) | 279 | f32::from(self.steps) / f32::from(Self::MAX_STEPS) |
| 278 | } | 280 | } |
| 279 | 281 | ||
| 282 | + /// The level as a whole number, for the button's fixed rect: muting swaps | ||
| 283 | + /// the glyph beside it, never the width of the box. | ||
| 284 | + fn percent(self) -> u32 { | ||
| 285 | + u32::from(self.steps) * 100 / u32::from(Self::MAX_STEPS) | ||
| 286 | + } | ||
| 287 | + | ||
| 280 | /// What the button reads. The level shows while muted too: it is what the | 288 | /// What the button reads. The level shows while muted too: it is what the |
| 281 | /// next press of the mute key brings back. | 289 | /// next press of the mute key brings back. |
| 282 | fn label(self) -> String { | 290 | fn label(self) -> String { |
| @@ -1559,6 +1567,18 @@ impl Player { | |||
| 1559 | /// menu item that names the same action. One table, so the two can never | 1567 | /// menu item that names the same action. One table, so the two can never |
| 1560 | /// come to mean different things. | 1568 | /// come to mean different things. |
| 1561 | fn act(&mut self, action: ActionId, cx: &mut Context<Self>) { | 1569 | fn act(&mut self, action: ActionId, cx: &mut Context<Self>) { |
| 1570 | + // Two doors, one oracle. This used to be the asymmetry the whole | ||
| 1571 | + // toolbar was built on: the buttons dimmed themselves off | ||
| 1572 | + // [`enable`] while the keyboard walked straight past it, so with no | ||
| 1573 | + // file open `s` toggled the snap and `v` added a track while the very | ||
| 1574 | + // same controls sat dim and *dead* to the pointer. Whatever refuses the | ||
| 1575 | + // button refuses the key, in the oracle's own words -- and a refusal | ||
| 1576 | + // that is silent from the keyboard is a bug the same size. | ||
| 1577 | + if let Some(why) = self.enable(action, None).why() { | ||
| 1578 | + self.notice = Some(format!("{} — {why}", action.label()).into()); | ||
| 1579 | + cx.notify(); | ||
| 1580 | + return; | ||
| 1581 | + } | ||
| 1562 | match action { | 1582 | match action { |
| 1563 | ActionId::Play => self.toggle_or_restart(cx), | 1583 | ActionId::Play => self.toggle_or_restart(cx), |
| 1564 | ActionId::StepBack => self.step(-1, cx), | 1584 | ActionId::StepBack => self.step(-1, cx), |
| @@ -1726,6 +1746,7 @@ impl Player { | |||
| 1726 | timeline: true, | 1746 | timeline: true, |
| 1727 | clipboard: self.clipboard.is_some(), | 1747 | clipboard: self.clipboard.is_some(), |
| 1728 | subtitles: !session.subtitles().is_empty(), | 1748 | subtitles: !session.subtitles().is_empty(), |
| 1749 | + playable: !nothing_to_play(Some(session)), | ||
| 1729 | exporting: self.exporting().is_some(), | 1750 | exporting: self.exporting().is_some(), |
| 1730 | } | 1751 | } |
| 1731 | } | 1752 | } |
| @@ -5716,21 +5737,14 @@ impl Render for Player { | |||
| 5716 | .flex_col() | 5737 | .flex_col() |
| 5717 | .bg(rgb(BG_CANVAS)) | 5738 | .bg(rgb(BG_CANVAS)) |
| 5718 | .text_color(rgb(FG_PRIMARY)) | 5739 | .text_color(rgb(FG_PRIMARY)) |
| 5719 | - .text_size(px(13.)) | 5740 | + .text_size(px(12.)) |
| 5720 | - .child( | 5741 | + // Four regions, the arrangement every consumer editor shares: |
| 5721 | - div() | 5742 | + // library left, picture centre, inspector right, and the timeline |
| 5722 | - .flex_none() | 5743 | + // full width along the bottom with its edit toolbar directly above |
| 5723 | - .h(px(HEADER_H)) | 5744 | + // it. Nothing here moves when the state changes -- the regions are |
| 5724 | - .flex() | 5745 | + // fixed and the panels keep their room whether or not anything is |
| 5725 | - .items_center() | 5746 | + // open in them. |
| 5726 | - .px(px(12.)) | 5747 | + .child(self.topbar(cx)) |
| 5727 | - .bg(rgb(BG_PANEL)) | ||
| 5728 | - .child(self.name.clone()), | ||
| 5729 | - ) | ||
| 5730 | - // The library beside the picture rather than under it: a media pool | ||
| 5731 | - // is a column in every editor that has one, and the timeline below | ||
| 5732 | - // already owns the full width. `library_w` is what keeps the | ||
| 5733 | - // picture the majority of the row at every window size. | ||
| 5734 | .child( | 5748 | .child( |
| 5735 | div() | 5749 | div() |
| 5736 | .flex_1() | 5750 | .flex_1() |
| @@ -5745,40 +5759,54 @@ impl Render for Player { | |||
| 5745 | div() | 5759 | div() |
| 5746 | .flex_1() | 5760 | .flex_1() |
| 5747 | .min_w(px(0.)) | 5761 | .min_w(px(0.)) |
| 5748 | - .overflow_hidden() | ||
| 5749 | - // The bed the cue plate is placed against: it hangs | ||
| 5750 | - // off the bottom of the picture region, which is the | ||
| 5751 | - // one box that is the picture and nothing else. | ||
| 5752 | - .relative() | ||
| 5753 | .flex() | 5762 | .flex() |
| 5754 | - .justify_center() | 5763 | + .flex_col() |
| 5755 | - .items_center() | 5764 | + .child( |
| 5756 | - .children( | 5765 | + div() |
| 5757 | - self.image | 5766 | + .flex_1() |
| 5758 | - .clone() | 5767 | + .min_h(px(0.)) |
| 5759 | - .map(|i| { | 5768 | + .overflow_hidden() |
| 5760 | - img(i) | 5769 | + // The bed the cue plate is placed against: |
| 5761 | - .size_full() | 5770 | + // it hangs off the bottom of the picture |
| 5762 | - .object_fit(gpui::ObjectFit::Contain) | 5771 | + // region, which is the one box that is the |
| 5763 | - .into_any_element() | 5772 | + // picture and nothing else. |
| 5764 | - }) | 5773 | + .relative() |
| 5765 | - // With no file open the letterbox is the | 5774 | + .flex() |
| 5766 | - // whole window, and a black rectangle says | 5775 | + .justify_center() |
| 5767 | - // only that something is broken -- so it | 5776 | + .items_center() |
| 5768 | - // says what it wants instead. The window is | 5777 | + .bg(rgb(BG_CANVAS)) |
| 5769 | - // already the drop target. | 5778 | + .children( |
| 5770 | - .or_else(|| { | 5779 | + self.image |
| 5771 | - self.session | 5780 | + .clone() |
| 5772 | - .is_none() | 5781 | + .map(|i| { |
| 5773 | - .then(|| empty_hint().into_any_element()) | 5782 | + img(i) |
| 5774 | - }), | 5783 | + .size_full() |
| 5784 | + .object_fit(gpui::ObjectFit::Contain) | ||
| 5785 | + .into_any_element() | ||
| 5786 | + }) | ||
| 5787 | + // With no file open the letterbox | ||
| 5788 | + // is the whole region, and a black | ||
| 5789 | + // rectangle says only that | ||
| 5790 | + // something is broken -- so it says | ||
| 5791 | + // what it wants instead. The window | ||
| 5792 | + // is already the drop target. | ||
| 5793 | + .or_else(|| { | ||
| 5794 | + self.session | ||
| 5795 | + .is_none() | ||
| 5796 | + .then(|| empty_hint().into_any_element()) | ||
| 5797 | + }), | ||
| 5798 | + ) | ||
| 5799 | + // After the picture, so the plate is drawn | ||
| 5800 | + // over it rather than under. | ||
| 5801 | + .children(self.subtitle_overlay(position, window)), | ||
| 5775 | ) | 5802 | ) |
| 5776 | - // After the picture, so the plate is drawn over it | 5803 | + .child(self.transport_bar(position, state, cx)), |
| 5777 | - // rather than under: siblings paint in order. | 5804 | + ) |
| 5778 | - .children(self.subtitle_overlay(position, window)), | 5805 | + // The settings cards live in here rather than over the |
| 5779 | - ), | 5806 | + // timeline: adjusting a clip must not hide the clip. |
| 5807 | + .child(self.inspector(window.viewport_size(), cx)), | ||
| 5780 | ) | 5808 | ) |
| 5781 | - // Above the panel and only when there is one to show, so it costs | 5809 | + // Above the toolbar and only when there is one to show, so it costs |
| 5782 | // the picture nothing the rest of the time. The import's line sits | 5810 | // the picture nothing the rest of the time. The import's line sits |
| 5783 | // over the notice's: a notice is about something that has already | 5811 | // over the notice's: a notice is about something that has already |
| 5784 | // happened, and this is about something still happening. | 5812 | // happened, and this is about something still happening. |
| @@ -5787,25 +5815,19 @@ impl Render for Player { | |||
| 5787 | // loud because a still picture is the only other evidence of it. | 5815 | // loud because a still picture is the only other evidence of it. |
| 5788 | .children(self.seek_bar()) | 5816 | .children(self.seek_bar()) |
| 5789 | .children(self.notice_bar(cx)) | 5817 | .children(self.notice_bar(cx)) |
| 5790 | - .child(self.panel(position, duration, state, cx)) | 5818 | + .child(self.toolbar(cx)) |
| 5791 | - // Over the panel it was opened on, and under the cards: it is only | 5819 | + .child(self.timeline(position, duration, state, cx)) |
| 5792 | - // ever up while neither of them is (`modal`). | 5820 | + // Over the region they were opened on, and under the modal cards: |
| 5821 | + // they are only ever up while none of those is (`modal`). | ||
| 5793 | .children(self.context_card(window.viewport_size(), cx)) | 5822 | .children(self.context_card(window.viewport_size(), cx)) |
| 5794 | - // The library's own menu, the same way and for the same reason: | ||
| 5795 | - // over the panel it was opened on, under the cards, and never up | ||
| 5796 | - // while one of them is. | ||
| 5797 | .children(self.library_card(window.viewport_size(), cx)) | 5823 | .children(self.library_card(window.viewport_size(), cx)) |
| 5798 | - // Last, so they are over everything -- they take no room in the | 5824 | + // The two that are genuinely modal -- the whole registry, and the |
| 5799 | - // column, and only one of the two is ever up. | 5825 | + // card that writes a file -- are the only sheets left over the |
| 5826 | + // window. | ||
| 5800 | .children(self.keys_overlay(cx)) | 5827 | .children(self.keys_overlay(cx)) |
| 5801 | .children(self.export_card(window.viewport_size(), cx)) | 5828 | .children(self.export_card(window.viewport_size(), cx)) |
| 5802 | - .children(self.eq_card(window.viewport_size(), cx)) | 5829 | + // Last, so it floats over whatever opened it -- an inspector row or |
| 5803 | - .children(self.color_card(cx)) | 5830 | + // a clip menu -- rather than under it. |
| 5804 | - .children(self.speed_card(cx)) | ||
| 5805 | - .children(self.silence_card(cx)) | ||
| 5806 | - .children(self.mix_card(cx)) | ||
| 5807 | - // Last, so it floats over whatever opened it -- the panel's button | ||
| 5808 | - // or a clip menu -- rather than under it. | ||
| 5809 | .children(self.picker_card(window.viewport_size(), cx)) | 5831 | .children(self.picker_card(window.viewport_size(), cx)) |
| 5810 | } | 5832 | } |
| 5811 | } | 5833 | } |
| @@ -6719,6 +6741,10 @@ struct Ctx { | |||
| 6719 | /// This timeline has at least one subtitle track: a toggle with nothing to | 6741 | /// This timeline has at least one subtitle track: a toggle with nothing to |
| 6720 | /// show is a switch that does nothing, and it says so rather than flipping. | 6742 | /// show is a switch that does nothing, and it says so rather than flipping. |
| 6721 | subtitles: bool, | 6743 | subtitles: bool, |
| 6744 | + /// There is something on the lanes to play. A transport with nothing under | ||
| 6745 | + /// it is the one refusal that is about the timeline's contents rather than | ||
| 6746 | + /// about a clip. | ||
| 6747 | + playable: bool, | ||
| 6722 | exporting: bool, | 6748 | exporting: bool, |
| 6723 | } | 6749 | } |
| 6724 | 6750 | ||
| @@ -6739,6 +6765,18 @@ fn enable(action: ActionId, ctx: Ctx) -> Enable { | |||
| 6739 | false => Enable::Yes, | 6765 | false => Enable::Yes, |
| 6740 | }; | 6766 | }; |
| 6741 | } | 6767 | } |
| 6768 | + // The four that are about the *editor* and its monitoring rather than | ||
| 6769 | + // about the edit list: they work with nothing open, the keyboard has | ||
| 6770 | + // always fired them there, and so their buttons are live there too. | ||
| 6771 | + if matches!( | ||
| 6772 | + action, | ||
| 6773 | + ActionId::ToggleSnap | ActionId::ToggleMute | ActionId::VolumeUp | ActionId::VolumeDown | ||
| 6774 | + ) { | ||
| 6775 | + return match ctx.exporting { | ||
| 6776 | + true => Enable::No("an export is running"), | ||
| 6777 | + false => Enable::Yes, | ||
| 6778 | + }; | ||
| 6779 | + } | ||
| 6742 | if !ctx.timeline { | 6780 | if !ctx.timeline { |
| 6743 | return Enable::No("no timeline open"); | 6781 | return Enable::No("no timeline open"); |
| 6744 | } | 6782 | } |
| @@ -6819,6 +6857,10 @@ fn enable(action: ActionId, ctx: Ctx) -> Enable { | |||
| 6819 | Enable::No("no subtitles yet") | 6857 | Enable::No("no subtitles yet") |
| 6820 | } | 6858 | } |
| 6821 | ActionId::CancelExport => Enable::No("nothing is exporting"), | 6859 | ActionId::CancelExport => Enable::No("nothing is exporting"), |
| 6860 | + // A clock started against an empty timeline is a clock counting | ||
| 6861 | + // nothing: the transport says so by being dim, which is what its own | ||
| 6862 | + // ad-hoc boolean used to say before the oracle knew the question. | ||
| 6863 | + ActionId::Play if !ctx.playable => Enable::No("put a clip on a lane first"), | ||
| 6822 | // A rate applies to a clip of either kind and to its whole group, so | 6864 | // A rate applies to a clip of either kind and to its whole group, so |
| 6823 | // there is no lane it means nothing on, and the engine words the one | 6865 | // there is no lane it means nothing on, and the engine words the one |
| 6824 | // refusal there is (no room). Everything else is the editor's own and | 6866 | // refusal there is (no room). Everything else is the editor's own and |
| @@ -8191,6 +8233,25 @@ fn panel_h(lanes: usize) -> f32 { | |||
| 8191 | PANEL_H + lanes_h(lanes.clamp(2, LANES_MAX)) - lanes_h(2) | 8233 | PANEL_H + lanes_h(lanes.clamp(2, LANES_MAX)) - lanes_h(2) |
| 8192 | } | 8234 | } |
| 8193 | 8235 | ||
| 8236 | +/// ...and how tall the timeline region alone is: the panel without the button | ||
| 8237 | +/// row that used to sit inside it, which is now its own region above | ||
| 8238 | +/// ([`Player::toolbar`], [`TOOLBAR_H`]). | ||
| 8239 | +fn timeline_h(lanes: usize) -> f32 { | ||
| 8240 | + panel_h(lanes) - TOOLBAR_H | ||
| 8241 | +} | ||
| 8242 | + | ||
| 8243 | +/// The edit toolbar directly above the timeline: one control's height in its | ||
| 8244 | +/// own padding, fixed so nothing in it can push the timeline down. | ||
| 8245 | +const TOOLBAR_H: f32 = CONTROL_H + 16.; | ||
| 8246 | + | ||
| 8247 | +/// The top bar: the project's name on the left, the two file actions on the | ||
| 8248 | +/// right. Fixed for the reason [`HEADER_H`] is. | ||
| 8249 | +const TOPBAR_H: f32 = 36.; | ||
| 8250 | + | ||
| 8251 | +/// The transport strip under the picture -- play, timecode, volume -- where a | ||
| 8252 | +/// player's own controls live in every consumer editor. | ||
| 8253 | +const TRANSPORT_H: f32 = CONTROL_H + 12.; | ||
| 8254 | + | ||
| 8194 | /// One press of a zoom key, or one notch of ctrl+wheel. | 8255 | /// One press of a zoom key, or one notch of ctrl+wheel. |
| 8195 | const ZOOM_STEP: f32 = 1.25; | 8256 | const ZOOM_STEP: f32 = 1.25; |
| 8196 | 8257 | ||
| @@ -9405,6 +9466,26 @@ mod tests { | |||
| 9405 | use std::path::{Path, PathBuf}; | 9466 | use std::path::{Path, PathBuf}; |
| 9406 | use std::time::{Duration, Instant}; | 9467 | use std::time::{Duration, Instant}; |
| 9407 | 9468 | ||
| 9469 | + /// Every line of UI source there is, as one string: the window used to be | ||
| 9470 | + /// one file and the scans below read it with `include_str!`. The regions | ||
| 9471 | + /// are modules now (`ui/`), so the scans read all of them -- a rule that | ||
| 9472 | + /// stopped at `main.rs` would pass by simply not looking where the pixels | ||
| 9473 | + /// moved to. | ||
| 9474 | + fn ui_source() -> String { | ||
| 9475 | + [ | ||
| 9476 | + include_str!("main.rs").split("#[cfg(test)]").next().unwrap(), | ||
| 9477 | + include_str!("ui/toolbar.rs"), | ||
| 9478 | + include_str!("ui/inspector.rs"), | ||
| 9479 | + include_str!("ui/timeline.rs"), | ||
| 9480 | + include_str!("ui/library.rs"), | ||
| 9481 | + include_str!("ui/preview.rs"), | ||
| 9482 | + include_str!("ui/cards.rs"), | ||
| 9483 | + include_str!("ui/overlays.rs"), | ||
| 9484 | + include_str!("ui/widgets.rs"), | ||
| 9485 | + ] | ||
| 9486 | + .concat() | ||
| 9487 | + } | ||
| 9488 | + | ||
| 9408 | fn asset(name: &str) -> PathBuf { | 9489 | fn asset(name: &str) -> PathBuf { |
| 9409 | Path::new(env!("CARGO_MANIFEST_DIR")) | 9490 | Path::new(env!("CARGO_MANIFEST_DIR")) |
| 9410 | .join("../../assets") | 9491 | .join("../../assets") |
| @@ -9870,9 +9951,37 @@ mod tests { | |||
| 9870 | ); | 9951 | ); |
| 9871 | let live = Ctx { | 9952 | let live = Ctx { |
| 9872 | timeline: true, | 9953 | timeline: true, |
| 9954 | + playable: true, | ||
| 9873 | ..Ctx::default() | 9955 | ..Ctx::default() |
| 9874 | }; | 9956 | }; |
| 9875 | assert!(whole(ActionId::Play, live).yes()); | 9957 | assert!(whole(ActionId::Play, live).yes()); |
| 9958 | + // ...and an open timeline with nothing on its lanes refuses the | ||
| 9959 | + // transport in the oracle rather than in the button, which is what | ||
| 9960 | + // makes the key and the button say the same thing. | ||
| 9961 | + assert_eq!( | ||
| 9962 | + whole( | ||
| 9963 | + ActionId::Play, | ||
| 9964 | + Ctx { | ||
| 9965 | + playable: false, | ||
| 9966 | + ..live | ||
| 9967 | + } | ||
| 9968 | + ), | ||
| 9969 | + Enable::No("put a clip on a lane first") | ||
| 9970 | + ); | ||
| 9971 | + // The magnet and the monitoring level are the editor's own and answer | ||
| 9972 | + // with no timeline at all -- the keyboard always fired them there, and | ||
| 9973 | + // now so does the toolbar. | ||
| 9974 | + for editor_wide in [ | ||
| 9975 | + ActionId::ToggleSnap, | ||
| 9976 | + ActionId::ToggleMute, | ||
| 9977 | + ActionId::VolumeUp, | ||
| 9978 | + ActionId::VolumeDown, | ||
| 9979 | + ] { | ||
| 9980 | + assert!( | ||
| 9981 | + whole(editor_wide, Ctx::default()).yes(), | ||
| 9982 | + "{editor_wide:?} is dead with no file open while its key still fires" | ||
| 9983 | + ); | ||
| 9984 | + } | ||
| 9876 | assert!(!whole(ActionId::Delete, live).yes()); | 9985 | assert!(!whole(ActionId::Delete, live).yes()); |
| 9877 | assert!(!whole(ActionId::Paste, live).yes()); | 9986 | assert!(!whole(ActionId::Paste, live).yes()); |
| 9878 | assert!( | 9987 | assert!( |
| @@ -10103,10 +10212,8 @@ mod tests { | |||
| 10103 | #[test] | 10212 | #[test] |
| 10104 | fn every_action_is_reachable_without_the_keyboard() { | 10213 | fn every_action_is_reachable_without_the_keyboard() { |
| 10105 | use keymap::ActionId; | 10214 | use keymap::ActionId; |
| 10106 | - let source = include_str!("main.rs") | 10215 | + let source = ui_source(); |
| 10107 | - .split("#[cfg(test)]") | 10216 | + let source = source.as_str(); |
| 10108 | - .next() | ||
| 10109 | - .unwrap(); | ||
| 10110 | let element = |id: &str| source.contains(&format!("\"{id}\"")); | 10217 | let element = |id: &str| source.contains(&format!("\"{id}\"")); |
| 10111 | let listed: Vec<ActionId> = keys_rows() | 10218 | let listed: Vec<ActionId> = keys_rows() |
| 10112 | .iter() | 10219 | .iter() |
| @@ -10181,10 +10288,8 @@ mod tests { | |||
| 10181 | /// the day it is added, which is the only way the two stay in step. | 10288 | /// the day it is added, which is the only way the two stay in step. |
| 10182 | #[test] | 10289 | #[test] |
| 10183 | fn every_card_closes_without_the_keyboard() { | 10290 | fn every_card_closes_without_the_keyboard() { |
| 10184 | - let source = include_str!("main.rs") | 10291 | + let source = ui_source(); |
| 10185 | - .split("#[cfg(test)]") | 10292 | + let source = source.as_str(); |
| 10186 | - .next() | ||
| 10187 | - .unwrap(); | ||
| 10188 | // A fn's source, up to the next one: enough of a body to scan. | 10293 | // A fn's source, up to the next one: enough of a body to scan. |
| 10189 | let body = |name: &str| -> &str { | 10294 | let body = |name: &str| -> &str { |
| 10190 | let at = source | 10295 | let at = source |
| @@ -12916,12 +13021,15 @@ mod tests { | |||
| 12916 | "refusal ink {:.2}", | 13021 | "refusal ink {:.2}", |
| 12917 | contrast(FG_SECONDARY, BG_RAISED) | 13022 | contrast(FG_SECONDARY, BG_RAISED) |
| 12918 | ); | 13023 | ); |
| 12919 | - // On the picked row that ink would only be 3.3:1 against the highlight, | 13024 | + // ...and on the picked row, where the highlight is the accent at |
| 12920 | - // so the row it lands on lifts its key and detail to `FG_PRIMARY`. | 13025 | + // surface brightness. Both inks clear 4.5:1 on it now -- the row still |
| 13026 | + // lifts its key and detail to `FG_PRIMARY`, as emphasis rather than as | ||
| 13027 | + // the rescue it used to be. | ||
| 12921 | assert!(contrast(FG_PRIMARY, BG_SELECTED) >= 4.5); | 13028 | assert!(contrast(FG_PRIMARY, BG_SELECTED) >= 4.5); |
| 12922 | assert!( | 13029 | assert!( |
| 12923 | - contrast(FG_SECONDARY, BG_SELECTED) < 4.5, | 13030 | + contrast(FG_SECONDARY, BG_SELECTED) >= 4.5, |
| 12924 | - "the lift is still needed" | 13031 | + "refusal ink on the picked row {:.2}", |
| 13032 | + contrast(FG_SECONDARY, BG_SELECTED) | ||
| 12925 | ); | 13033 | ); |
| 12926 | } | 13034 | } |
| 12927 | 13035 | ||
| @@ -14025,43 +14133,45 @@ mod tests { | |||
| 14025 | assert_eq!(cue_box(scale, &mapped[1]), (80., 40.)); | 14133 | assert_eq!(cue_box(scale, &mapped[1]), (80., 40.)); |
| 14026 | } | 14134 | } |
| 14027 | 14135 | ||
| 14028 | - /// The panel's button row against the 640x360 floor the whole editor is | 14136 | + /// The edit toolbar against the 640x360 floor the whole editor is measured |
| 14029 | - /// measured at. It does not fit and cannot be made to -- so what it may | 14137 | + /// at. It does not fit and cannot be made to -- so what it may never do is |
| 14030 | - /// never do is *hide* the tail: the row scrolls, and the door to everything | 14138 | + /// *hide* the tail: the row scrolls, and the door to everything scrolled |
| 14031 | - /// scrolled off it is pinned outside the scrolling box. | 14139 | + /// off it is pinned outside the scrolling box. |
| 14032 | #[test] | 14140 | #[test] |
| 14033 | fn toolbar_fits_the_smallest_window() { | 14141 | fn toolbar_fits_the_smallest_window() { |
| 14034 | - let source = include_str!("main.rs") | 14142 | + let toolbar = include_str!("ui/toolbar.rs"); |
| 14035 | - .split("#[cfg(test)]") | 14143 | + let row = &toolbar[toolbar.find("pub(crate) fn toolbar(").expect("the toolbar")..]; |
| 14036 | - .next() | ||
| 14037 | - .unwrap(); | ||
| 14038 | - let panel = &source[source.find(" fn panel(").expect("the panel") | ||
| 14039 | - ..source.find(" fn import_bar(").expect("the panel's end")]; | ||
| 14040 | // Every button in the row is a hit target, so none of them is narrower | 14144 | // Every button in the row is a hit target, so none of them is narrower |
| 14041 | - // than `HIT_MIN`, and they sit in 8 px gaps inside the panel's own | 14145 | + // than `HIT_MIN`, and they sit in 8 px gaps inside the row's own 12 px |
| 14042 | - // 12 px padding. The level slider is the one fixed width among them. | 14146 | + // padding. |
| 14043 | - let buttons = panel.matches("control(").count(); | 14147 | + let buttons = row.matches("action_control(").count(); |
| 14044 | - assert!(buttons >= 15, "the row's buttons moved; this scan is blind"); | 14148 | + assert!(buttons >= 11, "the row's buttons moved; this scan is blind"); |
| 14045 | - let row_w = buttons as f32 * (HIT_MIN + 8.) + VOLUME_W + 24.; | 14149 | + // The row is shorter than it was -- the project's own settings (size, |
| 14046 | - assert!( | 14150 | + // rate, HDR) are the inspector's now and the transport is the |
| 14047 | - row_w > 640., | 14151 | + // picture's -- so whether it fits at 640 px depends on the words in it |
| 14048 | - "{row_w} px of buttons now fits the floor -- the pinned door may go" | 14152 | + // and is not something this scan can measure. What it can hold to is |
| 14049 | - ); | 14153 | + // the rule: "it scrolls" is not "it can be found", so the door to |
| 14050 | - // So Export, Save and Actions are off the right edge at that width, and | 14154 | + // whatever is off the right edge is pinned outside the scrolling box |
| 14051 | - // "it scrolls" is not "it can be found": this is the button that never | 14155 | + // and the card it opens carries every action there is |
| 14052 | - // scrolls, and the card it opens carries every action there is | ||
| 14053 | // (`every_action_is_on_the_actions_card`). | 14156 | // (`every_action_is_on_the_actions_card`). |
| 14054 | assert!( | 14157 | assert!( |
| 14055 | - panel.contains("\"controls-more\""), | 14158 | + row.contains("\"controls-more\""), |
| 14056 | "nothing pinned beside the scrolling row: the tail is unreachable at 640 px" | 14159 | "nothing pinned beside the scrolling row: the tail is unreachable at 640 px" |
| 14057 | ); | 14160 | ); |
| 14058 | - // ...and it is outside the scrolling box, which is the whole point of | 14161 | + assert_eq!(row.matches("overflow_x_scroll").count(), 1); |
| 14059 | - // it: one `overflow_x_scroll`, and the door is written after it closes. | ||
| 14060 | - assert_eq!(panel.matches("overflow_x_scroll").count(), 1); | ||
| 14061 | assert!( | 14162 | assert!( |
| 14062 | - panel.find("\"controls-more\"") > panel.find("overflow_x_scroll"), | 14163 | + row.find("\"controls-more\"") > row.find("overflow_x_scroll"), |
| 14063 | "the pinned door is inside the row it is meant to outlive" | 14164 | "the pinned door is inside the row it is meant to outlive" |
| 14064 | ); | 14165 | ); |
| 14166 | + // ...and nothing in the row decides for itself whether it can act: the | ||
| 14167 | + // oracle does, once, for the key and the button alike. A raw `control(` | ||
| 14168 | + // in here is a button that can go dead while its stroke still fires -- | ||
| 14169 | + // the bug this redesign was called in for. | ||
| 14170 | + assert_eq!( | ||
| 14171 | + row.matches("\n .child(control(").count(), | ||
| 14172 | + 0, | ||
| 14173 | + "a toolbar button bypassing the availability oracle" | ||
| 14174 | + ); | ||
| 14065 | } | 14175 | } |
| 14066 | 14176 | ||
| 14067 | #[test] | 14177 | #[test] |
| @@ -14392,7 +14502,19 @@ mod tests { | |||
| 14392 | 14502 | ||
| 14393 | #[test] | 14503 | #[test] |
| 14394 | fn every_mark_on_a_clip_is_legible_on_it() { | 14504 | fn every_mark_on_a_clip_is_legible_on_it() { |
| 14395 | - for (i, tint) in SOURCE_TINTS.iter().enumerate() { | 14505 | + // The body a name and a waveform are drawn on is the clip's kind |
| 14506 | + // ([`clip_kind`]); the source tint is the border and the library | ||
| 14507 | + // swatch, and is measured for telling itself apart rather than for | ||
| 14508 | + // carrying text. | ||
| 14509 | + for (i, tint) in [ | ||
| 14510 | + crate::ui::theme::CLIP_VIDEO, | ||
| 14511 | + crate::ui::theme::CLIP_AUDIO, | ||
| 14512 | + crate::ui::theme::CLIP_IMAGE, | ||
| 14513 | + crate::ui::theme::CLIP_TEXT, | ||
| 14514 | + ] | ||
| 14515 | + .iter() | ||
| 14516 | + .enumerate() | ||
| 14517 | + { | ||
| 14396 | // WCAG 1.4.3: the clip's name is body text on its tint. | 14518 | // WCAG 1.4.3: the clip's name is body text on its tint. |
| 14397 | assert!( | 14519 | assert!( |
| 14398 | contrast(FG_PRIMARY, *tint) >= 4.5, | 14520 | contrast(FG_PRIMARY, *tint) >= 4.5, |
| @@ -14409,10 +14531,12 @@ mod tests { | |||
| 14409 | // A selected clip's bed is the same two marks on a different colour. | 14531 | // A selected clip's bed is the same two marks on a different colour. |
| 14410 | assert!(contrast(FG_PRIMARY, BG_SELECTED) >= 4.5); | 14532 | assert!(contrast(FG_PRIMARY, BG_SELECTED) >= 4.5); |
| 14411 | assert!(contrast(FG_SECONDARY, BG_SELECTED) >= 3.); | 14533 | assert!(contrast(FG_SECONDARY, BG_SELECTED) >= 3.); |
| 14412 | - // The bed a gap shows through has to read as a hole in the lane, and | 14534 | + // The bed a gap shows through has to read as a hole in the lane -- the |
| 14413 | - // the accent playhead has to be findable on it. | 14535 | + // clip is the object, the bed is the hole -- and the playhead has to be |
| 14414 | - assert!(contrast(BG_CANVAS, BG_RAISED) >= 1.5); | 14536 | + // findable on both. |
| 14415 | - assert!(contrast(ACCENT_PRIMARY, BG_CANVAS) >= 3.); | 14537 | + assert!(contrast(crate::ui::theme::CLIP_VIDEO, crate::ui::theme::BG_TIMELINE) >= 1.5); |
| 14538 | + assert!(contrast(crate::ui::theme::ACCENT_PLAYHEAD, crate::ui::theme::BG_TIMELINE) >= 3.); | ||
| 14539 | + assert!(contrast(crate::ui::theme::ACCENT_PLAYHEAD, crate::ui::theme::CLIP_VIDEO) >= 3.); | ||
| 14416 | // The sanity check on the ratio itself: black on white is 21:1. | 14540 | // The sanity check on the ratio itself: black on white is 21:1. |
| 14417 | assert!((contrast(0xffffff, 0x000000) - 21.).abs() < 0.01); | 14541 | assert!((contrast(0xffffff, 0x000000) - 21.).abs() < 0.01); |
| 14418 | } | 14542 | } |
crates/app/src/ui/cards.rsmodified+11 -5
| @@ -1025,7 +1025,9 @@ impl Player { | |||
| 1025 | div() | 1025 | div() |
| 1026 | .id(("color-bar", i)) | 1026 | .id(("color-bar", i)) |
| 1027 | .relative() | 1027 | .relative() |
| 1028 | - .w(px(COLOR_BAR_W)) | 1028 | + .flex_1() |
| 1029 | + .min_w(px(0.)) | ||
| 1030 | + .max_w(px(COLOR_BAR_W)) | ||
| 1029 | .h(px(KEYS_ROW_H)) | 1031 | .h(px(KEYS_ROW_H)) |
| 1030 | .flex() | 1032 | .flex() |
| 1031 | .items_center() | 1033 | .items_center() |
| @@ -1079,7 +1081,8 @@ impl Player { | |||
| 1079 | ) | 1081 | ) |
| 1080 | .child( | 1082 | .child( |
| 1081 | div() | 1083 | div() |
| 1082 | - .w(px(COLOR_W)) | 1084 | + .w_full() |
| 1085 | + .max_w(px(COLOR_W)) | ||
| 1083 | .on_mouse_down(MouseButton::Left, swallow) | 1086 | .on_mouse_down(MouseButton::Left, swallow) |
| 1084 | .flex() | 1087 | .flex() |
| 1085 | .flex_col() | 1088 | .flex_col() |
| @@ -1195,7 +1198,8 @@ impl Player { | |||
| 1195 | ) | 1198 | ) |
| 1196 | .child( | 1199 | .child( |
| 1197 | div() | 1200 | div() |
| 1198 | - .w(px(COLOR_W)) | 1201 | + .w_full() |
| 1202 | + .max_w(px(COLOR_W)) | ||
| 1199 | .on_mouse_down(MouseButton::Left, swallow) | 1203 | .on_mouse_down(MouseButton::Left, swallow) |
| 1200 | .flex() | 1204 | .flex() |
| 1201 | .flex_col() | 1205 | .flex_col() |
| @@ -1392,7 +1396,8 @@ impl Player { | |||
| 1392 | ) | 1396 | ) |
| 1393 | .child( | 1397 | .child( |
| 1394 | div() | 1398 | div() |
| 1395 | - .w(px(COLOR_W)) | 1399 | + .w_full() |
| 1400 | + .max_w(px(COLOR_W)) | ||
| 1396 | .on_mouse_down(MouseButton::Left, swallow) | 1401 | .on_mouse_down(MouseButton::Left, swallow) |
| 1397 | .max_h(px(360. - 24.)) | 1402 | .max_h(px(360. - 24.)) |
| 1398 | .flex() | 1403 | .flex() |
| @@ -1609,7 +1614,8 @@ impl Player { | |||
| 1609 | ) | 1614 | ) |
| 1610 | .child( | 1615 | .child( |
| 1611 | div() | 1616 | div() |
| 1612 | - .w(px(COLOR_W)) | 1617 | + .w_full() |
| 1618 | + .max_w(px(COLOR_W)) | ||
| 1613 | .on_mouse_down(MouseButton::Left, swallow) | 1619 | .on_mouse_down(MouseButton::Left, swallow) |
| 1614 | .flex() | 1620 | .flex() |
| 1615 | .flex_col() | 1621 | .flex_col() |
crates/app/src/ui/inspector.rsmodified+273 -0
| @@ -0,0 +1,273 @@ | |||
| 1 | +//! The right-hand region: what is selected, and what can be done to it. | ||
| 2 | +//! | ||
| 3 | +//! Every consumer editor has this column, and edith's settings used to be | ||
| 4 | +//! floating cards *over the timeline* instead -- so adjusting a clip hid the | ||
| 5 | +//! very clip being adjusted. The cards are docked in here now: the equalizer, | ||
| 6 | +//! the grade, the speed, the silence scan and the mix are children of this | ||
| 7 | +//! panel, and opening one occludes zero timeline pixels | ||
| 8 | +//! (`an_inspector_section_occludes_no_timeline`). | ||
| 9 | + | ||
| 10 | +use crate::*; | ||
| 11 | +use crate::ui::widgets::*; | ||
| 12 | + | ||
| 13 | +impl Player { | ||
| 14 | + /// The inspector column. Two sections that are always there -- the | ||
| 15 | + /// selection's and the project's -- and, over them, whichever settings card | ||
| 16 | + /// is open, which is a section of this panel rather than a sheet over the | ||
| 17 | + /// window. | ||
| 18 | + pub(crate) fn inspector(&self, viewport: Size<Pixels>, cx: &mut Context<Self>) -> impl IntoElement { | ||
| 19 | + let width = inspector_w(f32::from(viewport.width)); | ||
| 20 | + // The cards measure themselves against the room they are given, and the | ||
| 21 | + // room they are given is this column -- not the window. | ||
| 22 | + let room = size(px(width), viewport.height); | ||
| 23 | + div() | ||
| 24 | + .id("inspector") | ||
| 25 | + .flex_none() | ||
| 26 | + .w(px(width)) | ||
| 27 | + .h_full() | ||
| 28 | + // The bed the docked cards are placed against: `scrim()` is | ||
| 29 | + // `absolute().inset_0()`, so it covers this panel and nothing else. | ||
| 30 | + .relative() | ||
| 31 | + .flex() | ||
| 32 | + .flex_col() | ||
| 33 | + .bg(rgb(BG_PANEL)) | ||
| 34 | + .border_l_1() | ||
| 35 | + .border_color(rgb(STROKE_DIVIDER)) | ||
| 36 | + .child(section_head("Inspector")) | ||
| 37 | + .child( | ||
| 38 | + div() | ||
| 39 | + .id("inspector-rows") | ||
| 40 | + .flex_1() | ||
| 41 | + .min_h(px(0.)) | ||
| 42 | + .overflow_y_scroll() | ||
| 43 | + .flex() | ||
| 44 | + .flex_col() | ||
| 45 | + .gap(px(8.)) | ||
| 46 | + .p(px(8.)) | ||
| 47 | + .child(self.selection_section(cx)) | ||
| 48 | + .child(self.project_section(cx)), | ||
| 49 | + ) | ||
| 50 | + .children(self.eq_card(room, cx)) | ||
| 51 | + .children(self.color_card(cx)) | ||
| 52 | + .children(self.speed_card(cx)) | ||
| 53 | + .children(self.silence_card(cx)) | ||
| 54 | + .children(self.mix_card(cx)) | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + /// What is marked, and the settings that belong to *it*. A dump of every | ||
| 58 | + /// property regardless of what is selected is the anti-pattern this avoids: | ||
| 59 | + /// with nothing marked the section says how to get one, and each button is | ||
| 60 | + /// dimmed with the oracle's reason rather than missing. | ||
| 61 | + fn selection_section(&self, cx: &mut Context<Self>) -> impl IntoElement { | ||
| 62 | + let picked = self.selected.and_then(|(lane, idx)| { | ||
| 63 | + let session = self.session.as_ref()?; | ||
| 64 | + let clip = session.lane_clips(lane).get(idx).copied()?; | ||
| 65 | + let source = session.sources().get(clip.source); | ||
| 66 | + let image = source.is_some_and(|s| engine::is_image(&s.path)); | ||
| 67 | + Some(( | ||
| 68 | + lane, | ||
| 69 | + clip, | ||
| 70 | + source.map_or_else(|| lane.label().to_string(), |s| file_name(&s.path)), | ||
| 71 | + image, | ||
| 72 | + )) | ||
| 73 | + }); | ||
| 74 | + let head = match &picked { | ||
| 75 | + Some((lane, _, name, _)) => format!("{} · {}", lane.label(), name), | ||
| 76 | + None => "Nothing selected".to_string(), | ||
| 77 | + }; | ||
| 78 | + let detail = match &picked { | ||
| 79 | + Some((_, clip, _, _)) => format!( | ||
| 80 | + "{} → {} · {} · {}", | ||
| 81 | + timecode(f64::from(clip.start) / self.fps, self.fps), | ||
| 82 | + timecode(f64::from(clip.start + clip.frames()) / self.fps, self.fps), | ||
| 83 | + span_label(f64::from(clip.frames()) / self.fps), | ||
| 84 | + clip.speed, | ||
| 85 | + ), | ||
| 86 | + None => "Click a clip on the timeline to see its settings".to_string(), | ||
| 87 | + }; | ||
| 88 | + div() | ||
| 89 | + .flex() | ||
| 90 | + .flex_col() | ||
| 91 | + .gap(px(6.)) | ||
| 92 | + .p(px(8.)) | ||
| 93 | + .rounded(px(4.)) | ||
| 94 | + .bg(rgb(BG_HOVER_DIM)) | ||
| 95 | + .child( | ||
| 96 | + div() | ||
| 97 | + .flex_none() | ||
| 98 | + .truncate() | ||
| 99 | + .text_color(rgb(match picked.is_some() { | ||
| 100 | + true => FG_PRIMARY, | ||
| 101 | + false => FG_SECONDARY, | ||
| 102 | + })) | ||
| 103 | + // The kind's own colour, the same one its clip wears on the | ||
| 104 | + // timeline: the panel and the box are about the same thing. | ||
| 105 | + .when_some(picked.as_ref(), |d, (lane, _, _, image)| { | ||
| 106 | + d.border_l_2() | ||
| 107 | + .border_color(rgb(clip_kind(lane.kind, *image))) | ||
| 108 | + .pl(px(6.)) | ||
| 109 | + }) | ||
| 110 | + .child(head), | ||
| 111 | + ) | ||
| 112 | + .child( | ||
| 113 | + div() | ||
| 114 | + .flex_none() | ||
| 115 | + .text_size(px(11.)) | ||
| 116 | + .text_color(rgb(FG_SECONDARY)) | ||
| 117 | + .child(detail), | ||
| 118 | + ) | ||
| 119 | + .child( | ||
| 120 | + div() | ||
| 121 | + .flex() | ||
| 122 | + .flex_wrap() | ||
| 123 | + .gap(px(6.)) | ||
| 124 | + .child(self.action_control( | ||
| 125 | + "inspect-speed", | ||
| 126 | + 0., | ||
| 127 | + None, | ||
| 128 | + "Speed", | ||
| 129 | + "how fast this clip and its group play", | ||
| 130 | + ActionId::Speed, | ||
| 131 | + cx.listener(|this, _: &ClickEvent, _, cx| this.open_speed(cx)), | ||
| 132 | + )) | ||
| 133 | + .child(self.action_control( | ||
| 134 | + "inspect-color", | ||
| 135 | + 0., | ||
| 136 | + None, | ||
| 137 | + "Colour", | ||
| 138 | + "exposure, contrast, saturation and temperature", | ||
| 139 | + ActionId::Color, | ||
| 140 | + cx.listener(|this, _: &ClickEvent, _, cx| this.open_color(cx)), | ||
| 141 | + )) | ||
| 142 | + .child(self.action_control( | ||
| 143 | + "inspect-eq", | ||
| 144 | + 0., | ||
| 145 | + None, | ||
| 146 | + "Equalizer", | ||
| 147 | + "the bands this clip's sound is filtered through", | ||
| 148 | + ActionId::Equalizer, | ||
| 149 | + cx.listener(|this, _: &ClickEvent, _, cx| this.open_eq(cx)), | ||
| 150 | + )) | ||
| 151 | + .child(self.action_control( | ||
| 152 | + "inspect-silence", | ||
| 153 | + 0., | ||
| 154 | + None, | ||
| 155 | + "Silence", | ||
| 156 | + "finds the quiet stretches and cuts or speeds them", | ||
| 157 | + ActionId::Silence, | ||
| 158 | + cx.listener(|this, _: &ClickEvent, _, cx| this.open_silence(cx)), | ||
| 159 | + )) | ||
| 160 | + .child(self.action_control( | ||
| 161 | + "inspect-fit", | ||
| 162 | + 0., | ||
| 163 | + None, | ||
| 164 | + "Fit", | ||
| 165 | + "how this picture is placed on the project canvas", | ||
| 166 | + ActionId::Fit, | ||
| 167 | + cx.listener(|this, _: &ClickEvent, _, cx| this.cycle_fit(cx)), | ||
| 168 | + )) | ||
| 169 | + .child(self.action_control( | ||
| 170 | + "inspect-delete", | ||
| 171 | + 0., | ||
| 172 | + None, | ||
| 173 | + "Delete", | ||
| 174 | + "takes this clip off the timeline", | ||
| 175 | + ActionId::Delete, | ||
| 176 | + cx.listener(|this, _: &ClickEvent, _, cx| this.delete_selected(cx)), | ||
| 177 | + )), | ||
| 178 | + ) | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + /// The settings that are the *project's* rather than any clip's: the canvas | ||
| 182 | + /// every clip is composed onto, the rate it is cut at, the HDR rendition it | ||
| 183 | + /// is watched in, and the mix everything sums into. They used to be four | ||
| 184 | + /// more buttons in a toolbar row that already did not fit the floor. | ||
| 185 | + fn project_section(&self, cx: &mut Context<Self>) -> impl IntoElement { | ||
| 186 | + let resolution = self.session.as_ref().map(PlaybackSession::resolution); | ||
| 187 | + div() | ||
| 188 | + .flex() | ||
| 189 | + .flex_col() | ||
| 190 | + .gap(px(6.)) | ||
| 191 | + .p(px(8.)) | ||
| 192 | + .rounded(px(4.)) | ||
| 193 | + .bg(rgb(BG_HOVER_DIM)) | ||
| 194 | + .child( | ||
| 195 | + div() | ||
| 196 | + .flex_none() | ||
| 197 | + .text_size(px(11.)) | ||
| 198 | + .text_color(rgb(FG_SECONDARY)) | ||
| 199 | + .child("PROJECT"), | ||
| 200 | + ) | ||
| 201 | + .child( | ||
| 202 | + div() | ||
| 203 | + .flex() | ||
| 204 | + .flex_wrap() | ||
| 205 | + .gap(px(6.)) | ||
| 206 | + .child(self.action_control( | ||
| 207 | + "resolution", | ||
| 208 | + ZOOM_SLOT_W, | ||
| 209 | + None, | ||
| 210 | + resolution.map_or_else(|| "Size".to_string(), |(_, h)| format!("{h}p")), | ||
| 211 | + "the canvas every clip is composed onto, and the size the export comes out at", | ||
| 212 | + ActionId::Resolution, | ||
| 213 | + cx.listener(|this, event: &ClickEvent, _, cx| { | ||
| 214 | + this.open_picker(Pick::Resolution, event.position(), cx) | ||
| 215 | + }), | ||
| 216 | + )) | ||
| 217 | + .child(self.action_control( | ||
| 218 | + "fps", | ||
| 219 | + ZOOM_SLOT_W, | ||
| 220 | + None, | ||
| 221 | + match self.session.is_some() { | ||
| 222 | + true => format!("{} fps", fps_label(self.fps)), | ||
| 223 | + false => "Rate".to_string(), | ||
| 224 | + }, | ||
| 225 | + "the rate the whole timeline is cut and written at", | ||
| 226 | + ActionId::Resolution, | ||
| 227 | + cx.listener(|this, event: &ClickEvent, _, cx| { | ||
| 228 | + this.open_picker(Pick::Fps, event.position(), cx) | ||
| 229 | + }), | ||
| 230 | + )) | ||
| 231 | + .child(self.action_control( | ||
| 232 | + "tonemap", | ||
| 233 | + ZOOM_SLOT_W, | ||
| 234 | + None, | ||
| 235 | + match &self.session { | ||
| 236 | + Some(session) => format!("HDR {}", tone_label(session.tone())), | ||
| 237 | + None => "HDR".to_string(), | ||
| 238 | + }, | ||
| 239 | + "which rendition HDR media is watched in; SDR media is untouched", | ||
| 240 | + ActionId::Resolution, | ||
| 241 | + cx.listener(|this, event: &ClickEvent, _, cx| { | ||
| 242 | + this.open_picker(Pick::Tone, event.position(), cx) | ||
| 243 | + }), | ||
| 244 | + )) | ||
| 245 | + .child(self.action_control( | ||
| 246 | + "inspect-mix", | ||
| 247 | + 0., | ||
| 248 | + None, | ||
| 249 | + "Mix", | ||
| 250 | + "a fader per track and the limiter over the sum of them", | ||
| 251 | + ActionId::Mix, | ||
| 252 | + cx.listener(|this, _: &ClickEvent, _, cx| this.open_mix(None, cx)), | ||
| 253 | + )), | ||
| 254 | + ) | ||
| 255 | + } | ||
| 256 | +} | ||
| 257 | + | ||
| 258 | +/// A region's own title bar: the same 24 px strip in the library and the | ||
| 259 | +/// inspector, so the two columns read as the pair they are. | ||
| 260 | +pub(crate) fn section_head(title: &'static str) -> impl IntoElement { | ||
| 261 | + div() | ||
| 262 | + .flex_none() | ||
| 263 | + .h(px(24.)) | ||
| 264 | + .flex() | ||
| 265 | + .items_center() | ||
| 266 | + .px(px(8.)) | ||
| 267 | + .bg(rgb(BG_PANEL)) | ||
| 268 | + .border_b_1() | ||
| 269 | + .border_color(rgb(STROKE_DIVIDER)) | ||
| 270 | + .text_size(px(11.)) | ||
| 271 | + .text_color(rgb(FG_SECONDARY)) | ||
| 272 | + .child(title) | ||
| 273 | +} | ||
crates/app/src/ui/library.rsmodified+2 -0
| @@ -232,6 +232,7 @@ impl Player { | |||
| 232 | ) | 232 | ) |
| 233 | .child(control( | 233 | .child(control( |
| 234 | "import", | 234 | "import", |
| 235 | + 0., | ||
| 235 | None, | 236 | None, |
| 236 | "Import", | 237 | "Import", |
| 237 | "adds a file to this list — or drop one on the window".to_string(), | 238 | "adds a file to this list — or drop one on the window".to_string(), |
| @@ -266,6 +267,7 @@ impl Player { | |||
| 266 | .children(self.subtitle_section(width, viewport_h, cx)) | 267 | .children(self.subtitle_section(width, viewport_h, cx)) |
| 267 | .child(control( | 268 | .child(control( |
| 268 | "add-asset", | 269 | "add-asset", |
| 270 | + 0., | ||
| 269 | None, | 271 | None, |
| 270 | "Add at playhead", | 272 | "Add at playhead", |
| 271 | match self.selected_asset { | 273 | match self.selected_asset { |
crates/app/src/ui/overlays.rsmodified+3 -0
| @@ -50,6 +50,9 @@ impl Player { | |||
| 50 | .child(div().flex_1().min_w(px(0.)).child(line)) | 50 | .child(div().flex_1().min_w(px(0.)).child(line)) |
| 51 | .child(control( | 51 | .child(control( |
| 52 | "cancel-import", | 52 | "cancel-import", |
| 53 | + // Hugs its label: the bar's own line is what wants | ||
| 54 | + // the width, and this button never relabels. | ||
| 55 | + 0., | ||
| 53 | None, | 56 | None, |
| 54 | "Cancel", | 57 | "Cancel", |
| 55 | "stops this file and anything queued behind it; the read already \ | 58 | "stops this file and anything queued behind it; the read already \ |
crates/app/src/ui/theme.rsmodified+1 -1
| @@ -53,7 +53,7 @@ pub const FG_DISABLED: u32 = 0x6c7a8b; | |||
| 53 | pub const ACCENT_PRIMARY: u32 = 0x22d3ee; | 53 | pub const ACCENT_PRIMARY: u32 = 0x22d3ee; |
| 54 | /// Not the accent: the playhead crosses every clip colour there is and has to | 54 | /// Not the accent: the playhead crosses every clip colour there is and has to |
| 55 | /// stay the one line that is none of them. | 55 | /// stay the one line that is none of them. |
| 56 | -pub const ACCENT_PLAYHEAD: u32 = 0xff4d6d; | 56 | +pub const ACCENT_PLAYHEAD: u32 = 0xff9db0; |
| 57 | /// The accent as a translucent wash, for the marks drawn over a clip body. | 57 | /// The accent as a translucent wash, for the marks drawn over a clip body. |
| 58 | pub const ACCENT_WASH: u32 = 0x22d3eeaa; | 58 | pub const ACCENT_WASH: u32 = 0x22d3eeaa; |
| 59 | 59 | ||
crates/app/src/ui/timeline.rsmodified+30 -445
| @@ -4,8 +4,12 @@ use crate::*; | |||
| 4 | use crate::ui::widgets::*; | 4 | use crate::ui::widgets::*; |
| 5 | 5 | ||
| 6 | impl Player { | 6 | impl Player { |
| 7 | - /// Transport, edit and file buttons, timecode, playhead, clips lane. | 7 | + /// The bottom region, full width under everything else: the timecode and |
| 8 | - pub(crate) fn panel( | 8 | + /// what is decoding, the ruler, the lanes and the subtitle strip. The edit |
| 9 | + /// buttons are the row directly above it ([`Player::toolbar`]) -- the | ||
| 10 | + /// arrangement every consumer editor shares, and the reason this is no | ||
| 11 | + /// longer one "panel" that owned both. | ||
| 12 | + pub(crate) fn timeline( | ||
| 9 | &self, | 13 | &self, |
| 10 | position: f64, | 14 | position: f64, |
| 11 | duration: f64, | 15 | duration: f64, |
| @@ -22,13 +26,6 @@ impl Player { | |||
| 22 | // percentage and the accent bar are the same number, so the playhead | 26 | // percentage and the accent bar are the same number, so the playhead |
| 23 | // fill doubles as the progress bar for free. | 27 | // fill doubles as the progress bar for free. |
| 24 | let exporting = self.exporting().is_some(); | 28 | let exporting = self.exporting().is_some(); |
| 25 | - // Everything but Import and Keys needs a timeline to act on: with none | ||
| 26 | - // open they are dimmed rather than silently doing nothing. | ||
| 27 | - let live = state != Transport::Stopped && !exporting; | ||
| 28 | - // The project's own picture size, for the button that cycles it: read | ||
| 29 | - // per render like everything else here, so a cycle shows on the button | ||
| 30 | - // that made it. | ||
| 31 | - let resolution = self.session.as_ref().map(PlaybackSession::resolution); | ||
| 32 | let key = |action| self.keymap.display(action); | 29 | let key = |action| self.keymap.display(action); |
| 33 | // The lanes the project has, or the pair a fresh one starts with so the | 30 | // The lanes the project has, or the pair a fresh one starts with so the |
| 34 | // panel reads the same before a file is open as after. | 31 | // panel reads the same before a file is open as after. |
| @@ -103,439 +100,15 @@ impl Player { | |||
| 103 | }; | 100 | }; |
| 104 | div() | 101 | div() |
| 105 | .flex_none() | 102 | .flex_none() |
| 106 | - .h(px(panel_h(lanes.len()) + strip_h)) | 103 | + .h(px(timeline_h(lanes.len()) + strip_h)) |
| 107 | .flex() | 104 | .flex() |
| 108 | .flex_col() | 105 | .flex_col() |
| 109 | .gap(px(8.)) | 106 | .gap(px(8.)) |
| 110 | .px(px(12.)) | 107 | .px(px(12.)) |
| 111 | .py(px(8.)) | 108 | .py(px(8.)) |
| 112 | - .bg(rgb(BG_PANEL)) | 109 | + .bg(rgb(BG_TIMELINE)) |
| 113 | - // Transport | edit | file: three groups, so the eye can skip two of | 110 | + .border_t_1() |
| 114 | - // them. Every button says what it does; the tooltip adds its key. | 111 | + .border_color(rgb(STROKE_DIVIDER)) |
| 115 | - // | ||
| 116 | - // The row scrolls rather than losing its tail: at the 640 px floor | ||
| 117 | - // this window is sized for it is wider than the panel, and a button | ||
| 118 | - // off the right edge is a button a pointer cannot press. A plain | ||
| 119 | - // wheel moves it -- gpui puts a vertical delta on the x axis when | ||
| 120 | - // that is the only one scrolling (div.rs:2424). | ||
| 121 | - // | ||
| 122 | - // ...and "it scrolls" is not "it can be found": the button beside | ||
| 123 | - // the row is pinned outside it and never scrolls away, so Export, | ||
| 124 | - // Save and the rest are one press from the smallest window even | ||
| 125 | - // when the row's tail is off the edge. | ||
| 126 | - // `toolbar_fits_the_smallest_window` is the guard. | ||
| 127 | - .child( | ||
| 128 | - div() | ||
| 129 | - .flex_none() | ||
| 130 | - .flex() | ||
| 131 | - .items_center() | ||
| 132 | - .gap(px(8.)) | ||
| 133 | - .child( | ||
| 134 | - div() | ||
| 135 | - .id("controls") | ||
| 136 | - .flex_1() | ||
| 137 | - .min_w(px(0.)) | ||
| 138 | - .flex() | ||
| 139 | - .items_center() | ||
| 140 | - .gap(px(8.)) | ||
| 141 | - .overflow_x_scroll() | ||
| 142 | - .child(control( | ||
| 143 | - "transport", | ||
| 144 | - Some(transport_glyph(state).into_any_element()), | ||
| 145 | - if state.is_playing() { "Pause" } else { "Play" }, | ||
| 146 | - if nothing_to_play(self.session.as_ref()) && !state.is_playing() { | ||
| 147 | - format!("{} — put a clip on a lane first", key(ActionId::Play)) | ||
| 148 | - } else { | ||
| 149 | - key(ActionId::Play) | ||
| 150 | - }, | ||
| 151 | - // An empty timeline has nothing to play, so the button | ||
| 152 | - // says so by being dim rather than by starting a clock | ||
| 153 | - // against nothing (the key press answers with the | ||
| 154 | - // notice). Still live while it *is* playing: a delete | ||
| 155 | - // can empty the timeline mid-play and that has to stop. | ||
| 156 | - live && (state.is_playing() || !nothing_to_play(self.session.as_ref())), | ||
| 157 | - cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_or_restart(cx)), | ||
| 158 | - )) | ||
| 159 | - .child(separator()) | ||
| 160 | - .child(control( | ||
| 161 | - "cut", | ||
| 162 | - Some(cut_glyph().into_any_element()), | ||
| 163 | - "Cut", | ||
| 164 | - format!( | ||
| 165 | - "{} — splits the clip under the playhead", | ||
| 166 | - key(ActionId::Cut) | ||
| 167 | - ), | ||
| 168 | - live, | ||
| 169 | - cx.listener(|this, _: &ClickEvent, _, cx| this.cut(cx)), | ||
| 170 | - )) | ||
| 171 | - .child(control( | ||
| 172 | - "delete", | ||
| 173 | - Some(delete_glyph().into_any_element()), | ||
| 174 | - "Delete", | ||
| 175 | - if self.selected.is_some() { | ||
| 176 | - key(ActionId::Delete) | ||
| 177 | - } else { | ||
| 178 | - format!("{} — click a clip below first", key(ActionId::Delete)) | ||
| 179 | - }, | ||
| 180 | - live && self.selected.is_some(), | ||
| 181 | - cx.listener(|this, _: &ClickEvent, _, cx| this.delete_selected(cx)), | ||
| 182 | - )) | ||
| 183 | - // The way back from every one of them. It was a stroke and | ||
| 184 | - // nothing else, which made the whole edit group a one-way | ||
| 185 | - // door for anyone working with a pointer. | ||
| 186 | - .child(control( | ||
| 187 | - "undo", | ||
| 188 | - None, | ||
| 189 | - "Undo", | ||
| 190 | - format!("{} — takes the last edit back", key(ActionId::Undo)), | ||
| 191 | - live, | ||
| 192 | - cx.listener(|this, _: &ClickEvent, _, cx| this.undo(cx)), | ||
| 193 | - )) | ||
| 194 | - // With the edit group, beside the buttons that change the | ||
| 195 | - // edit list: a track is a row of it, and adding one is an | ||
| 196 | - // undoable edit like the rest. Two buttons rather than one | ||
| 197 | - // with a choice, because the choice is the whole action. | ||
| 198 | - .child(control( | ||
| 199 | - "add-video-lane", | ||
| 200 | - None, | ||
| 201 | - "+ V", | ||
| 202 | - format!( | ||
| 203 | - "{} — adds a video track under the ones there", | ||
| 204 | - key(ActionId::AddVideoLane) | ||
| 205 | - ), | ||
| 206 | - live, | ||
| 207 | - cx.listener(|this, _: &ClickEvent, _, cx| { | ||
| 208 | - this.add_lane(LaneKind::Video, cx) | ||
| 209 | - }), | ||
| 210 | - )) | ||
| 211 | - .child(control( | ||
| 212 | - "add-audio-lane", | ||
| 213 | - None, | ||
| 214 | - "+ A", | ||
| 215 | - format!( | ||
| 216 | - "{} — adds an audio track under the ones there", | ||
| 217 | - key(ActionId::AddAudioLane) | ||
| 218 | - ), | ||
| 219 | - live, | ||
| 220 | - cx.listener(|this, _: &ClickEvent, _, cx| { | ||
| 221 | - this.add_lane(LaneKind::Audio, cx) | ||
| 222 | - }), | ||
| 223 | - )) | ||
| 224 | - // The third kind of track this timeline carries, and | ||
| 225 | - // the only one that arrived through a drop alone: a | ||
| 226 | - // subtitle file nobody thought to drag was a track | ||
| 227 | - // the editor could not be asked for. What it opens is | ||
| 228 | - // a chooser rather than an empty row -- a subtitle | ||
| 229 | - // track is its file, and there is nothing to add | ||
| 230 | - // before one is named. | ||
| 231 | - .child(control( | ||
| 232 | - "add-subtitle-track", | ||
| 233 | - None, | ||
| 234 | - "+ S", | ||
| 235 | - // Dim, and saying why it is dim, out of the one | ||
| 236 | - // oracle -- the very words the key answers with | ||
| 237 | - // (`Player::pick_and_add_subtitles`), so the | ||
| 238 | - // tooltip and the notice cannot come to differ. | ||
| 239 | - match self.enable(ActionId::AddSubtitleTrack, None).why() { | ||
| 240 | - Some(why) => { | ||
| 241 | - format!("{} — {why}", key(ActionId::AddSubtitleTrack)) | ||
| 242 | - } | ||
| 243 | - None => format!( | ||
| 244 | - "{} — adds every subtitle track in a file you pick", | ||
| 245 | - key(ActionId::AddSubtitleTrack) | ||
| 246 | - ), | ||
| 247 | - }, | ||
| 248 | - live, | ||
| 249 | - cx.listener(|this, _: &ClickEvent, _, cx| { | ||
| 250 | - this.pick_and_add_subtitles(cx) | ||
| 251 | - }), | ||
| 252 | - )) | ||
| 253 | - // With the transport, not the edit group: it changes what | ||
| 254 | - // the file sounds like, never what it is. Reads as its own | ||
| 255 | - // state, so muted is legible without a tooltip. | ||
| 256 | - .child(control( | ||
| 257 | - "volume", | ||
| 258 | - None, | ||
| 259 | - self.volume.label(), | ||
| 260 | - format!( | ||
| 261 | - "{} mutes · {} louder · {} quieter", | ||
| 262 | - key(ActionId::ToggleMute), | ||
| 263 | - key(ActionId::VolumeUp), | ||
| 264 | - key(ActionId::VolumeDown) | ||
| 265 | - ), | ||
| 266 | - live, | ||
| 267 | - cx.listener(|this, _: &ClickEvent, _, cx| { | ||
| 268 | - this.set_volume(|volume| volume.muted = !volume.muted, cx) | ||
| 269 | - }), | ||
| 270 | - )) | ||
| 271 | - // The level itself, to drag. The button beside it stays the | ||
| 272 | - // mute -- one gesture each -- and the label above is what | ||
| 273 | - // this writes, live, so the number follows the hand. | ||
| 274 | - .child(volume_slider( | ||
| 275 | - self.volume, | ||
| 276 | - self.volume_bar.clone(), | ||
| 277 | - live, | ||
| 278 | - cx, | ||
| 279 | - )) | ||
| 280 | - .child(separator()) | ||
| 281 | - // The size every clip is composed onto, which is also the | ||
| 282 | - // size the export comes out at. Five sizes, so a click opens | ||
| 283 | - // the list of them with this one marked and picks whichever | ||
| 284 | - // was meant: a button that stepped one on per press made the | ||
| 285 | - // user click round the ladder to get back to where they | ||
| 286 | - // were. The stroke still steps, for the hand already on it. | ||
| 287 | - .child(control( | ||
| 288 | - "resolution", | ||
| 289 | - None, | ||
| 290 | - resolution.map_or_else(|| "Size".to_string(), |(_, h)| format!("{h}p")), | ||
| 291 | - match resolution { | ||
| 292 | - Some((w, h)) => format!( | ||
| 293 | - "click to pick a size — the project is {w}x{h}; {} steps to the next", | ||
| 294 | - key(ActionId::Resolution) | ||
| 295 | - ), | ||
| 296 | - None => format!("{} — open a file first", key(ActionId::Resolution)), | ||
| 297 | - }, | ||
| 298 | - live, | ||
| 299 | - cx.listener(|this, event: &ClickEvent, _, cx| { | ||
| 300 | - this.open_picker(Pick::Resolution, event.position(), cx) | ||
| 301 | - }), | ||
| 302 | - )) | ||
| 303 | - // The rate every clip is counted in, which is also the rate | ||
| 304 | - // the export is written at -- the other half of "the project | ||
| 305 | - // is not the media", and the one the panel could only ever | ||
| 306 | - // read out before. A click opens the rates with this one | ||
| 307 | - // marked; picking one conforms the whole timeline to it. | ||
| 308 | - .child(control( | ||
| 309 | - "fps", | ||
| 310 | - None, | ||
| 311 | - match self.session.is_some() { | ||
| 312 | - true => format!("{} fps", fps_label(self.fps)), | ||
| 313 | - false => "Rate".to_string(), | ||
| 314 | - }, | ||
| 315 | - match self.session.is_some() { | ||
| 316 | - true => format!( | ||
| 317 | - "click to pick a frame rate — the project is cut at {} fps", | ||
| 318 | - fps_label(self.fps) | ||
| 319 | - ), | ||
| 320 | - false => "the project's frame rate — open a file first".to_string(), | ||
| 321 | - }, | ||
| 322 | - live, | ||
| 323 | - cx.listener(|this, event: &ClickEvent, _, cx| { | ||
| 324 | - this.open_picker(Pick::Fps, event.position(), cx) | ||
| 325 | - }), | ||
| 326 | - )) | ||
| 327 | - // ...and which rendition its HDR media is watched in, the | ||
| 328 | - // third thing that is the project's rather than the media's. | ||
| 329 | - // Listed whatever is on the timeline, and the tooltip says | ||
| 330 | - // who it acts on: a control that came and went with the | ||
| 331 | - // media would be one nobody could find when they wanted it. | ||
| 332 | - .child(control( | ||
| 333 | - "tonemap", | ||
| 334 | - None, | ||
| 335 | - match &self.session { | ||
| 336 | - Some(session) => format!("HDR {}", tone_label(session.tone())), | ||
| 337 | - None => "HDR".to_string(), | ||
| 338 | - }, | ||
| 339 | - match &self.session { | ||
| 340 | - Some(session) => format!( | ||
| 341 | - "click to pick the HDR rendition — the project is {}; SDR media is untouched", | ||
| 342 | - tone_label(session.tone()) | ||
| 343 | - ), | ||
| 344 | - None => "the HDR rendition — open a file first".to_string(), | ||
| 345 | - }, | ||
| 346 | - live, | ||
| 347 | - cx.listener(|this, event: &ClickEvent, _, cx| { | ||
| 348 | - this.open_picker(Pick::Tone, event.position(), cx) | ||
| 349 | - }), | ||
| 350 | - )) | ||
| 351 | - // How much of the timeline the panel below is showing -- | ||
| 352 | - // beside the resolution, since neither of them edits | ||
| 353 | - // anything: they are both what is being looked at. The | ||
| 354 | - // middle one says how much of it is on the bed, and is the | ||
| 355 | - // way back to the whole of it. | ||
| 356 | - .child(control( | ||
| 357 | - "zoom-out", | ||
| 358 | - None, | ||
| 359 | - "−", | ||
| 360 | - format!( | ||
| 361 | - "{} — show more of the timeline; stops with all of it on the bed", | ||
| 362 | - key(ActionId::ZoomOut) | ||
| 363 | - ), | ||
| 364 | - live, | ||
| 365 | - cx.listener(|this, _: &ClickEvent, _, cx| { | ||
| 366 | - this.zoom(1. / ZOOM_STEP, None, cx) | ||
| 367 | - }), | ||
| 368 | - )) | ||
| 369 | - .child(control( | ||
| 370 | - "zoom-fit", | ||
| 371 | - None, | ||
| 372 | - // How much timeline is on the bed, not a multiple of | ||
| 373 | - // "the whole of it": the scale no longer knows what the | ||
| 374 | - // whole of it is, and a number that changed on every | ||
| 375 | - // import was a number that lied. | ||
| 376 | - span_label(self.view().span()), | ||
| 377 | - format!( | ||
| 378 | - "{} — fit the whole timeline; showing {} to {}", | ||
| 379 | - key(ActionId::ZoomFit), | ||
| 380 | - timecode(self.scale.start, self.fps), | ||
| 381 | - timecode( | ||
| 382 | - (self.scale.start + self.view().span()).min(duration), | ||
| 383 | - self.fps | ||
| 384 | - ) | ||
| 385 | - ), | ||
| 386 | - live, | ||
| 387 | - cx.listener(|this, _: &ClickEvent, _, cx| this.zoom_fit(cx)), | ||
| 388 | - )) | ||
| 389 | - .child(control( | ||
| 390 | - "zoom-in", | ||
| 391 | - None, | ||
| 392 | - "+", | ||
| 393 | - format!( | ||
| 394 | - "{} — magnify around the playhead; ctrl+wheel on the bar zooms at the pointer", | ||
| 395 | - key(ActionId::ZoomIn) | ||
| 396 | - ), | ||
| 397 | - live, | ||
| 398 | - cx.listener(|this, _: &ClickEvent, _, cx| this.zoom(ZOOM_STEP, None, cx)), | ||
| 399 | - )) | ||
| 400 | - // The magnet, beside the zoom for the zoom's own reason: it | ||
| 401 | - // changes nothing on the timeline, it changes how the hand | ||
| 402 | - // meets it. The label is the state, as the volume's is -- | ||
| 403 | - // a toggle that looks the same either way says nothing. | ||
| 404 | - .child(control( | ||
| 405 | - "snap", | ||
| 406 | - None, | ||
| 407 | - if self.snap { "Snap" } else { "No snap" }, | ||
| 408 | - format!( | ||
| 409 | - "{} — {}", | ||
| 410 | - key(ActionId::ToggleSnap), | ||
| 411 | - match self.snap { | ||
| 412 | - true => "drags and trims land on clip edges, the playhead and the start", | ||
| 413 | - false => "drags and trims land exactly where the hand leaves them", | ||
| 414 | - } | ||
| 415 | - ), | ||
| 416 | - live, | ||
| 417 | - cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_snap(cx)), | ||
| 418 | - )) | ||
| 419 | - // The cues over the picture, off and on -- beside the zoom | ||
| 420 | - // and the snap, since like both of them it changes what is | ||
| 421 | - // being looked at and nothing about the edit. The label is | ||
| 422 | - // the state, as the snap's is, and it says what there is to | ||
| 423 | - // toggle when there is nothing. | ||
| 424 | - .child(control( | ||
| 425 | - "subs", | ||
| 426 | - None, | ||
| 427 | - match (self.subtitle_track().is_some(), self.subs_on) { | ||
| 428 | - (false, _) => "No subs", | ||
| 429 | - (true, true) => "Subs", | ||
| 430 | - (true, false) => "Subs off", | ||
| 431 | - }, | ||
| 432 | - match self.enable(ActionId::ToggleSubtitles, None).why() { | ||
| 433 | - Some(why) => format!( | ||
| 434 | - "{} — {why}; drop a .srt on the window, or open an mkv that carries them", | ||
| 435 | - key(ActionId::ToggleSubtitles) | ||
| 436 | - ), | ||
| 437 | - None => format!( | ||
| 438 | - "{} — {}", | ||
| 439 | - key(ActionId::ToggleSubtitles), | ||
| 440 | - match self.subs_on { | ||
| 441 | - true => "the cue under the playhead is drawn over the picture", | ||
| 442 | - false => "the cues are on the timeline and off the picture", | ||
| 443 | - } | ||
| 444 | - ), | ||
| 445 | - }, | ||
| 446 | - live && self.enable(ActionId::ToggleSubtitles, None).yes(), | ||
| 447 | - cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_subtitles(cx)), | ||
| 448 | - )) | ||
| 449 | - // Import is not here: it belongs to the media list it adds | ||
| 450 | - // to, and two doors into one action is a question about | ||
| 451 | - // which one is the real one. | ||
| 452 | - // | ||
| 453 | - // While one runs, this button is the way out of it: the | ||
| 454 | - // progress line promised esc and nothing else, which left a | ||
| 455 | - // pointer no way to stop an export it had started. | ||
| 456 | - .child(control( | ||
| 457 | - "export", | ||
| 458 | - None, | ||
| 459 | - if exporting { "Cancel" } else { "Export" }, | ||
| 460 | - if exporting { | ||
| 461 | - format!( | ||
| 462 | - "{} — stops the export; the part-written file goes", | ||
| 463 | - key(ActionId::CancelExport) | ||
| 464 | - ) | ||
| 465 | - } else { | ||
| 466 | - format!( | ||
| 467 | - "{} — quality and destination, then writes the timeline out", | ||
| 468 | - key(ActionId::Export) | ||
| 469 | - ) | ||
| 470 | - }, | ||
| 471 | - if exporting { | ||
| 472 | - true | ||
| 473 | - } else { | ||
| 474 | - live && self.export.is_none() | ||
| 475 | - }, | ||
| 476 | - cx.listener(|this, _: &ClickEvent, _, cx| { | ||
| 477 | - if this.exporting().is_some() { | ||
| 478 | - this.cancel_export(); | ||
| 479 | - cx.notify(); | ||
| 480 | - } else { | ||
| 481 | - this.open_export(cx); | ||
| 482 | - } | ||
| 483 | - }), | ||
| 484 | - )) | ||
| 485 | - .child(control( | ||
| 486 | - "save", | ||
| 487 | - None, | ||
| 488 | - "Save", | ||
| 489 | - format!("{} — writes the project file", key(ActionId::Save)), | ||
| 490 | - live, | ||
| 491 | - cx.listener(|this, _: &ClickEvent, _, cx| this.save_project(cx)), | ||
| 492 | - )) | ||
| 493 | - // Closed while an export runs, which is what keeps a waiting | ||
| 494 | - // row from swallowing the escape the progress line promises | ||
| 495 | - // cancels the export. | ||
| 496 | - .child(control( | ||
| 497 | - "keys", | ||
| 498 | - None, | ||
| 499 | - "Actions", | ||
| 500 | - // The pointer's way to every action there is, including | ||
| 501 | - // the ones no button here has room for. | ||
| 502 | - format!( | ||
| 503 | - "{} — do any action, or change the key that does it", | ||
| 504 | - key(ActionId::ShowActions) | ||
| 505 | - ), | ||
| 506 | - !exporting, | ||
| 507 | - cx.listener(|this, _: &ClickEvent, _, cx| match this.keys_open { | ||
| 508 | - true => { | ||
| 509 | - this.keys_open = false; | ||
| 510 | - this.rebinding = None; | ||
| 511 | - cx.notify(); | ||
| 512 | - } | ||
| 513 | - false => this.show_actions(cx), | ||
| 514 | - }), | ||
| 515 | - )) | ||
| 516 | - ) | ||
| 517 | - // The door to everything the row cannot show at this | ||
| 518 | - // window: the same card the Actions button opens, by the | ||
| 519 | - // same call, pinned where a scroll cannot take it. | ||
| 520 | - .child(control( | ||
| 521 | - "controls-more", | ||
| 522 | - None, | ||
| 523 | - "⋯", | ||
| 524 | - format!( | ||
| 525 | - "{} — every action, including the ones scrolled off this row", | ||
| 526 | - key(ActionId::ShowActions) | ||
| 527 | - ), | ||
| 528 | - !exporting, | ||
| 529 | - cx.listener(|this, _: &ClickEvent, _, cx| match this.keys_open { | ||
| 530 | - true => { | ||
| 531 | - this.keys_open = false; | ||
| 532 | - this.rebinding = None; | ||
| 533 | - cx.notify(); | ||
| 534 | - } | ||
| 535 | - false => this.show_actions(cx), | ||
| 536 | - }), | ||
| 537 | - )), | ||
| 538 | - ) | ||
| 539 | .child( | 112 | .child( |
| 540 | div() | 113 | div() |
| 541 | .flex_none() | 114 | .flex_none() |
| @@ -1033,7 +606,7 @@ impl Player { | |||
| 1033 | .min_w(px(0.)) | 606 | .min_w(px(0.)) |
| 1034 | .h_full() | 607 | .h_full() |
| 1035 | .rounded(px(3.)) | 608 | .rounded(px(3.)) |
| 1036 | - .bg(rgb(BG_CANVAS)) | 609 | + .bg(rgb(BG_TIMELINE)) |
| 1037 | .overflow_hidden() | 610 | .overflow_hidden() |
| 1038 | .children(cues.into_iter().map(|(left, width)| { | 611 | .children(cues.into_iter().map(|(left, width)| { |
| 1039 | div() | 612 | div() |
| @@ -1054,8 +627,8 @@ impl Player { | |||
| 1054 | .top_0() | 627 | .top_0() |
| 1055 | .h_full() | 628 | .h_full() |
| 1056 | .left(px(filled)) | 629 | .left(px(filled)) |
| 1057 | - .w(px(1.)) | 630 | + .w(px(2.)) |
| 1058 | - .bg(rgb(ACCENT_PRIMARY)), | 631 | + .bg(rgb(ACCENT_PLAYHEAD)), |
| 1059 | ), | 632 | ), |
| 1060 | ), | 633 | ), |
| 1061 | ) | 634 | ) |
| @@ -1230,7 +803,7 @@ impl Player { | |||
| 1230 | .min_w(px(0.)) | 803 | .min_w(px(0.)) |
| 1231 | .h_full() | 804 | .h_full() |
| 1232 | .rounded(px(3.)) | 805 | .rounded(px(3.)) |
| 1233 | - .bg(rgb(BG_CANVAS)) | 806 | + .bg(rgb(BG_TIMELINE)) |
| 1234 | .overflow_hidden() | 807 | .overflow_hidden() |
| 1235 | // A library row let go over a lane is the same insert the | 808 | // A library row let go over a lane is the same insert the |
| 1236 | // Add button makes, through the same call -- but where the | 809 | // Add button makes, through the same call -- but where the |
| @@ -1313,6 +886,18 @@ impl Player { | |||
| 1313 | // streams of one file are two sources, and the library | 886 | // streams of one file are two sources, and the library |
| 1314 | // gives them one swatch because they are one file. | 887 | // gives them one swatch because they are one file. |
| 1315 | let tint = self.clip_tint(clip.source); | 888 | let tint = self.clip_tint(clip.source); |
| 889 | + // ...and painted by *kind*, which is the one thing a | ||
| 890 | + // glance down a timeline has to answer: video blue, | ||
| 891 | + // audio green, a still teal, the cues purple, the way | ||
| 892 | + // every editor with more than one track colours them. | ||
| 893 | + // The source tint stays the identity of the file and is | ||
| 894 | + // the border and the library swatch. | ||
| 895 | + let kind = clip_kind( | ||
| 896 | + lane.kind, | ||
| 897 | + sources | ||
| 898 | + .get(clip.source) | ||
| 899 | + .is_some_and(|s| engine::is_image(&s.path)), | ||
| 900 | + ); | ||
| 1316 | // What the clip is worth in pixels, and how wide its box | 901 | // What the clip is worth in pixels, and how wide its box |
| 1317 | // is drawn -- the two part company on a take too short | 902 | // is drawn -- the two part company on a take too short |
| 1318 | // to be hit at this zoom ([`clip_width`]). | 903 | // to be hit at this zoom ([`clip_width`]). |
| @@ -1370,13 +955,13 @@ impl Player { | |||
| 1370 | .rounded(px(3.)) | 955 | .rounded(px(3.)) |
| 1371 | .border_1() | 956 | .border_1() |
| 1372 | .border_color(rgb(if on { | 957 | .border_color(rgb(if on { |
| 1373 | - ACCENT_PRIMARY | 958 | + STROKE_SELECTED |
| 1374 | } else if grouped { | 959 | } else if grouped { |
| 1375 | tint | 960 | tint |
| 1376 | } else { | 961 | } else { |
| 1377 | FG_SECONDARY | 962 | FG_SECONDARY |
| 1378 | })) | 963 | })) |
| 1379 | - .bg(rgb(if on { BG_SELECTED } else { tint })) | 964 | + .bg(rgb(if on { BG_SELECTED } else { kind })) |
| 1380 | .cursor_pointer() | 965 | .cursor_pointer() |
| 1381 | .hover(|s| s.border_color(rgb(ACCENT_PRIMARY))) | 966 | .hover(|s| s.border_color(rgb(ACCENT_PRIMARY))) |
| 1382 | .tooltip(move |_, cx| cx.new(|_| Tip(tip.clone())).into()) | 967 | .tooltip(move |_, cx| cx.new(|_| Tip(tip.clone())).into()) |
| @@ -1637,8 +1222,8 @@ impl Player { | |||
| 1637 | .top_0() | 1222 | .top_0() |
| 1638 | .h_full() | 1223 | .h_full() |
| 1639 | .left(px(filled)) | 1224 | .left(px(filled)) |
| 1640 | - .w(px(1.)) | 1225 | + .w(px(2.)) |
| 1641 | - .bg(rgb(ACCENT_PRIMARY)), | 1226 | + .bg(rgb(ACCENT_PLAYHEAD)), |
| 1642 | ), | 1227 | ), |
| 1643 | ) | 1228 | ) |
| 1644 | } | 1229 | } |
crates/app/src/ui/toolbar.rsmodified+392 -0
| @@ -0,0 +1,392 @@ | |||
| 1 | +//! The three rows of chrome: the top bar over everything, the transport strip | ||
| 2 | +//! under the picture, and the edit toolbar directly above the timeline. | ||
| 3 | +//! | ||
| 4 | +//! Every button in all three comes out of [`Player::action_control`], which | ||
| 5 | +//! asks the one availability oracle whether the action can happen at all. That | ||
| 6 | +//! is the whole point of this module existing: the toolbar used to decide with | ||
| 7 | +//! ad-hoc booleans (`live && self.selected.is_some()`) while the keyboard asked | ||
| 8 | +//! nobody, so with no file open Snap and `+ V` were dimmed *and dead* to the | ||
| 9 | +//! pointer while the very same actions still fired from the keys. One oracle, | ||
| 10 | +//! two doors -- if the key fires, the button fires. | ||
| 11 | + | ||
| 12 | +use crate::*; | ||
| 13 | +use crate::ui::widgets::*; | ||
| 14 | + | ||
| 15 | +impl Player { | ||
| 16 | + /// A toolbar button for `action`: enabled exactly when [`enable`] says the | ||
| 17 | + /// action can happen, dimmed with the oracle's own reason in its tooltip | ||
| 18 | + /// when it cannot, and firing the same call the key fires when it can. | ||
| 19 | + /// | ||
| 20 | + /// `w` is the rect the label lives in. It is reserved once and never | ||
| 21 | + /// changes with state, so Play/Pause, Snap/No snap and Export/Cancel swap | ||
| 22 | + /// their words and their colour inside a box that does not move -- the | ||
| 23 | + /// complaint that started this redesign ("even button positions are | ||
| 24 | + /// changing according to its state"). | ||
| 25 | + pub(crate) fn action_control( | ||
| 26 | + &self, | ||
| 27 | + id: &'static str, | ||
| 28 | + w: f32, | ||
| 29 | + glyph: Option<AnyElement>, | ||
| 30 | + label: impl Into<SharedString>, | ||
| 31 | + hint: &str, | ||
| 32 | + action: ActionId, | ||
| 33 | + on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static, | ||
| 34 | + ) -> impl IntoElement { | ||
| 35 | + let enabled = self.enable(action, None); | ||
| 36 | + let key = self.keymap.display(action); | ||
| 37 | + // The dimmed button says *why* in the oracle's own words -- the same | ||
| 38 | + // string the key answers with, so the tooltip and the notice cannot | ||
| 39 | + // come to differ. | ||
| 40 | + let say = match enabled.why() { | ||
| 41 | + Some(why) => format!("{key} — {why}"), | ||
| 42 | + None => format!("{key} — {hint}"), | ||
| 43 | + }; | ||
| 44 | + control(id, w, glyph, label, say, enabled.yes(), on_click) | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + /// The bar over everything: what is open on the left, the two actions that | ||
| 48 | + /// write a file on the right. Export is the one accented button in the | ||
| 49 | + /// window -- the primary action of an editor, where every consumer editor | ||
| 50 | + /// puts it -- and it keeps its rect while it is a Cancel. | ||
| 51 | + pub(crate) fn topbar(&self, cx: &mut Context<Self>) -> impl IntoElement { | ||
| 52 | + let exporting = self.exporting().is_some(); | ||
| 53 | + div() | ||
| 54 | + .flex_none() | ||
| 55 | + .h(px(TOPBAR_H)) | ||
| 56 | + .flex() | ||
| 57 | + .items_center() | ||
| 58 | + .gap(px(8.)) | ||
| 59 | + .px(px(12.)) | ||
| 60 | + .bg(rgb(BG_PANEL)) | ||
| 61 | + .border_b_1() | ||
| 62 | + .border_color(rgb(STROKE_DIVIDER)) | ||
| 63 | + .child( | ||
| 64 | + div() | ||
| 65 | + .flex_none() | ||
| 66 | + .w(px(10.)) | ||
| 67 | + .h(px(10.)) | ||
| 68 | + .rounded(px(2.)) | ||
| 69 | + .bg(rgb(ACCENT_PRIMARY)), | ||
| 70 | + ) | ||
| 71 | + .child( | ||
| 72 | + div() | ||
| 73 | + .flex_1() | ||
| 74 | + .min_w(px(0.)) | ||
| 75 | + .truncate() | ||
| 76 | + .child(self.name.clone()), | ||
| 77 | + ) | ||
| 78 | + .child(self.action_control( | ||
| 79 | + "save", | ||
| 80 | + 0., | ||
| 81 | + None, | ||
| 82 | + "Save", | ||
| 83 | + "writes the project file", | ||
| 84 | + ActionId::Save, | ||
| 85 | + cx.listener(|this, _: &ClickEvent, _, cx| this.save_project(cx)), | ||
| 86 | + )) | ||
| 87 | + // One rect, two states: exporting swaps the word and the colour, | ||
| 88 | + // never the box. `the_export_button_never_moves` is the guard. | ||
| 89 | + .child( | ||
| 90 | + div() | ||
| 91 | + .flex_none() | ||
| 92 | + .w(px(EXPORT_SLOT_W)) | ||
| 93 | + .child(self.action_control( | ||
| 94 | + "export", | ||
| 95 | + EXPORT_SLOT_W, | ||
| 96 | + None, | ||
| 97 | + if exporting { "Cancel" } else { "Export" }, | ||
| 98 | + if exporting { | ||
| 99 | + "stops the export; the part-written file goes" | ||
| 100 | + } else { | ||
| 101 | + "quality and destination, then writes the timeline out" | ||
| 102 | + }, | ||
| 103 | + if exporting { | ||
| 104 | + ActionId::CancelExport | ||
| 105 | + } else { | ||
| 106 | + ActionId::Export | ||
| 107 | + }, | ||
| 108 | + cx.listener(|this, _: &ClickEvent, _, cx| { | ||
| 109 | + if this.exporting().is_some() { | ||
| 110 | + this.cancel_export(); | ||
| 111 | + cx.notify(); | ||
| 112 | + } else { | ||
| 113 | + this.open_export(cx); | ||
| 114 | + } | ||
| 115 | + }), | ||
| 116 | + )) | ||
| 117 | + .when(!exporting, |d| d.text_color(rgb(BG_CANVAS))) | ||
| 118 | + .when(exporting, |d| d.text_color(rgb(FG_PRIMARY))), | ||
| 119 | + ) | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + /// The player's own strip, under the picture and over the timeline: the | ||
| 123 | + /// transport, the clock, and the level. Where a consumer editor puts them, | ||
| 124 | + /// and the reason the edit toolbar below is nothing but edit tools. | ||
| 125 | + pub(crate) fn transport_bar( | ||
| 126 | + &self, | ||
| 127 | + position: f64, | ||
| 128 | + state: Transport, | ||
| 129 | + cx: &mut Context<Self>, | ||
| 130 | + ) -> impl IntoElement { | ||
| 131 | + let muted = self.volume.muted; | ||
| 132 | + div() | ||
| 133 | + .flex_none() | ||
| 134 | + .h(px(TRANSPORT_H)) | ||
| 135 | + .flex() | ||
| 136 | + .items_center() | ||
| 137 | + .gap(px(8.)) | ||
| 138 | + .px(px(12.)) | ||
| 139 | + .bg(rgb(BG_PANEL)) | ||
| 140 | + .border_t_1() | ||
| 141 | + .border_color(rgb(STROKE_DIVIDER)) | ||
| 142 | + .child(self.action_control( | ||
| 143 | + "transport", | ||
| 144 | + 40., | ||
| 145 | + Some(transport_glyph(state).into_any_element()), | ||
| 146 | + "", | ||
| 147 | + "plays and pauses the timeline", | ||
| 148 | + ActionId::Play, | ||
| 149 | + cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_or_restart(cx)), | ||
| 150 | + )) | ||
| 151 | + // One line, one fixed width: changing digits must not push the | ||
| 152 | + // strip around, and the clock is the one number that changes | ||
| 153 | + // sixty times a second. | ||
| 154 | + .child( | ||
| 155 | + div() | ||
| 156 | + .flex_none() | ||
| 157 | + .w(px(TIME_W)) | ||
| 158 | + .truncate() | ||
| 159 | + .text_color(rgb(FG_PRIMARY)) | ||
| 160 | + .child(format!( | ||
| 161 | + "{} / {}", | ||
| 162 | + timecode(position, self.fps), | ||
| 163 | + timecode( | ||
| 164 | + self.session | ||
| 165 | + .as_ref() | ||
| 166 | + .map_or(0., PlaybackSession::timeline_duration), | ||
| 167 | + self.fps | ||
| 168 | + ) | ||
| 169 | + )), | ||
| 170 | + ) | ||
| 171 | + .child(div().flex_1().min_w(px(0.))) | ||
| 172 | + // The level as a number in its own rect, so muting swaps a glyph | ||
| 173 | + // and a colour rather than relabelling the button "Muted 80%" and | ||
| 174 | + // shoving the slider beside it along. | ||
| 175 | + .child(self.action_control( | ||
| 176 | + "volume", | ||
| 177 | + VOLUME_SLOT_W, | ||
| 178 | + None, | ||
| 179 | + match muted { | ||
| 180 | + true => format!("🔇 {}%", self.volume.percent()), | ||
| 181 | + false => format!("🔊 {}%", self.volume.percent()), | ||
| 182 | + }, | ||
| 183 | + "mutes and unmutes; the level is what it comes back to", | ||
| 184 | + ActionId::ToggleMute, | ||
| 185 | + cx.listener(|this, _: &ClickEvent, _, cx| { | ||
| 186 | + this.set_volume(|volume| volume.muted = !volume.muted, cx) | ||
| 187 | + }), | ||
| 188 | + )) | ||
| 189 | + .child(volume_slider( | ||
| 190 | + self.volume, | ||
| 191 | + self.volume_bar.clone(), | ||
| 192 | + self.enable(ActionId::ToggleMute, None).yes(), | ||
| 193 | + cx, | ||
| 194 | + )) | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + /// The edit toolbar, directly above the timeline it acts on: split, delete, | ||
| 198 | + /// undo, the tracks, the magnet and the zoom -- the arrangement Movavi and | ||
| 199 | + /// CapCut share, and nothing in it that is not an edit or a way of looking | ||
| 200 | + /// at one. | ||
| 201 | + /// | ||
| 202 | + /// The row scrolls rather than losing its tail at the 640 px floor, and the | ||
| 203 | + /// door to everything scrolled off it is pinned outside the scrolling box: | ||
| 204 | + /// "it scrolls" is not "it can be found" (`toolbar_fits_the_smallest_window`). | ||
| 205 | + pub(crate) fn toolbar(&self, cx: &mut Context<Self>) -> impl IntoElement { | ||
| 206 | + let exporting = self.exporting().is_some(); | ||
| 207 | + div() | ||
| 208 | + .flex_none() | ||
| 209 | + .h(px(TOOLBAR_H)) | ||
| 210 | + .flex() | ||
| 211 | + .items_center() | ||
| 212 | + .gap(px(8.)) | ||
| 213 | + .px(px(12.)) | ||
| 214 | + .bg(rgb(BG_PANEL)) | ||
| 215 | + .border_t_1() | ||
| 216 | + .border_color(rgb(STROKE_DIVIDER)) | ||
| 217 | + .child( | ||
| 218 | + div() | ||
| 219 | + .id("controls") | ||
| 220 | + .flex_1() | ||
| 221 | + .min_w(px(0.)) | ||
| 222 | + .flex() | ||
| 223 | + .items_center() | ||
| 224 | + .gap(px(8.)) | ||
| 225 | + .overflow_x_scroll() | ||
| 226 | + .child(self.action_control( | ||
| 227 | + "cut", | ||
| 228 | + 0., | ||
| 229 | + Some(cut_glyph().into_any_element()), | ||
| 230 | + "Split", | ||
| 231 | + "splits the clip under the playhead", | ||
| 232 | + ActionId::Cut, | ||
| 233 | + cx.listener(|this, _: &ClickEvent, _, cx| this.cut(cx)), | ||
| 234 | + )) | ||
| 235 | + .child(self.action_control( | ||
| 236 | + "delete", | ||
| 237 | + 0., | ||
| 238 | + Some(delete_glyph().into_any_element()), | ||
| 239 | + "Delete", | ||
| 240 | + "takes the marked clip off the timeline", | ||
| 241 | + ActionId::Delete, | ||
| 242 | + cx.listener(|this, _: &ClickEvent, _, cx| this.delete_selected(cx)), | ||
| 243 | + )) | ||
| 244 | + .child(self.action_control( | ||
| 245 | + "undo", | ||
| 246 | + 0., | ||
| 247 | + None, | ||
| 248 | + "Undo", | ||
| 249 | + "takes the last edit back", | ||
| 250 | + ActionId::Undo, | ||
| 251 | + cx.listener(|this, _: &ClickEvent, _, cx| this.undo(cx)), | ||
| 252 | + )) | ||
| 253 | + .child(separator()) | ||
| 254 | + .child(self.action_control( | ||
| 255 | + "add-video-lane", | ||
| 256 | + 0., | ||
| 257 | + None, | ||
| 258 | + "+ V", | ||
| 259 | + "adds a video track under the ones there", | ||
| 260 | + ActionId::AddVideoLane, | ||
| 261 | + cx.listener(|this, _: &ClickEvent, _, cx| { | ||
| 262 | + this.add_lane(LaneKind::Video, cx) | ||
| 263 | + }), | ||
| 264 | + )) | ||
| 265 | + .child(self.action_control( | ||
| 266 | + "add-audio-lane", | ||
| 267 | + 0., | ||
| 268 | + None, | ||
| 269 | + "+ A", | ||
| 270 | + "adds an audio track under the ones there", | ||
| 271 | + ActionId::AddAudioLane, | ||
| 272 | + cx.listener(|this, _: &ClickEvent, _, cx| { | ||
| 273 | + this.add_lane(LaneKind::Audio, cx) | ||
| 274 | + }), | ||
| 275 | + )) | ||
| 276 | + .child(self.action_control( | ||
| 277 | + "add-subtitle-track", | ||
| 278 | + 0., | ||
| 279 | + None, | ||
| 280 | + "+ S", | ||
| 281 | + "adds every subtitle track in a file you pick", | ||
| 282 | + ActionId::AddSubtitleTrack, | ||
| 283 | + cx.listener(|this, _: &ClickEvent, _, cx| { | ||
| 284 | + this.pick_and_add_subtitles(cx) | ||
| 285 | + }), | ||
| 286 | + )) | ||
| 287 | + .child(separator()) | ||
| 288 | + // Both toggles keep a rect of their own: the label is the | ||
| 289 | + // state, and a state that resized its own button is what | ||
| 290 | + // made the row shuffle every time it was pressed. | ||
| 291 | + .child(self.action_control( | ||
| 292 | + "snap", | ||
| 293 | + SNAP_SLOT_W, | ||
| 294 | + None, | ||
| 295 | + if self.snap { "Snap on" } else { "Snap off" }, | ||
| 296 | + match self.snap { | ||
| 297 | + true => "drags and trims land on clip edges, the playhead and the start", | ||
| 298 | + false => "drags and trims land exactly where the hand leaves them", | ||
| 299 | + }, | ||
| 300 | + ActionId::ToggleSnap, | ||
| 301 | + cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_snap(cx)), | ||
| 302 | + )) | ||
| 303 | + .child(self.action_control( | ||
| 304 | + "subs", | ||
| 305 | + SNAP_SLOT_W, | ||
| 306 | + None, | ||
| 307 | + match (self.subtitle_track().is_some(), self.subs_on) { | ||
| 308 | + (false, _) => "No subs", | ||
| 309 | + (true, true) => "Subs on", | ||
| 310 | + (true, false) => "Subs off", | ||
| 311 | + }, | ||
| 312 | + "draws the cue under the playhead over the picture", | ||
| 313 | + ActionId::ToggleSubtitles, | ||
| 314 | + cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_subtitles(cx)), | ||
| 315 | + )) | ||
| 316 | + .child(separator()) | ||
| 317 | + .child(self.action_control( | ||
| 318 | + "zoom-out", | ||
| 319 | + CONTROL_H, | ||
| 320 | + None, | ||
| 321 | + "−", | ||
| 322 | + "show more of the timeline; stops with all of it on the bed", | ||
| 323 | + ActionId::ZoomOut, | ||
| 324 | + cx.listener(|this, _: &ClickEvent, _, cx| { | ||
| 325 | + this.zoom(1. / ZOOM_STEP, None, cx) | ||
| 326 | + }), | ||
| 327 | + )) | ||
| 328 | + .child(self.action_control( | ||
| 329 | + "zoom-fit", | ||
| 330 | + ZOOM_SLOT_W, | ||
| 331 | + None, | ||
| 332 | + span_label(self.view().span()), | ||
| 333 | + "fit the whole timeline on the bed", | ||
| 334 | + ActionId::ZoomFit, | ||
| 335 | + cx.listener(|this, _: &ClickEvent, _, cx| this.zoom_fit(cx)), | ||
| 336 | + )) | ||
| 337 | + .child(self.action_control( | ||
| 338 | + "zoom-in", | ||
| 339 | + CONTROL_H, | ||
| 340 | + None, | ||
| 341 | + "+", | ||
| 342 | + "magnify around the playhead; ctrl+wheel on the ruler zooms at the pointer", | ||
| 343 | + ActionId::ZoomIn, | ||
| 344 | + cx.listener(|this, _: &ClickEvent, _, cx| this.zoom(ZOOM_STEP, None, cx)), | ||
| 345 | + )) | ||
| 346 | + .child(self.action_control( | ||
| 347 | + "keys", | ||
| 348 | + 0., | ||
| 349 | + None, | ||
| 350 | + "Actions", | ||
| 351 | + "do any action, or change the key that does it", | ||
| 352 | + ActionId::ShowActions, | ||
| 353 | + cx.listener(|this, _: &ClickEvent, _, cx| match this.keys_open { | ||
| 354 | + true => { | ||
| 355 | + this.keys_open = false; | ||
| 356 | + this.rebinding = None; | ||
| 357 | + cx.notify(); | ||
| 358 | + } | ||
| 359 | + false => this.show_actions(cx), | ||
| 360 | + }), | ||
| 361 | + )), | ||
| 362 | + ) | ||
| 363 | + // The door to everything the row cannot show at this window, pinned | ||
| 364 | + // where a scroll cannot take it. | ||
| 365 | + .child(control( | ||
| 366 | + "controls-more", | ||
| 367 | + CONTROL_H, | ||
| 368 | + None, | ||
| 369 | + "⋯", | ||
| 370 | + format!( | ||
| 371 | + "{} — every action, including the ones scrolled off this row", | ||
| 372 | + self.keymap.display(ActionId::ShowActions) | ||
| 373 | + ), | ||
| 374 | + !exporting, | ||
| 375 | + cx.listener(|this, _: &ClickEvent, _, cx| match this.keys_open { | ||
| 376 | + true => { | ||
| 377 | + this.keys_open = false; | ||
| 378 | + this.rebinding = None; | ||
| 379 | + cx.notify(); | ||
| 380 | + } | ||
| 381 | + false => this.show_actions(cx), | ||
| 382 | + }), | ||
| 383 | + )) | ||
| 384 | + } | ||
| 385 | +} | ||
| 386 | + | ||
| 387 | +/// The rects the stateful buttons live in. Wide enough for the longest word | ||
| 388 | +/// each of them can say, so the swap happens inside the box. | ||
| 389 | +pub(crate) const EXPORT_SLOT_W: f32 = 76.; | ||
| 390 | +pub(crate) const SNAP_SLOT_W: f32 = 76.; | ||
| 391 | +pub(crate) const ZOOM_SLOT_W: f32 = 76.; | ||
| 392 | +pub(crate) const VOLUME_SLOT_W: f32 = 76.; | ||
crates/app/src/ui/widgets.rsmodified+8 -1
| @@ -43,6 +43,11 @@ pub(crate) fn waveform(peaks: Arc<Vec<(f32, f32)>>, from: f64, to: f64) -> impl | |||
| 43 | /// A button that would do nothing says so: dimmed, no pointer, no listener. | 43 | /// A button that would do nothing says so: dimmed, no pointer, no listener. |
| 44 | pub(crate) fn control( | 44 | pub(crate) fn control( |
| 45 | id: &'static str, | 45 | id: &'static str, |
| 46 | + // The rect the label is allowed to change inside: 0 hugs the text, anything | ||
| 47 | + // else is reserved once and never moves again, which is what keeps a button | ||
| 48 | + // that relabels itself ("Export"/"Cancel") from shoving its neighbours | ||
| 49 | + // along the row every time its state changes. | ||
| 50 | + w: f32, | ||
| 46 | glyph: Option<AnyElement>, | 51 | glyph: Option<AnyElement>, |
| 47 | // Not `&'static str`: the volume button's label is its state. | 52 | // Not `&'static str`: the volume button's label is its state. |
| 48 | label: impl Into<SharedString>, | 53 | label: impl Into<SharedString>, |
| @@ -58,9 +63,11 @@ pub(crate) fn control( | |||
| 58 | .h(px(CONTROL_H)) | 63 | .h(px(CONTROL_H)) |
| 59 | .flex() | 64 | .flex() |
| 60 | .items_center() | 65 | .items_center() |
| 66 | + .justify_center() | ||
| 61 | .gap(px(6.)) | 67 | .gap(px(6.)) |
| 62 | .px(px(8.)) | 68 | .px(px(8.)) |
| 63 | - .rounded(px(3.)) | 69 | + .when(w > 0., |d| d.w(px(w)).overflow_hidden()) |
| 70 | + .rounded(px(4.)) | ||
| 64 | .bg(rgb(BG_RAISED)) | 71 | .bg(rgb(BG_RAISED)) |
| 65 | .children(glyph) | 72 | .children(glyph) |
| 66 | .child(label) | 73 | .child(label) |