Extract the UI out of main.rs into ui/ modules
Browse files at this commitd8bffff84ffdc9903060e11345e997ab7bd86c04Parent: 0e88697- refactor
- extract the UI out of main.rs into ui/ modules
11 changed files +5218 -5095
- crates/app/src/main.rs +103 -5095
- crates/app/src/ui/cards.rs +1657 -0
- crates/app/src/ui/inspector.rs +0 -0
- crates/app/src/ui/library.rs +472 -0
- crates/app/src/ui/mod.rs +14 -0
- crates/app/src/ui/overlays.rs +776 -0
- crates/app/src/ui/preview.rs +169 -0
- crates/app/src/ui/theme.rs +119 -0
- crates/app/src/ui/timeline.rs +1645 -0
- crates/app/src/ui/toolbar.rs +0 -0
- crates/app/src/ui/widgets.rs +263 -0
crates/app/src/main.rsmodified+103 -5095
Diff too large; view file
| @@ -1,4 +1,8 @@ | ||
| 1 | 1 | mod keymap; |
| 2 | +mod ui; | |
| 3 | + | |
| 4 | +use ui::theme::*; | |
| 5 | +use ui::widgets::*; | |
| 2 | 6 | |
| 3 | 7 | use keymap::{ActionId, Keymap}; |
| 4 | 8 | |
| @@ -28,43 +32,10 @@ use gpui::{ | ||
| 28 | 32 | canvas, div, img, point, prelude::*, px, relative, rgb, rgba, size, |
| 29 | 33 | }; |
| 30 | 34 | |
| 31 | -/// Editor chrome: three grays and one accent, all darker than the picture so the | |
| 32 | -/// frame is what the eye lands on. `LETTERBOX` stays the video's own bed. | |
| 33 | -const LETTERBOX: u32 = 0x101010; | |
| 34 | -const CHROME: u32 = 0x242424; | |
| 35 | -const SURFACE: u32 = 0x333333; | |
| 36 | -const INK: u32 = 0xc8c8c8; | |
| 37 | -const ACCENT: u32 = 0x4a9eff; | |
| 38 | -/// The accent at surface brightness: a selected clip is tinted, not lit up. | |
| 39 | -const SELECTED: u32 = 0x2a4a6b; | |
| 40 | -/// One per source, so a clip that came from an imported file reads as coming | |
| 41 | -/// from somewhere else. Same brightness as `SURFACE` and only the hue moves: | |
| 42 | -/// the lane stays in the dark family the rest of the chrome lives in | |
| 43 | -/// (ledger:187). The first entry is a colour like the rest rather than `SURFACE` | |
| 44 | -/// itself -- a first import whose swatch is the panel's own background is a | |
| 45 | -/// swatch nobody can see, and a file with one colour is what the whole | |
| 46 | -/// association is built on. | |
| 47 | -const SOURCE_TINTS: [u32; 4] = [0x29333b, 0x3b3329, 0x293b33, 0x33293b]; | |
| 48 | -/// The mirror of `SELECTED`: a drop the lane will not take, tinting the shadow | |
| 49 | -/// a drag draws ([`Ghost`]) so a refusal is seen before the release rather than | |
| 50 | -/// read afterwards. Same brightness as the rest of the chrome -- a warning, not | |
| 51 | -/// an alarm. | |
| 52 | -const REFUSE: u32 = 0x6b2a2a; | |
| 53 | -/// How solid that shadow is (`0xRRGGBBAA`): enough to read as a box, little | |
| 54 | -/// enough that the clip it is drawn over is still legible through it. | |
| 55 | -const GHOST_ALPHA: u32 = 0x66; | |
| 56 | 35 | /// ...and the narrowest it is drawn: a library row whose length the engine has |
| 57 | 36 | /// not measured yet has a landing place but no width, and a head marker says |
| 58 | 37 | /// where it goes where a zero-width box would say nothing. |
| 59 | 38 | const GHOST_MIN: f32 = 2.; |
| 60 | -/// One step lighter than whatever it sits on: the pointer's answer that this is | |
| 61 | -/// clickable. Two of them, because buttons stand on `SURFACE` and the scrub | |
| 62 | -/// strip stands on `CHROME`. | |
| 63 | -const HOVER: u32 = 0x3f3f3f; | |
| 64 | -const HOVER_DIM: u32 = 0x2c2c2c; | |
| 65 | -/// Secondary text -- shortcuts, dismissal hints. Dimmer than `INK` and still | |
| 66 | -/// past 4.5:1 on both `SURFACE` and `CHROME`. | |
| 67 | -const INK_DIM: u32 = 0xa0a0a0; | |
| 68 | 39 | |
| 69 | 40 | /// Fixed so the video region takes every pixel the window gains and the controls |
| 70 | 41 | /// never clip at 640x360. |
| @@ -176,12 +147,6 @@ const MENU_W: f32 = 260.; | ||
| 176 | 147 | const MENU_ROW_H: f32 = HIT_MIN; |
| 177 | 148 | const MENU_PAD: f32 = 6.; |
| 178 | 149 | |
| 179 | -/// The subtitle over the picture: white on a black plate, because a cue is read | |
| 180 | -/// against whatever the film happens to be showing under it and the chrome's own | |
| 181 | -/// greys are not a contrast the picture agrees to. 21:1 against the plate, which | |
| 182 | -/// is the only pair here that is not a chrome-on-chrome one. | |
| 183 | -const SUB_INK: u32 = 0xffffff; | |
| 184 | -const SUB_SHADE: u32 = 0x000000cc; | |
| 185 | 150 | /// A cue's text, and the line it sits on. Fixed rather than a share of the |
| 186 | 151 | /// picture: the video region is 108 px tall at the 640x360 floor and a |
| 187 | 152 | /// proportional size there would be unreadable at exactly the size where it has |
| @@ -990,9 +955,6 @@ const EQ_TICKS: [(f32, &str); 5] = [ | ||
| 990 | 955 | /// named at the corners instead. |
| 991 | 956 | const EQ_DB_GRID: [f32; 2] = [6., -6.]; |
| 992 | 957 | |
| 993 | -/// The grid's ink: above the card's background and below everything drawn on | |
| 994 | -/// it, so the lines are a ruling rather than a thing to look at. | |
| 995 | -const EQ_GRID: u32 = 0x3a3a3a; | |
| 996 | 958 | |
| 997 | 959 | /// How many played samples one spectrum frame is transformed from. A power of |
| 998 | 960 | /// two ([`fft`] is radix-2) and the whole of the engine's tap: 1024 at 48 kHz |
| @@ -1006,18 +968,8 @@ const EQ_FFT: usize = 1024; | ||
| 1006 | 968 | /// the numbers on the axis are the curve's dB, never the analyser's. |
| 1007 | 969 | const EQ_SPECTRUM_DB: (f32, f32) = (-96., -12.); |
| 1008 | 970 | |
| 1009 | -/// The analyser's fill, behind the curve: a dim blue-grey with enough alpha to | |
| 1010 | -/// read as a haze the accent line sits on top of. | |
| 1011 | -const EQ_SPECTRUM_INK: u32 = 0x7f95ad66; | |
| 1012 | 971 | |
| 1013 | -/// The area under the response curve, same accent as the line at a tenth of | |
| 1014 | -/// its weight: it is what makes a boost read as a hill rather than as a wire. | |
| 1015 | -const EQ_FILL_INK: u32 = 0x4a9eff26; | |
| 1016 | 972 | |
| 1017 | -/// One band's own response, drawn under the sum: a dim thread per band, so a | |
| 1018 | -/// boost pushed against a cut can be *seen* as two bands rather than as the | |
| 1019 | -/// flat line their total makes. | |
| 1020 | -const EQ_BELL_INK: u32 = 0x4a9eff66; | |
| 1021 | 973 | |
| 1022 | 974 | /// The colour card's four controls, in the order it lists them: what each is |
| 1023 | 975 | /// called and the range it moves in. The order is `ColorParams`' own, which is |
| @@ -1057,9 +1009,6 @@ const HIST_SAMPLES: usize = 8_192; | ||
| 1057 | 1009 | /// rows stand under it and the card still has to fit a 360 px window. |
| 1058 | 1010 | const HIST_H: f32 = 96.; |
| 1059 | 1011 | |
| 1060 | -/// What each channel's line is drawn in, in `[r, g, b]` order -- the channel it | |
| 1061 | -/// counts, lightened enough to read on the dark box. | |
| 1062 | -const HIST_INK: [u32; 3] = [0xE0_5A_5A, 0x5A_D0_7A, 0x5A_9A_E0]; | |
| 1063 | 1012 | |
| 1064 | 1013 | /// Where the transport is. The one answer the button's glyph, its label, its |
| 1065 | 1014 | /// enablement, the play key and the repaint loop all read -- there is no play |
| @@ -2892,7 +2841,7 @@ impl Player { | ||
| 2892 | 2841 | let refusal = match (self.selected, &self.session) { |
| 2893 | 2842 | (_, None) => Some("NO TIMELINE — open a file first".to_string()), |
| 2894 | 2843 | (None, _) => Some(format!( |
| 2895 | - "NOTHING SELECTED — click an audio clip or press {}, then ask again", | |
| 2844 | + "NOTHING BG_SELECTED — click an audio clip or press {}, then ask again", | |
| 2896 | 2845 | self.keymap.display(ActionId::Select) |
| 2897 | 2846 | )), |
| 2898 | 2847 | (Some((lane, _)), _) if lane.kind != LaneKind::Audio => Some( |
| @@ -3620,7 +3569,7 @@ impl Player { | ||
| 3620 | 3569 | .map_or(0, |session| session.file_frames(path)), |
| 3621 | 3570 | // A path with no source entry has no colour of its own, and the |
| 3622 | 3571 | // shadow wears the lane's own instead of borrowing another file's. |
| 3623 | - tint: file_tint(self.sources(), path).unwrap_or(SURFACE), | |
| 3572 | + tint: file_tint(self.sources(), path).unwrap_or(BG_RAISED), | |
| 3624 | 3573 | refused: lane_refuses(path, to).is_some(), |
| 3625 | 3574 | }; |
| 3626 | 3575 | self.set_ghost(Some(ghost), cx); |
| @@ -5765,8 +5714,8 @@ impl Render for Player { | ||
| 5765 | 5714 | .size_full() |
| 5766 | 5715 | .flex() |
| 5767 | 5716 | .flex_col() |
| 5768 | - .bg(rgb(LETTERBOX)) | |
| 5769 | - .text_color(rgb(INK)) | |
| 5717 | + .bg(rgb(BG_CANVAS)) | |
| 5718 | + .text_color(rgb(FG_PRIMARY)) | |
| 5770 | 5719 | .text_size(px(13.)) |
| 5771 | 5720 | .child( |
| 5772 | 5721 | div() |
| @@ -5775,7 +5724,7 @@ impl Render for Player { | ||
| 5775 | 5724 | .flex() |
| 5776 | 5725 | .items_center() |
| 5777 | 5726 | .px(px(12.)) |
| 5778 | - .bg(rgb(CHROME)) | |
| 5727 | + .bg(rgb(BG_PANEL)) | |
| 5779 | 5728 | .child(self.name.clone()), |
| 5780 | 5729 | ) |
| 5781 | 5730 | // The library beside the picture rather than under it: a media pool |
| @@ -5861,4771 +5810,81 @@ impl Render for Player { | ||
| 5861 | 5810 | } |
| 5862 | 5811 | } |
| 5863 | 5812 | |
| 5864 | -impl Player { | |
| 5865 | - /// The media library: a row per source the timeline knows, in the order | |
| 5866 | - /// they arrived, each wearing the tint its clips wear in the lanes -- the | |
| 5867 | - /// swatch *is* what says which boxes down there came from this file. A | |
| 5868 | - /// click picks a row, the button under the list drops that source in at the | |
| 5869 | - /// playhead, and a row dragged onto either lane does the same thing through | |
| 5870 | - /// the same call. | |
| 5871 | - /// | |
| 5872 | - /// Import lives here, because this is the list it adds to. Plain divs like | |
| 5873 | - /// the rest of this window: nothing in it takes focus, so the root keeps | |
| 5874 | - /// the keyboard and the play key still works after a row is clicked | |
| 5875 | - /// (ledger:182). | |
| 5876 | - fn library(&self, width: f32, viewport_h: f32, cx: &mut Context<Self>) -> impl IntoElement { | |
| 5877 | - let exporting = self.exporting().is_some(); | |
| 5878 | - let sources = self | |
| 5879 | - .session | |
| 5880 | - .as_ref() | |
| 5881 | - .map_or(&[][..], PlaybackSession::sources); | |
| 5882 | - // Every source matches the first in size and rate or it was refused at | |
| 5883 | - // the door (the import policy, ledger:436), so the session's own meta | |
| 5884 | - // describes every row and nothing has to be probed to say so. | |
| 5885 | - let meta = self.session.as_ref().map(PlaybackSession::meta); | |
| 5886 | - // Its own length, not one derived from what is on the lanes: a row | |
| 5887 | - // imported and never placed is a row with a length, and it is the | |
| 5888 | - // length a drag would put down. | |
| 5889 | - let rows: Vec<_> = library_rows( | |
| 5890 | - sources, | |
| 5891 | - &self.streams, | |
| 5892 | - &self.decoders, | |
| 5893 | - self.timeline_audio(), | |
| 5894 | - |path| { | |
| 5895 | - self.session | |
| 5896 | - .as_ref() | |
| 5897 | - .map_or(0, |session| session.file_frames(path)) | |
| 5898 | - }, | |
| 5899 | - ) | |
| 5900 | - .into_iter() | |
| 5901 | - .enumerate() | |
| 5902 | - .map(|(i, row)| { | |
| 5903 | - let picked = self | |
| 5904 | - .selected_asset | |
| 5905 | - .as_ref() | |
| 5906 | - .is_some_and(|p| *p == (row.path.clone(), row.stream)); | |
| 5907 | - let name: SharedString = row.name.clone().into(); | |
| 5908 | - let says: String = match (&row.unusable, meta) { | |
| 5909 | - // A greyed row says why in full, where its length would be: | |
| 5910 | - // the list is the one place the file's own tracks are named. | |
| 5911 | - (Some(why), _) => format!("{} — {why}", row.path.display()), | |
| 5912 | - // A file with no picture has no size and no frame rate to | |
| 5913 | - // report, and only one lane it can go on: saying so is the | |
| 5914 | - // difference between a hint and a lie. | |
| 5915 | - (None, _) if engine::is_audio(&row.path) => format!( | |
| 5916 | - "{} — audio only · drag onto the audio lane, or Add at playhead", | |
| 5917 | - row.path.display() | |
| 5918 | - ), | |
| 5919 | - // A still is the mirror: its own size (the timeline's meta | |
| 5920 | - // describes video, and a picture placed on that canvas is not | |
| 5921 | - // the same shape), no frame rate, and one kind of lane. | |
| 5922 | - (None, _) if engine::is_image(&row.path) => format!( | |
| 5923 | - "{} — still image{} · drag onto a video lane, or Add at playhead", | |
| 5924 | - row.path.display(), | |
| 5925 | - match self.sizes.get(&row.path).copied().flatten() { | |
| 5926 | - Some((w, h)) => format!(" · {w}x{h}"), | |
| 5927 | - None => String::new(), | |
| 5928 | - } | |
| 5929 | - ), | |
| 5930 | - // The file's *own* frame rate, not the timeline's: a clip shot | |
| 5931 | - // at another rate plays at the speed it was shot at, and the | |
| 5932 | - // row that says where it came from has to say which rate that | |
| 5933 | - // was. | |
| 5934 | - (None, Some(meta)) => format!( | |
| 5935 | - "{} — {}x{} @ {:.2} fps · drag it where you want it, or Add at playhead", | |
| 5936 | - row.path.display(), | |
| 5937 | - meta.width, | |
| 5938 | - meta.height, | |
| 5939 | - self.session | |
| 5940 | - .as_ref() | |
| 5941 | - .map_or(meta.frame_rate, |session| session.file_fps(&row.path)) | |
| 5942 | - ), | |
| 5943 | - (None, None) => row.path.display().to_string(), | |
| 5944 | - }; | |
| 5945 | - // The menu is the third way into a row, after the click and the | |
| 5946 | - // drag, and a right-click nothing advertises is one nobody finds. | |
| 5947 | - let tip: SharedString = format!("{says} · right-click for more").into(); | |
| 5948 | - let ghost = name.clone(); | |
| 5949 | - // What the second line says: the stream, then either its length or | |
| 5950 | - // the reason it cannot be used. | |
| 5951 | - let under = match &row.unusable { | |
| 5952 | - Some(why) => join_detail(&row.detail, why), | |
| 5953 | - // A still has no length to report -- the ten minutes it is | |
| 5954 | - // *held* to is a wall, not a duration -- so the line says what | |
| 5955 | - // it is and how big it is instead. | |
| 5956 | - None if engine::is_image(&row.path) => join_detail( | |
| 5957 | - &row.detail, | |
| 5958 | - &match self.sizes.get(&row.path).copied().flatten() { | |
| 5959 | - Some((w, h)) => format!("still image · {w}x{h}"), | |
| 5960 | - None => "still image".to_string(), | |
| 5961 | - }, | |
| 5962 | - ), | |
| 5963 | - None => join_detail( | |
| 5964 | - &row.detail, | |
| 5965 | - &timecode(f64::from(row.frames) / self.fps, self.fps), | |
| 5966 | - ), | |
| 5967 | - }; | |
| 5968 | - let usable = row.unusable.is_none(); | |
| 5969 | - let (path, stream) = (row.path.clone(), row.stream); | |
| 5970 | - let dragged = (path.clone(), stream); | |
| 5971 | - let menu_path = path.clone(); | |
| 5972 | - div() | |
| 5973 | - .id(("asset", i)) | |
| 5974 | - .flex_none() | |
| 5975 | - .h(px(ROW_H)) | |
| 5976 | - .flex() | |
| 5977 | - .items_center() | |
| 5978 | - .gap(px(6.)) | |
| 5979 | - .pr(px(6.)) | |
| 5980 | - .rounded(px(3.)) | |
| 5981 | - // A row that cannot be placed takes no click and no drag, and | |
| 5982 | - // reads as unavailable rather than merely unlucky. | |
| 5983 | - .when(!usable, |d| d.text_color(rgb(INK_DIM)).opacity(0.55)) | |
| 5984 | - .when(usable, |d| { | |
| 5985 | - d.cursor_pointer() | |
| 5986 | - .hover(|s| s.bg(rgb(HOVER))) | |
| 5987 | - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 5988 | - this.selected_asset = Some((path.clone(), stream)); | |
| 5989 | - cx.notify(); | |
| 5990 | - })) | |
| 5991 | - // The drag carries the row's file and stream and the | |
| 5992 | - // row's name: one for the drop to insert, one for the | |
| 5993 | - // pointer to carry, so what is being dragged is legible | |
| 5994 | - // on the way down. | |
| 5995 | - .on_drag(AssetDrag(dragged.0, dragged.1), move |_, _, _, cx| { | |
| 5996 | - cx.new(|_| Tip(ghost.clone())) | |
| 5997 | - }) | |
| 5998 | - }) | |
| 5999 | - // The right button hangs the row's own menu at the pointer. | |
| 6000 | - // Every row takes it, greyed ones included: a file that cannot | |
| 6001 | - // join this timeline can still be revealed, described and taken | |
| 6002 | - // out of the list, and Add is the one item that then refuses -- | |
| 6003 | - // in the engine's words, where the row's grey already says why. | |
| 6004 | - .on_mouse_down( | |
| 6005 | - MouseButton::Right, | |
| 6006 | - cx.listener(move |this, event: &MouseDownEvent, _, cx| { | |
| 6007 | - if this.modal() { | |
| 6008 | - return; | |
| 6009 | - } | |
| 6010 | - // Picked as a left-click would pick it, so the row the | |
| 6011 | - // menu is about is the row that reads as chosen -- but | |
| 6012 | - // only a row that *can* be picked, which is what keeps | |
| 6013 | - // the Add button under the list honest. | |
| 6014 | - if usable { | |
| 6015 | - this.selected_asset = Some((menu_path.clone(), stream)); | |
| 6016 | - } | |
| 6017 | - this.library_menu = Some(LibraryMenu { | |
| 6018 | - path: menu_path.clone(), | |
| 6019 | - stream, | |
| 6020 | - at: event.position, | |
| 6021 | - details: false, | |
| 6022 | - }); | |
| 6023 | - cx.notify(); | |
| 6024 | - }), | |
| 6025 | - ) | |
| 6026 | - .when(picked, |d| d.bg(rgb(SELECTED)).border_1()) | |
| 6027 | - .tooltip(move |_, cx| cx.new(|_| Tip(tip.clone())).into()) | |
| 6028 | - // Full height and hard against the edge: the tint reads as | |
| 6029 | - // the lane's colour continuing into the list, not as a chip | |
| 6030 | - // that happens to be near it. | |
| 6031 | - .child( | |
| 6032 | - div() | |
| 6033 | - .flex_none() | |
| 6034 | - .w(px(SWATCH_W)) | |
| 6035 | - .h_full() | |
| 6036 | - .rounded(px(2.)) | |
| 6037 | - .bg(rgb(source_tint(row.tint))), | |
| 6038 | - ) | |
| 6039 | - .child( | |
| 6040 | - div() | |
| 6041 | - .flex_1() | |
| 6042 | - .min_w(px(0.)) | |
| 6043 | - .flex() | |
| 6044 | - .flex_col() | |
| 6045 | - // Two lines rather than two columns: at the width | |
| 6046 | - // this panel yields to, a name and a timecode side | |
| 6047 | - // by side leave room for neither. | |
| 6048 | - // Cut out of the middle, not the end: two episodes off | |
| 6049 | - // one release are the same words up to the number, and | |
| 6050 | - // the number is at the end. | |
| 6051 | - .child( | |
| 6052 | - div() | |
| 6053 | - .truncate() | |
| 6054 | - .text_size(px(11.)) | |
| 6055 | - .child(clip_middle(&name, row_text_w(width))), | |
| 6056 | - ) | |
| 6057 | - .child( | |
| 6058 | - div() | |
| 6059 | - .truncate() | |
| 6060 | - .text_size(px(10.)) | |
| 6061 | - .text_color(rgb(INK_DIM)) | |
| 6062 | - .child(under), | |
| 6063 | - ), | |
| 6064 | - ) | |
| 6065 | - }) | |
| 6066 | - .collect(); | |
| 6067 | - div() | |
| 6068 | - .flex_none() | |
| 6069 | - .w(px(width)) | |
| 6070 | - .h_full() | |
| 6071 | - .flex() | |
| 6072 | - .flex_col() | |
| 6073 | - .gap(px(6.)) | |
| 6074 | - .p(px(8.)) | |
| 6075 | - .bg(rgb(CHROME)) | |
| 6076 | - .child( | |
| 6077 | - div() | |
| 6078 | - .flex_none() | |
| 6079 | - .flex() | |
| 6080 | - .items_center() | |
| 6081 | - .gap(px(6.)) | |
| 6082 | - .child( | |
| 6083 | - div() | |
| 6084 | - .flex_1() | |
| 6085 | - .min_w(px(0.)) | |
| 6086 | - .truncate() | |
| 6087 | - .text_size(px(11.)) | |
| 6088 | - .text_color(rgb(INK_DIM)) | |
| 6089 | - .child("Media"), | |
| 6090 | - ) | |
| 6091 | - .child(control( | |
| 6092 | - "import", | |
| 6093 | - None, | |
| 6094 | - "Import", | |
| 6095 | - "adds a file to this list — or drop one on the window".to_string(), | |
| 6096 | - !exporting, | |
| 6097 | - cx.listener(|this, _: &ClickEvent, _, cx| this.pick_and_import(cx)), | |
| 6098 | - )), | |
| 6099 | - ) | |
| 6100 | - .child( | |
| 6101 | - div() | |
| 6102 | - .id("library-rows") | |
| 6103 | - .flex_1() | |
| 6104 | - .min_h(px(0.)) | |
| 6105 | - .flex() | |
| 6106 | - .flex_col() | |
| 6107 | - .gap(px(2.)) | |
| 6108 | - .overflow_y_scroll() | |
| 6109 | - // Never a blank column: with nothing imported the list is | |
| 6110 | - // where the way in is said. | |
| 6111 | - .when(rows.is_empty(), |d| { | |
| 6112 | - d.child( | |
| 6113 | - div() | |
| 6114 | - .text_size(px(11.)) | |
| 6115 | - .text_color(rgb(INK_DIM)) | |
| 6116 | - .child("No media yet — Import, or drop a file on the window"), | |
| 6117 | - ) | |
| 6118 | - }) | |
| 6119 | - .children(rows), | |
| 6120 | - ) | |
| 6121 | - // Under the media it belongs to: a subtitle track is not a source -- | |
| 6122 | - // it goes on no lane and is dragged nowhere -- but it is a thing the | |
| 6123 | - // timeline holds, and this is the list of those. | |
| 6124 | - .children(self.subtitle_section(width, viewport_h, cx)) | |
| 6125 | - .child(control( | |
| 6126 | - "add-asset", | |
| 6127 | - None, | |
| 6128 | - "Add at playhead", | |
| 6129 | - match self.selected_asset { | |
| 6130 | - Some(_) => "inserts the picked file at the playhead".to_string(), | |
| 6131 | - None => "click a file above first — or drag one where you want it".to_string(), | |
| 6132 | - }, | |
| 6133 | - can_add( | |
| 6134 | - self.selected_asset.as_ref(), | |
| 6135 | - self.session.is_some(), | |
| 6136 | - exporting, | |
| 6137 | - ), | |
| 6138 | - cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 6139 | - if let Some((path, stream)) = this.selected_asset.clone() { | |
| 6140 | - // No lane: the button means "wherever this belongs", | |
| 6141 | - // which for a file with no picture is the audio lane. | |
| 6142 | - this.insert_source(&path, stream, None, None, cx); | |
| 6143 | - } | |
| 6144 | - }), | |
| 6145 | - )) | |
| 6146 | - } | |
| 6147 | 5813 | |
| 6148 | - /// The subtitle tracks this timeline holds, under the media list: one row | |
| 6149 | - /// each, the picked one marked, and a click makes another one the picked one | |
| 6150 | - /// -- which is the whole of choosing between the two tracks of a film. A row | |
| 6151 | - /// per track and no cycle: three of them is an ordinary number for a remux, | |
| 6152 | - /// and a key that steps through three is a key nobody can aim. | |
| 6153 | - /// | |
| 6154 | - /// A track that could not be read is *here*, greyed and saying why, exactly | |
| 6155 | - /// as a media row the timeline cannot take is: PGS subtitles are pictures, | |
| 6156 | - /// and a film carrying four of them says so instead of listing nothing. | |
| 6157 | - /// | |
| 6158 | - /// Every row names the file it came out of itself, in words and in the tint | |
| 6159 | - /// that file's clips wear on the lanes -- but only where there is more than | |
| 6160 | - /// one file to tell apart, the way [`row_name`] numbers audio streams only | |
| 6161 | - /// where a file gave several. Where the window is tall enough for it | |
| 6162 | - /// ([`sub_headers_fit`]) each file's block is headed by its name as well: a | |
| 6163 | - /// label and nothing more, no click and nothing to fold, so the rows under | |
| 6164 | - /// it are the only things anybody has to aim at. At the 640x360 floor the | |
| 6165 | - /// headers are gone and the rows still say whose they are. | |
| 6166 | - /// | |
| 6167 | - /// `None` when there are none -- an empty heading is a section about | |
| 6168 | - /// nothing. | |
| 6169 | - fn subtitle_section( | |
| 6170 | - &self, | |
| 6171 | - width: f32, | |
| 6172 | - viewport_h: f32, | |
| 6173 | - cx: &mut Context<Self>, | |
| 6174 | - ) -> Option<impl IntoElement> { | |
| 6175 | - let tracks = self.session.as_ref()?.subtitles(); | |
| 6176 | - if tracks.is_empty() { | |
| 6177 | - return None; | |
| 6178 | - } | |
| 6179 | - let groups = subtitle_rows(tracks); | |
| 6180 | - // One file's tracks need no prefix saying which file: it is the only | |
| 6181 | - // one, and every row would carry the same word. | |
| 6182 | - let several_files = groups.len() > 1; | |
| 6183 | - let headed = several_files && sub_headers_fit(viewport_h); | |
| 6184 | - let text_w = row_text_w(width); | |
| 6185 | - let rows: Vec<_> = groups | |
| 6186 | - .into_iter() | |
| 6187 | - .map(|SubGroup { name, path, rows }| { | |
| 6188 | - // The file's own colour, the one its media rows and its clips | |
| 6189 | - // wear -- and none at all for a standalone `.srt`, which came | |
| 6190 | - // off no file on this timeline. | |
| 6191 | - let tint = file_tint(self.sources(), &path); | |
| 6192 | - let numbered = rows.len() > 1; | |
| 6193 | - // The name twice over: all of it the header can hold, and the | |
| 6194 | - // share of a row a prefix may take in front of the label. | |
| 6195 | - let head = clip_middle(&name, text_w); | |
| 6196 | - let prefix = clip_middle(&name, text_w * SUB_STEM_SHARE); | |
| 6197 | - let rows: Vec<_> = rows | |
| 6198 | - .into_iter() | |
| 6199 | - .map(|row| { | |
| 6200 | - let track = row.track; | |
| 6201 | - let picked = track == self.sub_track; | |
| 6202 | - let usable = row.refused.is_none(); | |
| 6203 | - // Two tracks off one remux that both say "eng" are told | |
| 6204 | - // apart by their number and by nothing else -- the same | |
| 6205 | - // count [`sub_pick_name`] echoes. | |
| 6206 | - let title = match numbered { | |
| 6207 | - true => format!("{} {}", row.label, row.number), | |
| 6208 | - false => row.label, | |
| 6209 | - }; | |
| 6210 | - // A standalone `.srt` is named after its own file, so | |
| 6211 | - // the file in front of it says the same word twice | |
| 6212 | - // ("Legend.of.… · Legend.of.…"). [`sub_pick_name`]'s | |
| 6213 | - // rule, on the row it is about. | |
| 6214 | - let owned = several_files && !title.starts_with(name.as_str()); | |
| 6215 | - // The whole path, never clipped: the row says which | |
| 6216 | - // file, and the tooltip says which one on disk. | |
| 6217 | - let tip: SharedString = match &row.refused { | |
| 6218 | - Some(why) => format!("{} — {why}", path.display()), | |
| 6219 | - None => format!( | |
| 6220 | - "{} — click to show this track over the picture", | |
| 6221 | - path.display() | |
| 6222 | - ), | |
| 6223 | - } | |
| 6224 | - .into(); | |
| 6225 | - // Named, because a × is the same glyph on every row and | |
| 6226 | - // the tooltip is what says which track it takes off. | |
| 6227 | - let remove_tip: SharedString = | |
| 6228 | - format!("Remove {title} — importing the file again brings it back") | |
| 6229 | - .into(); | |
| 6230 | - div() | |
| 6231 | - // The *flat* index into the session's add-order | |
| 6232 | - // list, which is what a pick is and what a save | |
| 6233 | - // writes: the grouping moved the row on screen and | |
| 6234 | - // never the track it stands for. | |
| 6235 | - .id(("subtitle-track", track)) | |
| 6236 | - .flex_none() | |
| 6237 | - .h(px(ROW_H)) | |
| 6238 | - .flex() | |
| 6239 | - .items_center() | |
| 6240 | - .gap(px(6.)) | |
| 6241 | - .pr(px(6.)) | |
| 6242 | - .rounded(px(3.)) | |
| 6243 | - .when(!usable, |d| d.text_color(rgb(INK_DIM)).opacity(0.55)) | |
| 6244 | - .when(usable, |d| { | |
| 6245 | - d.cursor_pointer() | |
| 6246 | - .hover(|s| s.bg(rgb(HOVER))) | |
| 6247 | - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 6248 | - this.sub_track = track; | |
| 6249 | - // Picking a track is asking to see it: a | |
| 6250 | - // click that changed nothing on screen | |
| 6251 | - // because the toggle was off would read | |
| 6252 | - // as a dead row. | |
| 6253 | - this.subs_on = true; | |
| 6254 | - cx.notify(); | |
| 6255 | - })) | |
| 6256 | - }) | |
| 6257 | - .when(picked, |d| d.bg(rgb(SELECTED))) | |
| 6258 | - .tooltip(move |_, cx| cx.new(|_| Tip(tip.clone())).into()) | |
| 6259 | - // The media rows' bar, same width and hard against | |
| 6260 | - // the same edge: one association across the panel | |
| 6261 | - // and the lanes. Kept as room rather than dropped | |
| 6262 | - // where there is no tint, so a standalone `.srt` | |
| 6263 | - // still lines its words up with the rest. | |
| 6264 | - .child( | |
| 6265 | - div() | |
| 6266 | - .flex_none() | |
| 6267 | - .w(px(SWATCH_W)) | |
| 6268 | - .h_full() | |
| 6269 | - .rounded(px(2.)) | |
| 6270 | - .when_some(tint, |d, tint| d.bg(rgb(tint))), | |
| 6271 | - ) | |
| 6272 | - .child( | |
| 6273 | - div() | |
| 6274 | - .flex_1() | |
| 6275 | - .min_w(px(0.)) | |
| 6276 | - .flex() | |
| 6277 | - .flex_col() | |
| 6278 | - .child( | |
| 6279 | - div() | |
| 6280 | - .flex() | |
| 6281 | - .text_size(px(11.)) | |
| 6282 | - // In front, because the column | |
| 6283 | - // truncates from the right: an | |
| 6284 | - // ownership word at the end is a | |
| 6285 | - // word the floor never shows. | |
| 6286 | - .when(owned, |d| { | |
| 6287 | - d.child( | |
| 6288 | - div() | |
| 6289 | - .flex_none() | |
| 6290 | - // Said twice where a | |
| 6291 | - // header says it above: | |
| 6292 | - // still there, out of | |
| 6293 | - // the way. | |
| 6294 | - .when(headed, |d| { | |
| 6295 | - d.text_color(rgb(INK_DIM)) | |
| 6296 | - }) | |
| 6297 | - .child(format!("{prefix} · ")), | |
| 6298 | - ) | |
| 6299 | - }) | |
| 6300 | - .child( | |
| 6301 | - div() | |
| 6302 | - .flex_1() | |
| 6303 | - .min_w(px(0.)) | |
| 6304 | - .truncate() | |
| 6305 | - .child(title), | |
| 6306 | - ), | |
| 6307 | - ) | |
| 6308 | - .child( | |
| 6309 | - div() | |
| 6310 | - .truncate() | |
| 6311 | - .text_size(px(10.)) | |
| 6312 | - .text_color(rgb(INK_DIM)) | |
| 6313 | - .child(row.detail), | |
| 6314 | - ), | |
| 6315 | - ) | |
| 6316 | - // The way back off the timeline, on every row and on | |
| 6317 | - // the last one too -- a list of subtitles is allowed | |
| 6318 | - // to be empty, unlike a lane. A `HIT_MIN` target and | |
| 6319 | - // never hidden, the lane header's ×, and it stops | |
| 6320 | - // the click there: the row under it picks a track, | |
| 6321 | - // and picking the track that has just gone would | |
| 6322 | - // leave the pick naming nothing. | |
| 6323 | - .child( | |
| 6324 | - div() | |
| 6325 | - .id(("subtitle-remove", track)) | |
| 6326 | - .flex_none() | |
| 6327 | - .w(px(HIT_MIN)) | |
| 6328 | - .h_full() | |
| 6329 | - .flex() | |
| 6330 | - .items_center() | |
| 6331 | - .justify_center() | |
| 6332 | - .rounded(px(3.)) | |
| 6333 | - .cursor_pointer() | |
| 6334 | - .hover(|s| s.bg(rgb(HOVER))) | |
| 6335 | - .tooltip(move |_, cx| cx.new(|_| Tip(remove_tip.clone())).into()) | |
| 6336 | - .on_click(cx.listener( | |
| 6337 | - move |this, _: &ClickEvent, _, cx| { | |
| 6338 | - cx.stop_propagation(); | |
| 6339 | - this.remove_subtitle_track(track, cx); | |
| 6340 | - }, | |
| 6341 | - )) | |
| 6342 | - .child("×"), | |
| 6343 | - ) | |
| 6344 | - }) | |
| 6345 | - .collect(); | |
| 6346 | - div() | |
| 6347 | - .flex_none() | |
| 6348 | - .flex() | |
| 6349 | - .flex_col() | |
| 6350 | - .gap(px(2.)) | |
| 6351 | - // The header: which film these came out of, in words and not | |
| 6352 | - // in colour alone. No id, no click, nothing to fold -- a | |
| 6353 | - // label, which is why it is allowed under `HIT_MIN`. | |
| 6354 | - .when(headed, |d| { | |
| 6355 | - d.child( | |
| 6356 | - div() | |
| 6357 | - .flex_none() | |
| 6358 | - .h(px(SUB_HEAD_H)) | |
| 6359 | - .flex() | |
| 6360 | - .items_center() | |
| 6361 | - .gap(px(6.)) | |
| 6362 | - .text_size(px(10.)) | |
| 6363 | - .text_color(rgb(INK_DIM)) | |
| 6364 | - .when_some(tint, |d, tint| { | |
| 6365 | - d.child( | |
| 6366 | - div() | |
| 6367 | - .flex_none() | |
| 6368 | - .w(px(SWATCH_W)) | |
| 6369 | - .h_full() | |
| 6370 | - .rounded(px(2.)) | |
| 6371 | - .bg(rgb(tint)), | |
| 6372 | - ) | |
| 6373 | - }) | |
| 6374 | - .child(div().flex_1().min_w(px(0.)).truncate().child(head)), | |
| 6375 | - ) | |
| 6376 | - }) | |
| 6377 | - .children(rows) | |
| 6378 | - }) | |
| 6379 | - .collect(); | |
| 6380 | - Some( | |
| 6381 | - div() | |
| 6382 | - .flex_none() | |
| 6383 | - .flex() | |
| 6384 | - .flex_col() | |
| 6385 | - .gap(px(2.)) | |
| 6386 | - .child( | |
| 6387 | - div() | |
| 6388 | - .truncate() | |
| 6389 | - .text_size(px(11.)) | |
| 6390 | - .text_color(rgb(INK_DIM)) | |
| 6391 | - .child(match (self.subs_on, sub_pick_name(tracks, self.sub_track)) { | |
| 6392 | - // Which of them is on screen, named by its film: | |
| 6393 | - // the heading over a list of five is where the one | |
| 6394 | - // being shown is worth saying out loud. | |
| 6395 | - (true, Some(pick)) => format!("Subtitles — {pick}"), | |
| 6396 | - (true, None) => "Subtitles".to_string(), | |
| 6397 | - // The toggle's state where the tracks are listed: a | |
| 6398 | - // list of subtitles nothing on screen is showing has | |
| 6399 | - // to say that it is showing none. | |
| 6400 | - (false, _) => "Subtitles — hidden".to_string(), | |
| 6401 | - }), | |
| 6402 | - ) | |
| 6403 | - .child( | |
| 6404 | - div() | |
| 6405 | - .id("subtitle-rows") | |
| 6406 | - .flex() | |
| 6407 | - .flex_col() | |
| 6408 | - .gap(px(2.)) | |
| 6409 | - .max_h(px(SUB_ROWS_H)) | |
| 6410 | - .overflow_y_scroll() | |
| 6411 | - .children(rows), | |
| 6412 | - ), | |
| 6413 | - ) | |
| 6414 | - } | |
| 5814 | +/// Rate limit for scrub seeks: a video worker reopen costs 72-87 ms on the | |
| 5815 | +/// hardware path for the small files it was measured on (215 ms in software), so | |
| 5816 | +/// one seek per mouse move would only queue workers that are cancelled before | |
| 5817 | +/// they decode anything. | |
| 5818 | +/// | |
| 5819 | +/// It is a *floor*, not a bound: the reopen is a demux open | |
| 5820 | +/// ([`engine::decode::open_worker`]), and on a 25 GB film that is 550-750 ms -- | |
| 5821 | +/// five to seven times this gap, which therefore gates nothing there. Where the | |
| 5822 | +/// cost had to be bounded rather than thinned -- the colour and speed drags -- | |
| 5823 | +/// the gate is the frame the worker delivers ([`Player::flush_drag`]) and no | |
| 5824 | +/// timer at all. The ruler keeps this one: a scrub has no value to hold back, | |
| 5825 | +/// only a position that the next mouse move replaces anyway. | |
| 5826 | +const SCRUB_GAP: Duration = Duration::from_millis(100); | |
| 6415 | 5827 | |
| 6416 | - /// The cues of the picked track that are on screen at `at`, over the picture | |
| 6417 | - /// and nothing else: bottom-centred where every player puts them, white on a | |
| 6418 | - /// plate so the film underneath cannot swallow them, and each cue its own | |
| 6419 | - /// plate so two at one moment stack rather than run together. | |
| 6420 | - /// | |
| 6421 | - /// `None` -- no element at all -- while the toggle is off, with no track | |
| 6422 | - /// picked, and between cues: the picture is what this window is for, and a | |
| 6423 | - /// permanent empty band across it would be in the way of exactly that. | |
| 6424 | - /// | |
| 6425 | - /// The cues are the *timeline's* ([`PlaybackSession::timeline_cues`]) and | |
| 6426 | - /// not the track's own: on a cut timeline an embedded track's cues ride the | |
| 6427 | - /// pictures they belong to, and this is the same map the export writes the | |
| 6428 | - /// file with -- so what is read here is what the file says. | |
| 6429 | - /// | |
| 6430 | - /// A cue off a PGS track is a *picture* and not a line | |
| 6431 | - /// ([`engine::subtitle::CueImage`]), and is drawn as one: the disc's whole | |
| 6432 | - /// canvas fitted over the picture region exactly as the picture itself is, | |
| 6433 | - /// which puts every cue where the disc put it relative to its own frame. | |
| 6434 | - /// | |
| 6435 | - /// ponytail: exact only while the canvas and the encode are the same shape | |
| 6436 | - /// -- a 16:9 canvas over a 2.39:1 encode fits to the region's height and | |
| 6437 | - /// the film to its width, so a cue sits a little low on a scope film. The | |
| 6438 | - /// upgrade path is the picture's own rect, which wants `VideoMeta`'s aspect | |
| 6439 | - /// and the measured bounds rather than the shared `Contain`. | |
| 6440 | - fn subtitle_overlay( | |
| 6441 | - &mut self, | |
| 6442 | - at: f64, | |
| 6443 | - window: &mut Window, | |
| 6444 | - ) -> Option<impl IntoElement + use<>> { | |
| 6445 | - // One way out, and it lets the drawn picture go on the way: the toggle | |
| 6446 | - // going off, the file closing and the gap between two cues are the same | |
| 6447 | - // "nothing on screen", and an 8 MB atlas tile may not survive any of | |
| 6448 | - // them (an early return above this leaked one per toggle-off). | |
| 6449 | - let mapped = match self.session.as_ref().filter(|_| self.subs_on) { | |
| 6450 | - Some(session) => session.timeline_cues(self.sub_track), | |
| 6451 | - None => Vec::new(), | |
| 6452 | - }; | |
| 6453 | - let cues = cues_at(&mapped, at); | |
| 6454 | - if cues.is_empty() { | |
| 6455 | - self.drop_sub_image(window); | |
| 6456 | - return None; | |
| 5828 | +fn scrub_due(target: u32, last_target: u32, since: Duration) -> bool { | |
| 5829 | + target != last_target && since >= SCRUB_GAP | |
| 5830 | +} | |
| 5831 | + | |
| 5832 | +/// The gate a live drag sample goes through. With the worker still owing a | |
| 5833 | +/// frame (`busy`), writing now would only cancel the open the picture is already | |
| 5834 | +/// waiting for -- the sample is held in `stash` instead, and the frame that | |
| 5835 | +/// lands writes it ([`Player::flush_drag`]). Returns what to write, if anything. | |
| 5836 | +/// | |
| 5837 | +/// The press (`first`) never waits: it is the undo step the whole gesture rolls | |
| 5838 | +/// back to, so it has to be taken against the state the hand picked up. | |
| 5839 | +fn stash_or_write<T: Copy>(stash: &mut Option<T>, value: T, first: bool, busy: bool) -> Option<T> { | |
| 5840 | + match busy && !first { | |
| 5841 | + true => { | |
| 5842 | + *stash = Some(value); | |
| 5843 | + None | |
| 6457 | 5844 | } |
| 6458 | - // The first picture cue up, decoded once and kept: two bitmap cues at | |
| 6459 | - // one moment is a thing PGS composes into one display set, so there is | |
| 6460 | - // never a second picture to stack under the first. | |
| 6461 | - let picture = cues | |
| 6462 | - .iter() | |
| 6463 | - .find_map(|cue| Some((cue.start_us, cue.image.as_ref()?))) | |
| 6464 | - .and_then(|(start_us, image)| self.sub_picture(start_us, image, window)); | |
| 6465 | - // A picture is fitted onto the whole region and a plate hangs off the | |
| 6466 | - // bottom of it, and a track is one or the other -- so they are two | |
| 6467 | - // shapes and not one with the parts switched off. | |
| 6468 | - if let Some(image) = picture { | |
| 6469 | - // A *flex* box with the canvas as its one growing item: a percentage | |
| 6470 | - // size (`size_full`) inside an absolutely placed box has nothing to | |
| 6471 | - // be a percentage of and lays the picture out to nothing, while a | |
| 6472 | - // flex item is sized by the box itself. Fitted the way the picture | |
| 6473 | - // above it is -- `Contain` over the same box -- so a canvas of the | |
| 6474 | - // picture's own shape lands exactly on it. | |
| 6475 | - return Some(div().absolute().inset_0().flex().child( | |
| 6476 | - img(image).flex_1().h_full().object_fit(gpui::ObjectFit::Contain), | |
| 6477 | - )); | |
| 6478 | - } | |
| 6479 | - Some( | |
| 6480 | - div() | |
| 6481 | - .absolute() | |
| 6482 | - .left_0() | |
| 6483 | - .right_0() | |
| 6484 | - .bottom(px(SUB_BOTTOM)) | |
| 6485 | - .flex() | |
| 6486 | - .flex_col() | |
| 6487 | - .items_center() | |
| 6488 | - .gap(px(2.)) | |
| 6489 | - // The plate takes no click: the picture behind it is still the | |
| 6490 | - // drop target the whole window is. | |
| 6491 | - .children(cues.into_iter().filter(|c| c.image.is_none()).map(|cue| { | |
| 6492 | - div() | |
| 6493 | - .max_w(relative(0.9)) | |
| 6494 | - .px(px(6.)) | |
| 6495 | - .rounded(px(3.)) | |
| 6496 | - .bg(rgba(SUB_SHADE)) | |
| 6497 | - .text_size(px(SUB_TEXT)) | |
| 6498 | - .text_color(rgb(SUB_INK)) | |
| 6499 | - .text_align(TextAlign::Center) | |
| 6500 | - // A line of the cue is a line on screen: the break the | |
| 6501 | - // parser kept is not whitespace to be re-flowed. What a | |
| 6502 | - // *long* line does is wrap inside its own div, which is | |
| 6503 | - // what the width cap above is for. | |
| 6504 | - .children( | |
| 6505 | - cue.text | |
| 6506 | - .split('\n') | |
| 6507 | - .map(|line| div().min_h(px(SUB_LINE_H)).child(line.to_string())), | |
| 6508 | - ) | |
| 6509 | - })), | |
| 6510 | - ) | |
| 5845 | + false => Some(value), | |
| 6511 | 5846 | } |
| 5847 | +} | |
| 6512 | 5848 | |
| 6513 | - /// The cue starting at `start_us` as a drawable picture, decoded on the | |
| 6514 | - /// first repaint it is up for and kept until another cue takes its place | |
| 6515 | - /// ([`Player::sub_image`]). `None` for a display set the decoder refuses, | |
| 6516 | - /// which draws nothing rather than failing the frame. | |
| 6517 | - /// | |
| 6518 | - /// Its atlas tile is released as the video's is: every [`RenderImage`] gets | |
| 6519 | - /// a fresh id and its own tile, so a film's worth of cues would grow the | |
| 6520 | - /// sprite atlas by the whole film. | |
| 6521 | - fn sub_picture( | |
| 6522 | - &mut self, | |
| 6523 | - start_us: i64, | |
| 6524 | - image: &engine::subtitle::CueImage, | |
| 6525 | - window: &mut Window, | |
| 6526 | - ) -> Option<Arc<RenderImage>> { | |
| 6527 | - let key = (self.sub_track, start_us); | |
| 6528 | - if let Some((up, ready)) = &self.sub_image | |
| 6529 | - && *up == key | |
| 6530 | - { | |
| 6531 | - return Some(ready.clone()); | |
| 6532 | - } | |
| 6533 | - let mut rgba = image.rgba()?; | |
| 6534 | - // gpui's atlas is BGRA with straight alpha; PGS decodes to RGBA with | |
| 6535 | - // straight alpha. The same swap the video frames get. | |
| 6536 | - for pixel in rgba.chunks_exact_mut(4) { | |
| 6537 | - pixel.swap(0, 2); | |
| 6538 | - } | |
| 6539 | - let buf = image::RgbaImage::from_raw(image.width, image.height, rgba)?; | |
| 6540 | - let next = Arc::new(RenderImage::new(vec![image::Frame::new(buf)])); | |
| 6541 | - self.drop_sub_image(window); | |
| 6542 | - self.sub_image = Some((key, next.clone())); | |
| 6543 | - Some(next) | |
| 6544 | - } | |
| 6545 | - | |
| 6546 | - /// Lets go of the drawn cue and its atlas tile. Called where the cue stops | |
| 6547 | - /// being on screen, which is every gap between two of them: an 8 MB tile | |
| 6548 | - /// per cue is not a thing to leave behind a film. | |
| 6549 | - fn drop_sub_image(&mut self, window: &mut Window) { | |
| 6550 | - if let Some((_, old)) = self.sub_image.take() { | |
| 6551 | - let _ = window.drop_image(old); | |
| 6552 | - } | |
| 6553 | - } | |
| 6554 | - | |
| 6555 | - /// What is decoding the picture right now, for the transport line: the | |
| 6556 | - /// backend is the running worker's own (it is written where a hardware | |
| 6557 | - /// session falls back to software, so this follows reality), and the codec | |
| 6558 | - /// comes from the clip under the playhead. Empty when nothing is playing -- | |
| 6559 | - /// the question is about what is happening, not about what would. | |
| 6560 | - fn live_decode(&self, position: f64, playing: bool) -> String { | |
| 6561 | - let Some(session) = self.session.as_ref().filter(|_| playing) else { | |
| 6562 | - return String::new(); | |
| 6563 | - }; | |
| 6564 | - let backend = session.decode_backend(); | |
| 6565 | - let codec = session | |
| 6566 | - .video_clip_at(position) | |
| 6567 | - .and_then(|(lane, idx)| session.lane_clips(lane).get(idx).map(|clip| clip.source)) | |
| 6568 | - .and_then(|source| session.sources().get(source)) | |
| 6569 | - .and_then(|source| self.decoders.get(&source.path).copied().flatten()) | |
| 6570 | - .and_then(|(codec, _)| codec); | |
| 6571 | - match backend { | |
| 6572 | - // Neither is a decode, and saying "SW" of them would be a lie. | |
| 6573 | - Backend::Gap => "gap · nothing to decode".to_string(), | |
| 6574 | - Backend::Still => "still · one decode, held".to_string(), | |
| 6575 | - _ => format!("{} decode", decode_label(codec, backend)), | |
| 6576 | - } | |
| 6577 | - } | |
| 6578 | - | |
| 6579 | - /// Transport, edit and file buttons, timecode, playhead, clips lane. | |
| 6580 | - fn panel( | |
| 6581 | - &self, | |
| 6582 | - position: f64, | |
| 6583 | - duration: f64, | |
| 6584 | - state: Transport, | |
| 6585 | - cx: &mut Context<Self>, | |
| 6586 | - ) -> impl IntoElement { | |
| 6587 | - // Where the playhead is *on the bed*, in pixels from its left edge. | |
| 6588 | - // Clamped to the bed because it is drawn as a width as well as an | |
| 6589 | - // offset, and the view follows the playhead anyway, so it is never off | |
| 6590 | - // the bed for long. | |
| 6591 | - let bed_w = f32::from(self.ruler.get().size.width); | |
| 6592 | - let filled = self.scale.px_at(position).clamp(0., bed_w); | |
| 6593 | - // An export owns the hint slot and the ruler while it runs: the | |
| 6594 | - // percentage and the accent bar are the same number, so the playhead | |
| 6595 | - // fill doubles as the progress bar for free. | |
| 6596 | - let exporting = self.exporting().is_some(); | |
| 6597 | - // Everything but Import and Keys needs a timeline to act on: with none | |
| 6598 | - // open they are dimmed rather than silently doing nothing. | |
| 6599 | - let live = state != Transport::Stopped && !exporting; | |
| 6600 | - // The project's own picture size, for the button that cycles it: read | |
| 6601 | - // per render like everything else here, so a cycle shows on the button | |
| 6602 | - // that made it. | |
| 6603 | - let resolution = self.session.as_ref().map(PlaybackSession::resolution); | |
| 6604 | - let key = |action| self.keymap.display(action); | |
| 6605 | - // The lanes the project has, or the pair a fresh one starts with so the | |
| 6606 | - // panel reads the same before a file is open as after. | |
| 6607 | - let lanes = self | |
| 6608 | - .session | |
| 6609 | - .as_ref() | |
| 6610 | - .map_or_else(|| vec![Lane::V1, Lane::A1], PlaybackSession::lanes); | |
| 6611 | - // A loop rather than a `map`: each row takes `cx` in turn, where a | |
| 6612 | - // closure would hold it for as long as the iterator lives. | |
| 6613 | - let mut rows = Vec::new(); | |
| 6614 | - for &lane in &lanes { | |
| 6615 | - rows.push(self.lane_row(lane, filled, cx)); | |
| 6616 | - } | |
| 6617 | - // Built from the same playhead pixel the lanes are, and before the | |
| 6618 | - // export takes `filled` over below: the strip is a picture of the | |
| 6619 | - // timeline, not of an export's progress. | |
| 6620 | - let strip = self.subtitle_strip(filled); | |
| 6621 | - let strip_h = subtitle_strip_h(strip.is_some()); | |
| 6622 | - let (hint, filled) = if let Some(export) = self.exporting() { | |
| 6623 | - let progress = export.progress(); | |
| 6624 | - let elapsed = self | |
| 6625 | - .export_started | |
| 6626 | - .map_or(0., |t| t.elapsed().as_secs_f32()); | |
| 6627 | - // Two numbers that must both be honest: the one that counts up is | |
| 6628 | - // measured, the one that counts down is a guess and says so. | |
| 6629 | - let left = eta_secs(&self.export_marks, elapsed, progress).map_or_else( | |
| 6630 | - || "estimating…".to_owned(), | |
| 6631 | - |s| format!("~{} left", clock(s)), | |
| 6632 | - ); | |
| 6633 | - ( | |
| 6634 | - format!( | |
| 6635 | - // Clocks, then the way out, then what is encoding: at the | |
| 6636 | - // 640 px floor the tail is what truncation eats, and the | |
| 6637 | - // codec pair is the one part of this line the card already | |
| 6638 | - // said. The escape must not be what goes missing. | |
| 6639 | - "EXPORTING {}% · {} elapsed · {left} — {} cancels · {} · {}", | |
| 6640 | - (progress * 100.) as u32, | |
| 6641 | - clock(elapsed), | |
| 6642 | - key(ActionId::CancelExport), | |
| 6643 | - // The row that was picked; the engine's line below names the | |
| 6644 | - // seats alone, since the library is what identifies a codec. | |
| 6645 | - format_label(self.format), | |
| 6646 | - // What the worker actually opened, so a fallback to the | |
| 6647 | - // software encoder shows here rather than being invisible. | |
| 6648 | - export | |
| 6649 | - .encoders() | |
| 6650 | - .unwrap_or_else(|| "opening the encoder".to_string()), | |
| 6651 | - ), | |
| 6652 | - progress, | |
| 6653 | - ) | |
| 6654 | - } else { | |
| 6655 | - // The strokes no button carries; the rest ride on the buttons' | |
| 6656 | - // tooltips. Keys first: at a 640 px window the tail is what a | |
| 6657 | - // truncation eats, and the two hints at the end are also on the | |
| 6658 | - // ruler's and Import's tooltips. | |
| 6659 | - // While it plays, what is decoding it goes first: it is the | |
| 6660 | - // answer that changes as the playhead crosses a cut, and the tail | |
| 6661 | - // of this line is what a narrow window truncates. | |
| 6662 | - ( | |
| 6663 | - join_detail( | |
| 6664 | - &self.live_decode(position, state.is_playing()), | |
| 6665 | - &format!( | |
| 6666 | - "{} copy · {} paste · {} undo · click the bar to seek · drop a file to \ | |
| 6667 | - import", | |
| 6668 | - key(ActionId::Copy), | |
| 6669 | - key(ActionId::Paste), | |
| 6670 | - key(ActionId::Undo) | |
| 6671 | - ), | |
| 6672 | - ), | |
| 6673 | - filled, | |
| 6674 | - ) | |
| 6675 | - }; | |
| 6676 | - div() | |
| 6677 | - .flex_none() | |
| 6678 | - .h(px(panel_h(lanes.len()) + strip_h)) | |
| 6679 | - .flex() | |
| 6680 | - .flex_col() | |
| 6681 | - .gap(px(8.)) | |
| 6682 | - .px(px(12.)) | |
| 6683 | - .py(px(8.)) | |
| 6684 | - .bg(rgb(CHROME)) | |
| 6685 | - // Transport | edit | file: three groups, so the eye can skip two of | |
| 6686 | - // them. Every button says what it does; the tooltip adds its key. | |
| 6687 | - // | |
| 6688 | - // The row scrolls rather than losing its tail: at the 640 px floor | |
| 6689 | - // this window is sized for it is wider than the panel, and a button | |
| 6690 | - // off the right edge is a button a pointer cannot press. A plain | |
| 6691 | - // wheel moves it -- gpui puts a vertical delta on the x axis when | |
| 6692 | - // that is the only one scrolling (div.rs:2424). | |
| 6693 | - // | |
| 6694 | - // ...and "it scrolls" is not "it can be found": the button beside | |
| 6695 | - // the row is pinned outside it and never scrolls away, so Export, | |
| 6696 | - // Save and the rest are one press from the smallest window even | |
| 6697 | - // when the row's tail is off the edge. | |
| 6698 | - // `toolbar_fits_the_smallest_window` is the guard. | |
| 6699 | - .child( | |
| 6700 | - div() | |
| 6701 | - .flex_none() | |
| 6702 | - .flex() | |
| 6703 | - .items_center() | |
| 6704 | - .gap(px(8.)) | |
| 6705 | - .child( | |
| 6706 | - div() | |
| 6707 | - .id("controls") | |
| 6708 | - .flex_1() | |
| 6709 | - .min_w(px(0.)) | |
| 6710 | - .flex() | |
| 6711 | - .items_center() | |
| 6712 | - .gap(px(8.)) | |
| 6713 | - .overflow_x_scroll() | |
| 6714 | - .child(control( | |
| 6715 | - "transport", | |
| 6716 | - Some(transport_glyph(state).into_any_element()), | |
| 6717 | - if state.is_playing() { "Pause" } else { "Play" }, | |
| 6718 | - if nothing_to_play(self.session.as_ref()) && !state.is_playing() { | |
| 6719 | - format!("{} — put a clip on a lane first", key(ActionId::Play)) | |
| 6720 | - } else { | |
| 6721 | - key(ActionId::Play) | |
| 6722 | - }, | |
| 6723 | - // An empty timeline has nothing to play, so the button | |
| 6724 | - // says so by being dim rather than by starting a clock | |
| 6725 | - // against nothing (the key press answers with the | |
| 6726 | - // notice). Still live while it *is* playing: a delete | |
| 6727 | - // can empty the timeline mid-play and that has to stop. | |
| 6728 | - live && (state.is_playing() || !nothing_to_play(self.session.as_ref())), | |
| 6729 | - cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_or_restart(cx)), | |
| 6730 | - )) | |
| 6731 | - .child(separator()) | |
| 6732 | - .child(control( | |
| 6733 | - "cut", | |
| 6734 | - Some(cut_glyph().into_any_element()), | |
| 6735 | - "Cut", | |
| 6736 | - format!( | |
| 6737 | - "{} — splits the clip under the playhead", | |
| 6738 | - key(ActionId::Cut) | |
| 6739 | - ), | |
| 6740 | - live, | |
| 6741 | - cx.listener(|this, _: &ClickEvent, _, cx| this.cut(cx)), | |
| 6742 | - )) | |
| 6743 | - .child(control( | |
| 6744 | - "delete", | |
| 6745 | - Some(delete_glyph().into_any_element()), | |
| 6746 | - "Delete", | |
| 6747 | - if self.selected.is_some() { | |
| 6748 | - key(ActionId::Delete) | |
| 6749 | - } else { | |
| 6750 | - format!("{} — click a clip below first", key(ActionId::Delete)) | |
| 6751 | - }, | |
| 6752 | - live && self.selected.is_some(), | |
| 6753 | - cx.listener(|this, _: &ClickEvent, _, cx| this.delete_selected(cx)), | |
| 6754 | - )) | |
| 6755 | - // The way back from every one of them. It was a stroke and | |
| 6756 | - // nothing else, which made the whole edit group a one-way | |
| 6757 | - // door for anyone working with a pointer. | |
| 6758 | - .child(control( | |
| 6759 | - "undo", | |
| 6760 | - None, | |
| 6761 | - "Undo", | |
| 6762 | - format!("{} — takes the last edit back", key(ActionId::Undo)), | |
| 6763 | - live, | |
| 6764 | - cx.listener(|this, _: &ClickEvent, _, cx| this.undo(cx)), | |
| 6765 | - )) | |
| 6766 | - // With the edit group, beside the buttons that change the | |
| 6767 | - // edit list: a track is a row of it, and adding one is an | |
| 6768 | - // undoable edit like the rest. Two buttons rather than one | |
| 6769 | - // with a choice, because the choice is the whole action. | |
| 6770 | - .child(control( | |
| 6771 | - "add-video-lane", | |
| 6772 | - None, | |
| 6773 | - "+ V", | |
| 6774 | - format!( | |
| 6775 | - "{} — adds a video track under the ones there", | |
| 6776 | - key(ActionId::AddVideoLane) | |
| 6777 | - ), | |
| 6778 | - live, | |
| 6779 | - cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 6780 | - this.add_lane(LaneKind::Video, cx) | |
| 6781 | - }), | |
| 6782 | - )) | |
| 6783 | - .child(control( | |
| 6784 | - "add-audio-lane", | |
| 6785 | - None, | |
| 6786 | - "+ A", | |
| 6787 | - format!( | |
| 6788 | - "{} — adds an audio track under the ones there", | |
| 6789 | - key(ActionId::AddAudioLane) | |
| 6790 | - ), | |
| 6791 | - live, | |
| 6792 | - cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 6793 | - this.add_lane(LaneKind::Audio, cx) | |
| 6794 | - }), | |
| 6795 | - )) | |
| 6796 | - // The third kind of track this timeline carries, and | |
| 6797 | - // the only one that arrived through a drop alone: a | |
| 6798 | - // subtitle file nobody thought to drag was a track | |
| 6799 | - // the editor could not be asked for. What it opens is | |
| 6800 | - // a chooser rather than an empty row -- a subtitle | |
| 6801 | - // track is its file, and there is nothing to add | |
| 6802 | - // before one is named. | |
| 6803 | - .child(control( | |
| 6804 | - "add-subtitle-track", | |
| 6805 | - None, | |
| 6806 | - "+ S", | |
| 6807 | - // Dim, and saying why it is dim, out of the one | |
| 6808 | - // oracle -- the very words the key answers with | |
| 6809 | - // (`Player::pick_and_add_subtitles`), so the | |
| 6810 | - // tooltip and the notice cannot come to differ. | |
| 6811 | - match self.enable(ActionId::AddSubtitleTrack, None).why() { | |
| 6812 | - Some(why) => { | |
| 6813 | - format!("{} — {why}", key(ActionId::AddSubtitleTrack)) | |
| 6814 | - } | |
| 6815 | - None => format!( | |
| 6816 | - "{} — adds every subtitle track in a file you pick", | |
| 6817 | - key(ActionId::AddSubtitleTrack) | |
| 6818 | - ), | |
| 6819 | - }, | |
| 6820 | - live, | |
| 6821 | - cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 6822 | - this.pick_and_add_subtitles(cx) | |
| 6823 | - }), | |
| 6824 | - )) | |
| 6825 | - // With the transport, not the edit group: it changes what | |
| 6826 | - // the file sounds like, never what it is. Reads as its own | |
| 6827 | - // state, so muted is legible without a tooltip. | |
| 6828 | - .child(control( | |
| 6829 | - "volume", | |
| 6830 | - None, | |
| 6831 | - self.volume.label(), | |
| 6832 | - format!( | |
| 6833 | - "{} mutes · {} louder · {} quieter", | |
| 6834 | - key(ActionId::ToggleMute), | |
| 6835 | - key(ActionId::VolumeUp), | |
| 6836 | - key(ActionId::VolumeDown) | |
| 6837 | - ), | |
| 6838 | - live, | |
| 6839 | - cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 6840 | - this.set_volume(|volume| volume.muted = !volume.muted, cx) | |
| 6841 | - }), | |
| 6842 | - )) | |
| 6843 | - // The level itself, to drag. The button beside it stays the | |
| 6844 | - // mute -- one gesture each -- and the label above is what | |
| 6845 | - // this writes, live, so the number follows the hand. | |
| 6846 | - .child(volume_slider( | |
| 6847 | - self.volume, | |
| 6848 | - self.volume_bar.clone(), | |
| 6849 | - live, | |
| 6850 | - cx, | |
| 6851 | - )) | |
| 6852 | - .child(separator()) | |
| 6853 | - // The size every clip is composed onto, which is also the | |
| 6854 | - // size the export comes out at. Five sizes, so a click opens | |
| 6855 | - // the list of them with this one marked and picks whichever | |
| 6856 | - // was meant: a button that stepped one on per press made the | |
| 6857 | - // user click round the ladder to get back to where they | |
| 6858 | - // were. The stroke still steps, for the hand already on it. | |
| 6859 | - .child(control( | |
| 6860 | - "resolution", | |
| 6861 | - None, | |
| 6862 | - resolution.map_or_else(|| "Size".to_string(), |(_, h)| format!("{h}p")), | |
| 6863 | - match resolution { | |
| 6864 | - Some((w, h)) => format!( | |
| 6865 | - "click to pick a size — the project is {w}x{h}; {} steps to the next", | |
| 6866 | - key(ActionId::Resolution) | |
| 6867 | - ), | |
| 6868 | - None => format!("{} — open a file first", key(ActionId::Resolution)), | |
| 6869 | - }, | |
| 6870 | - live, | |
| 6871 | - cx.listener(|this, event: &ClickEvent, _, cx| { | |
| 6872 | - this.open_picker(Pick::Resolution, event.position(), cx) | |
| 6873 | - }), | |
| 6874 | - )) | |
| 6875 | - // The rate every clip is counted in, which is also the rate | |
| 6876 | - // the export is written at -- the other half of "the project | |
| 6877 | - // is not the media", and the one the panel could only ever | |
| 6878 | - // read out before. A click opens the rates with this one | |
| 6879 | - // marked; picking one conforms the whole timeline to it. | |
| 6880 | - .child(control( | |
| 6881 | - "fps", | |
| 6882 | - None, | |
| 6883 | - match self.session.is_some() { | |
| 6884 | - true => format!("{} fps", fps_label(self.fps)), | |
| 6885 | - false => "Rate".to_string(), | |
| 6886 | - }, | |
| 6887 | - match self.session.is_some() { | |
| 6888 | - true => format!( | |
| 6889 | - "click to pick a frame rate — the project is cut at {} fps", | |
| 6890 | - fps_label(self.fps) | |
| 6891 | - ), | |
| 6892 | - false => "the project's frame rate — open a file first".to_string(), | |
| 6893 | - }, | |
| 6894 | - live, | |
| 6895 | - cx.listener(|this, event: &ClickEvent, _, cx| { | |
| 6896 | - this.open_picker(Pick::Fps, event.position(), cx) | |
| 6897 | - }), | |
| 6898 | - )) | |
| 6899 | - // ...and which rendition its HDR media is watched in, the | |
| 6900 | - // third thing that is the project's rather than the media's. | |
| 6901 | - // Listed whatever is on the timeline, and the tooltip says | |
| 6902 | - // who it acts on: a control that came and went with the | |
| 6903 | - // media would be one nobody could find when they wanted it. | |
| 6904 | - .child(control( | |
| 6905 | - "tonemap", | |
| 6906 | - None, | |
| 6907 | - match &self.session { | |
| 6908 | - Some(session) => format!("HDR {}", tone_label(session.tone())), | |
| 6909 | - None => "HDR".to_string(), | |
| 6910 | - }, | |
| 6911 | - match &self.session { | |
| 6912 | - Some(session) => format!( | |
| 6913 | - "click to pick the HDR rendition — the project is {}; SDR media is untouched", | |
| 6914 | - tone_label(session.tone()) | |
| 6915 | - ), | |
| 6916 | - None => "the HDR rendition — open a file first".to_string(), | |
| 6917 | - }, | |
| 6918 | - live, | |
| 6919 | - cx.listener(|this, event: &ClickEvent, _, cx| { | |
| 6920 | - this.open_picker(Pick::Tone, event.position(), cx) | |
| 6921 | - }), | |
| 6922 | - )) | |
| 6923 | - // How much of the timeline the panel below is showing -- | |
| 6924 | - // beside the resolution, since neither of them edits | |
| 6925 | - // anything: they are both what is being looked at. The | |
| 6926 | - // middle one says how much of it is on the bed, and is the | |
| 6927 | - // way back to the whole of it. | |
| 6928 | - .child(control( | |
| 6929 | - "zoom-out", | |
| 6930 | - None, | |
| 6931 | - "−", | |
| 6932 | - format!( | |
| 6933 | - "{} — show more of the timeline; stops with all of it on the bed", | |
| 6934 | - key(ActionId::ZoomOut) | |
| 6935 | - ), | |
| 6936 | - live, | |
| 6937 | - cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 6938 | - this.zoom(1. / ZOOM_STEP, None, cx) | |
| 6939 | - }), | |
| 6940 | - )) | |
| 6941 | - .child(control( | |
| 6942 | - "zoom-fit", | |
| 6943 | - None, | |
| 6944 | - // How much timeline is on the bed, not a multiple of | |
| 6945 | - // "the whole of it": the scale no longer knows what the | |
| 6946 | - // whole of it is, and a number that changed on every | |
| 6947 | - // import was a number that lied. | |
| 6948 | - span_label(self.view().span()), | |
| 6949 | - format!( | |
| 6950 | - "{} — fit the whole timeline; showing {} to {}", | |
| 6951 | - key(ActionId::ZoomFit), | |
| 6952 | - timecode(self.scale.start, self.fps), | |
| 6953 | - timecode( | |
| 6954 | - (self.scale.start + self.view().span()).min(duration), | |
| 6955 | - self.fps | |
| 6956 | - ) | |
| 6957 | - ), | |
| 6958 | - live, | |
| 6959 | - cx.listener(|this, _: &ClickEvent, _, cx| this.zoom_fit(cx)), | |
| 6960 | - )) | |
| 6961 | - .child(control( | |
| 6962 | - "zoom-in", | |
| 6963 | - None, | |
| 6964 | - "+", | |
| 6965 | - format!( | |
| 6966 | - "{} — magnify around the playhead; ctrl+wheel on the bar zooms at the pointer", | |
| 6967 | - key(ActionId::ZoomIn) | |
| 6968 | - ), | |
| 6969 | - live, | |
| 6970 | - cx.listener(|this, _: &ClickEvent, _, cx| this.zoom(ZOOM_STEP, None, cx)), | |
| 6971 | - )) | |
| 6972 | - // The magnet, beside the zoom for the zoom's own reason: it | |
| 6973 | - // changes nothing on the timeline, it changes how the hand | |
| 6974 | - // meets it. The label is the state, as the volume's is -- | |
| 6975 | - // a toggle that looks the same either way says nothing. | |
| 6976 | - .child(control( | |
| 6977 | - "snap", | |
| 6978 | - None, | |
| 6979 | - if self.snap { "Snap" } else { "No snap" }, | |
| 6980 | - format!( | |
| 6981 | - "{} — {}", | |
| 6982 | - key(ActionId::ToggleSnap), | |
| 6983 | - match self.snap { | |
| 6984 | - true => "drags and trims land on clip edges, the playhead and the start", | |
| 6985 | - false => "drags and trims land exactly where the hand leaves them", | |
| 6986 | - } | |
| 6987 | - ), | |
| 6988 | - live, | |
| 6989 | - cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_snap(cx)), | |
| 6990 | - )) | |
| 6991 | - // The cues over the picture, off and on -- beside the zoom | |
| 6992 | - // and the snap, since like both of them it changes what is | |
| 6993 | - // being looked at and nothing about the edit. The label is | |
| 6994 | - // the state, as the snap's is, and it says what there is to | |
| 6995 | - // toggle when there is nothing. | |
| 6996 | - .child(control( | |
| 6997 | - "subs", | |
| 6998 | - None, | |
| 6999 | - match (self.subtitle_track().is_some(), self.subs_on) { | |
| 7000 | - (false, _) => "No subs", | |
| 7001 | - (true, true) => "Subs", | |
| 7002 | - (true, false) => "Subs off", | |
| 7003 | - }, | |
| 7004 | - match self.enable(ActionId::ToggleSubtitles, None).why() { | |
| 7005 | - Some(why) => format!( | |
| 7006 | - "{} — {why}; drop a .srt on the window, or open an mkv that carries them", | |
| 7007 | - key(ActionId::ToggleSubtitles) | |
| 7008 | - ), | |
| 7009 | - None => format!( | |
| 7010 | - "{} — {}", | |
| 7011 | - key(ActionId::ToggleSubtitles), | |
| 7012 | - match self.subs_on { | |
| 7013 | - true => "the cue under the playhead is drawn over the picture", | |
| 7014 | - false => "the cues are on the timeline and off the picture", | |
| 7015 | - } | |
| 7016 | - ), | |
| 7017 | - }, | |
| 7018 | - live && self.enable(ActionId::ToggleSubtitles, None).yes(), | |
| 7019 | - cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_subtitles(cx)), | |
| 7020 | - )) | |
| 7021 | - // Import is not here: it belongs to the media list it adds | |
| 7022 | - // to, and two doors into one action is a question about | |
| 7023 | - // which one is the real one. | |
| 7024 | - // | |
| 7025 | - // While one runs, this button is the way out of it: the | |
| 7026 | - // progress line promised esc and nothing else, which left a | |
| 7027 | - // pointer no way to stop an export it had started. | |
| 7028 | - .child(control( | |
| 7029 | - "export", | |
| 7030 | - None, | |
| 7031 | - if exporting { "Cancel" } else { "Export" }, | |
| 7032 | - if exporting { | |
| 7033 | - format!( | |
| 7034 | - "{} — stops the export; the part-written file goes", | |
| 7035 | - key(ActionId::CancelExport) | |
| 7036 | - ) | |
| 7037 | - } else { | |
| 7038 | - format!( | |
| 7039 | - "{} — quality and destination, then writes the timeline out", | |
| 7040 | - key(ActionId::Export) | |
| 7041 | - ) | |
| 7042 | - }, | |
| 7043 | - if exporting { | |
| 7044 | - true | |
| 7045 | - } else { | |
| 7046 | - live && self.export.is_none() | |
| 7047 | - }, | |
| 7048 | - cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 7049 | - if this.exporting().is_some() { | |
| 7050 | - this.cancel_export(); | |
| 7051 | - cx.notify(); | |
| 7052 | - } else { | |
| 7053 | - this.open_export(cx); | |
| 7054 | - } | |
| 7055 | - }), | |
| 7056 | - )) | |
| 7057 | - .child(control( | |
| 7058 | - "save", | |
| 7059 | - None, | |
| 7060 | - "Save", | |
| 7061 | - format!("{} — writes the project file", key(ActionId::Save)), | |
| 7062 | - live, | |
| 7063 | - cx.listener(|this, _: &ClickEvent, _, cx| this.save_project(cx)), | |
| 7064 | - )) | |
| 7065 | - // Closed while an export runs, which is what keeps a waiting | |
| 7066 | - // row from swallowing the escape the progress line promises | |
| 7067 | - // cancels the export. | |
| 7068 | - .child(control( | |
| 7069 | - "keys", | |
| 7070 | - None, | |
| 7071 | - "Actions", | |
| 7072 | - // The pointer's way to every action there is, including | |
| 7073 | - // the ones no button here has room for. | |
| 7074 | - format!( | |
| 7075 | - "{} — do any action, or change the key that does it", | |
| 7076 | - key(ActionId::ShowActions) | |
| 7077 | - ), | |
| 7078 | - !exporting, | |
| 7079 | - cx.listener(|this, _: &ClickEvent, _, cx| match this.keys_open { | |
| 7080 | - true => { | |
| 7081 | - this.keys_open = false; | |
| 7082 | - this.rebinding = None; | |
| 7083 | - cx.notify(); | |
| 7084 | - } | |
| 7085 | - false => this.show_actions(cx), | |
| 7086 | - }), | |
| 7087 | - )) | |
| 7088 | - ) | |
| 7089 | - // The door to everything the row cannot show at this | |
| 7090 | - // window: the same card the Actions button opens, by the | |
| 7091 | - // same call, pinned where a scroll cannot take it. | |
| 7092 | - .child(control( | |
| 7093 | - "controls-more", | |
| 7094 | - None, | |
| 7095 | - "⋯", | |
| 7096 | - format!( | |
| 7097 | - "{} — every action, including the ones scrolled off this row", | |
| 7098 | - key(ActionId::ShowActions) | |
| 7099 | - ), | |
| 7100 | - !exporting, | |
| 7101 | - cx.listener(|this, _: &ClickEvent, _, cx| match this.keys_open { | |
| 7102 | - true => { | |
| 7103 | - this.keys_open = false; | |
| 7104 | - this.rebinding = None; | |
| 7105 | - cx.notify(); | |
| 7106 | - } | |
| 7107 | - false => this.show_actions(cx), | |
| 7108 | - }), | |
| 7109 | - )), | |
| 7110 | - ) | |
| 7111 | - .child( | |
| 7112 | - div() | |
| 7113 | - .flex_none() | |
| 7114 | - .flex() | |
| 7115 | - .items_center() | |
| 7116 | - .gap(px(12.)) | |
| 7117 | - // Fixed width and one line: changing digits must not push | |
| 7118 | - // the row around, nor wrap and change its height. | |
| 7119 | - // The timeline's own length, never the drawn one: a tail | |
| 7120 | - // being dragged inflates the bed to the room that edge has | |
| 7121 | - // ([`Player::drawn_duration`]), and for a still that room is | |
| 7122 | - // ten minutes -- a total that jumped to 10:00:00 the moment | |
| 7123 | - // a picture's edge was pressed, and back on release. | |
| 7124 | - .child(div().flex_none().w(px(TIME_W)).truncate().child(format!( | |
| 7125 | - "{} / {}", | |
| 7126 | - timecode(position, self.fps), | |
| 7127 | - timecode( | |
| 7128 | - self.session | |
| 7129 | - .as_ref() | |
| 7130 | - .map_or(0., PlaybackSession::timeline_duration), | |
| 7131 | - self.fps | |
| 7132 | - ) | |
| 7133 | - ))) | |
| 7134 | - .child( | |
| 7135 | - div() | |
| 7136 | - .flex_1() | |
| 7137 | - .min_w(px(0.)) | |
| 7138 | - .truncate() | |
| 7139 | - .text_size(px(11.)) | |
| 7140 | - .text_color(rgb(INK_DIM)) | |
| 7141 | - .child(hint), | |
| 7142 | - ), | |
| 7143 | - ) | |
| 7144 | - // Press to seek, drag to scrub: the move and release halves live on | |
| 7145 | - // the root, since the pointer leaves the bar immediately. The bar | |
| 7146 | - // stays 6 px to look at; the strip that takes the click is 24, so | |
| 7147 | - // it can be hit without aiming (WCAG 2.5.8). | |
| 7148 | - .child( | |
| 7149 | - div() | |
| 7150 | - .flex_none() | |
| 7151 | - .flex() | |
| 7152 | - .gap(px(HEADER_GAP)) | |
| 7153 | - // The lanes' header column, empty here: the ruler's own bar | |
| 7154 | - // has to start where their beds start, or the playhead | |
| 7155 | - // would point at a different moment in each row. | |
| 7156 | - .child(div().flex_none().w(px(HEADER_W))) | |
| 7157 | - .child( | |
| 7158 | - div() | |
| 7159 | - .id("ruler") | |
| 7160 | - .flex_1() | |
| 7161 | - .min_w(px(0.)) | |
| 7162 | - .h(px(RULER_HIT_H)) | |
| 7163 | - .flex() | |
| 7164 | - .flex_col() | |
| 7165 | - .justify_center() | |
| 7166 | - .rounded(px(3.)) | |
| 7167 | - .cursor_pointer() | |
| 7168 | - .hover(|s| s.bg(rgb(HOVER_DIM))) | |
| 7169 | - // The strip carries no text, so the tooltip is the only | |
| 7170 | - // place it can say what it is. | |
| 7171 | - .tooltip(|_, cx| { | |
| 7172 | - cx.new(|_| Tip("Seek — click or drag; ctrl+wheel zooms".into())) | |
| 7173 | - .into() | |
| 7174 | - }) | |
| 7175 | - // Ctrl+wheel is what every timeline zooms with, and | |
| 7176 | - // the point held still is the one under the pointer | |
| 7177 | - // rather than the playhead. Only with ctrl: a bare | |
| 7178 | - // wheel here is the window's to scroll, and the | |
| 7179 | - // controls row above scrolls on exactly that. | |
| 7180 | - .on_scroll_wheel(cx.listener( | |
| 7181 | - |this, event: &ScrollWheelEvent, _, cx| { | |
| 7182 | - if !event.modifiers.control { | |
| 7183 | - return; | |
| 7184 | - } | |
| 7185 | - let dy = match event.delta { | |
| 7186 | - ScrollDelta::Lines(d) => d.y, | |
| 7187 | - ScrollDelta::Pixels(d) => f32::from(d.y), | |
| 7188 | - }; | |
| 7189 | - if dy == 0. { | |
| 7190 | - return; | |
| 7191 | - } | |
| 7192 | - let anchor = px_along(event.position.x, this.ruler.get()); | |
| 7193 | - let factor = if dy > 0. { ZOOM_STEP } else { 1. / ZOOM_STEP }; | |
| 7194 | - this.zoom(factor, Some(anchor), cx); | |
| 7195 | - }, | |
| 7196 | - )) | |
| 7197 | - .on_mouse_down( | |
| 7198 | - MouseButton::Left, | |
| 7199 | - cx.listener(|this, event: &MouseDownEvent, _, cx| { | |
| 7200 | - this.scrubbing = true; | |
| 7201 | - this.scrub_to(event.position.x, true, cx); | |
| 7202 | - }), | |
| 7203 | - ) | |
| 7204 | - .child( | |
| 7205 | - div() | |
| 7206 | - .w_full() | |
| 7207 | - .h(px(6.)) | |
| 7208 | - .rounded(px(3.)) | |
| 7209 | - .bg(rgb(SURFACE)) | |
| 7210 | - .child(bounds_probe(self.ruler.clone())) | |
| 7211 | - .child( | |
| 7212 | - div() | |
| 7213 | - .h_full() | |
| 7214 | - .w(px(filled)) | |
| 7215 | - .rounded(px(3.)) | |
| 7216 | - .bg(rgb(ACCENT)), | |
| 7217 | - ), | |
| 7218 | - ), | |
| 7219 | - ), | |
| 7220 | - ) | |
| 7221 | - // Every lane the project has, in its own order -- and its own | |
| 7222 | - // column, so a project with more lanes than the panel is tall | |
| 7223 | - // scrolls its tracks instead of pushing the picture off the window. | |
| 7224 | - // The gap is the panel's own, so two lanes lay out exactly as they | |
| 7225 | - // did when they were two children of it. | |
| 7226 | - .child( | |
| 7227 | - div() | |
| 7228 | - .id("lanes") | |
| 7229 | - .flex_none() | |
| 7230 | - .flex() | |
| 7231 | - .flex_col() | |
| 7232 | - .gap(px(8.)) | |
| 7233 | - .max_h(px(lanes_h(LANES_MAX))) | |
| 7234 | - .overflow_y_scroll() | |
| 7235 | - .children(rows), | |
| 7236 | - ) | |
| 7237 | - // Under the tracks and outside their scrolling column: a subtitle is | |
| 7238 | - // not a track -- nothing can be dropped on it and nothing dragged | |
| 7239 | - // along it -- and a strip that scrolled away with the sixth lane | |
| 7240 | - // would be a strip nobody could see while editing. | |
| 7241 | - .children(strip) | |
| 7242 | - } | |
| 5849 | +/// How long an open may stand before the window says so in words. Well past an | |
| 5850 | +/// ordinary seek (a warm reopen is under a tenth of this) and well under what a | |
| 5851 | +/// cold read of a big film takes, which is the only case worth a line. | |
| 5852 | +const SEEK_STALL: Duration = Duration::from_secs(2); | |
| 7243 | 5853 | |
| 7244 | - /// The running import holds its own bar above the notice's, for the notice | |
| 7245 | - /// bar's reason: the message is the point. Not a notice, though -- nothing | |
| 7246 | - /// dismisses it, because it is about work still going on, and it leaves by | |
| 7247 | - /// itself when the file lands. | |
| 7248 | - /// | |
| 7249 | - /// The bar under the words is a *sweep*, not a fill: neither read reports | |
| 7250 | - /// where in the file it is, so a fill would have to invent the one number | |
| 7251 | - /// this cannot know. What it does say truthfully is "something is still | |
| 7252 | - /// running", which is exactly the question a frozen-looking window raises. | |
| 7253 | - /// | |
| 7254 | - /// ...and beside them the way out. A read that may be twenty seconds of a | |
| 7255 | - /// cold 24 GB film needs one, and the only honest place for it is the line | |
| 7256 | - /// that says the read is happening ([`Player::cancel_import`]). | |
| 7257 | - fn import_bar(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> { | |
| 7258 | - let import = self.importing.as_ref()?; | |
| 7259 | - let elapsed = import.started.elapsed().as_secs_f32(); | |
| 7260 | - let line = import_line( | |
| 7261 | - &file_name(&import.path), | |
| 7262 | - import.seen, | |
| 7263 | - elapsed, | |
| 7264 | - import.since.elapsed().as_secs_f32(), | |
| 7265 | - self.imports.len(), | |
| 7266 | - arrival(self.opening.as_deref(), &import.path) != Landing::Import, | |
| 7267 | - ); | |
| 7268 | - // A quarter of the bar, crossing it every three seconds and wrapping. | |
| 7269 | - // Tied to the elapsed clock, so it moves for as long as the read does | |
| 7270 | - // and stops dead the instant the file lands. | |
| 7271 | - const SWEEP: f32 = 0.25; | |
| 7272 | - let at = (elapsed / 3.).fract() * (1. + SWEEP) - SWEEP; | |
| 7273 | - Some( | |
| 7274 | - div() | |
| 7275 | - .flex_none() | |
| 7276 | - .flex() | |
| 7277 | - .flex_col() | |
| 7278 | - .gap(px(4.)) | |
| 7279 | - .px(px(12.)) | |
| 7280 | - .py(px(6.)) | |
| 7281 | - .bg(rgb(SURFACE)) | |
| 7282 | - .child( | |
| 7283 | - div() | |
| 7284 | - .flex() | |
| 7285 | - .items_center() | |
| 7286 | - .gap(px(8.)) | |
| 7287 | - .child(div().flex_1().min_w(px(0.)).child(line)) | |
| 7288 | - .child(control( | |
| 7289 | - "cancel-import", | |
| 7290 | - None, | |
| 7291 | - "Cancel", | |
| 7292 | - "stops this file and anything queued behind it; the read already \ | |
| 7293 | - running finishes unheeded" | |
| 7294 | - .to_string(), | |
| 7295 | - true, | |
| 7296 | - cx.listener(|this, _: &ClickEvent, _, cx| this.cancel_import(cx)), | |
| 7297 | - )), | |
| 7298 | - ) | |
| 7299 | - .child( | |
| 7300 | - div() | |
| 7301 | - .relative() | |
| 7302 | - .w_full() | |
| 7303 | - .h(px(2.)) | |
| 7304 | - .bg(rgb(HOVER)) | |
| 7305 | - .child( | |
| 7306 | - div() | |
| 7307 | - .absolute() | |
| 7308 | - .top_0() | |
| 7309 | - .left(relative(at.max(0.))) | |
| 7310 | - // Clipped at both ends by hand: the segment | |
| 7311 | - // enters from the left edge and leaves past the | |
| 7312 | - // right one, and a width that overhung would | |
| 7313 | - // paint outside the track. | |
| 7314 | - .w(relative((at + SWEEP).min(1.) - at.max(0.))) | |
| 7315 | - .h(px(2.)) | |
| 7316 | - .bg(rgb(ACCENT)), | |
| 7317 | - ), | |
| 7318 | - ), | |
| 7319 | - ) | |
| 7320 | - } | |
| 5854 | +/// What a seek that has stood past [`SEEK_STALL`] says, and nothing at all | |
| 5855 | +/// before that: a line on every click of the ruler would be a flicker, and the | |
| 5856 | +/// picture holding still for a tenth of a second is not something to explain. | |
| 5857 | +/// The import bar's words, for the import bar's reason -- a window that cannot | |
| 5858 | +/// move and a window that has hung look identical, so this one says which. | |
| 5859 | +fn seek_line(standing: Option<Duration>) -> Option<String> { | |
| 5860 | + let since = standing.filter(|d| *d >= SEEK_STALL)?; | |
| 5861 | + Some(format!( | |
| 5862 | + "still opening the picture — a cold read of a big file is seconds of it, and the window \ | |
| 5863 | + is not frozen · {} elapsed", | |
| 5864 | + clock(since.as_secs_f32()) | |
| 5865 | + )) | |
| 5866 | +} | |
| 7321 | 5867 | |
| 7322 | - /// The line a long-standing seek shows, in the import bar's place and by the | |
| 7323 | - /// import bar's rules: nothing dismisses it, and it leaves by itself the | |
| 7324 | - /// moment the frame lands. No sweep under it -- an open reports nothing about | |
| 7325 | - /// where it has got to, and the clock is the honest half of that bar anyway. | |
| 7326 | - fn seek_bar(&self) -> Option<impl IntoElement> { | |
| 7327 | - let line = seek_line(self.seek_since.map(|t| t.elapsed()))?; | |
| 7328 | - Some( | |
| 7329 | - div() | |
| 7330 | - .flex_none() | |
| 7331 | - .px(px(12.)) | |
| 7332 | - .py(px(6.)) | |
| 7333 | - .bg(rgb(SURFACE)) | |
| 7334 | - .child(line), | |
| 7335 | - ) | |
| 7336 | - } | |
| 5868 | +/// How a finished export announces itself. Written by `poll_export` and read | |
| 5869 | +/// by the notice bar, which is what makes that one line clickable. | |
| 5870 | +const EXPORT_DONE: &str = "EXPORT DONE → "; | |
| 7337 | 5871 | |
| 7338 | - /// A notice holds its own bar, full width, until it is answered: any key | |
| 7339 | - /// retires it (the key handler) and so does a click on it. Its own surface | |
| 7340 | - /// because the message is the point -- a failure cut to the timecode's slot | |
| 7341 | - /// is a failure nobody read. | |
| 7342 | - /// | |
| 7343 | - /// The export's own line is more than a message: it names a file that is | |
| 7344 | - /// now on disk, so the same click that retires it shows that file in the | |
| 7345 | - /// desktop's file manager. | |
| 7346 | - fn notice_bar(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> { | |
| 7347 | - let notice = self.notice.clone()?; | |
| 7348 | - // The path travels with the text it was written for: a later notice | |
| 7349 | - // holds the bar and the click is a plain dismissal again. | |
| 7350 | - let exported = self | |
| 7351 | - .exported | |
| 7352 | - .clone() | |
| 7353 | - .filter(|_| notice.starts_with(EXPORT_DONE)); | |
| 7354 | - let hint = match exported { | |
| 7355 | - Some(_) => "click — open file location", | |
| 7356 | - None => "click or press any key to dismiss", | |
| 7357 | - }; | |
| 7358 | - Some( | |
| 7359 | - div() | |
| 7360 | - .id("notice") | |
| 7361 | - .when(exported.is_some(), |d| { | |
| 7362 | - d.tooltip(|_, cx| { | |
| 7363 | - cx.new(|_| { | |
| 7364 | - Tip("Open file location — shows the export in the file manager".into()) | |
| 7365 | - }) | |
| 7366 | - .into() | |
| 7367 | - }) | |
| 7368 | - }) | |
| 7369 | - .flex_none() | |
| 7370 | - .flex() | |
| 7371 | - .items_start() | |
| 7372 | - .gap(px(12.)) | |
| 7373 | - .px(px(12.)) | |
| 7374 | - .py(px(6.)) | |
| 7375 | - .bg(rgb(SURFACE)) | |
| 7376 | - .cursor_pointer() | |
| 7377 | - .hover(|s| s.bg(rgb(HOVER))) | |
| 7378 | - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 7379 | - // Another process starting: off the UI thread, and it | |
| 7380 | - // outlives the notice it was asked from. | |
| 7381 | - if let Some(path) = exported.clone() { | |
| 7382 | - cx.background_executor() | |
| 7383 | - .spawn(async move { show_in_file_manager(&path) }) | |
| 7384 | - .detach(); | |
| 7385 | - } | |
| 7386 | - this.notice = None; | |
| 7387 | - cx.notify(); | |
| 7388 | - })) | |
| 7389 | - .child(div().flex_1().min_w(px(0.)).child(notice)) | |
| 7390 | - .child( | |
| 7391 | - div() | |
| 7392 | - .flex_none() | |
| 7393 | - .text_size(px(11.)) | |
| 7394 | - .text_color(rgb(INK_DIM)) | |
| 7395 | - .child(hint), | |
| 7396 | - ), | |
| 7397 | - ) | |
| 5872 | +/// The path as a URI the bus will take: percent-encoded, because an export | |
| 5873 | +/// lands wherever its source lives and those directories have spaces in them. | |
| 5874 | +/// Bytes, not chars -- a path is not required to be UTF-8. | |
| 5875 | +fn file_uri(path: &std::path::Path) -> String { | |
| 5876 | + use std::os::unix::ffi::OsStrExt; | |
| 5877 | + let mut uri = String::from("file://"); | |
| 5878 | + for &b in path.as_os_str().as_bytes() { | |
| 5879 | + match b { | |
| 5880 | + b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' | b'/' => { | |
| 5881 | + uri.push(b as char) | |
| 5882 | + } | |
| 5883 | + _ => uri.push_str(&format!("%{b:02X}")), | |
| 5884 | + } | |
| 7398 | 5885 | } |
| 7399 | - | |
| 7400 | - /// Every binding, and the way to change one: a row per entry, click it and | |
| 7401 | - /// the next stroke becomes its chord. Over the whole window, because while | |
| 7402 | - /// it is up nothing under it may answer -- the scrim stops the clicks | |
| 7403 | - /// (gpui dispatches mouse listeners topmost-first, window.rs:3705) and the | |
| 7404 | - /// key handler's own branch stops the strokes. | |
| 7405 | - /// | |
| 7406 | - /// Plain divs, like every control here: nothing in it takes focus, so the | |
| 7407 | - /// root is still the one reading the keyboard -- which is exactly what a | |
| 7408 | - /// waiting row depends on. | |
| 7409 | - fn keys_overlay(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> { | |
| 7410 | - if !self.keys_open { | |
| 7411 | - return None; | |
| 7412 | - } | |
| 7413 | - // The way out, spelled the way the rows spell a chord. | |
| 7414 | - let out = keymap::Chord { | |
| 7415 | - key: ESCAPE.to_string(), | |
| 7416 | - ctrl: false, | |
| 7417 | - } | |
| 7418 | - .pretty(); | |
| 7419 | - // Every action there is, under its heading, and the strokes the modal | |
| 7420 | - // cards answer to beside them -- `keys_rows` is the whole of the order | |
| 7421 | - // and every word in it comes off the registry. | |
| 7422 | - // | |
| 7423 | - // A row is two targets, not one: its label *does* the action, which is | |
| 7424 | - // the pointer's way to the ones no button carries, and its stroke | |
| 7425 | - // changes that stroke. An action with two strokes reads as one line | |
| 7426 | - // ("x or delete") and a rebind replaces that whole set. | |
| 7427 | - let mut rows: Vec<AnyElement> = Vec::new(); | |
| 7428 | - let row = || { | |
| 7429 | - div() | |
| 7430 | - .flex() | |
| 7431 | - // The floor, not the height: a row that needed two lines | |
| 7432 | - // would otherwise paint over the one under it -- which it did | |
| 7433 | - // anyway until this said `flex_none`, a row inside a capped | |
| 7434 | - // scrolling list being shrunk to fit by default (the export | |
| 7435 | - // card's rows had the same shape and the same overlap). | |
| 7436 | - .flex_none() | |
| 7437 | - .min_h(px(KEYS_ROW_H)) | |
| 7438 | - .items_center() | |
| 7439 | - .justify_between() | |
| 7440 | - .gap(px(12.)) | |
| 7441 | - .px(px(6.)) | |
| 7442 | - .rounded(px(3.)) | |
| 7443 | - }; | |
| 7444 | - let found = keys_filter(&self.keys_search, &self.keymap); | |
| 7445 | - // What the search box says: the typed text, and how much of the list is | |
| 7446 | - // left under it -- a filter that found nothing has to say so, or the | |
| 7447 | - // card reads as a list that lost its rows. | |
| 7448 | - let search = if self.keys_search.is_empty() { | |
| 7449 | - "search: type to filter · ↑ ↓ scroll the list · a click away closes".to_string() | |
| 7450 | - } else { | |
| 7451 | - let rows = found | |
| 7452 | - .iter() | |
| 7453 | - .filter(|(_, r)| !matches!(r, KeyRow::Head(_))) | |
| 7454 | - .count(); | |
| 7455 | - match rows { | |
| 7456 | - 0 => format!( | |
| 7457 | - "search: {} — nothing matches · {out} clears", | |
| 7458 | - self.keys_search | |
| 7459 | - ), | |
| 7460 | - n => format!("search: {} — {n} shown · {out} clears", self.keys_search), | |
| 7461 | - } | |
| 7462 | - }; | |
| 7463 | - for (i, key_row) in found { | |
| 7464 | - rows.push(match key_row { | |
| 7465 | - KeyRow::Head(category) => div() | |
| 7466 | - .flex_none() | |
| 7467 | - .px(px(6.)) | |
| 7468 | - .pt(px(4.)) | |
| 7469 | - .text_size(px(11.)) | |
| 7470 | - .text_color(rgb(INK_DIM)) | |
| 7471 | - .child(category.label()) | |
| 7472 | - .into_any_element(), | |
| 7473 | - KeyRow::Act(action) => { | |
| 7474 | - let capturing = self.rebinding == Some(action); | |
| 7475 | - // Why the label half will not answer, if it will not: the | |
| 7476 | - // registry's one answer, the same the clip menu dims by. | |
| 7477 | - let refusal = self.enable(action, None); | |
| 7478 | - let out = out.clone(); | |
| 7479 | - row() | |
| 7480 | - .when(capturing, |d| d.bg(rgb(SELECTED))) | |
| 7481 | - .child( | |
| 7482 | - div() | |
| 7483 | - .id(("do", i)) | |
| 7484 | - .flex_1() | |
| 7485 | - .min_w(px(0.)) | |
| 7486 | - .flex() | |
| 7487 | - .min_h(px(KEYS_ROW_H)) | |
| 7488 | - .items_center() | |
| 7489 | - // One line, cut where the stroke's column | |
| 7490 | - // starts: a label longer than the room it has | |
| 7491 | - // printed straight over the stroke beside it, | |
| 7492 | - // and two overprinted words are less readable | |
| 7493 | - // than one truncated one. | |
| 7494 | - .truncate() | |
| 7495 | - .child(action.label()) | |
| 7496 | - // The reason rides on the label rather than in | |
| 7497 | - // the stroke column, which the rebind half | |
| 7498 | - // needs whatever the editor's state is: an | |
| 7499 | - // action nobody can ask for right now is still | |
| 7500 | - // one whose key may be changed. | |
| 7501 | - .when_some(refusal.why(), |d, why| { | |
| 7502 | - let why: SharedString = why.into(); | |
| 7503 | - d.tooltip(move |_, cx| cx.new(|_| Tip(why.clone())).into()) | |
| 7504 | - }) | |
| 7505 | - .when(!refusal.yes(), |d| d.opacity(0.4).cursor_not_allowed()) | |
| 7506 | - .when(refusal.yes(), |d| { | |
| 7507 | - d.cursor_pointer().hover(|s| s.bg(rgb(HOVER))).on_click( | |
| 7508 | - cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 7509 | - // The card goes first: several of | |
| 7510 | - // these open a card of their own, | |
| 7511 | - // and every edit moves the indices | |
| 7512 | - // the menus are holding. | |
| 7513 | - this.keys_open = false; | |
| 7514 | - this.rebinding = None; | |
| 7515 | - this.act(action, cx); | |
| 7516 | - cx.notify(); | |
| 7517 | - }), | |
| 7518 | - ) | |
| 7519 | - }), | |
| 7520 | - ) | |
| 7521 | - .child( | |
| 7522 | - // ponytail: the column is as wide as the stroke it | |
| 7523 | - // prints, so a one-character chord gives this half a | |
| 7524 | - // hit area under the 24px WCAG 2.5.8 floor -- tall | |
| 7525 | - // enough, narrow. Upgrade: a min_w of HIT_MIN here. | |
| 7526 | - div() | |
| 7527 | - .id(("bind", i)) | |
| 7528 | - .flex_none() | |
| 7529 | - .flex() | |
| 7530 | - .min_h(px(KEYS_ROW_H)) | |
| 7531 | - .items_center() | |
| 7532 | - .cursor_pointer() | |
| 7533 | - .hover(|s| s.bg(rgb(HOVER))) | |
| 7534 | - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 7535 | - this.rebinding = Some(action); | |
| 7536 | - cx.notify(); | |
| 7537 | - })) | |
| 7538 | - .child(if capturing { | |
| 7539 | - div() | |
| 7540 | - .text_color(rgb(INK_DIM)) | |
| 7541 | - .child(format!("press a key — {out} cancels")) | |
| 7542 | - } else { | |
| 7543 | - div().child(self.keymap.display(action)) | |
| 7544 | - }), | |
| 7545 | - ) | |
| 7546 | - .into_any_element() | |
| 7547 | - } | |
| 7548 | - KeyRow::Fixed(f) => { | |
| 7549 | - let f = &keymap::FIXED[f]; | |
| 7550 | - row() | |
| 7551 | - .child(f.label) | |
| 7552 | - // Dim, and no hover: this one is not a row you can click. | |
| 7553 | - .child(div().text_color(rgb(INK_DIM)).child(f.chord.clone())) | |
| 7554 | - .into_any_element() | |
| 7555 | - } | |
| 7556 | - }); | |
| 7557 | - } | |
| 7558 | - Some( | |
| 7559 | - scrim() | |
| 7560 | - .flex() | |
| 7561 | - .justify_center() | |
| 7562 | - .items_center() | |
| 7563 | - // The picture behind is out of reach, and looks it. The press is | |
| 7564 | - // swallowed here so a button under the scrim cannot take it -- | |
| 7565 | - // and it closes the card on the way, which is the pointer's exit | |
| 7566 | - // from every card here ([`Player::close_card`]). | |
| 7567 | - .bg(rgba(0x101010cc)) | |
| 7568 | - .on_mouse_down( | |
| 7569 | - MouseButton::Left, | |
| 7570 | - cx.listener(|this, _: &MouseDownEvent, _, cx| { | |
| 7571 | - this.close_card(); | |
| 7572 | - cx.notify(); | |
| 7573 | - cx.stop_propagation(); | |
| 7574 | - }), | |
| 7575 | - ) | |
| 7576 | - .child( | |
| 7577 | - div() | |
| 7578 | - .w(px(KEYS_W)) | |
| 7579 | - .on_mouse_down(MouseButton::Left, swallow) | |
| 7580 | - .flex() | |
| 7581 | - .flex_col() | |
| 7582 | - .gap(px(2.)) | |
| 7583 | - .p(px(12.)) | |
| 7584 | - .rounded(px(6.)) | |
| 7585 | - .bg(rgb(SURFACE)) | |
| 7586 | - // Title and instruction are two children, never one | |
| 7587 | - // wrapping line: a fixed-height slot whose text wrapped | |
| 7588 | - // painted its second line over the first row. | |
| 7589 | - .child(div().flex_none().px(px(6.)).child("Actions & keys")) | |
| 7590 | - // One status line, under the title where the eye starts. | |
| 7591 | - // A refusal takes it over -- it is the more urgent of the | |
| 7592 | - // two, and the notice bar it would otherwise appear in is | |
| 7593 | - // under the scrim. | |
| 7594 | - // | |
| 7595 | - // The row list below is capped and scrolls, so neither a | |
| 7596 | - // wrapped refusal here nor another action added to `ALL` | |
| 7597 | - // can push the card past a 360 px window any more. | |
| 7598 | - .child( | |
| 7599 | - div() | |
| 7600 | - .flex_none() | |
| 7601 | - .px(px(6.)) | |
| 7602 | - .text_size(px(11.)) | |
| 7603 | - .text_color(rgb(INK_DIM)) | |
| 7604 | - .child( | |
| 7605 | - self.notice | |
| 7606 | - .clone() | |
| 7607 | - .unwrap_or_else(|| { | |
| 7608 | - "click an action to do it · click its key to change it" | |
| 7609 | - .into() | |
| 7610 | - }), | |
| 7611 | - ), | |
| 7612 | - ) | |
| 7613 | - // The search box: no focus and no text field -- the | |
| 7614 | - // card's key handler is the field, exactly as the | |
| 7615 | - // export card's bitrate is typed into it. Its own line | |
| 7616 | - // above the list, so the rows below it are always the | |
| 7617 | - // answer to what it says. | |
| 7618 | - .child( | |
| 7619 | - div() | |
| 7620 | - .flex_none() | |
| 7621 | - .px(px(6.)) | |
| 7622 | - .text_size(px(11.)) | |
| 7623 | - .text_color(rgb(INK_DIM)) | |
| 7624 | - .child(search), | |
| 7625 | - ) | |
| 7626 | - // Capped and scrolling rather than as tall as the action | |
| 7627 | - // list happens to be: the list grows with the editor, | |
| 7628 | - // the smallest window does not. | |
| 7629 | - .child( | |
| 7630 | - div() | |
| 7631 | - .id("keys-rows") | |
| 7632 | - .flex() | |
| 7633 | - .flex_col() | |
| 7634 | - .gap(px(2.)) | |
| 7635 | - .max_h(px(KEYS_ROWS_H)) | |
| 7636 | - // The line the list scrolls under: a row half | |
| 7637 | - // out of the viewport sat against the search | |
| 7638 | - // line with nothing between them, and read as a | |
| 7639 | - // row painted over the heading rather than as a | |
| 7640 | - // list with more above it. | |
| 7641 | - .mt(px(4.)) | |
| 7642 | - .border_t_1() | |
| 7643 | - .border_color(rgb(CHROME)) | |
| 7644 | - .pt(px(4.)) | |
| 7645 | - .overflow_y_scroll() | |
| 7646 | - // The wheel's offset and the arrow keys' are | |
| 7647 | - // the same one, so the two cannot disagree | |
| 7648 | - // about where the list is. | |
| 7649 | - .track_scroll(&self.keys_scroll) | |
| 7650 | - .children(rows), | |
| 7651 | - ), | |
| 7652 | - ), | |
| 7653 | - ) | |
| 7654 | - } | |
| 7655 | - | |
| 7656 | - /// What an export is going to be, before there is one: the codec, the box | |
| 7657 | - /// it goes into, the bitrate, where it lands -- and, above the button, the | |
| 7658 | - /// two lines that state the file all of that adds up to. The same scrim and | |
| 7659 | - /// row shape as the keybindings overlay (two cards of different builds over | |
| 7660 | - /// one window read as two different programs) and the same plain divs, so | |
| 7661 | - /// the root keeps the keyboard and the custom row's field is typed into | |
| 7662 | - /// through it ([`NumberEdit`]). | |
| 7663 | - /// |
crates/app/src/ui/cards.rsadded+1657 -0
| @@ -0,0 +1,1657 @@ | ||
| 1 | +//! The property cards -- docked into the inspector, or floated when modal. | |
| 2 | + | |
| 3 | +use crate::*; | |
| 4 | +use crate::ui::widgets::*; | |
| 5 | + | |
| 6 | +impl Player { | |
| 7 | + /// What an export is going to be, before there is one: the codec, the box | |
| 8 | + /// it goes into, the bitrate, where it lands -- and, above the button, the | |
| 9 | + /// two lines that state the file all of that adds up to. The same scrim and | |
| 10 | + /// row shape as the keybindings overlay (two cards of different builds over | |
| 11 | + /// one window read as two different programs) and the same plain divs, so | |
| 12 | + /// the root keeps the keyboard and the custom row's field is typed into | |
| 13 | + /// through it ([`NumberEdit`]). | |
| 14 | + /// | |
| 15 | + /// Every row carries the key that picks it, so the card is drivable end to | |
| 16 | + /// end without a pointer *and* without a legend to memorise -- and every | |
| 17 | + /// row is clickable, the bitrate's steppers included, so it is drivable end | |
| 18 | + /// to end without a keyboard as well. | |
| 19 | + /// | |
| 20 | + /// Two shapes of it, behind `g` and `r`: sections against one flat list, | |
| 21 | + /// and the codecs with no encoder collapsed into a footer against a dimmed | |
| 22 | + /// row each. Grouped and collapsed is what opens. | |
| 23 | + pub(crate) fn export_card( | |
| 24 | + &self, | |
| 25 | + viewport: Size<Pixels>, | |
| 26 | + cx: &mut Context<Self>, | |
| 27 | + ) -> Option<impl IntoElement> { | |
| 28 | + if !self.export_open { | |
| 29 | + return None; | |
| 30 | + } | |
| 31 | + // The cap is what keeps the card inside the smallest window; a taller | |
| 32 | + // one gets a taller list rather than a scroll past empty space, and the | |
| 33 | + // card is still only as tall as the rows it has. | |
| 34 | + let rows_h = (f32::from(viewport.height) - EXPORT_FIXED_H - 24.).max(EXPORT_ROWS_H); | |
| 35 | + let row = |id: (&'static str, usize)| { | |
| 36 | + div() | |
| 37 | + .id(id) | |
| 38 | + .flex() | |
| 39 | + // The floor, not the height: the destination's path wraps on a | |
| 40 | + // long name and must not paint over the row under it. Which it | |
| 41 | + // did: inside a capped, scrolling list a row shrinks to fit by | |
| 42 | + // default, so a wrapped detail was drawn over the row beneath | |
| 43 | + // it (the Sound row's "the source's own packets are copied…" | |
| 44 | + // over Subtitles). The list scrolls -- a row is as tall as what | |
| 45 | + // it has to say. | |
| 46 | + .flex_none() | |
| 47 | + .min_h(px(KEYS_ROW_H)) | |
| 48 | + .items_center() | |
| 49 | + .justify_between() | |
| 50 | + .gap(px(12.)) | |
| 51 | + .px(px(6.)) | |
| 52 | + .rounded(px(3.)) | |
| 53 | + }; | |
| 54 | + // A row that cannot be picked is dimmed and takes no click, exactly as | |
| 55 | + // an inapplicable item in the clip menu is: it still says its piece. | |
| 56 | + let live = |d: Stateful<Div>, enabled: bool| { | |
| 57 | + d.when(!enabled, |d| { | |
| 58 | + d.cursor_not_allowed().text_color(rgb(FG_SECONDARY)) | |
| 59 | + }) | |
| 60 | + .when(enabled, |d| d.cursor_pointer().hover(|s| s.bg(rgb(BG_HOVER)))) | |
| 61 | + }; | |
| 62 | + // A row as this card writes them: the mark saying which one is picked, | |
| 63 | + // the key that picks it, its name, and what the choice means. The mark | |
| 64 | + // is a glyph and not only a colour -- a background alone is gone the | |
| 65 | + // moment a hover lands on the row, and invisible to anyone who cannot | |
| 66 | + // tell the two greys apart (WCAG 1.4.1). | |
| 67 | + let entry = |id: (&'static str, usize), | |
| 68 | + key: &str, | |
| 69 | + label: SharedString, | |
| 70 | + detail: SharedString, | |
| 71 | + picked: bool, | |
| 72 | + enabled: bool| { | |
| 73 | + // The small print of a picked row sits on the highlight, where the | |
| 74 | + // dim ink is only 3.3:1 -- the row it lands on lifts it (WCAG | |
| 75 | + // 1.4.3, and the fit test pins both numbers). | |
| 76 | + let ink = match picked { | |
| 77 | + true => FG_PRIMARY, | |
| 78 | + false => FG_SECONDARY, | |
| 79 | + }; | |
| 80 | + live(row(id), enabled) | |
| 81 | + .when(picked, |d| d.bg(rgb(BG_SELECTED))) | |
| 82 | + .child( | |
| 83 | + div() | |
| 84 | + .flex() | |
| 85 | + .flex_none() | |
| 86 | + .items_center() | |
| 87 | + .gap(px(8.)) | |
| 88 | + .child(div().w(px(10.)).child(match picked { | |
| 89 | + true => "✓", | |
| 90 | + false => " ", | |
| 91 | + })) | |
| 92 | + .child( | |
| 93 | + div() | |
| 94 | + .w(px(EXPORT_KEY_W)) | |
| 95 | + .text_size(px(11.)) | |
| 96 | + .text_color(rgb(ink)) | |
| 97 | + .child(SharedString::from(key.to_string())), | |
| 98 | + ) | |
| 99 | + .child(label), | |
| 100 | + ) | |
| 101 | + // Wraps rather than runs off the row: a refusal is the longest | |
| 102 | + // thing in this column and the half of it past the edge is the | |
| 103 | + // half that says what to do instead. | |
| 104 | + .child( | |
| 105 | + div() | |
| 106 | + .min_w(px(0.)) | |
| 107 | + .flex_shrink() | |
| 108 | + .text_size(px(11.)) | |
| 109 | + .text_color(rgb(ink)) | |
| 110 | + .child(detail), | |
| 111 | + ) | |
| 112 | + }; | |
| 113 | + let header = |text: &'static str| { | |
| 114 | + div() | |
| 115 | + .flex_none() | |
| 116 | + .px(px(6.)) | |
| 117 | + .pt(px(4.)) | |
| 118 | + .text_size(px(10.)) | |
| 119 | + .text_color(rgb(FG_SECONDARY)) | |
| 120 | + .child(text) | |
| 121 | + .into_any_element() | |
| 122 | + }; | |
| 123 | + let mut list: Vec<AnyElement> = Vec::new(); | |
| 124 | + if self.export_grouped { | |
| 125 | + list.push(header("FORMAT")); | |
| 126 | + } | |
| 127 | + // The codecs first: which one is being written decides whether every | |
| 128 | + // row under it means anything. One a *this* timeline cannot be written | |
| 129 | + // as (an audio-only edit, for a picture codec) reads exactly like one | |
| 130 | + // there is no encoder for -- dimmed, unclickable, and carrying its own | |
| 131 | + // reason where its detail was, with nothing to click to find that out. | |
| 132 | + let mut refusals: Vec<String> = Vec::new(); | |
| 133 | + for (i, (boxes, key, label, detail)) in FORMATS.into_iter().enumerate() { | |
| 134 | + let format = same_box(boxes, self.format); | |
| 135 | + let refused = format | |
| 136 | + .zip(self.session.as_ref()) | |
| 137 | + .and_then(|(f, s)| format_refusal(s, f)); | |
| 138 | + // A codec with no encoder here at all is the other kind of refusal, | |
| 139 | + // and the one the footer collects: it can never become pickable, so | |
| 140 | + // a row each is dead rows above the fold. | |
| 141 | + if format.is_none() { | |
| 142 | + refusals.push(format!("{label} — {detail}")); | |
| 143 | + if !self.export_refusals_inline { | |
| 144 | + continue; | |
| 145 | + } | |
| 146 | + } | |
| 147 | + let detail: SharedString = match &refused { | |
| 148 | + Some(why) => why.clone().into(), | |
| 149 | + None => detail.into(), | |
| 150 | + }; | |
| 151 | + let format = format.filter(|_| refused.is_none()); | |
| 152 | + let mut r = entry( | |
| 153 | + ("format", i), | |
| 154 | + key, | |
| 155 | + label.into(), | |
| 156 | + detail, | |
| 157 | + boxes.contains(&self.format), | |
| 158 | + format.is_some(), | |
| 159 | + ); | |
| 160 | + if let Some(format) = format { | |
| 161 | + r = r.on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 162 | + this.set_format(format); | |
| 163 | + cx.notify(); | |
| 164 | + })); | |
| 165 | + } | |
| 166 | + list.push(r.into_any_element()); | |
| 167 | + } | |
| 168 | + if self.export_grouped { | |
| 169 | + list.push(header("DETAILS")); | |
| 170 | + } | |
| 171 | + // The container, and only where the picked codec has more than one box: | |
| 172 | + // a row offering a single choice reads as a choice. | |
| 173 | + let boxes = containers(self.format); | |
| 174 | + if boxes.len() > 1 { | |
| 175 | + let next = next_container(self.format); | |
| 176 | + list.push( | |
| 177 | + entry( | |
| 178 | + ("container", 0), | |
| 179 | + "c", | |
| 180 | + "Container".into(), | |
| 181 | + format!( | |
| 182 | + "{} — c for {}", | |
| 183 | + self.format.ext().to_uppercase(), | |
| 184 | + next.ext().to_uppercase() | |
| 185 | + ) | |
| 186 | + .into(), | |
| 187 | + false, | |
| 188 | + true, | |
| 189 | + ) | |
| 190 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 191 | + this.cycle_container(); | |
| 192 | + cx.notify(); | |
| 193 | + })) | |
| 194 | + .into_any_element(), | |
| 195 | + ); | |
| 196 | + } | |
| 197 | + match bitrate_refusal(self.format) { | |
| 198 | + // One dimmed row carrying the reason, rather than five rows of a | |
| 199 | + // figure that will not be written: the quality rows are the | |
| 200 | + // *picture's* bitrate, and this file has no picture in it. | |
| 201 | + Some(why) => list.push( | |
| 202 | + entry( | |
| 203 | + ("quality", 0), | |
| 204 | + "q", | |
| 205 | + "Quality".into(), | |
| 206 | + why.into(), | |
| 207 | + false, | |
| 208 | + false, | |
| 209 | + ) | |
| 210 | + .into_any_element(), | |
| 211 | + ), | |
| 212 | + None => { | |
| 213 | + for (i, quality) in Quality::ALL.into_iter().enumerate() { | |
| 214 | + // The custom row is a field: `n` opens it, a click in it | |
| 215 | + // opens it too, and while it is open the row shows what is | |
| 216 | + // being typed with a caret in it rather than the number in | |
| 217 | + // force. The other four are picked whole. | |
| 218 | + let field = self.mbps_edit.as_ref().filter(|_| quality == Quality::Custom); | |
| 219 | + let mut r = entry( | |
| 220 | + ("quality", i), | |
| 221 | + match quality { | |
| 222 | + Quality::Custom => "n", | |
| 223 | + _ => "q", | |
| 224 | + }, | |
| 225 | + quality.label().into(), | |
| 226 | + match field { | |
| 227 | + Some(edit) => edit.detail().into(), | |
| 228 | + None => quality.detail(self.custom_mbps).into(), | |
| 229 | + }, | |
| 230 | + self.quality == quality, | |
| 231 | + true, | |
| 232 | + ) | |
| 233 | + .on_click(cx.listener( | |
| 234 | + move |this, _: &ClickEvent, _, cx| { | |
| 235 | + match quality { | |
| 236 | + Quality::Custom => this.edit_mbps(), | |
| 237 | + _ => this.quality = quality, | |
| 238 | + } | |
| 239 | + cx.notify(); | |
| 240 | + }, | |
| 241 | + )); | |
| 242 | + if quality == Quality::Custom { | |
| 243 | + r = r.child(self.mbps_steppers(cx)); | |
| 244 | + } | |
| 245 | + list.push(r.into_any_element()); | |
| 246 | + } | |
| 247 | + } | |
| 248 | + } | |
| 249 | + // The other half of the file, and the one this card used to write at a | |
| 250 | + // fixed rate without saying so: what the *sound* is coded at, for every | |
| 251 | + // format that codes it -- the AAC inside a video export as much as an | |
| 252 | + // MP3. Four rates, so the pointer gets the *list* of them | |
| 253 | + // ([`Pick::AudioRate`]) rather than a button clicked round -- the | |
| 254 | + // resolution row's rule, and the key still steps as `ctrl+r` still | |
| 255 | + // does. Dimmed with the reason where this timeline has no rate to pick, | |
| 256 | + // like the quality rows are. | |
| 257 | + let sound = self.audio_rate_refusal(); | |
| 258 | + let mut r = entry( | |
| 259 | + ("sound", 0), | |
| 260 | + "b", | |
| 261 | + "Sound".into(), | |
| 262 | + match sound { | |
| 263 | + Some(why) => why.into(), | |
| 264 | + None => format!("{} kbps — b steps", self.audio_kbps).into(), | |
| 265 | + }, | |
| 266 | + false, | |
| 267 | + sound.is_none(), | |
| 268 | + ); | |
| 269 | + if sound.is_none() { | |
| 270 | + r = r.on_click(cx.listener(|this, event: &ClickEvent, _, cx| { | |
| 271 | + this.open_picker(Pick::AudioRate, event.position(), cx) | |
| 272 | + })); | |
| 273 | + } | |
| 274 | + list.push(r.into_any_element()); | |
| 275 | + // What happens to the subtitles on this timeline, in one line: how many | |
| 276 | + // are written into the file and under what names, or the reason each one | |
| 277 | + // is not. Which tracks travel is not a pick -- everything with a cue on | |
| 278 | + // the timeline goes ([`Player::export_subs`]) -- so the row says rather | |
| 279 | + // than offers, like the machine lines below. | |
| 280 | + // ...and the ones that do not travel are named here too, which they were | |
| 281 | + // not: `export_subs` had already filtered a track with no cue on *this* | |
| 282 | + // timeline out of the engine's sight, so the card said nothing about a | |
| 283 | + // row the list was still showing ([`subtitle_plan`]). | |
| 284 | + let plan = self.subtitle_line(); | |
| 285 | + // The row used to end in "click for <fmt> in MKV" whenever the picture | |
| 286 | + // was going into an mp4, on the grounds that only Matroska carries a | |
| 287 | + // text track. An mp4 carries one now (`Mp4Muxer::write_subtitles` writes | |
| 288 | + // `tx3g`), so that was a refusal offering a way out of nothing: the | |
| 289 | + // container the card is already set to embeds them. The refusals left in | |
| 290 | + // `planned_subtitles` are the true ones -- a sound-only format has | |
| 291 | + // nowhere to put a track, and a PGS track is pictures whatever the box. | |
| 292 | + list.push( | |
| 293 | + entry( | |
| 294 | + ("subtitles", 0), | |
| 295 | + "", | |
| 296 | + "Subtitles".into(), | |
| 297 | + plan.into(), | |
| 298 | + false, | |
| 299 | + false, | |
| 300 | + ) | |
| 301 | + .into_any_element(), | |
| 302 | + ); | |
| 303 | + let destination = entry( | |
| 304 | + ("destination", 0), | |
| 305 | + "d", | |
| 306 | + "Destination".into(), | |
| 307 | + file_name(&self.export_path).into(), | |
| 308 | + false, | |
| 309 | + true, | |
| 310 | + ) | |
| 311 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.pick_destination(cx))) | |
| 312 | + .into_any_element(); | |
| 313 | + // The card's own two layout switches. They were `g` and `r` and nothing | |
| 314 | + // else, while the status line under the title advertised both of them: | |
| 315 | + // a hand on the mouse read what they do and had nothing to press. | |
| 316 | + list.push( | |
| 317 | + entry( | |
| 318 | + ("export-layout", 0), | |
| 319 | + "g", | |
| 320 | + "Layout".into(), | |
| 321 | + match self.export_grouped { | |
| 322 | + true => "sections — g for one flat list".into(), | |
| 323 | + false => "one flat list — g for sections".into(), | |
| 324 | + }, | |
| 325 | + self.export_grouped, | |
| 326 | + true, | |
| 327 | + ) | |
| 328 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 329 | + this.export_grouped = !this.export_grouped; | |
| 330 | + cx.notify(); | |
| 331 | + })) | |
| 332 | + .into_any_element(), | |
| 333 | + ); | |
| 334 | + list.push( | |
| 335 | + entry( | |
| 336 | + ("export-refusals", 0), | |
| 337 | + "r", | |
| 338 | + "Codecs with no encoder".into(), | |
| 339 | + match self.export_refusals_inline { | |
| 340 | + true => "a dimmed row each — r collapses them".into(), | |
| 341 | + false => "one line at the foot — r shows a row each".into(), | |
| 342 | + }, | |
| 343 | + self.export_refusals_inline, | |
| 344 | + true, | |
| 345 | + ) | |
| 346 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 347 | + this.export_refusals_inline = !this.export_refusals_inline; | |
| 348 | + cx.notify(); | |
| 349 | + })) | |
| 350 | + .into_any_element(), | |
| 351 | + ); | |
| 352 | + match self.export_grouped { | |
| 353 | + true => list.push(destination), | |
| 354 | + // Flat: the same rows with no headers over them, and the | |
| 355 | + // destination back at the top where the card used to open with it. | |
| 356 | + false => list.insert(0, destination), | |
| 357 | + } | |
| 358 | + if !self.export_refusals_inline && !refusals.is_empty() { | |
| 359 | + // Last, and one line: the reason travels with the name (a footer | |
| 360 | + // that only listed them would be the "why not?" the rows exist to | |
| 361 | + // answer), but nothing here can ever be picked, so it sits under | |
| 362 | + // every row that can rather than above them. | |
| 363 | + list.push( | |
| 364 | + div() | |
| 365 | + .flex_none() | |
| 366 | + .px(px(6.)) | |
| 367 | + .py(px(2.)) | |
| 368 | + .text_size(px(11.)) | |
| 369 | + .text_color(rgb(FG_SECONDARY)) | |
| 370 | + .child(format!("cannot write: {}", refusals.join(" · "))) | |
| 371 | + .into_any_element(), | |
| 372 | + ); | |
| 373 | + } | |
| 374 | + // What is doing the work, on this machine and in this build: the GPU | |
| 375 | + // half is asked of the driver through the plugin (a different answer on | |
| 376 | + // every machine, and "none" where there is no plugin at all), the build | |
| 377 | + // half is the crates that were compiled in. Last in the list, because it | |
| 378 | + // is what a user checks rather than what they pick -- and a listing | |
| 379 | + // rather than rows, since none of it can be clicked. | |
| 380 | + if self.export_grouped { | |
| 381 | + list.push(header("THIS MACHINE")); | |
| 382 | + } | |
| 383 | + let note = |text: String| { | |
| 384 | + div() | |
| 385 | + .flex_none() | |
| 386 | + .px(px(6.)) | |
| 387 | + .py(px(2.)) | |
| 388 | + .text_size(px(11.)) | |
| 389 | + .text_color(rgb(FG_SECONDARY)) | |
| 390 | + .child(text) | |
| 391 | + .into_any_element() | |
| 392 | + }; | |
| 393 | + list.push(note(format!( | |
| 394 | + "GPU: {}", | |
| 395 | + self.hw_caps.clone().unwrap_or_else(|| "asking…".into()) | |
| 396 | + ))); | |
| 397 | + list.push(note(format!("Built in: {}", engine::caps::software()))); | |
| 398 | + // What the rows add up to, which is the one thing that has to be right: | |
| 399 | + // codec, box, size, rate, sound, where it goes and about how big. Two | |
| 400 | + // lines, outside the scrolling list, so it is on screen whatever the | |
| 401 | + // list is scrolled to and whatever is picked. | |
| 402 | + let picture = self | |
| 403 | + .session | |
| 404 | + .as_ref() | |
| 405 | + .map(|s| (s.resolution(), s.meta().frame_rate)); | |
| 406 | + let audio = self | |
| 407 | + .session | |
| 408 | + .as_ref() | |
| 409 | + .map_or("", |s| s.planned_audio(self.format)); | |
| 410 | + let settings = | |
| 411 | + export_settings(self.quality, self.custom_mbps, self.format, self.audio_kbps); | |
| 412 | + let size = estimated_bytes( | |
| 413 | + settings.bitrate.filter(|_| self.format.has_video()), | |
| 414 | + self.session | |
| 415 | + .as_ref() | |
| 416 | + .map_or(0., PlaybackSession::timeline_duration), | |
| 417 | + ); | |
| 418 | + let head = summary_head(self.format, picture, audio); | |
| 419 | + let tail = summary_tail( | |
| 420 | + &self.export_path, | |
| 421 | + size, | |
| 422 | + self.export_seat.as_ref().and_then(|(.., seat)| *seat), | |
| 423 | + self.format.has_video(), | |
| 424 | + ); | |
| 425 | + // The button says the refusal *before* it is pressed: the picked codec | |
| 426 | + // can go invalid one edit after it was picked (a cleared video lane), | |
| 427 | + // and a button that looks ready until it is pressed is the lie the | |
| 428 | + // dimmed rows above it are there to avoid. | |
| 429 | + let blocked = self | |
| 430 | + .session | |
| 431 | + .as_ref() | |
| 432 | + .and_then(|s| format_refusal(s, self.format)); | |
| 433 | + let action: SharedString = match &blocked { | |
| 434 | + Some(why) => { | |
| 435 | + format!("Cannot export — {}", why.split(" — ").next().unwrap_or(why)).into() | |
| 436 | + } | |
| 437 | + None => "Export".into(), | |
| 438 | + }; | |
| 439 | + Some( | |
| 440 | + scrim() | |
| 441 | + .flex() | |
| 442 | + .justify_center() | |
| 443 | + .items_center() | |
| 444 | + .bg(rgba(SCRIM)) | |
| 445 | + // Click away closes it, as on every card here. | |
| 446 | + .on_mouse_down( | |
| 447 | + MouseButton::Left, | |
| 448 | + cx.listener(|this, _: &MouseDownEvent, _, cx| { | |
| 449 | + this.close_card(); | |
| 450 | + cx.notify(); | |
| 451 | + cx.stop_propagation(); | |
| 452 | + }), | |
| 453 | + ) | |
| 454 | + .child( | |
| 455 | + div() | |
| 456 | + .w(px(EXPORT_W)) | |
| 457 | + .on_mouse_down(MouseButton::Left, swallow) | |
| 458 | + .flex() | |
| 459 | + .flex_col() | |
| 460 | + .gap(px(2.)) | |
| 461 | + .p(px(12.)) | |
| 462 | + .rounded(px(6.)) | |
| 463 | + .bg(rgb(BG_RAISED)) | |
| 464 | + .child(div().flex_none().px(px(6.)).child("Export")) | |
| 465 | + // The status line, where a refusal from the save dialog | |
| 466 | + // lands: the notice bar it would otherwise take is under | |
| 467 | + // the scrim. The keys are on the rows, so this says how | |
| 468 | + // the card as a whole is answered rather than listing | |
| 469 | + // them a second time. | |
| 470 | + .child( | |
| 471 | + div() | |
| 472 | + .flex_none() | |
| 473 | + .px(px(6.)) | |
| 474 | + .text_size(px(11.)) | |
| 475 | + .text_color(rgb(FG_SECONDARY)) | |
| 476 | + .child(match (&self.mbps_edit, &self.notice) { | |
| 477 | + // A field being typed into says so here as | |
| 478 | + // well as in its row: this line is outside | |
| 479 | + // the scrolling list and on screen at every | |
| 480 | + // window size, and at 360 px the custom row | |
| 481 | + // itself can be below the fold -- a number | |
| 482 | + // typed where it cannot be seen is the | |
| 483 | + // blind capture this field replaced. | |
| 484 | + (Some(edit), _) => { | |
| 485 | + SharedString::from(format!("Custom bitrate {}", edit.detail())) | |
| 486 | + } | |
| 487 | + (None, Some(notice)) => notice.clone(), | |
| 488 | + (None, None) => "the keys are on the rows · enter exports · \ | |
| 489 | + a click away or esc closes · g/r change the layout" | |
| 490 | + .into(), | |
| 491 | + }), | |
| 492 | + ) | |
| 493 | + // Capped and scrolling like the keybindings list: the | |
| 494 | + // rows are more than a 360 px window has room for, and | |
| 495 | + // it is the list that scrolls, never the card that | |
| 496 | + // grows -- the summary and the button below stay put. | |
| 497 | + .child( | |
| 498 | + div() | |
| 499 | + .id("export-rows") | |
| 500 | + .flex() | |
| 501 | + .flex_col() | |
| 502 | + .gap(px(2.)) | |
| 503 | + .max_h(px(rows_h)) | |
| 504 | + .overflow_y_scroll() | |
| 505 | + .children(list), | |
| 506 | + ) | |
| 507 | + .child(div().flex_none().px(px(6.)).text_size(px(11.)).child(head)) | |
| 508 | + .child( | |
| 509 | + div() | |
| 510 | + .flex_none() | |
| 511 | + .px(px(6.)) | |
| 512 | + .text_size(px(11.)) | |
| 513 | + .text_color(rgb(FG_SECONDARY)) | |
| 514 | + .child(tail), | |
| 515 | + ) | |
| 516 | + .child( | |
| 517 | + div() | |
| 518 | + .id("export-confirm") | |
| 519 | + .mt(px(4.)) | |
| 520 | + .flex() | |
| 521 | + .h(px(CONTROL_H)) | |
| 522 | + .items_center() | |
| 523 | + .justify_center() | |
| 524 | + .rounded(px(3.)) | |
| 525 | + .bg(rgb(match blocked.is_some() { | |
| 526 | + true => BG_PANEL, | |
| 527 | + false => BG_SELECTED, | |
| 528 | + })) | |
| 529 | + .cursor_pointer() | |
| 530 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 531 | + .on_click( | |
| 532 | + cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 533 | + this.start_export(cx) | |
| 534 | + }), | |
| 535 | + ) | |
| 536 | + .child(action), | |
| 537 | + ), | |
| 538 | + ), | |
| 539 | + ) | |
| 540 | + } | |
| 541 | + | |
| 542 | + /// The custom bitrate's two pointer buttons. The typed digits were the last | |
| 543 | + /// control in this card a mouse could not reach at all -- and a number that | |
| 544 | + /// can only be typed is a number a hand on the pointer has to leave the | |
| 545 | + /// card to change. `HIT_MIN` square, like every other target here. | |
| 546 | + pub(crate) fn mbps_steppers(&self, cx: &mut Context<Self>) -> impl IntoElement { | |
| 547 | + let step = |id: &'static str, label: &'static str, by: i32, cx: &mut Context<Self>| { | |
| 548 | + div() | |
| 549 | + .id(id) | |
| 550 | + .flex() | |
| 551 | + .w(px(HIT_MIN)) | |
| 552 | + .h(px(HIT_MIN)) | |
| 553 | + .items_center() | |
| 554 | + .justify_center() | |
| 555 | + .rounded(px(3.)) | |
| 556 | + .bg(rgb(BG_PANEL)) | |
| 557 | + .cursor_pointer() | |
| 558 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 559 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 560 | + this.nudge_mbps(by); | |
| 561 | + cx.notify(); | |
| 562 | + })) | |
| 563 | + .child(label) | |
| 564 | + }; | |
| 565 | + div() | |
| 566 | + .flex() | |
| 567 | + .gap(px(4.)) | |
| 568 | + .child(step("mbps-down", "−", -1, cx)) | |
| 569 | + .child(step("mbps-up", "+", 1, cx)) | |
| 570 | + } | |
| 571 | + | |
| 572 | + /// The equalizer of one audio clip: its frequency response drawn as a | |
| 573 | + /// curve, a handle per band sitting on it, each band's own bell under the | |
| 574 | + /// sum, and a row that reads and moves the picked band's three numbers. The | |
| 575 | + /// curve is the clip's actual filter (`EqParams::response_db` reads the | |
| 576 | + /// coefficients the samples go through), and it is redrawn on every pointer | |
| 577 | + /// sample of a drag, so the shape bends under the hand. | |
| 578 | + /// | |
| 579 | + /// Wider than the other cards and wider still on a bigger window | |
| 580 | + /// ([`eq_card_w`]): every pixel across is frequency resolution, which none | |
| 581 | + /// of the row-shaped cards have any use for. The same scrim and the same | |
| 582 | + /// plain divs -- nothing here takes focus, so the root keeps the keyboard | |
| 583 | + /// and the card's own strokes (a digit, the arrows, `a`, `x`, `f`, `r`, | |
| 584 | + /// `s`) reach it. | |
| 585 | + /// | |
| 586 | + /// Every change is written at the clip as it is made | |
| 587 | + /// ([`Player::commit_eq`]), so what the card shows is always what is | |
| 588 | + /// playing: there is no OK button to forget, and closing it changes | |
| 589 | + /// nothing. What takes a curve back off is undo, like every other edit. | |
| 590 | + pub(crate) fn eq_card( | |
| 591 | + &self, | |
| 592 | + viewport: Size<Pixels>, | |
| 593 | + cx: &mut Context<Self>, | |
| 594 | + ) -> Option<impl IntoElement> { | |
| 595 | + let (lane, idx) = self.eq_open?; | |
| 596 | + // The rate the engine filters this timeline at, so the drawn curve is | |
| 597 | + // the one those coefficients make -- near the top of the axis a 44.1 kHz | |
| 598 | + // clip and a 48 kHz one are not the same shape. | |
| 599 | + let sample_rate = self.timeline_audio().map_or(48_000, |(rate, _)| rate); | |
| 600 | + let picked = self.eq_params.bands.get(self.eq_band); | |
| 601 | + // What is playing, drawn behind the curve -- and only while something | |
| 602 | + // *is* playing: the tap freezes with the device, and a still spectrum | |
| 603 | + // under a paused timeline would look like sound that is not there. | |
| 604 | + let spectrum = self | |
| 605 | + .eq_spectrum | |
| 606 | + .then_some(self.session.as_ref()) | |
| 607 | + .flatten() | |
| 608 | + .filter(|session| session.is_playing()) | |
| 609 | + .and_then(PlaybackSession::audio_tap) | |
| 610 | + .map(|(samples, rate)| eq_spectrum(&samples, rate)) | |
| 611 | + .filter(|levels| !levels.is_empty()) | |
| 612 | + .map(eq_spectrum_curve); | |
| 613 | + let handles: Vec<_> = self | |
| 614 | + .eq_params | |
| 615 | + .bands | |
| 616 | + .iter() | |
| 617 | + .enumerate() | |
| 618 | + .map(|(i, band)| { | |
| 619 | + div() | |
| 620 | + .absolute() | |
| 621 | + .left(relative(eq_x(band.freq_hz))) | |
| 622 | + .top(relative(eq_y(band.gain_db))) | |
| 623 | + // Centred on its own point: it hangs off the graph's corner, | |
| 624 | + // so it is pulled back by half of itself both ways. | |
| 625 | + .ml(px(-EQ_HANDLE / 2.)) | |
| 626 | + .mt(px(-EQ_HANDLE / 2.)) | |
| 627 | + .w(px(EQ_HANDLE)) | |
| 628 | + .h(px(EQ_HANDLE)) | |
| 629 | + .rounded(px(EQ_HANDLE / 2.)) | |
| 630 | + .bg(rgb(match i == self.eq_band { | |
| 631 | + true => ACCENT_PRIMARY, | |
| 632 | + false => FG_SECONDARY, | |
| 633 | + })) | |
| 634 | + }) | |
| 635 | + .collect(); | |
| 636 | + let graph = div() | |
| 637 | + // Ided like the band rows it replaces: what the pointer presses on | |
| 638 | + // is one element with its own hitbox, which is what a drag is | |
| 639 | + // tracked from. | |
| 640 | + .id("eq-graph") | |
| 641 | + .relative() | |
| 642 | + .flex_none() | |
| 643 | + .h(px(EQ_GRAPH_H)) | |
| 644 | + .rounded(px(3.)) | |
| 645 | + .bg(rgb(BG_HOVER_DIM)) | |
| 646 | + .cursor_pointer() | |
| 647 | + // The press picks the band under it *and* is already the first | |
| 648 | + // sample of the drag, so a plain click sets a value. A second click | |
| 649 | + // takes that band back to flat instead: the gesture that undoes one | |
| 650 | + // handle, with no modifier to remember. | |
| 651 | + .on_mouse_down( | |
| 652 | + MouseButton::Left, | |
| 653 | + cx.listener(|this, event: &MouseDownEvent, _, cx| { | |
| 654 | + this.eq_band = this.nearest_band(event.position.x); | |
| 655 | + if event.click_count >= 2 { | |
| 656 | + this.eq_dragging = false; | |
| 657 | + this.nudge_band(|b| b.gain_db = 0., cx); | |
| 658 | + return; | |
| 659 | + } | |
| 660 | + this.eq_dragging = true; | |
| 661 | + this.drag_band(event.position, cx); | |
| 662 | + }), | |
| 663 | + ) | |
| 664 | + .child(bounds_probe(self.eq_graph.clone())) | |
| 665 | + // The analyser first, so everything else is drawn on top of it. | |
| 666 | + .children(spectrum) | |
| 667 | + // The decades, so a hump can be read as "around 200 Hz" without | |
| 668 | + // dropping the eye to the labels along the bottom. The two ends | |
| 669 | + // are the box's own edges and rule nothing. | |
| 670 | + .children( | |
| 671 | + EQ_TICKS | |
| 672 | + .iter() | |
| 673 | + .filter(|(freq, _)| *freq > EQ_FREQ_LOW && *freq < EQ_FREQ_HIGH) | |
| 674 | + .map(|(freq, _)| { | |
| 675 | + div() | |
| 676 | + .absolute() | |
| 677 | + .left(relative(eq_x(*freq))) | |
| 678 | + .w(px(1.)) | |
| 679 | + .h_full() | |
| 680 | + .bg(rgb(EQ_GRID)) | |
| 681 | + }) | |
| 682 | + .collect::<Vec<_>>(), | |
| 683 | + ) | |
| 684 | + // Half way to each limit, each carrying its own number: the curve | |
| 685 | + // is a curve of decibels, and until now only one of them was drawn. | |
| 686 | + .children(EQ_DB_GRID.map(|db| { | |
| 687 | + div() | |
| 688 | + .absolute() | |
| 689 | + .top(relative(eq_y(db))) | |
| 690 | + .w_full() | |
| 691 | + .h(px(1.)) | |
| 692 | + .bg(rgb(EQ_GRID)) | |
| 693 | + .child( | |
| 694 | + div() | |
| 695 | + .absolute() | |
| 696 | + .left(px(4.)) | |
| 697 | + .top(px(-11.)) | |
| 698 | + .text_size(px(9.)) | |
| 699 | + .text_color(rgb(FG_SECONDARY)) | |
| 700 | + .child(format!("{db:+.0}")), | |
| 701 | + ) | |
| 702 | + })) | |
| 703 | + // 0 dB: the line a boost is a boost *from*. | |
| 704 | + .child( | |
| 705 | + div() | |
| 706 | + .absolute() | |
| 707 | + .top(relative(0.5)) | |
| 708 | + .w_full() | |
| 709 | + .h(px(1.)) | |
| 710 | + .bg(rgb(BG_HOVER)), | |
| 711 | + ) | |
| 712 | + .child(eq_curve(self.eq_params.clone(), sample_rate)) | |
| 713 | + .children(handles) | |
| 714 | + .children(EQ_TICKS.map(|(freq, label)| { | |
| 715 | + div() | |
| 716 | + .absolute() | |
| 717 | + .left(relative(eq_x(freq))) | |
| 718 | + // Pulled back so the mark reads as sitting *at* its | |
| 719 | + // frequency; the two ends then hug the corners. | |
| 720 | + .ml(px(-12.)) | |
| 721 | + .bottom(px(1.)) | |
| 722 | + .w(px(24.)) | |
| 723 | + .text_align(TextAlign::Center) | |
| 724 | + .text_size(px(9.)) | |
| 725 | + .text_color(rgb(FG_SECONDARY)) | |
| 726 | + .child(label) | |
| 727 | + })) | |
| 728 | + .child( | |
| 729 | + div() | |
| 730 | + .absolute() | |
| 731 | + .top(px(2.)) | |
| 732 | + .left(px(4.)) | |
| 733 | + .text_size(px(9.)) | |
| 734 | + .text_color(rgb(FG_SECONDARY)) | |
| 735 | + .child(format!("+{EQ_GAIN_LIMIT:.0} dB")), | |
| 736 | + ); | |
| 737 | + // The bottom of the axis is not named: -12 dB would land in the same | |
| 738 | + // corner as the 20 Hz tick, and the two lines above it (+6 and -6) | |
| 739 | + // already say what the box is worth per pixel. | |
| 740 | + Some( | |
| 741 | + scrim() | |
| 742 | + .flex() | |
| 743 | + .justify_center() | |
| 744 | + .items_center() | |
| 745 | + .bg(rgba(SCRIM)) | |
| 746 | + // Click away closes it, as on every card here. | |
| 747 | + .on_mouse_down( | |
| 748 | + MouseButton::Left, | |
| 749 | + cx.listener(|this, _: &MouseDownEvent, _, cx| { | |
| 750 | + this.close_card(); | |
| 751 | + cx.notify(); | |
| 752 | + cx.stop_propagation(); | |
| 753 | + }), | |
| 754 | + ) | |
| 755 | + .child( | |
| 756 | + div() | |
| 757 | + .w(px(eq_card_w(f32::from(viewport.width)))) | |
| 758 | + .on_mouse_down(MouseButton::Left, swallow) | |
| 759 | + .flex() | |
| 760 | + .flex_col() | |
| 761 | + .gap(px(2.)) | |
| 762 | + .p(px(12.)) | |
| 763 | + .rounded(px(6.)) | |
| 764 | + .bg(rgb(BG_RAISED)) | |
| 765 | + // Which clip, because the card is modal and the lane it | |
| 766 | + // was opened from is behind a scrim by the time it is up. | |
| 767 | + .child(div().flex_none().px(px(6.)).child(format!( | |
| 768 | + "Equalizer — {} clip {}", | |
| 769 | + lane.label(), | |
| 770 | + idx + 1 | |
| 771 | + ))) | |
| 772 | + .child( | |
| 773 | + div() | |
| 774 | + .flex_none() | |
| 775 | + .px(px(6.)) | |
| 776 | + .text_size(px(11.)) | |
| 777 | + .text_color(rgb(FG_SECONDARY)) | |
| 778 | + .child(self.notice.clone().unwrap_or_else(|| { | |
| 779 | + "drag a handle, or a digit picks a band — ←→ moves it, ↑↓ its gain, shift+←→ its width; a adds, x removes, f flattens it, r all, s spectrum; a click away or esc closes".into() | |
| 780 | + })), | |
| 781 | + ) | |
| 782 | + .child(graph) | |
| 783 | + // Which band the keyboard is holding and every number it | |
| 784 | + // is set to, each with the pair of buttons that moves it: | |
| 785 | + // the curve shows the sum, and a band pushed against one | |
| 786 | + // pulling the other way is not readable off it. | |
| 787 | + .child(self.eq_numbers(picked, cx)) | |
| 788 | + .child( | |
| 789 | + div() | |
| 790 | + .mt(px(4.)) | |
| 791 | + .flex() | |
| 792 | + .gap(px(4.)) | |
| 793 | + .child( | |
| 794 | + div() | |
| 795 | + .id("eq-reset") | |
| 796 | + .flex() | |
| 797 | + .flex_1() | |
| 798 | + .h(px(CONTROL_H)) | |
| 799 | + .items_center() | |
| 800 | + .justify_center() | |
| 801 | + .rounded(px(3.)) | |
| 802 | + .bg(rgb(BG_SELECTED)) | |
| 803 | + .cursor_pointer() | |
| 804 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 805 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 806 | + for band in &mut this.eq_params.bands { | |
| 807 | + band.gain_db = 0.; | |
| 808 | + } | |
| 809 | + this.commit_eq(cx); | |
| 810 | + })) | |
| 811 | + .child("Flatten all"), | |
| 812 | + ) | |
| 813 | + // The two that change how many bands there are. | |
| 814 | + // The engine takes any cascade -- the count was | |
| 815 | + // only ever fixed because this card had no way | |
| 816 | + // to say otherwise. | |
| 817 | + .child( | |
| 818 | + div() | |
| 819 | + .id("eq-add") | |
| 820 | + .flex() | |
| 821 | + .flex_1() | |
| 822 | + .h(px(CONTROL_H)) | |
| 823 | + .items_center() | |
| 824 | + .justify_center() | |
| 825 | + .rounded(px(3.)) | |
| 826 | + .bg(rgb(BG_PANEL)) | |
| 827 | + .cursor_pointer() | |
| 828 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 829 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 830 | + this.add_band(cx) | |
| 831 | + })) | |
| 832 | + .child("Add band"), | |
| 833 | + ) | |
| 834 | + .child( | |
| 835 | + div() | |
| 836 | + .id("eq-remove") | |
| 837 | + .flex() | |
| 838 | + .flex_1() | |
| 839 | + .h(px(CONTROL_H)) | |
| 840 | + .items_center() | |
| 841 | + .justify_center() | |
| 842 | + .rounded(px(3.)) | |
| 843 | + .bg(rgb(BG_PANEL)) | |
| 844 | + .cursor_pointer() | |
| 845 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 846 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 847 | + this.remove_band(cx) | |
| 848 | + })) | |
| 849 | + .child("Remove band"), | |
| 850 | + ) | |
| 851 | + // The analyser's switch, next to the one other | |
| 852 | + // button the card has: `s` does the same, and a | |
| 853 | + // toggle only a keystroke can reach is one most | |
| 854 | + // people never find. | |
| 855 | + .child( | |
| 856 | + div() | |
| 857 | + .id("eq-spectrum") | |
| 858 | + .flex() | |
| 859 | + .flex_1() | |
| 860 | + .h(px(CONTROL_H)) | |
| 861 | + .items_center() | |
| 862 | + .justify_center() | |
| 863 | + .rounded(px(3.)) | |
| 864 | + .bg(rgb(match self.eq_spectrum { | |
| 865 | + true => BG_SELECTED, | |
| 866 | + false => BG_HOVER_DIM, | |
| 867 | + })) | |
| 868 | + .cursor_pointer() | |
| 869 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 870 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 871 | + this.eq_spectrum = !this.eq_spectrum; | |
| 872 | + cx.notify(); | |
| 873 | + })) | |
| 874 | + .child(match self.eq_spectrum { | |
| 875 | + true => "Spectrum on", | |
| 876 | + false => "Spectrum off", | |
| 877 | + }), | |
| 878 | + ), | |
| 879 | + ), | |
| 880 | + ), | |
| 881 | + ) | |
| 882 | + } | |
| 883 | + | |
| 884 | + /// The picked band's three numbers -- where it sits, how far it pushes and | |
| 885 | + /// how wide it is -- each beside the pair of buttons that moves it. The | |
| 886 | + /// arrows do the same three things, but a value only a key can change is a | |
| 887 | + /// value a hand on the pointer cannot reach at all, which is the same reason | |
| 888 | + /// [`Player::mbps_steppers`] exists. | |
| 889 | + pub(crate) fn eq_numbers(&self, picked: Option<&Band>, cx: &mut Context<Self>) -> impl IntoElement { | |
| 890 | + let row = div() | |
| 891 | + .flex_none() | |
| 892 | + .flex() | |
| 893 | + .items_center() | |
| 894 | + .gap(px(10.)) | |
| 895 | + .px(px(6.)) | |
| 896 | + .text_size(px(11.)); | |
| 897 | + let Some(band) = picked.copied() else { | |
| 898 | + return row.child("no bands — a adds one"); | |
| 899 | + }; | |
| 900 | + let step = |id: &'static str, | |
| 901 | + label: &'static str, | |
| 902 | + change: fn(&mut Band), | |
| 903 | + cx: &mut Context<Self>| { | |
| 904 | + div() | |
| 905 | + .id(id) | |
| 906 | + .flex() | |
| 907 | + .w(px(HIT_MIN)) | |
| 908 | + .h(px(HIT_MIN)) | |
| 909 | + .items_center() | |
| 910 | + .justify_center() | |
| 911 | + .rounded(px(3.)) | |
| 912 | + .bg(rgb(BG_PANEL)) | |
| 913 | + .cursor_pointer() | |
| 914 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 915 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 916 | + this.nudge_band(change, cx) | |
| 917 | + })) | |
| 918 | + .child(label) | |
| 919 | + }; | |
| 920 | + let number = |value: String, | |
| 921 | + ids: (&'static str, &'static str), | |
| 922 | + by: (fn(&mut Band), fn(&mut Band)), | |
| 923 | + cx: &mut Context<Self>| { | |
| 924 | + div() | |
| 925 | + .flex() | |
| 926 | + .items_center() | |
| 927 | + .gap(px(4.)) | |
| 928 | + .child(div().child(value)) | |
| 929 | + .child(step(ids.0, "−", by.0, cx)) | |
| 930 | + .child(step(ids.1, "+", by.1, cx)) | |
| 931 | + }; | |
| 932 | + row.child(format!( | |
| 933 | + "Band {} of {}", | |
| 934 | + self.eq_band + 1, | |
| 935 | + self.eq_params.bands.len() | |
| 936 | + )) | |
| 937 | + .child(number( | |
| 938 | + band_label(&band), | |
| 939 | + ("eq-freq-down", "eq-freq-up"), | |
| 940 | + ( | |
| 941 | + |b| b.freq_hz /= EQ_FREQ_STEP, | |
| 942 | + |b| b.freq_hz *= EQ_FREQ_STEP, | |
| 943 | + ), | |
| 944 | + cx, | |
| 945 | + )) | |
| 946 | + .child(number( | |
| 947 | + format!("{:+.1} dB", band.gain_db), | |
| 948 | + ("eq-gain-down", "eq-gain-up"), | |
| 949 | + (|b| b.gain_db -= EQ_STEP, |b| b.gain_db += EQ_STEP), | |
| 950 | + cx, | |
| 951 | + )) | |
| 952 | + // Q is width, so its buttons are labelled by what they *do* to the | |
| 953 | + // hump rather than by which way the number goes: a wider band is a | |
| 954 | + // smaller Q, and nobody should have to know that to use the card. | |
| 955 | + .child(number( | |
| 956 | + format!("Q {:.2}", band.q), | |
| 957 | + ("eq-q-wider", "eq-q-narrower"), | |
| 958 | + (|b| b.q /= EQ_Q_STEP, |b| b.q *= EQ_Q_STEP), | |
| 959 | + cx, | |
| 960 | + )) | |
| 961 | + .child( | |
| 962 | + div() | |
| 963 | + .id("eq-flat-band") | |
| 964 | + .flex() | |
| 965 | + .h(px(HIT_MIN)) | |
| 966 | + .px(px(8.)) | |
| 967 | + .items_center() | |
| 968 | + .rounded(px(3.)) | |
| 969 | + .bg(rgb(BG_PANEL)) | |
| 970 | + .cursor_pointer() | |
| 971 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 972 | + .on_click( | |
| 973 | + cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 974 | + this.nudge_band(|b| b.gain_db = 0., cx) | |
| 975 | + }), | |
| 976 | + ) | |
| 977 | + .child("Flatten this"), | |
| 978 | + ) | |
| 979 | + } | |
| 980 | + | |
| 981 | + /// The colour card: the graded frame's histogram over a row per control, | |
| 982 | + /// each row a bar the pointer drags straight to a value -- no stepper | |
| 983 | + /// buttons, because a slider is a thing to pull, and the arrow keys still | |
| 984 | + /// move the same value for anyone not using a pointer. Same scrim, surface | |
| 985 | + /// and row shape as the other two cards, and the same plain divs, so the | |
| 986 | + /// root keeps the keyboard. | |
| 987 | + /// | |
| 988 | + /// The values are read from the project every render: what is drawn is what | |
| 989 | + /// the decoder is grading with, never a copy that could drift from it. The | |
| 990 | + /// graph above them is counted off the frame that came *back* through that | |
| 991 | + /// grade ([`histogram`]), so pulling exposure tilts it while the hand moves. | |
| 992 | + pub(crate) fn color_card(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> { | |
| 993 | + let (lane, idx) = self.color_open?; | |
| 994 | + let params = self.color_params(); | |
| 995 | + let rows: Vec<_> = COLOR_BANDS | |
| 996 | + .iter() | |
| 997 | + .enumerate() | |
| 998 | + .map(|(i, &(label, low, high))| { | |
| 999 | + let mut read = params; | |
| 1000 | + let value = *band_mut(&mut read, i); | |
| 1001 | + let frac = ((value - low) / (high - low)).clamp(0., 1.); | |
| 1002 | + let picked = i == self.color_band; | |
| 1003 | + div() | |
| 1004 | + .id(("color-row", i)) | |
| 1005 | + .flex() | |
| 1006 | + .min_h(px(KEYS_ROW_H)) | |
| 1007 | + .items_center() | |
| 1008 | + .gap(px(8.)) | |
| 1009 | + .px(px(6.)) | |
| 1010 | + .rounded(px(3.)) | |
| 1011 | + .cursor_pointer() | |
| 1012 | + .when(picked, |d| d.bg(rgb(BG_SELECTED))) | |
| 1013 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 1014 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 1015 | + this.color_band = i; | |
| 1016 | + cx.notify(); | |
| 1017 | + })) | |
| 1018 | + .child(div().flex_1().min_w(px(0.)).truncate().child(label)) | |
| 1019 | + .child( | |
| 1020 | + // The bar is 4 px to look at and a whole row to hit | |
| 1021 | + // (WCAG 2.5.8), the same split the ruler makes between | |
| 1022 | + // what is drawn and what is grabbed. The press is | |
| 1023 | + // already the first sample of the drag, so a plain click | |
| 1024 | + // sets the value it landed on. | |
| 1025 | + div() | |
| 1026 | + .id(("color-bar", i)) | |
| 1027 | + .relative() | |
| 1028 | + .w(px(COLOR_BAR_W)) | |
| 1029 | + .h(px(KEYS_ROW_H)) | |
| 1030 | + .flex() | |
| 1031 | + .items_center() | |
| 1032 | + .on_mouse_down( | |
| 1033 | + MouseButton::Left, | |
| 1034 | + cx.listener(move |this, event: &MouseDownEvent, _, cx| { | |
| 1035 | + this.color_band = i; | |
| 1036 | + this.color_dragging = true; | |
| 1037 | + this.drag_color(event.position.x, true, cx); | |
| 1038 | + }), | |
| 1039 | + ) | |
| 1040 | + .child(bounds_probe(self.color_bars[i].clone())) | |
| 1041 | + .child( | |
| 1042 | + div() | |
| 1043 | + .w_full() | |
| 1044 | + .h(px(4.)) | |
| 1045 | + .rounded(px(2.)) | |
| 1046 | + .bg(rgb(BG_PANEL)) | |
| 1047 | + .child( | |
| 1048 | + div() | |
| 1049 | + .h_full() | |
| 1050 | + .w(relative(frac)) | |
| 1051 | + .rounded(px(2.)) | |
| 1052 | + .bg(rgb(ACCENT_PRIMARY)), | |
| 1053 | + ), | |
| 1054 | + ), | |
| 1055 | + ) | |
| 1056 | + .child( | |
| 1057 | + div() | |
| 1058 | + .w(px(44.)) | |
| 1059 | + .text_size(px(11.)) | |
| 1060 | + .text_color(rgb(FG_SECONDARY)) | |
| 1061 | + .child(format!("{value:.2}")), | |
| 1062 | + ) | |
| 1063 | + }) | |
| 1064 | + .collect(); | |
| 1065 | + Some( | |
| 1066 | + scrim() | |
| 1067 | + .flex() | |
| 1068 | + .justify_center() | |
| 1069 | + .items_center() | |
| 1070 | + .bg(rgba(SCRIM)) | |
| 1071 | + // Click away closes it, as on every card here. | |
| 1072 | + .on_mouse_down( | |
| 1073 | + MouseButton::Left, | |
| 1074 | + cx.listener(|this, _: &MouseDownEvent, _, cx| { | |
| 1075 | + this.close_card(); | |
| 1076 | + cx.notify(); | |
| 1077 | + cx.stop_propagation(); | |
| 1078 | + }), | |
| 1079 | + ) | |
| 1080 | + .child( | |
| 1081 | + div() | |
| 1082 | + .w(px(COLOR_W)) | |
| 1083 | + .on_mouse_down(MouseButton::Left, swallow) | |
| 1084 | + .flex() | |
| 1085 | + .flex_col() | |
| 1086 | + .gap(px(2.)) | |
| 1087 | + .p(px(12.)) | |
| 1088 | + .rounded(px(6.)) | |
| 1089 | + .bg(rgb(BG_RAISED)) | |
| 1090 | + .child(div().flex_none().px(px(6.)).child(format!( | |
| 1091 | + "Colour — {} clip {}", | |
| 1092 | + lane.label(), | |
| 1093 | + idx + 1 | |
| 1094 | + ))) | |
| 1095 | + .child( | |
| 1096 | + div() | |
| 1097 | + .flex_none() | |
| 1098 | + .px(px(6.)) | |
| 1099 | + .text_size(px(11.)) | |
| 1100 | + .text_color(rgb(FG_SECONDARY)) | |
| 1101 | + .child( | |
| 1102 | + "drag a bar, or ↑↓ picks one and ←→ moves it, r resets — a click away or esc closes", | |
| 1103 | + ), | |
| 1104 | + ) | |
| 1105 | + // The frame as it is being graded, over the controls | |
| 1106 | + // grading it: the three lines are what the picture is | |
| 1107 | + // made of, and every sample of a drag reseeks, so they | |
| 1108 | + // move with the bar under the hand. | |
| 1109 | + .child( | |
| 1110 | + div() | |
| 1111 | + .flex_none() | |
| 1112 | + .h(px(HIST_H)) | |
| 1113 | + .rounded(px(3.)) | |
| 1114 | + .bg(rgb(BG_HOVER_DIM)) | |
| 1115 | + .relative() | |
| 1116 | + .child(hist_curves(self.histogram)), | |
| 1117 | + ) | |
| 1118 | + .children(rows) | |
| 1119 | + .child( | |
| 1120 | + div() | |
| 1121 | + .id("color-reset") | |
| 1122 | + .mt(px(4.)) | |
| 1123 | + .flex() | |
| 1124 | + .h(px(CONTROL_H)) | |
| 1125 | + .items_center() | |
| 1126 | + .justify_center() | |
| 1127 | + .rounded(px(3.)) | |
| 1128 | + .bg(rgb(BG_SELECTED)) | |
| 1129 | + .cursor_pointer() | |
| 1130 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 1131 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 1132 | + this.set_color(ColorParams::default(), cx); | |
| 1133 | + })) | |
| 1134 | + .child("Reset"), | |
| 1135 | + ), | |
| 1136 | + ), | |
| 1137 | + ) | |
| 1138 | + } | |
| 1139 | + | |
| 1140 | + /// The speed card: one bar from a quarter speed to four times it, the rates | |
| 1141 | + /// people name as buttons under it, and the clip's new length in frames -- | |
| 1142 | + /// which is the number a person is actually choosing. Built like the colour | |
| 1143 | + /// card down to the scrim and the bar's own hit height, because it is the | |
| 1144 | + /// same kind of card: one continuous value on one clip, live at the clip as | |
| 1145 | + /// it moves. | |
| 1146 | + /// | |
| 1147 | + /// Honest about what it does: the sound is *resampled*, so the pitch goes up | |
| 1148 | + /// with the rate, which is what the tape in the title means. | |
| 1149 | + pub(crate) fn speed_card(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> { | |
| 1150 | + let (lane, idx) = self.speed_open?; | |
| 1151 | + let speed = self.card_speed(); | |
| 1152 | + let session = self.session.as_ref()?; | |
| 1153 | + let clip = session.lane_clips(lane).get(idx).copied()?; | |
| 1154 | + let lo = f32::from(Speed::MIN.permille()); | |
| 1155 | + let hi = f32::from(Speed::MAX.permille()); | |
| 1156 | + let frac = ((f32::from(speed.permille()) - lo) / (hi - lo)).clamp(0., 1.); | |
| 1157 | + let presets: Vec<_> = SPEED_PRESETS | |
| 1158 | + .into_iter() | |
| 1159 | + .map(|permille| { | |
| 1160 | + let at = Speed::from_permille(permille); | |
| 1161 | + div() | |
| 1162 | + .id(("speed-preset", usize::from(permille))) | |
| 1163 | + .flex_1() | |
| 1164 | + .flex() | |
| 1165 | + .h(px(CONTROL_H)) | |
| 1166 | + .items_center() | |
| 1167 | + .justify_center() | |
| 1168 | + .rounded(px(3.)) | |
| 1169 | + .bg(rgb(match at == speed { | |
| 1170 | + true => BG_SELECTED, | |
| 1171 | + false => BG_PANEL, | |
| 1172 | + })) | |
| 1173 | + .cursor_pointer() | |
| 1174 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 1175 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 1176 | + this.set_speed(at, cx); | |
| 1177 | + })) | |
| 1178 | + .child(format!("{at}")) | |
| 1179 | + }) | |
| 1180 | + .collect(); | |
| 1181 | + Some( | |
| 1182 | + scrim() | |
| 1183 | + .flex() | |
| 1184 | + .justify_center() | |
| 1185 | + .items_center() | |
| 1186 | + .bg(rgba(SCRIM)) | |
| 1187 | + // Click away closes it, as on every card here. | |
| 1188 | + .on_mouse_down( | |
| 1189 | + MouseButton::Left, | |
| 1190 | + cx.listener(|this, _: &MouseDownEvent, _, cx| { | |
| 1191 | + this.close_card(); | |
| 1192 | + cx.notify(); | |
| 1193 | + cx.stop_propagation(); | |
| 1194 | + }), | |
| 1195 | + ) | |
| 1196 | + .child( | |
| 1197 | + div() | |
| 1198 | + .w(px(COLOR_W)) | |
| 1199 | + .on_mouse_down(MouseButton::Left, swallow) | |
| 1200 | + .flex() | |
| 1201 | + .flex_col() | |
| 1202 | + .gap(px(6.)) | |
| 1203 | + .p(px(12.)) | |
| 1204 | + .rounded(px(6.)) | |
| 1205 | + .bg(rgb(BG_RAISED)) | |
| 1206 | + .child(div().flex_none().px(px(6.)).child(format!( | |
| 1207 | + "Speed (tape) — {} clip {}", | |
| 1208 | + lane.label(), | |
| 1209 | + idx + 1 | |
| 1210 | + ))) | |
| 1211 | + .child( | |
| 1212 | + div() | |
| 1213 | + .flex_none() | |
| 1214 | + .px(px(6.)) | |
| 1215 | + .text_size(px(11.)) | |
| 1216 | + .text_color(rgb(FG_SECONDARY)) | |
| 1217 | + .child( | |
| 1218 | + "drag the bar or ←→ moves it, r is 1.00x — the pitch moves with the rate; a click away or esc closes", | |
| 1219 | + ), | |
| 1220 | + ) | |
| 1221 | + .child( | |
| 1222 | + // 4 px to look at and a whole row to hit (WCAG | |
| 1223 | + // 2.5.8), the split the colour sliders and the ruler | |
| 1224 | + // both make. | |
| 1225 | + div() | |
| 1226 | + .id("speed-bar") | |
| 1227 | + .relative() | |
| 1228 | + .w_full() | |
| 1229 | + .h(px(KEYS_ROW_H)) | |
| 1230 | + .flex() | |
| 1231 | + .items_center() | |
| 1232 | + .cursor_pointer() | |
| 1233 | + .on_mouse_down( | |
| 1234 | + MouseButton::Left, | |
| 1235 | + cx.listener(move |this, event: &MouseDownEvent, _, cx| { | |
| 1236 | + this.speed_dragging = true; | |
| 1237 | + this.drag_speed(event.position.x, true, cx); | |
| 1238 | + }), | |
| 1239 | + ) | |
| 1240 | + .child(bounds_probe(self.speed_bar.clone())) | |
| 1241 | + .child( | |
| 1242 | + div() | |
| 1243 | + .w_full() | |
| 1244 | + .h(px(4.)) | |
| 1245 | + .rounded(px(2.)) | |
| 1246 | + .bg(rgb(BG_PANEL)) | |
| 1247 | + .child( | |
| 1248 | + div() | |
| 1249 | + .h_full() | |
| 1250 | + .w(relative(frac)) | |
| 1251 | + .rounded(px(2.)) | |
| 1252 | + .bg(rgb(ACCENT_PRIMARY)), | |
| 1253 | + ), | |
| 1254 | + ), | |
| 1255 | + ) | |
| 1256 | + .child(div().flex().gap(px(4.)).children(presets)) | |
| 1257 | + .child( | |
| 1258 | + div() | |
| 1259 | + .flex_none() | |
| 1260 | + .px(px(6.)) | |
| 1261 | + .text_size(px(11.)) | |
| 1262 | + .text_color(rgb(FG_SECONDARY)) | |
| 1263 | + // What the choice *is*, in the numbers the | |
| 1264 | + // timeline is measured in: the source range | |
| 1265 | + // never moves, the room it takes does. | |
| 1266 | + .child(format!( | |
| 1267 | + "{speed} — {} source frames over {} on the timeline ({})", | |
| 1268 | + clip.len(), | |
| 1269 | + clip.frames(), | |
| 1270 | + timecode(f64::from(clip.frames()) / self.fps, self.fps) | |
| 1271 | + )), | |
| 1272 | + ), | |
| 1273 | + ), | |
| 1274 | + ) | |
| 1275 | + } | |
| 1276 | + | |
| 1277 | + /// The mix card: one fader per audio track and the master limiter under | |
| 1278 | + /// them -- the two settings that belong to the *sound of the whole | |
| 1279 | + /// timeline* rather than to any clip on it. | |
| 1280 | + /// | |
| 1281 | + /// A track's fader moves everything on that track by the same amount, | |
| 1282 | + /// every frequency of it: it is not the equalizer (one take, one band) and | |
| 1283 | + /// it is not the volume in the panel, which is what this machine monitors | |
| 1284 | + /// at and is written to no file. The limiter is over the sum of them all, | |
| 1285 | + /// which is where a mix can pass full scale and where a clamp used to | |
| 1286 | + /// square it off. | |
| 1287 | + /// | |
| 1288 | + /// The silence card's shape, down to the steppers: a row is a label, a | |
| 1289 | + /// value and the two presses that move it, and the arrows pick a row and | |
| 1290 | + /// move it too. The rows scroll rather than the card growing past the | |
| 1291 | + /// window -- a timeline may hold more tracks than a 360 px window has room | |
| 1292 | + /// for faders. | |
| 1293 | + pub(crate) fn mix_card(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> { | |
| 1294 | + if !self.mix_open { | |
| 1295 | + return None; | |
| 1296 | + } | |
| 1297 | + let session = self.session.as_ref(); | |
| 1298 | + let lanes = self.mix_lanes(); | |
| 1299 | + let limiter = session.map_or_else(Limiter::default, PlaybackSession::limiter); | |
| 1300 | + let mut rows: Vec<(String, String)> = lanes | |
| 1301 | + .iter() | |
| 1302 | + .map(|&lane| { | |
| 1303 | + let db = session.map_or(0., |s| s.lane_gain_db(lane)); | |
| 1304 | + (format!("{} plays at", lane.label()), format!("{db:+.0} dB")) | |
| 1305 | + }) | |
| 1306 | + .collect(); | |
| 1307 | + // The ceiling in dBFS and the faders in dB, the silence card's rule: | |
| 1308 | + // a ceiling is a level below full scale, a fader is a change. | |
| 1309 | + rows.push(( | |
| 1310 | + "Limiter ceiling".into(), | |
| 1311 | + format!("{:+.0} dBFS", limiter.ceiling_db), | |
| 1312 | + )); | |
| 1313 | + rows.push(( | |
| 1314 | + "Limiter".into(), | |
| 1315 | + match limiter.on { | |
| 1316 | + true => "on".into(), | |
| 1317 | + false => "off".into(), | |
| 1318 | + }, | |
| 1319 | + )); | |
| 1320 | + let rows: Vec<_> = rows | |
| 1321 | + .into_iter() | |
| 1322 | + .enumerate() | |
| 1323 | + .map(|(n, (label, value))| { | |
| 1324 | + div() | |
| 1325 | + .id(("mix-row", n)) | |
| 1326 | + .flex() | |
| 1327 | + .flex_none() | |
| 1328 | + .min_h(px(KEYS_ROW_H)) | |
| 1329 | + .items_center() | |
| 1330 | + .justify_between() | |
| 1331 | + .px(px(6.)) | |
| 1332 | + .rounded(px(3.)) | |
| 1333 | + .bg(rgb(match n == self.mix_field { | |
| 1334 | + true => BG_SELECTED, | |
| 1335 | + false => BG_PANEL, | |
| 1336 | + })) | |
| 1337 | + .cursor_pointer() | |
| 1338 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 1339 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 1340 | + this.mix_field = n; | |
| 1341 | + cx.notify(); | |
| 1342 | + })) | |
| 1343 | + .child(div().text_color(rgb(FG_SECONDARY)).child(label)) | |
| 1344 | + .child( | |
| 1345 | + div() | |
| 1346 | + .flex() | |
| 1347 | + .items_center() | |
| 1348 | + .gap(px(4.)) | |
| 1349 | + .child(value) | |
| 1350 | + .children([-1, 1].map(|steps: i32| { | |
| 1351 | + div() | |
| 1352 | + .id(("mix-step", n * 2 + usize::from(steps > 0))) | |
| 1353 | + .flex_none() | |
| 1354 | + .w(px(HIT_MIN)) | |
| 1355 | + .h(px(KEYS_ROW_H)) | |
| 1356 | + .flex() | |
| 1357 | + .items_center() | |
| 1358 | + .justify_center() | |
| 1359 | + .rounded(px(3.)) | |
| 1360 | + .bg(rgb(BG_PANEL)) | |
| 1361 | + .cursor_pointer() | |
| 1362 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 1363 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 1364 | + // Picked as well as moved, the silence | |
| 1365 | + // card's rule: the row a press lands on | |
| 1366 | + // is the row the arrows carry on from. | |
| 1367 | + this.mix_field = n; | |
| 1368 | + this.nudge_mix(steps, cx); | |
| 1369 | + })) | |
| 1370 | + .child(match steps > 0 { | |
| 1371 | + true => "+", | |
| 1372 | + false => "−", | |
| 1373 | + }) | |
| 1374 | + })), | |
| 1375 | + ) | |
| 1376 | + }) | |
| 1377 | + .collect(); | |
| 1378 | + Some( | |
| 1379 | + scrim() | |
| 1380 | + .flex() | |
| 1381 | + .justify_center() | |
| 1382 | + .items_center() | |
| 1383 | + .bg(rgba(SCRIM)) | |
| 1384 | + // Click away closes it, as on every card here. | |
| 1385 | + .on_mouse_down( | |
| 1386 | + MouseButton::Left, | |
| 1387 | + cx.listener(|this, _: &MouseDownEvent, _, cx| { | |
| 1388 | + this.close_card(); | |
| 1389 | + cx.notify(); | |
| 1390 | + cx.stop_propagation(); | |
| 1391 | + }), | |
| 1392 | + ) | |
| 1393 | + .child( | |
| 1394 | + div() | |
| 1395 | + .w(px(COLOR_W)) | |
| 1396 | + .on_mouse_down(MouseButton::Left, swallow) | |
| 1397 | + .max_h(px(360. - 24.)) | |
| 1398 | + .flex() | |
| 1399 | + .flex_col() | |
| 1400 | + .gap(px(6.)) | |
| 1401 | + .p(px(12.)) | |
| 1402 | + .rounded(px(6.)) | |
| 1403 | + .bg(rgb(BG_RAISED)) | |
| 1404 | + .child( | |
| 1405 | + div() | |
| 1406 | + .flex_none() | |
| 1407 | + .px(px(6.)) | |
| 1408 | + .child("Mix — track volumes and the master limiter"), | |
| 1409 | + ) | |
| 1410 | + .child( | |
| 1411 | + div() | |
| 1412 | + .flex_none() | |
| 1413 | + .px(px(6.)) | |
| 1414 | + .text_size(px(11.)) | |
| 1415 | + .text_color(rgb(FG_SECONDARY)) | |
| 1416 | + .child( | |
| 1417 | + "− and + move a setting, or ↑↓ picks one and ←→ moves it (hold to run it) — a track fader moves everything on that track; a click away or esc closes", | |
| 1418 | + ), | |
| 1419 | + ) | |
| 1420 | + .child( | |
| 1421 | + div() | |
| 1422 | + .id("mix-rows") | |
| 1423 | + .flex() | |
| 1424 | + .flex_col() | |
| 1425 | + .gap(px(6.)) | |
| 1426 | + .overflow_y_scroll() | |
| 1427 | + .children(rows), | |
| 1428 | + ) | |
| 1429 | + .child( | |
| 1430 | + div() | |
| 1431 | + .flex_none() | |
| 1432 | + .px(px(6.)) | |
| 1433 | + .text_size(px(11.)) | |
| 1434 | + .text_color(rgb(FG_SECONDARY)) | |
| 1435 | + // What the choice *is*: the limiter's own line, | |
| 1436 | + // because "on" alone says nothing about what it | |
| 1437 | + // does to a mix that never reaches the ceiling. | |
| 1438 | + .child(match limiter.on { | |
| 1439 | + true => format!( | |
| 1440 | + "the mix is held under {:+.0} dBFS — quieter passages are untouched", | |
| 1441 | + limiter.ceiling_db | |
| 1442 | + ), | |
| 1443 | + false => "the limiter is out of circuit — a hot mix clips at full scale".to_string(), | |
| 1444 | + }), | |
| 1445 | + ), | |
| 1446 | + ), | |
| 1447 | + ) | |
| 1448 | + } | |
| 1449 | + | |
| 1450 | + /// The silence card: what the scan is looking for, what it found, and the | |
| 1451 | + /// two things that can be done about it. | |
| 1452 | + /// | |
| 1453 | + /// Its scrim is the lightest of the cards' on purpose. Every other card is | |
| 1454 | + /// about the clip it names and can black the timeline out; this one is | |
| 1455 | + /// *about* the timeline -- the marks under it are the whole preview -- so | |
| 1456 | + /// the bed stays readable and the card sits up in the picture area rather | |
| 1457 | + /// than over the lanes. | |
| 1458 | + pub(crate) fn silence_card(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> { | |
| 1459 | + let (lane, idx) = self.silence_open?; | |
| 1460 | + let cfg = self.silence; | |
| 1461 | + // The unit is a label, never a conversion: the threshold is a level | |
| 1462 | + // below full scale whichever of the two the row says (`silence_dbfs`). | |
| 1463 | + let unit = match self.silence_dbfs { | |
| 1464 | + true => "dBFS", | |
| 1465 | + false => "dB", | |
| 1466 | + }; | |
| 1467 | + let rows = [ | |
| 1468 | + ("Apply to", self.silence_scope.label(&self.silence_lanes())), | |
| 1469 | + ( | |
| 1470 | + "Silence is under", | |
| 1471 | + format!("{:.0} {unit}", cfg.threshold_db), | |
| 1472 | + ), | |
| 1473 | + ("Level read in", format!("{unit} (0 = full scale)")), | |
| 1474 | + ( | |
| 1475 | + "Forgive quiet shorter than", | |
| 1476 | + format!("{:.2} s", cfg.min_silence), | |
| 1477 | + ), | |
| 1478 | + ( | |
| 1479 | + "Keep either side of speech", | |
| 1480 | + format!("{:.2} s", cfg.padding), | |
| 1481 | + ), | |
| 1482 | + ( | |
| 1483 | + "Swallow kept slivers under", | |
| 1484 | + format!("{:.2} s", cfg.min_keep), | |
| 1485 | + ), | |
| 1486 | + ("Speed-up plays at", format!("{}", self.silence_factor)), | |
| 1487 | + ]; | |
| 1488 | + let found = self.silence_marks.len(); | |
| 1489 | + let secs = | |
| 1490 | + f64::from(self.silence_marks.iter().map(|&(_, len)| len).sum::<u32>()) / self.fps; | |
| 1491 | + // The line under the rows: where a scan still running has got to -- a | |
| 1492 | + // card is up from the frame it is asked for, numbers or no numbers -- | |
| 1493 | + // or what the settings found in levels already read. | |
| 1494 | + let status = match &self.silence_scan { | |
| 1495 | + Some(scan) => silence_line( | |
| 1496 | + scan.seen as f32 / 10., | |
| 1497 | + scan.progress.total.load(std::sync::atomic::Ordering::Relaxed) as f32 / 10., | |
| 1498 | + scan.started.elapsed().as_secs_f32(), | |
| 1499 | + scan.since.elapsed().as_secs_f32(), | |
| 1500 | + ), | |
| 1501 | + None => match found { | |
| 1502 | + 0 => "nothing quiet enough for long enough".to_string(), | |
| 1503 | + 1 => format!("1 silence, {}", secs_label(secs)), | |
| 1504 | + n => format!("{n} silences, {}", secs_label(secs)), | |
| 1505 | + }, | |
| 1506 | + }; | |
| 1507 | + let rows: Vec<_> = rows | |
| 1508 | + .into_iter() | |
| 1509 | + .enumerate() | |
| 1510 | + .map(|(n, (label, value))| { | |
| 1511 | + div() | |
| 1512 | + .id(("silence-row", n)) | |
| 1513 | + .flex() | |
| 1514 | + .min_h(px(KEYS_ROW_H)) | |
| 1515 | + .items_center() | |
| 1516 | + .justify_between() | |
| 1517 | + .px(px(6.)) | |
| 1518 | + .rounded(px(3.)) | |
| 1519 | + .bg(rgb(match n == self.silence_field { | |
| 1520 | + true => BG_SELECTED, | |
| 1521 | + false => BG_PANEL, | |
| 1522 | + })) | |
| 1523 | + .cursor_pointer() | |
| 1524 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 1525 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 1526 | + this.silence_field = n; | |
| 1527 | + cx.notify(); | |
| 1528 | + })) | |
| 1529 | + .child(div().text_color(rgb(FG_SECONDARY)).child(label)) | |
| 1530 | + // The value and the two steps that move it. Every other | |
| 1531 | + // card has something to drag or press; this one had the | |
| 1532 | + // arrow keys and nothing else, so a row was a setting a | |
| 1533 | + // pointer could pick but never change. One press each, the | |
| 1534 | + // same call the arrows make -- the hold-to-run is the | |
| 1535 | + // keyboard's own and is not a thing a button has. | |
| 1536 | + .child( | |
| 1537 | + div() | |
| 1538 | + .flex() | |
| 1539 | + .items_center() | |
| 1540 | + .gap(px(4.)) | |
| 1541 | + .child(value) | |
| 1542 | + .children([-1, 1].map(|steps: i32| { | |
| 1543 | + div() | |
| 1544 | + .id(("silence-step", n * 2 + usize::from(steps > 0))) | |
| 1545 | + .flex_none() | |
| 1546 | + .w(px(HIT_MIN)) | |
| 1547 | + .h(px(KEYS_ROW_H)) | |
| 1548 | + .flex() | |
| 1549 | + .items_center() | |
| 1550 | + .justify_center() | |
| 1551 | + .rounded(px(3.)) | |
| 1552 | + .bg(rgb(BG_PANEL)) | |
| 1553 | + .cursor_pointer() | |
| 1554 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 1555 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 1556 | + // Picked as well as moved: the row a | |
| 1557 | + // press lands on is the row the arrows | |
| 1558 | + // carry on from. | |
| 1559 | + this.silence_field = n; | |
| 1560 | + this.nudge_silence(steps); | |
| 1561 | + cx.notify(); | |
| 1562 | + })) | |
| 1563 | + .child(match steps > 0 { | |
| 1564 | + true => "+", | |
| 1565 | + false => "−", | |
| 1566 | + }) | |
| 1567 | + })), | |
| 1568 | + ) | |
| 1569 | + }) | |
| 1570 | + .collect(); | |
| 1571 | + // The two buttons the ask names, side by side: a mode toggle would hide | |
| 1572 | + // one of them behind the other, and there are only two. | |
| 1573 | + let button = |n: usize, text: String, act: fn(&mut Self, &mut Context<Self>)| { | |
| 1574 | + div() | |
| 1575 | + .id(("silence-apply", n)) | |
| 1576 | + .flex_1() | |
| 1577 | + .flex() | |
| 1578 | + .min_h(px(KEYS_ROW_H)) | |
| 1579 | + .items_center() | |
| 1580 | + .justify_center() | |
| 1581 | + .rounded(px(3.)) | |
| 1582 | + .bg(rgb(match found { | |
| 1583 | + 0 => BG_PANEL, | |
| 1584 | + _ => BG_SELECTED, | |
| 1585 | + })) | |
| 1586 | + .cursor_pointer() | |
| 1587 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 1588 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| act(this, cx))) | |
| 1589 | + .child(text) | |
| 1590 | + }; | |
| 1591 | + Some( | |
| 1592 | + scrim() | |
| 1593 | + .flex() | |
| 1594 | + .justify_center() | |
| 1595 | + .items_start() | |
| 1596 | + .pt(px(HEADER_H + 8.)) | |
| 1597 | + // Light enough to read the lanes and the marks on them through: | |
| 1598 | + // the preview is the point of this card. | |
| 1599 | + .bg(rgba(SCRIM_LIGHT)) | |
| 1600 | + // Click away closes it, as on every card here -- and the marks | |
| 1601 | + // go with it, which is what makes this one a call and not a flag. | |
| 1602 | + .on_mouse_down( | |
| 1603 | + MouseButton::Left, | |
| 1604 | + cx.listener(|this, _: &MouseDownEvent, _, cx| { | |
| 1605 | + this.close_card(); | |
| 1606 | + cx.notify(); | |
| 1607 | + cx.stop_propagation(); | |
| 1608 | + }), | |
| 1609 | + ) | |
| 1610 | + .child( | |
| 1611 | + div() | |
| 1612 | + .w(px(COLOR_W)) | |
| 1613 | + .on_mouse_down(MouseButton::Left, swallow) | |
| 1614 | + .flex() | |
| 1615 | + .flex_col() | |
| 1616 | + .gap(px(6.)) | |
| 1617 | + .p(px(12.)) | |
| 1618 | + .rounded(px(6.)) | |
| 1619 | + .bg(rgb(BG_RAISED)) | |
| 1620 | + .child(div().flex_none().px(px(6.)).child(format!( | |
| 1621 | + "Silences — {} clip {}", | |
| 1622 | + lane.label(), | |
| 1623 | + idx + 1 | |
| 1624 | + ))) | |
| 1625 | + .child( | |
| 1626 | + div() | |
| 1627 | + .flex_none() | |
| 1628 | + .px(px(6.)) | |
| 1629 | + .text_size(px(11.)) | |
| 1630 | + .text_color(rgb(FG_SECONDARY)) | |
| 1631 | + .child( | |
| 1632 | + "− and + move a setting, or ↑↓ picks one and ←→ moves it (hold to run it) — the marks on the lane are what would go; a click away or esc closes", | |
| 1633 | + ), | |
| 1634 | + ) | |
| 1635 | + .children(rows) | |
| 1636 | + .child( | |
| 1637 | + div() | |
| 1638 | + .flex_none() | |
| 1639 | + .px(px(6.)) | |
| 1640 | + .text_color(rgb(match (&self.silence_scan, found) { | |
| 1641 | + (None, 1..) => ACCENT_PRIMARY, | |
| 1642 | + _ => FG_SECONDARY, | |
| 1643 | + })) | |
| 1644 | + .child(status), | |
| 1645 | + ) | |
| 1646 | + .child(div().flex().gap(px(4.)).children([ | |
| 1647 | + button(0, "Cut them out (enter)".into(), Self::cut_silences), | |
| 1648 | + button( | |
| 1649 | + 1, | |
| 1650 | + format!("Play them at {} (f)", self.silence_factor), | |
| 1651 | + Self::speed_silences, | |
| 1652 | + ), | |
| 1653 | + ])), | |
| 1654 | + ), | |
| 1655 | + ) | |
| 1656 | + } | |
| 1657 | +} |
crates/app/src/ui/inspector.rsadded+0 -0
crates/app/src/ui/library.rsadded+472 -0
| @@ -0,0 +1,472 @@ | ||
| 1 | +//! The media library: the left panel's rows and the menu over them. | |
| 2 | + | |
| 3 | +use crate::*; | |
| 4 | +use crate::ui::widgets::*; | |
| 5 | + | |
| 6 | +impl Player { | |
| 7 | + /// The media library: a row per source the timeline knows, in the order | |
| 8 | + /// they arrived, each wearing the tint its clips wear in the lanes -- the | |
| 9 | + /// swatch *is* what says which boxes down there came from this file. A | |
| 10 | + /// click picks a row, the button under the list drops that source in at the | |
| 11 | + /// playhead, and a row dragged onto either lane does the same thing through | |
| 12 | + /// the same call. | |
| 13 | + /// | |
| 14 | + /// Import lives here, because this is the list it adds to. Plain divs like | |
| 15 | + /// the rest of this window: nothing in it takes focus, so the root keeps | |
| 16 | + /// the keyboard and the play key still works after a row is clicked | |
| 17 | + /// (ledger:182). | |
| 18 | + pub(crate) fn library(&self, width: f32, viewport_h: f32, cx: &mut Context<Self>) -> impl IntoElement { | |
| 19 | + let exporting = self.exporting().is_some(); | |
| 20 | + let sources = self | |
| 21 | + .session | |
| 22 | + .as_ref() | |
| 23 | + .map_or(&[][..], PlaybackSession::sources); | |
| 24 | + // Every source matches the first in size and rate or it was refused at | |
| 25 | + // the door (the import policy, ledger:436), so the session's own meta | |
| 26 | + // describes every row and nothing has to be probed to say so. | |
| 27 | + let meta = self.session.as_ref().map(PlaybackSession::meta); | |
| 28 | + // Its own length, not one derived from what is on the lanes: a row | |
| 29 | + // imported and never placed is a row with a length, and it is the | |
| 30 | + // length a drag would put down. | |
| 31 | + let rows: Vec<_> = library_rows( | |
| 32 | + sources, | |
| 33 | + &self.streams, | |
| 34 | + &self.decoders, | |
| 35 | + self.timeline_audio(), | |
| 36 | + |path| { | |
| 37 | + self.session | |
| 38 | + .as_ref() | |
| 39 | + .map_or(0, |session| session.file_frames(path)) | |
| 40 | + }, | |
| 41 | + ) | |
| 42 | + .into_iter() | |
| 43 | + .enumerate() | |
| 44 | + .map(|(i, row)| { | |
| 45 | + let picked = self | |
| 46 | + .selected_asset | |
| 47 | + .as_ref() | |
| 48 | + .is_some_and(|p| *p == (row.path.clone(), row.stream)); | |
| 49 | + let name: SharedString = row.name.clone().into(); | |
| 50 | + let says: String = match (&row.unusable, meta) { | |
| 51 | + // A greyed row says why in full, where its length would be: | |
| 52 | + // the list is the one place the file's own tracks are named. | |
| 53 | + (Some(why), _) => format!("{} — {why}", row.path.display()), | |
| 54 | + // A file with no picture has no size and no frame rate to | |
| 55 | + // report, and only one lane it can go on: saying so is the | |
| 56 | + // difference between a hint and a lie. | |
| 57 | + (None, _) if engine::is_audio(&row.path) => format!( | |
| 58 | + "{} — audio only · drag onto the audio lane, or Add at playhead", | |
| 59 | + row.path.display() | |
| 60 | + ), | |
| 61 | + // A still is the mirror: its own size (the timeline's meta | |
| 62 | + // describes video, and a picture placed on that canvas is not | |
| 63 | + // the same shape), no frame rate, and one kind of lane. | |
| 64 | + (None, _) if engine::is_image(&row.path) => format!( | |
| 65 | + "{} — still image{} · drag onto a video lane, or Add at playhead", | |
| 66 | + row.path.display(), | |
| 67 | + match self.sizes.get(&row.path).copied().flatten() { | |
| 68 | + Some((w, h)) => format!(" · {w}x{h}"), | |
| 69 | + None => String::new(), | |
| 70 | + } | |
| 71 | + ), | |
| 72 | + // The file's *own* frame rate, not the timeline's: a clip shot | |
| 73 | + // at another rate plays at the speed it was shot at, and the | |
| 74 | + // row that says where it came from has to say which rate that | |
| 75 | + // was. | |
| 76 | + (None, Some(meta)) => format!( | |
| 77 | + "{} — {}x{} @ {:.2} fps · drag it where you want it, or Add at playhead", | |
| 78 | + row.path.display(), | |
| 79 | + meta.width, | |
| 80 | + meta.height, | |
| 81 | + self.session | |
| 82 | + .as_ref() | |
| 83 | + .map_or(meta.frame_rate, |session| session.file_fps(&row.path)) | |
| 84 | + ), | |
| 85 | + (None, None) => row.path.display().to_string(), | |
| 86 | + }; | |
| 87 | + // The menu is the third way into a row, after the click and the | |
| 88 | + // drag, and a right-click nothing advertises is one nobody finds. | |
| 89 | + let tip: SharedString = format!("{says} · right-click for more").into(); | |
| 90 | + let ghost = name.clone(); | |
| 91 | + // What the second line says: the stream, then either its length or | |
| 92 | + // the reason it cannot be used. | |
| 93 | + let under = match &row.unusable { | |
| 94 | + Some(why) => join_detail(&row.detail, why), | |
| 95 | + // A still has no length to report -- the ten minutes it is | |
| 96 | + // *held* to is a wall, not a duration -- so the line says what | |
| 97 | + // it is and how big it is instead. | |
| 98 | + None if engine::is_image(&row.path) => join_detail( | |
| 99 | + &row.detail, | |
| 100 | + &match self.sizes.get(&row.path).copied().flatten() { | |
| 101 | + Some((w, h)) => format!("still image · {w}x{h}"), | |
| 102 | + None => "still image".to_string(), | |
| 103 | + }, | |
| 104 | + ), | |
| 105 | + None => join_detail( | |
| 106 | + &row.detail, | |
| 107 | + &timecode(f64::from(row.frames) / self.fps, self.fps), | |
| 108 | + ), | |
| 109 | + }; | |
| 110 | + let usable = row.unusable.is_none(); | |
| 111 | + let (path, stream) = (row.path.clone(), row.stream); | |
| 112 | + let dragged = (path.clone(), stream); | |
| 113 | + let menu_path = path.clone(); | |
| 114 | + div() | |
| 115 | + .id(("asset", i)) | |
| 116 | + .flex_none() | |
| 117 | + .h(px(ROW_H)) | |
| 118 | + .flex() | |
| 119 | + .items_center() | |
| 120 | + .gap(px(6.)) | |
| 121 | + .pr(px(6.)) | |
| 122 | + .rounded(px(3.)) | |
| 123 | + // A row that cannot be placed takes no click and no drag, and | |
| 124 | + // reads as unavailable rather than merely unlucky. | |
| 125 | + .when(!usable, |d| d.text_color(rgb(FG_SECONDARY)).opacity(0.55)) | |
| 126 | + .when(usable, |d| { | |
| 127 | + d.cursor_pointer() | |
| 128 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 129 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 130 | + this.selected_asset = Some((path.clone(), stream)); | |
| 131 | + cx.notify(); | |
| 132 | + })) | |
| 133 | + // The drag carries the row's file and stream and the | |
| 134 | + // row's name: one for the drop to insert, one for the | |
| 135 | + // pointer to carry, so what is being dragged is legible | |
| 136 | + // on the way down. | |
| 137 | + .on_drag(AssetDrag(dragged.0, dragged.1), move |_, _, _, cx| { | |
| 138 | + cx.new(|_| Tip(ghost.clone())) | |
| 139 | + }) | |
| 140 | + }) | |
| 141 | + // The right button hangs the row's own menu at the pointer. | |
| 142 | + // Every row takes it, greyed ones included: a file that cannot | |
| 143 | + // join this timeline can still be revealed, described and taken | |
| 144 | + // out of the list, and Add is the one item that then refuses -- | |
| 145 | + // in the engine's words, where the row's grey already says why. | |
| 146 | + .on_mouse_down( | |
| 147 | + MouseButton::Right, | |
| 148 | + cx.listener(move |this, event: &MouseDownEvent, _, cx| { | |
| 149 | + if this.modal() { | |
| 150 | + return; | |
| 151 | + } | |
| 152 | + // Picked as a left-click would pick it, so the row the | |
| 153 | + // menu is about is the row that reads as chosen -- but | |
| 154 | + // only a row that *can* be picked, which is what keeps | |
| 155 | + // the Add button under the list honest. | |
| 156 | + if usable { | |
| 157 | + this.selected_asset = Some((menu_path.clone(), stream)); | |
| 158 | + } | |
| 159 | + this.library_menu = Some(LibraryMenu { | |
| 160 | + path: menu_path.clone(), | |
| 161 | + stream, | |
| 162 | + at: event.position, | |
| 163 | + details: false, | |
| 164 | + }); | |
| 165 | + cx.notify(); | |
| 166 | + }), | |
| 167 | + ) | |
| 168 | + .when(picked, |d| d.bg(rgb(BG_SELECTED)).border_1()) | |
| 169 | + .tooltip(move |_, cx| cx.new(|_| Tip(tip.clone())).into()) | |
| 170 | + // Full height and hard against the edge: the tint reads as | |
| 171 | + // the lane's colour continuing into the list, not as a chip | |
| 172 | + // that happens to be near it. | |
| 173 | + .child( | |
| 174 | + div() | |
| 175 | + .flex_none() | |
| 176 | + .w(px(SWATCH_W)) | |
| 177 | + .h_full() | |
| 178 | + .rounded(px(2.)) | |
| 179 | + .bg(rgb(source_tint(row.tint))), | |
| 180 | + ) | |
| 181 | + .child( | |
| 182 | + div() | |
| 183 | + .flex_1() | |
| 184 | + .min_w(px(0.)) | |
| 185 | + .flex() | |
| 186 | + .flex_col() | |
| 187 | + // Two lines rather than two columns: at the width | |
| 188 | + // this panel yields to, a name and a timecode side | |
| 189 | + // by side leave room for neither. | |
| 190 | + // Cut out of the middle, not the end: two episodes off | |
| 191 | + // one release are the same words up to the number, and | |
| 192 | + // the number is at the end. | |
| 193 | + .child( | |
| 194 | + div() | |
| 195 | + .truncate() | |
| 196 | + .text_size(px(11.)) | |
| 197 | + .child(clip_middle(&name, row_text_w(width))), | |
| 198 | + ) | |
| 199 | + .child( | |
| 200 | + div() | |
| 201 | + .truncate() | |
| 202 | + .text_size(px(10.)) | |
| 203 | + .text_color(rgb(FG_SECONDARY)) | |
| 204 | + .child(under), | |
| 205 | + ), | |
| 206 | + ) | |
| 207 | + }) | |
| 208 | + .collect(); | |
| 209 | + div() | |
| 210 | + .flex_none() | |
| 211 | + .w(px(width)) | |
| 212 | + .h_full() | |
| 213 | + .flex() | |
| 214 | + .flex_col() | |
| 215 | + .gap(px(6.)) | |
| 216 | + .p(px(8.)) | |
| 217 | + .bg(rgb(BG_PANEL)) | |
| 218 | + .child( | |
| 219 | + div() | |
| 220 | + .flex_none() | |
| 221 | + .flex() | |
| 222 | + .items_center() | |
| 223 | + .gap(px(6.)) | |
| 224 | + .child( | |
| 225 | + div() | |
| 226 | + .flex_1() | |
| 227 | + .min_w(px(0.)) | |
| 228 | + .truncate() | |
| 229 | + .text_size(px(11.)) | |
| 230 | + .text_color(rgb(FG_SECONDARY)) | |
| 231 | + .child("Media"), | |
| 232 | + ) | |
| 233 | + .child(control( | |
| 234 | + "import", | |
| 235 | + None, | |
| 236 | + "Import", | |
| 237 | + "adds a file to this list — or drop one on the window".to_string(), | |
| 238 | + !exporting, | |
| 239 | + cx.listener(|this, _: &ClickEvent, _, cx| this.pick_and_import(cx)), | |
| 240 | + )), | |
| 241 | + ) | |
| 242 | + .child( | |
| 243 | + div() | |
| 244 | + .id("library-rows") | |
| 245 | + .flex_1() | |
| 246 | + .min_h(px(0.)) | |
| 247 | + .flex() | |
| 248 | + .flex_col() | |
| 249 | + .gap(px(2.)) | |
| 250 | + .overflow_y_scroll() | |
| 251 | + // Never a blank column: with nothing imported the list is | |
| 252 | + // where the way in is said. | |
| 253 | + .when(rows.is_empty(), |d| { | |
| 254 | + d.child( | |
| 255 | + div() | |
| 256 | + .text_size(px(11.)) | |
| 257 | + .text_color(rgb(FG_SECONDARY)) | |
| 258 | + .child("No media yet — Import, or drop a file on the window"), | |
| 259 | + ) | |
| 260 | + }) | |
| 261 | + .children(rows), | |
| 262 | + ) | |
| 263 | + // Under the media it belongs to: a subtitle track is not a source -- | |
| 264 | + // it goes on no lane and is dragged nowhere -- but it is a thing the | |
| 265 | + // timeline holds, and this is the list of those. | |
| 266 | + .children(self.subtitle_section(width, viewport_h, cx)) | |
| 267 | + .child(control( | |
| 268 | + "add-asset", | |
| 269 | + None, | |
| 270 | + "Add at playhead", | |
| 271 | + match self.selected_asset { | |
| 272 | + Some(_) => "inserts the picked file at the playhead".to_string(), | |
| 273 | + None => "click a file above first — or drag one where you want it".to_string(), | |
| 274 | + }, | |
| 275 | + can_add( | |
| 276 | + self.selected_asset.as_ref(), | |
| 277 | + self.session.is_some(), | |
| 278 | + exporting, | |
| 279 | + ), | |
| 280 | + cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 281 | + if let Some((path, stream)) = this.selected_asset.clone() { | |
| 282 | + // No lane: the button means "wherever this belongs", | |
| 283 | + // which for a file with no picture is the audio lane. | |
| 284 | + this.insert_source(&path, stream, None, None, cx); | |
| 285 | + } | |
| 286 | + }), | |
| 287 | + )) | |
| 288 | + } | |
| 289 | + | |
| 290 | + /// The menu a right-click on a library row opens: what can be done with the | |
| 291 | + /// *file* rather than with a clip of it, and a turn-over side saying what | |
| 292 | + /// that file is. Built like [`Player::context_card`] down to the scrim, the | |
| 293 | + /// row height and the clamp, because it is the same menu on the other panel | |
| 294 | + /// -- a click away or any stroke closes it. | |
| 295 | + pub(crate) fn library_card( | |
| 296 | + &self, | |
| 297 | + viewport: Size<Pixels>, | |
| 298 | + cx: &mut Context<Self>, | |
| 299 | + ) -> Option<impl IntoElement> { | |
| 300 | + let menu = self.library_menu.clone()?; | |
| 301 | + let path = menu.path.clone(); | |
| 302 | + let row = |n: usize| { | |
| 303 | + div() | |
| 304 | + .id(("library-menu", n)) | |
| 305 | + .flex() | |
| 306 | + .min_h(px(MENU_ROW_H)) | |
| 307 | + .items_center() | |
| 308 | + .justify_between() | |
| 309 | + .gap(px(12.)) | |
| 310 | + .px(px(6.)) | |
| 311 | + .rounded(px(3.)) | |
| 312 | + }; | |
| 313 | + let mut rows: Vec<AnyElement> = Vec::new(); | |
| 314 | + // What every item of this menu is answered from, read once. | |
| 315 | + let ctx = self.row_ctx(&path, menu.stream); | |
| 316 | + if menu.details { | |
| 317 | + // What the library knows about this row and nothing probed for the | |
| 318 | + // card: the streams table is filled once per file at import. | |
| 319 | + let info = self | |
| 320 | + .streams | |
| 321 | + .get(&path) | |
| 322 | + .and_then(|of_file| of_file.iter().find(|s| s.index == menu.stream)); | |
| 323 | + let frames = self | |
| 324 | + .session | |
| 325 | + .as_ref() | |
| 326 | + .map_or(0, |session| session.file_frames(&path)); | |
| 327 | + // How many clips play from this exact row -- the number that | |
| 328 | + // decides whether Remove is refused, so the card answers the | |
| 329 | + // question the refusal would otherwise raise. | |
| 330 | + let placed = ctx.placed; | |
| 331 | + // A still is described by what it has -- a picture, a size, and a | |
| 332 | + // longest it may be held for -- where a media file is described by | |
| 333 | + // its streams and its length. Same card, the rows that mean | |
| 334 | + // something for this kind of source. | |
| 335 | + let image = engine::is_image(&path); | |
| 336 | + let kind = match self.sizes.get(&path).copied().flatten() { | |
| 337 | + Some((w, h)) => format!("still image · {w}x{h}"), | |
| 338 | + None => "still image".to_string(), | |
| 339 | + }; | |
| 340 | + for (label, value) in [ | |
| 341 | + ("File", file_name(&path)), | |
| 342 | + ("Path", path.display().to_string()), | |
| 343 | + match image { | |
| 344 | + true => ("Picture", kind), | |
| 345 | + false => ( | |
| 346 | + "Audio", | |
| 347 | + info.map_or_else(|| "no track of its own".to_string(), stream_detail), | |
| 348 | + ), | |
| 349 | + }, | |
| 350 | + ( | |
| 351 | + "Bitrate", | |
| 352 | + bitrate_detail( | |
| 353 | + self.bitrates.get(&path).copied().flatten(), | |
| 354 | + self.streams.get(&path).map_or(0, Vec::len), | |
| 355 | + ), | |
| 356 | + ), | |
| 357 | + match image { | |
| 358 | + true => ( | |
| 359 | + "Longest hold", | |
| 360 | + timecode(f64::from(frames) / self.fps, self.fps), | |
| 361 | + ), | |
| 362 | + false => ("Length", timecode(f64::from(frames) / self.fps, self.fps)), | |
| 363 | + }, | |
| 364 | + ("On the timeline", format!("{placed} clips")), | |
| 365 | + ] { | |
| 366 | + rows.push( | |
| 367 | + row(rows.len()) | |
| 368 | + .child(label) | |
| 369 | + .child( | |
| 370 | + div() | |
| 371 | + .min_w(px(0.)) | |
| 372 | + .truncate() | |
| 373 | + .text_size(px(11.)) | |
| 374 | + .text_color(rgb(FG_SECONDARY)) | |
| 375 | + .child(value), | |
| 376 | + ) | |
| 377 | + .into_any_element(), | |
| 378 | + ); | |
| 379 | + } | |
| 380 | + } else { | |
| 381 | + // The oracle's list, exactly as the clip menu takes its rows from | |
| 382 | + // `menu_items`: an item that means nothing for the file that was | |
| 383 | + // right-clicked is not a row, and one this moment refuses is drawn | |
| 384 | + // dimmed and says why in place of its hint. | |
| 385 | + for item in row_items(ctx) { | |
| 386 | + let refusal = row_enable(item, ctx); | |
| 387 | + let enabled = refusal.yes(); | |
| 388 | + rows.push( | |
| 389 | + row(rows.len()) | |
| 390 | + .child(item.label()) | |
| 391 | + .child( | |
| 392 | + div() | |
| 393 | + .min_w(px(0.)) | |
| 394 | + .truncate() | |
| 395 | + .text_color(rgb(FG_SECONDARY)) | |
| 396 | + .child(refusal.why().unwrap_or_else(|| item.hint())), | |
| 397 | + ) | |
| 398 | + .when(!enabled, |d| d.opacity(0.4).cursor_not_allowed()) | |
| 399 | + .when(enabled, |d| { | |
| 400 | + d.cursor_pointer() | |
| 401 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 402 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 403 | + this.act_on_row(item, cx); | |
| 404 | + })) | |
| 405 | + }) | |
| 406 | + .into_any_element(), | |
| 407 | + ); | |
| 408 | + } | |
| 409 | + } | |
| 410 | + // Placed by the height it is drawn to, and drawn to what the window has | |
| 411 | + // room for -- the clip menu's rule, one function for all three. | |
| 412 | + let list_h = menu_rows_h(rows.len(), viewport); | |
| 413 | + let (x, y) = menu_at(menu.at, viewport, MENU_PAD * 2. + list_h); | |
| 414 | + let full: SharedString = path.display().to_string().into(); | |
| 415 | + Some( | |
| 416 | + scrim() | |
| 417 | + .on_mouse_down( | |
| 418 | + MouseButton::Left, | |
| 419 | + cx.listener(|this, _: &MouseDownEvent, _, cx| { | |
| 420 | + this.library_menu = None; | |
| 421 | + cx.notify(); | |
| 422 | + cx.stop_propagation(); | |
| 423 | + }), | |
| 424 | + ) | |
| 425 | + .on_mouse_down( | |
| 426 | + MouseButton::Right, | |
| 427 | + cx.listener(|this, _: &MouseDownEvent, _, cx| { | |
| 428 | + this.library_menu = None; | |
| 429 | + cx.notify(); | |
| 430 | + cx.stop_propagation(); | |
| 431 | + }), | |
| 432 | + ) | |
| 433 | + .child( | |
| 434 | + div() | |
| 435 | + .id("library-menu-card") | |
| 436 | + .absolute() | |
| 437 | + .left(px(x)) | |
| 438 | + .top(px(y)) | |
| 439 | + .w(px(MENU_W)) | |
| 440 | + .flex() | |
| 441 | + .flex_col() | |
| 442 | + .p(px(MENU_PAD)) | |
| 443 | + .rounded(px(6.)) | |
| 444 | + .bg(rgb(BG_RAISED)) | |
| 445 | + // Painted after the scrim, so this listener runs first | |
| 446 | + // and a press meant for an item never closes the menu | |
| 447 | + // out from under its own click (`context_card`). | |
| 448 | + .on_mouse_down(MouseButton::Left, |_: &MouseDownEvent, _, cx| { | |
| 449 | + cx.stop_propagation() | |
| 450 | + }) | |
| 451 | + .on_mouse_down(MouseButton::Right, |_: &MouseDownEvent, _, cx| { | |
| 452 | + cx.stop_propagation() | |
| 453 | + }) | |
| 454 | + .when(menu.details, |d| { | |
| 455 | + d.tooltip(move |_, cx| cx.new(|_| Tip(full.clone())).into()) | |
| 456 | + }) | |
| 457 | + // Scrolls where the window has no room for the list, | |
| 458 | + // like the clip menu's -- an item hanging off the bottom | |
| 459 | + // edge is an item nobody can click. | |
| 460 | + .child( | |
| 461 | + div() | |
| 462 | + .id("library-menu-rows") | |
| 463 | + .flex() | |
| 464 | + .flex_col() | |
| 465 | + .max_h(px(list_h)) | |
| 466 | + .overflow_y_scroll() | |
| 467 | + .children(rows), | |
| 468 | + ), | |
| 469 | + ), | |
| 470 | + ) | |
| 471 | + } | |
| 472 | +} |
crates/app/src/ui/mod.rsadded+14 -0
| @@ -0,0 +1,14 @@ | ||
| 1 | +//! Every pixel this editor draws, one module per region of the window. | |
| 2 | +//! | |
| 3 | +//! The whole UI used to be one 19,916-line file with one `Render` impl in it, | |
| 4 | +//! which is why a colour or a rule fixed in one place kept surviving in the | |
| 5 | +//! next: there was no seam to sweep. The seams are the regions themselves. | |
| 6 | +pub mod cards; | |
| 7 | +pub mod inspector; | |
| 8 | +pub mod library; | |
| 9 | +pub mod overlays; | |
| 10 | +pub mod preview; | |
| 11 | +pub mod theme; | |
| 12 | +pub mod timeline; | |
| 13 | +pub mod toolbar; | |
| 14 | +pub mod widgets; |
crates/app/src/ui/overlays.rsadded+776 -0
| @@ -0,0 +1,776 @@ | ||
| 1 | +//! The bars and the floating cards that are not inspector sections. | |
| 2 | + | |
| 3 | +use crate::*; | |
| 4 | +use crate::ui::widgets::*; | |
| 5 | + | |
| 6 | +impl Player { | |
| 7 | + /// The running import holds its own bar above the notice's, for the notice | |
| 8 | + /// bar's reason: the message is the point. Not a notice, though -- nothing | |
| 9 | + /// dismisses it, because it is about work still going on, and it leaves by | |
| 10 | + /// itself when the file lands. | |
| 11 | + /// | |
| 12 | + /// The bar under the words is a *sweep*, not a fill: neither read reports | |
| 13 | + /// where in the file it is, so a fill would have to invent the one number | |
| 14 | + /// this cannot know. What it does say truthfully is "something is still | |
| 15 | + /// running", which is exactly the question a frozen-looking window raises. | |
| 16 | + /// | |
| 17 | + /// ...and beside them the way out. A read that may be twenty seconds of a | |
| 18 | + /// cold 24 GB film needs one, and the only honest place for it is the line | |
| 19 | + /// that says the read is happening ([`Player::cancel_import`]). | |
| 20 | + pub(crate) fn import_bar(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> { | |
| 21 | + let import = self.importing.as_ref()?; | |
| 22 | + let elapsed = import.started.elapsed().as_secs_f32(); | |
| 23 | + let line = import_line( | |
| 24 | + &file_name(&import.path), | |
| 25 | + import.seen, | |
| 26 | + elapsed, | |
| 27 | + import.since.elapsed().as_secs_f32(), | |
| 28 | + self.imports.len(), | |
| 29 | + arrival(self.opening.as_deref(), &import.path) != Landing::Import, | |
| 30 | + ); | |
| 31 | + // A quarter of the bar, crossing it every three seconds and wrapping. | |
| 32 | + // Tied to the elapsed clock, so it moves for as long as the read does | |
| 33 | + // and stops dead the instant the file lands. | |
| 34 | + const SWEEP: f32 = 0.25; | |
| 35 | + let at = (elapsed / 3.).fract() * (1. + SWEEP) - SWEEP; | |
| 36 | + Some( | |
| 37 | + div() | |
| 38 | + .flex_none() | |
| 39 | + .flex() | |
| 40 | + .flex_col() | |
| 41 | + .gap(px(4.)) | |
| 42 | + .px(px(12.)) | |
| 43 | + .py(px(6.)) | |
| 44 | + .bg(rgb(BG_RAISED)) | |
| 45 | + .child( | |
| 46 | + div() | |
| 47 | + .flex() | |
| 48 | + .items_center() | |
| 49 | + .gap(px(8.)) | |
| 50 | + .child(div().flex_1().min_w(px(0.)).child(line)) | |
| 51 | + .child(control( | |
| 52 | + "cancel-import", | |
| 53 | + None, | |
| 54 | + "Cancel", | |
| 55 | + "stops this file and anything queued behind it; the read already \ | |
| 56 | + running finishes unheeded" | |
| 57 | + .to_string(), | |
| 58 | + true, | |
| 59 | + cx.listener(|this, _: &ClickEvent, _, cx| this.cancel_import(cx)), | |
| 60 | + )), | |
| 61 | + ) | |
| 62 | + .child( | |
| 63 | + div() | |
| 64 | + .relative() | |
| 65 | + .w_full() | |
| 66 | + .h(px(2.)) | |
| 67 | + .bg(rgb(BG_HOVER)) | |
| 68 | + .child( | |
| 69 | + div() | |
| 70 | + .absolute() | |
| 71 | + .top_0() | |
| 72 | + .left(relative(at.max(0.))) | |
| 73 | + // Clipped at both ends by hand: the segment | |
| 74 | + // enters from the left edge and leaves past the | |
| 75 | + // right one, and a width that overhung would | |
| 76 | + // paint outside the track. | |
| 77 | + .w(relative((at + SWEEP).min(1.) - at.max(0.))) | |
| 78 | + .h(px(2.)) | |
| 79 | + .bg(rgb(ACCENT_PRIMARY)), | |
| 80 | + ), | |
| 81 | + ), | |
| 82 | + ) | |
| 83 | + } | |
| 84 | + | |
| 85 | + /// The line a long-standing seek shows, in the import bar's place and by the | |
| 86 | + /// import bar's rules: nothing dismisses it, and it leaves by itself the | |
| 87 | + /// moment the frame lands. No sweep under it -- an open reports nothing about | |
| 88 | + /// where it has got to, and the clock is the honest half of that bar anyway. | |
| 89 | + pub(crate) fn seek_bar(&self) -> Option<impl IntoElement> { | |
| 90 | + let line = seek_line(self.seek_since.map(|t| t.elapsed()))?; | |
| 91 | + Some( | |
| 92 | + div() | |
| 93 | + .flex_none() | |
| 94 | + .px(px(12.)) | |
| 95 | + .py(px(6.)) | |
| 96 | + .bg(rgb(BG_RAISED)) | |
| 97 | + .child(line), | |
| 98 | + ) | |
| 99 | + } | |
| 100 | + | |
| 101 | + /// A notice holds its own bar, full width, until it is answered: any key | |
| 102 | + /// retires it (the key handler) and so does a click on it. Its own surface | |
| 103 | + /// because the message is the point -- a failure cut to the timecode's slot | |
| 104 | + /// is a failure nobody read. | |
| 105 | + /// | |
| 106 | + /// The export's own line is more than a message: it names a file that is | |
| 107 | + /// now on disk, so the same click that retires it shows that file in the | |
| 108 | + /// desktop's file manager. | |
| 109 | + pub(crate) fn notice_bar(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> { | |
| 110 | + let notice = self.notice.clone()?; | |
| 111 | + // The path travels with the text it was written for: a later notice | |
| 112 | + // holds the bar and the click is a plain dismissal again. | |
| 113 | + let exported = self | |
| 114 | + .exported | |
| 115 | + .clone() | |
| 116 | + .filter(|_| notice.starts_with(EXPORT_DONE)); | |
| 117 | + let hint = match exported { | |
| 118 | + Some(_) => "click — open file location", | |
| 119 | + None => "click or press any key to dismiss", | |
| 120 | + }; | |
| 121 | + Some( | |
| 122 | + div() | |
| 123 | + .id("notice") | |
| 124 | + .when(exported.is_some(), |d| { | |
| 125 | + d.tooltip(|_, cx| { | |
| 126 | + cx.new(|_| { | |
| 127 | + Tip("Open file location — shows the export in the file manager".into()) | |
| 128 | + }) | |
| 129 | + .into() | |
| 130 | + }) | |
| 131 | + }) | |
| 132 | + .flex_none() | |
| 133 | + .flex() | |
| 134 | + .items_start() | |
| 135 | + .gap(px(12.)) | |
| 136 | + .px(px(12.)) | |
| 137 | + .py(px(6.)) | |
| 138 | + .bg(rgb(BG_RAISED)) | |
| 139 | + .cursor_pointer() | |
| 140 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 141 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 142 | + // Another process starting: off the UI thread, and it | |
| 143 | + // outlives the notice it was asked from. | |
| 144 | + if let Some(path) = exported.clone() { | |
| 145 | + cx.background_executor() | |
| 146 | + .spawn(async move { show_in_file_manager(&path) }) | |
| 147 | + .detach(); | |
| 148 | + } | |
| 149 | + this.notice = None; | |
| 150 | + cx.notify(); | |
| 151 | + })) | |
| 152 | + .child(div().flex_1().min_w(px(0.)).child(notice)) | |
| 153 | + .child( | |
| 154 | + div() | |
| 155 | + .flex_none() | |
| 156 | + .text_size(px(11.)) | |
| 157 | + .text_color(rgb(FG_SECONDARY)) | |
| 158 | + .child(hint), | |
| 159 | + ), | |
| 160 | + ) | |
| 161 | + } | |
| 162 | + | |
| 163 | + /// Every binding, and the way to change one: a row per entry, click it and | |
| 164 | + /// the next stroke becomes its chord. Over the whole window, because while | |
| 165 | + /// it is up nothing under it may answer -- the scrim stops the clicks | |
| 166 | + /// (gpui dispatches mouse listeners topmost-first, window.rs:3705) and the | |
| 167 | + /// key handler's own branch stops the strokes. | |
| 168 | + /// | |
| 169 | + /// Plain divs, like every control here: nothing in it takes focus, so the | |
| 170 | + /// root is still the one reading the keyboard -- which is exactly what a | |
| 171 | + /// waiting row depends on. | |
| 172 | + pub(crate) fn keys_overlay(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> { | |
| 173 | + if !self.keys_open { | |
| 174 | + return None; | |
| 175 | + } | |
| 176 | + // The way out, spelled the way the rows spell a chord. | |
| 177 | + let out = keymap::Chord { | |
| 178 | + key: ESCAPE.to_string(), | |
| 179 | + ctrl: false, | |
| 180 | + } | |
| 181 | + .pretty(); | |
| 182 | + // Every action there is, under its heading, and the strokes the modal | |
| 183 | + // cards answer to beside them -- `keys_rows` is the whole of the order | |
| 184 | + // and every word in it comes off the registry. | |
| 185 | + // | |
| 186 | + // A row is two targets, not one: its label *does* the action, which is | |
| 187 | + // the pointer's way to the ones no button carries, and its stroke | |
| 188 | + // changes that stroke. An action with two strokes reads as one line | |
| 189 | + // ("x or delete") and a rebind replaces that whole set. | |
| 190 | + let mut rows: Vec<AnyElement> = Vec::new(); | |
| 191 | + let row = || { | |
| 192 | + div() | |
| 193 | + .flex() | |
| 194 | + // The floor, not the height: a row that needed two lines | |
| 195 | + // would otherwise paint over the one under it -- which it did | |
| 196 | + // anyway until this said `flex_none`, a row inside a capped | |
| 197 | + // scrolling list being shrunk to fit by default (the export | |
| 198 | + // card's rows had the same shape and the same overlap). | |
| 199 | + .flex_none() | |
| 200 | + .min_h(px(KEYS_ROW_H)) | |
| 201 | + .items_center() | |
| 202 | + .justify_between() | |
| 203 | + .gap(px(12.)) | |
| 204 | + .px(px(6.)) | |
| 205 | + .rounded(px(3.)) | |
| 206 | + }; | |
| 207 | + let found = keys_filter(&self.keys_search, &self.keymap); | |
| 208 | + // What the search box says: the typed text, and how much of the list is | |
| 209 | + // left under it -- a filter that found nothing has to say so, or the | |
| 210 | + // card reads as a list that lost its rows. | |
| 211 | + let search = if self.keys_search.is_empty() { | |
| 212 | + "search: type to filter · ↑ ↓ scroll the list · a click away closes".to_string() | |
| 213 | + } else { | |
| 214 | + let rows = found | |
| 215 | + .iter() | |
| 216 | + .filter(|(_, r)| !matches!(r, KeyRow::Head(_))) | |
| 217 | + .count(); | |
| 218 | + match rows { | |
| 219 | + 0 => format!( | |
| 220 | + "search: {} — nothing matches · {out} clears", | |
| 221 | + self.keys_search | |
| 222 | + ), | |
| 223 | + n => format!("search: {} — {n} shown · {out} clears", self.keys_search), | |
| 224 | + } | |
| 225 | + }; | |
| 226 | + for (i, key_row) in found { | |
| 227 | + rows.push(match key_row { | |
| 228 | + KeyRow::Head(category) => div() | |
| 229 | + .flex_none() | |
| 230 | + .px(px(6.)) | |
| 231 | + .pt(px(4.)) | |
| 232 | + .text_size(px(11.)) | |
| 233 | + .text_color(rgb(FG_SECONDARY)) | |
| 234 | + .child(category.label()) | |
| 235 | + .into_any_element(), | |
| 236 | + KeyRow::Act(action) => { | |
| 237 | + let capturing = self.rebinding == Some(action); | |
| 238 | + // Why the label half will not answer, if it will not: the | |
| 239 | + // registry's one answer, the same the clip menu dims by. | |
| 240 | + let refusal = self.enable(action, None); | |
| 241 | + let out = out.clone(); | |
| 242 | + row() | |
| 243 | + .when(capturing, |d| d.bg(rgb(BG_SELECTED))) | |
| 244 | + .child( | |
| 245 | + div() | |
| 246 | + .id(("do", i)) | |
| 247 | + .flex_1() | |
| 248 | + .min_w(px(0.)) | |
| 249 | + .flex() | |
| 250 | + .min_h(px(KEYS_ROW_H)) | |
| 251 | + .items_center() | |
| 252 | + // One line, cut where the stroke's column | |
| 253 | + // starts: a label longer than the room it has | |
| 254 | + // printed straight over the stroke beside it, | |
| 255 | + // and two overprinted words are less readable | |
| 256 | + // than one truncated one. | |
| 257 | + .truncate() | |
| 258 | + .child(action.label()) | |
| 259 | + // The reason rides on the label rather than in | |
| 260 | + // the stroke column, which the rebind half | |
| 261 | + // needs whatever the editor's state is: an | |
| 262 | + // action nobody can ask for right now is still | |
| 263 | + // one whose key may be changed. | |
| 264 | + .when_some(refusal.why(), |d, why| { | |
| 265 | + let why: SharedString = why.into(); | |
| 266 | + d.tooltip(move |_, cx| cx.new(|_| Tip(why.clone())).into()) | |
| 267 | + }) | |
| 268 | + .when(!refusal.yes(), |d| d.opacity(0.4).cursor_not_allowed()) | |
| 269 | + .when(refusal.yes(), |d| { | |
| 270 | + d.cursor_pointer().hover(|s| s.bg(rgb(BG_HOVER))).on_click( | |
| 271 | + cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 272 | + // The card goes first: several of | |
| 273 | + // these open a card of their own, | |
| 274 | + // and every edit moves the indices | |
| 275 | + // the menus are holding. | |
| 276 | + this.keys_open = false; | |
| 277 | + this.rebinding = None; | |
| 278 | + this.act(action, cx); | |
| 279 | + cx.notify(); | |
| 280 | + }), | |
| 281 | + ) | |
| 282 | + }), | |
| 283 | + ) | |
| 284 | + .child( | |
| 285 | + // ponytail: the column is as wide as the stroke it | |
| 286 | + // prints, so a one-character chord gives this half a | |
| 287 | + // hit area under the 24px WCAG 2.5.8 floor -- tall | |
| 288 | + // enough, narrow. Upgrade: a min_w of HIT_MIN here. | |
| 289 | + div() | |
| 290 | + .id(("bind", i)) | |
| 291 | + .flex_none() | |
| 292 | + .flex() | |
| 293 | + .min_h(px(KEYS_ROW_H)) | |
| 294 | + .items_center() | |
| 295 | + .cursor_pointer() | |
| 296 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 297 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 298 | + this.rebinding = Some(action); | |
| 299 | + cx.notify(); | |
| 300 | + })) | |
| 301 | + .child(if capturing { | |
| 302 | + div() | |
| 303 | + .text_color(rgb(FG_SECONDARY)) | |
| 304 | + .child(format!("press a key — {out} cancels")) | |
| 305 | + } else { | |
| 306 | + div().child(self.keymap.display(action)) | |
| 307 | + }), | |
| 308 | + ) | |
| 309 | + .into_any_element() | |
| 310 | + } | |
| 311 | + KeyRow::Fixed(f) => { | |
| 312 | + let f = &keymap::FIXED[f]; | |
| 313 | + row() | |
| 314 | + .child(f.label) | |
| 315 | + // Dim, and no hover: this one is not a row you can click. | |
| 316 | + .child(div().text_color(rgb(FG_SECONDARY)).child(f.chord.clone())) | |
| 317 | + .into_any_element() | |
| 318 | + } | |
| 319 | + }); | |
| 320 | + } | |
| 321 | + Some( | |
| 322 | + scrim() | |
| 323 | + .flex() | |
| 324 | + .justify_center() | |
| 325 | + .items_center() | |
| 326 | + // The picture behind is out of reach, and looks it. The press is | |
| 327 | + // swallowed here so a button under the scrim cannot take it -- | |
| 328 | + // and it closes the card on the way, which is the pointer's exit | |
| 329 | + // from every card here ([`Player::close_card`]). | |
| 330 | + .bg(rgba(SCRIM)) | |
| 331 | + .on_mouse_down( | |
| 332 | + MouseButton::Left, | |
| 333 | + cx.listener(|this, _: &MouseDownEvent, _, cx| { | |
| 334 | + this.close_card(); | |
| 335 | + cx.notify(); | |
| 336 | + cx.stop_propagation(); | |
| 337 | + }), | |
| 338 | + ) | |
| 339 | + .child( | |
| 340 | + div() | |
| 341 | + .w(px(KEYS_W)) | |
| 342 | + .on_mouse_down(MouseButton::Left, swallow) | |
| 343 | + .flex() | |
| 344 | + .flex_col() | |
| 345 | + .gap(px(2.)) | |
| 346 | + .p(px(12.)) | |
| 347 | + .rounded(px(6.)) | |
| 348 | + .bg(rgb(BG_RAISED)) | |
| 349 | + // Title and instruction are two children, never one | |
| 350 | + // wrapping line: a fixed-height slot whose text wrapped | |
| 351 | + // painted its second line over the first row. | |
| 352 | + .child(div().flex_none().px(px(6.)).child("Actions & keys")) | |
| 353 | + // One status line, under the title where the eye starts. | |
| 354 | + // A refusal takes it over -- it is the more urgent of the | |
| 355 | + // two, and the notice bar it would otherwise appear in is | |
| 356 | + // under the scrim. | |
| 357 | + // | |
| 358 | + // The row list below is capped and scrolls, so neither a | |
| 359 | + // wrapped refusal here nor another action added to `ALL` | |
| 360 | + // can push the card past a 360 px window any more. | |
| 361 | + .child( | |
| 362 | + div() | |
| 363 | + .flex_none() | |
| 364 | + .px(px(6.)) | |
| 365 | + .text_size(px(11.)) | |
| 366 | + .text_color(rgb(FG_SECONDARY)) | |
| 367 | + .child( | |
| 368 | + self.notice | |
| 369 | + .clone() | |
| 370 | + .unwrap_or_else(|| { | |
| 371 | + "click an action to do it · click its key to change it" | |
| 372 | + .into() | |
| 373 | + }), | |
| 374 | + ), | |
| 375 | + ) | |
| 376 | + // The search box: no focus and no text field -- the | |
| 377 | + // card's key handler is the field, exactly as the | |
| 378 | + // export card's bitrate is typed into it. Its own line | |
| 379 | + // above the list, so the rows below it are always the | |
| 380 | + // answer to what it says. | |
| 381 | + .child( | |
| 382 | + div() | |
| 383 | + .flex_none() | |
| 384 | + .px(px(6.)) | |
| 385 | + .text_size(px(11.)) | |
| 386 | + .text_color(rgb(FG_SECONDARY)) | |
| 387 | + .child(search), | |
| 388 | + ) | |
| 389 | + // Capped and scrolling rather than as tall as the action | |
| 390 | + // list happens to be: the list grows with the editor, | |
| 391 | + // the smallest window does not. | |
| 392 | + .child( | |
| 393 | + div() | |
| 394 | + .id("keys-rows") | |
| 395 | + .flex() | |
| 396 | + .flex_col() | |
| 397 | + .gap(px(2.)) | |
| 398 | + .max_h(px(KEYS_ROWS_H)) | |
| 399 | + // The line the list scrolls under: a row half | |
| 400 | + // out of the viewport sat against the search | |
| 401 | + // line with nothing between them, and read as a | |
| 402 | + // row painted over the heading rather than as a | |
| 403 | + // list with more above it. | |
| 404 | + .mt(px(4.)) | |
| 405 | + .border_t_1() | |
| 406 | + .border_color(rgb(BG_PANEL)) | |
| 407 | + .pt(px(4.)) | |
| 408 | + .overflow_y_scroll() | |
| 409 | + // The wheel's offset and the arrow keys' are | |
| 410 | + // the same one, so the two cannot disagree | |
| 411 | + // about where the list is. | |
| 412 | + .track_scroll(&self.keys_scroll) | |
| 413 | + .children(rows), | |
| 414 | + ), | |
| 415 | + ), | |
| 416 | + ) | |
| 417 | + } | |
| 418 | + | |
| 419 | + /// The menu a right-click on a clip opens: what that clip can be given, | |
| 420 | + /// each item beside the stroke that does the very same thing, and a | |
| 421 | + /// turn-over side that says what the clip *is*. An item that would do | |
| 422 | + /// nothing where the playhead is standing is dimmed and takes no click | |
| 423 | + /// rather than disappearing, so the menu reads the same every time. | |
| 424 | + /// | |
| 425 | + /// Every item goes through [`Player::act`], the table the key handler uses: | |
| 426 | + /// an item is its stroke, asked for with the mouse. Plain divs like the | |
| 427 | + /// rest of this window, so the root keeps the keyboard and escape still | |
| 428 | + /// reaches the handler that closes this. | |
| 429 | + pub(crate) fn context_card( | |
| 430 | + &self, | |
| 431 | + viewport: Size<Pixels>, | |
| 432 | + cx: &mut Context<Self>, | |
| 433 | + ) -> Option<impl IntoElement> { | |
| 434 | + let menu = self.context_menu?; | |
| 435 | + let session = self.session.as_ref()?; | |
| 436 | + let clip = *session.lane_clips(menu.lane).get(menu.idx)?; | |
| 437 | + let source = session.sources().get(clip.source).cloned()?; | |
| 438 | + let secs = |frames: u32| timecode(f64::from(frames) / self.fps, self.fps); | |
| 439 | + let row = |n: usize| { | |
| 440 | + div() | |
| 441 | + .id(("menu", n)) | |
| 442 | + .flex() | |
| 443 | + // The floor, not the height: a long label wrapping must not | |
| 444 | + // paint over the item under it. | |
| 445 | + .min_h(px(MENU_ROW_H)) | |
| 446 | + .items_center() | |
| 447 | + .justify_between() | |
| 448 | + .gap(px(12.)) | |
| 449 | + .px(px(6.)) | |
| 450 | + .rounded(px(3.)) | |
| 451 | + }; | |
| 452 | + let mut rows: Vec<AnyElement> = Vec::new(); | |
| 453 | + if menu.details { | |
| 454 | + // Read-only, so no ids and no hover: this side is a card, not a | |
| 455 | + // list of things to click. Each value is one truncated line, which | |
| 456 | + // is what keeps the height below the one the clamp was given. | |
| 457 | + for (label, value) in [ | |
| 458 | + ("File", file_name(&source.path)), | |
| 459 | + ("Path", source.path.display().to_string()), | |
| 460 | + ( | |
| 461 | + "Source range", | |
| 462 | + format!("{} – {}", secs(clip.in_frame), secs(clip.out_frame)), | |
| 463 | + ), | |
| 464 | + // How long it is *where it sits*, which its rate decides -- and | |
| 465 | + // the rate itself beside it, because a clip half its source's | |
| 466 | + // length could be either a trim or a 2x. | |
| 467 | + ("This clip", secs(clip.frames())), | |
| 468 | + ("Speed", format!("{} (tape)", clip.speed)), | |
| 469 | + ("Source duration", secs(session.file_frames(&source.path))), | |
| 470 | + ( | |
| 471 | + "Bitrate", | |
| 472 | + bitrate_detail( | |
| 473 | + self.bitrates.get(&source.path).copied().flatten(), | |
| 474 | + self.streams.get(&source.path).map_or(0, Vec::len), | |
| 475 | + ), | |
| 476 | + ), | |
| 477 | + ] { | |
| 478 | + rows.push( | |
| 479 | + row(rows.len()) | |
| 480 | + .child(label) | |
| 481 | + .child( | |
| 482 | + div() | |
| 483 | + .min_w(px(0.)) | |
| 484 | + .truncate() | |
| 485 | + // A size smaller than the labels: a timecode | |
| 486 | + // pair is 25 characters and has to fit beside | |
| 487 | + // its label inside `MENU_W`. | |
| 488 | + .text_size(px(11.)) | |
| 489 | + .text_color(rgb(FG_SECONDARY)) | |
| 490 | + .child(value), | |
| 491 | + ) | |
| 492 | + .into_any_element(), | |
| 493 | + ); | |
| 494 | + } | |
| 495 | + } else { | |
| 496 | + // A grade on a waveform, an equalizer on a picture, a silence scan | |
| 497 | + // on a still: things that do not exist for what was right-clicked, | |
| 498 | + // so the menu is the list of what this clip can do rather than the | |
| 499 | + // registry with most of it struck through. One filter, in | |
| 500 | + // `menu_items`, so there is no second answer to keep in step. The | |
| 501 | + // state refusals below stay, dimmed and saying why -- the next | |
| 502 | + // click of the playhead lights them. | |
| 503 | + let ctx = self.ctx(Some((menu.lane, menu.idx))); | |
| 504 | + for action in menu_items(ctx) { | |
| 505 | + // The registry's own answer, the same one the actions card | |
| 506 | + // dims a row with -- and a row that takes no click says *why* | |
| 507 | + // rather than printing a stroke that would do nothing. | |
| 508 | + let refusal = enable(action, ctx); | |
| 509 | + let enabled = refusal.yes(); | |
| 510 | + // The one item that is not about this clip says so, and says it | |
| 511 | + // here rather than in the registry: the stroke is global too, | |
| 512 | + // but its row in the keys menu is not sitting on a clip. | |
| 513 | + let label = if matches!(action, ActionId::ToggleMute | ActionId::Paste) { | |
| 514 | + format!("{} (global)", action.label()) | |
| 515 | + } else { | |
| 516 | + action.label().to_string() | |
| 517 | + }; | |
| 518 | + rows.push( | |
| 519 | + row(rows.len()) | |
| 520 | + .child(label) | |
| 521 | + .child(match refusal.why() { | |
| 522 | + // One truncated line, like the details side: a | |
| 523 | + // reason that wrapped would make the card taller | |
| 524 | + // than the height `menu_at` placed it by. | |
| 525 | + Some(why) => div() | |
| 526 | + .min_w(px(0.)) | |
| 527 | + .truncate() | |
| 528 | + .text_size(px(11.)) | |
| 529 | + .text_color(rgb(FG_SECONDARY)) | |
| 530 | + .child(why), | |
| 531 | + None => div() | |
| 532 | + .text_color(rgb(FG_SECONDARY)) | |
| 533 | + .child(self.keymap.display(action)), | |
| 534 | + }) | |
| 535 | + .when(!enabled, |d| d.opacity(0.4).cursor_not_allowed()) | |
| 536 | + .when(enabled, |d| { | |
| 537 | + d.cursor_pointer() | |
| 538 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 539 | + .on_click(cx.listener(move |this, event: &ClickEvent, _, cx| { | |
| 540 | + // Closed first: the action moves the very | |
| 541 | + // indices this menu is holding. | |
| 542 | + this.context_menu = None; | |
| 543 | + // The one item that is a *choice* and not a | |
| 544 | + // doing: four policies, so the pointer gets | |
| 545 | + // the list of them on this clip rather than | |
| 546 | + // the next one stepped to behind the click. | |
| 547 | + // The stroke still steps -- same door. | |
| 548 | + if action == ActionId::Fit { | |
| 549 | + this.open_picker( | |
| 550 | + Pick::Fit(menu.lane, menu.idx), | |
| 551 | + event.position(), | |
| 552 | + cx, | |
| 553 | + ); | |
| 554 | + } else { | |
| 555 | + this.act(action, cx); | |
| 556 | + } | |
| 557 | + })) | |
| 558 | + }) | |
| 559 | + .into_any_element(), | |
| 560 | + ); | |
| 561 | + } | |
| 562 | + rows.push( | |
| 563 | + row(rows.len()) | |
| 564 | + .cursor_pointer() | |
| 565 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 566 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { | |
| 567 | + if let Some(menu) = &mut this.context_menu { | |
| 568 | + menu.details = true; | |
| 569 | + } | |
| 570 | + cx.notify(); | |
| 571 | + })) | |
| 572 | + .child("Properties") | |
| 573 | + // No stroke reaches this one, and a blank column would read | |
| 574 | + // as one that was forgotten. | |
| 575 | + .child(div().text_color(rgb(FG_SECONDARY)).child("…")) | |
| 576 | + .into_any_element(), | |
| 577 | + ); | |
| 578 | + } | |
| 579 | + // The height the card is *placed* by and the height its list is drawn | |
| 580 | + // to are one number: placed by a taller one, the card would hang off the | |
| 581 | + // window's floor -- the very thing the clamp is for. | |
| 582 | + let list_h = menu_rows_h(rows.len(), viewport); | |
| 583 | + let (x, y) = menu_at(menu.at, viewport, MENU_PAD * 2. + list_h); | |
| 584 | + let full: SharedString = source.path.display().to_string().into(); | |
| 585 | + Some( | |
| 586 | + scrim() | |
| 587 | + // Click away closes it, either button, and the press is | |
| 588 | + // swallowed so nothing under the menu also takes it. No tint, | |
| 589 | + // unlike the modal cards: the timeline this menu is about has | |
| 590 | + // to stay readable behind it. | |
| 591 | + .on_mouse_down( | |
| 592 | + MouseButton::Left, | |
| 593 | + cx.listener(|this, _: &MouseDownEvent, _, cx| { | |
| 594 | + this.context_menu = None; | |
| 595 | + cx.notify(); | |
| 596 | + cx.stop_propagation(); | |
| 597 | + }), | |
| 598 | + ) | |
| 599 | + .on_mouse_down( | |
| 600 | + MouseButton::Right, | |
| 601 | + cx.listener(|this, _: &MouseDownEvent, _, cx| { | |
| 602 | + this.context_menu = None; | |
| 603 | + cx.notify(); | |
| 604 | + cx.stop_propagation(); | |
| 605 | + }), | |
| 606 | + ) | |
| 607 | + .child( | |
| 608 | + div() | |
| 609 | + // Only so the details side can carry a tooltip, which | |
| 610 | + // gpui gives to identified elements alone. | |
| 611 | + .id("menu-card") | |
| 612 | + .absolute() | |
| 613 | + .left(px(x)) | |
| 614 | + .top(px(y)) | |
| 615 | + .w(px(MENU_W)) | |
| 616 | + .flex() | |
| 617 | + .flex_col() | |
| 618 | + .p(px(MENU_PAD)) | |
| 619 | + .rounded(px(6.)) | |
| 620 | + .bg(rgb(BG_RAISED)) | |
| 621 | + // Painted after the scrim, so this listener runs first | |
| 622 | + // (gpui bubbles mouse events in reverse, window.rs:3705) | |
| 623 | + // and a press meant for an item never closes the menu | |
| 624 | + // out from under its own click. | |
| 625 | + .on_mouse_down(MouseButton::Left, |_: &MouseDownEvent, _, cx| { | |
| 626 | + cx.stop_propagation() | |
| 627 | + }) | |
| 628 | + .on_mouse_down(MouseButton::Right, |_: &MouseDownEvent, _, cx| { | |
| 629 | + cx.stop_propagation() | |
| 630 | + }) | |
| 631 | + // The one value the details side has to truncate. | |
| 632 | + .when(menu.details, |d| { | |
| 633 | + d.tooltip(move |_, cx| cx.new(|_| Tip(full.clone())).into()) | |
| 634 | + }) | |
| 635 | + // The list scrolls where the card would otherwise grow | |
| 636 | + // past the window's floor -- an item hanging off the | |
| 637 | + // bottom edge is an item nobody can click. | |
| 638 | + .child( | |
| 639 | + div() | |
| 640 | + .id("menu-rows") | |
| 641 | + .flex() | |
| 642 | + .flex_col() | |
| 643 | + .max_h(px(list_h)) | |
| 644 | + .overflow_y_scroll() | |
| 645 | + .children(rows), | |
| 646 | + ), | |
| 647 | + ), | |
| 648 | + ) | |
| 649 | + } | |
| 650 | + | |
| 651 | + /// The open choice list: every value of one enumerated setting at once, the | |
| 652 | + /// one in force marked, and a click on any of them picks *that* one -- what | |
| 653 | + /// a button stepping one value on per click could never say. Built on the | |
| 654 | + /// clip menu's machinery down to the scrim, the placement and the scroll | |
| 655 | + /// cap, so it hangs and closes exactly as the menus do and fits the same | |
| 656 | + /// 640x360 floor. The stroke for the setting is untouched: this is the | |
| 657 | + /// pointer's door to it, not a second setting. | |
| 658 | + pub(crate) fn picker_card( | |
| 659 | + &self, | |
| 660 | + viewport: Size<Pixels>, | |
| 661 | + cx: &mut Context<Self>, | |
| 662 | + ) -> Option<impl IntoElement> { | |
| 663 | + let picker = self.picker?; | |
| 664 | + let rows: Vec<AnyElement> = self | |
| 665 | + .choices(picker.of) | |
| 666 | + .into_iter() | |
| 667 | + .enumerate() | |
| 668 | + .map(|(n, (choice, label, detail, picked))| { | |
| 669 | + div() | |
| 670 | + .id(("picker-row", n)) | |
| 671 | + .flex() | |
| 672 | + // The floor, not the height, and `HIT_MIN` of it: a row of a | |
| 673 | + // list is a click target like every other one here (WCAG | |
| 674 | + // 2.5.8). | |
| 675 | + .min_h(px(MENU_ROW_H)) | |
| 676 | + .items_center() | |
| 677 | + .justify_between() | |
| 678 | + .gap(px(12.)) | |
| 679 | + .px(px(6.)) | |
| 680 | + .rounded(px(3.)) | |
| 681 | + .cursor_pointer() | |
| 682 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 683 | + // The mark is a glyph as well as a highlight, like the | |
| 684 | + // export card's rows: a background alone is gone under a | |
| 685 | + // hover and invisible to anyone who cannot tell the two | |
| 686 | + // greys apart (WCAG 1.4.1). | |
| 687 | + .when(picked, |d| d.bg(rgb(BG_SELECTED))) | |
| 688 | + .child( | |
| 689 | + div() | |
| 690 | + .flex() | |
| 691 | + .flex_none() | |
| 692 | + .items_center() | |
| 693 | + .gap(px(8.)) | |
| 694 | + .child(div().w(px(10.)).child(match picked { | |
| 695 | + true => "✓", | |
| 696 | + false => " ", | |
| 697 | + })) | |
| 698 | + .child(label), | |
| 699 | + ) | |
| 700 | + .child( | |
| 701 | + div() | |
| 702 | + .min_w(px(0.)) | |
| 703 | + .truncate() | |
| 704 | + .text_size(px(11.)) | |
| 705 | + // On the picked row the dim ink sits on the | |
| 706 | + // highlight, where it is only 3.3:1 (WCAG 1.4.3). | |
| 707 | + .text_color(rgb(match picked { | |
| 708 | + true => FG_PRIMARY, | |
| 709 | + false => FG_SECONDARY, | |
| 710 | + })) | |
| 711 | + .child(detail), | |
| 712 | + ) | |
| 713 | + .on_click( | |
| 714 | + cx.listener(move |this, _: &ClickEvent, _, cx| this.choose(choice, cx)), | |
| 715 | + ) | |
| 716 | + .into_any_element() | |
| 717 | + }) | |
| 718 | + .collect(); | |
| 719 | + // The window's own room, and the list scrolls only where the window has | |
| 720 | + // none -- the clip menu's rule, one function for both. | |
| 721 | + let list_h = menu_rows_h(rows.len(), viewport); | |
| 722 | + let (x, y) = menu_at(picker.at, viewport, MENU_PAD * 2. + list_h); | |
| 723 | + Some( | |
| 724 | + scrim() | |
| 725 | + // Click away closes it, either button, swallowed so nothing | |
| 726 | + // under the list also takes the press -- the clip menu's rule. | |
| 727 | + .on_mouse_down( | |
| 728 | + MouseButton::Left, | |
| 729 | + cx.listener(|this, _: &MouseDownEvent, _, cx| { | |
| 730 | + this.picker = None; | |
| 731 | + cx.notify(); | |
| 732 | + cx.stop_propagation(); | |
| 733 | + }), | |
| 734 | + ) | |
| 735 | + .on_mouse_down( | |
| 736 | + MouseButton::Right, | |
| 737 | + cx.listener(|this, _: &MouseDownEvent, _, cx| { | |
| 738 | + this.picker = None; | |
| 739 | + cx.notify(); | |
| 740 | + cx.stop_propagation(); | |
| 741 | + }), | |
| 742 | + ) | |
| 743 | + .child( | |
| 744 | + div() | |
| 745 | + .id("picker-card") | |
| 746 | + .absolute() | |
| 747 | + .left(px(x)) | |
| 748 | + .top(px(y)) | |
| 749 | + .w(px(MENU_W)) | |
| 750 | + .flex() | |
| 751 | + .flex_col() | |
| 752 | + .p(px(MENU_PAD)) | |
| 753 | + .rounded(px(6.)) | |
| 754 | + .bg(rgb(BG_RAISED)) | |
| 755 | + // Painted after the scrim, so this listener runs first | |
| 756 | + // and a press meant for a row never closes the list out | |
| 757 | + // from under its own click (`context_card`). | |
| 758 | + .on_mouse_down(MouseButton::Left, |_: &MouseDownEvent, _, cx| { | |
| 759 | + cx.stop_propagation() | |
| 760 | + }) | |
| 761 | + .on_mouse_down(MouseButton::Right, |_: &MouseDownEvent, _, cx| { | |
| 762 | + cx.stop_propagation() | |
| 763 | + }) | |
| 764 | + .child( | |
| 765 | + div() | |
| 766 | + .id("picker-rows") | |
| 767 | + .flex() | |
| 768 | + .flex_col() | |
| 769 | + .max_h(px(list_h)) | |
| 770 | + .overflow_y_scroll() | |
| 771 | + .children(rows), | |
| 772 | + ), | |
| 773 | + ), | |
| 774 | + ) | |
| 775 | + } | |
| 776 | +} |
crates/app/src/ui/preview.rsadded+169 -0
| @@ -0,0 +1,169 @@ | ||
| 1 | +//! The picture: what is drawn over it and what is read off it. | |
| 2 | + | |
| 3 | +use crate::*; | |
| 4 | +use crate::ui::widgets::*; | |
| 5 | + | |
| 6 | +impl Player { | |
| 7 | + /// The cues of the picked track that are on screen at `at`, over the picture | |
| 8 | + /// and nothing else: bottom-centred where every player puts them, white on a | |
| 9 | + /// plate so the film underneath cannot swallow them, and each cue its own | |
| 10 | + /// plate so two at one moment stack rather than run together. | |
| 11 | + /// | |
| 12 | + /// `None` -- no element at all -- while the toggle is off, with no track | |
| 13 | + /// picked, and between cues: the picture is what this window is for, and a | |
| 14 | + /// permanent empty band across it would be in the way of exactly that. | |
| 15 | + /// | |
| 16 | + /// The cues are the *timeline's* ([`PlaybackSession::timeline_cues`]) and | |
| 17 | + /// not the track's own: on a cut timeline an embedded track's cues ride the | |
| 18 | + /// pictures they belong to, and this is the same map the export writes the | |
| 19 | + /// file with -- so what is read here is what the file says. | |
| 20 | + /// | |
| 21 | + /// A cue off a PGS track is a *picture* and not a line | |
| 22 | + /// ([`engine::subtitle::CueImage`]), and is drawn as one: the disc's whole | |
| 23 | + /// canvas fitted over the picture region exactly as the picture itself is, | |
| 24 | + /// which puts every cue where the disc put it relative to its own frame. | |
| 25 | + /// | |
| 26 | + /// ponytail: exact only while the canvas and the encode are the same shape | |
| 27 | + /// -- a 16:9 canvas over a 2.39:1 encode fits to the region's height and | |
| 28 | + /// the film to its width, so a cue sits a little low on a scope film. The | |
| 29 | + /// upgrade path is the picture's own rect, which wants `VideoMeta`'s aspect | |
| 30 | + /// and the measured bounds rather than the shared `Contain`. | |
| 31 | + pub(crate) fn subtitle_overlay( | |
| 32 | + &mut self, | |
| 33 | + at: f64, | |
| 34 | + window: &mut Window, | |
| 35 | + ) -> Option<impl IntoElement + use<>> { | |
| 36 | + // One way out, and it lets the drawn picture go on the way: the toggle | |
| 37 | + // going off, the file closing and the gap between two cues are the same | |
| 38 | + // "nothing on screen", and an 8 MB atlas tile may not survive any of | |
| 39 | + // them (an early return above this leaked one per toggle-off). | |
| 40 | + let mapped = match self.session.as_ref().filter(|_| self.subs_on) { | |
| 41 | + Some(session) => session.timeline_cues(self.sub_track), | |
| 42 | + None => Vec::new(), | |
| 43 | + }; | |
| 44 | + let cues = cues_at(&mapped, at); | |
| 45 | + if cues.is_empty() { | |
| 46 | + self.drop_sub_image(window); | |
| 47 | + return None; | |
| 48 | + } | |
| 49 | + // The first picture cue up, decoded once and kept: two bitmap cues at | |
| 50 | + // one moment is a thing PGS composes into one display set, so there is | |
| 51 | + // never a second picture to stack under the first. | |
| 52 | + let picture = cues | |
| 53 | + .iter() | |
| 54 | + .find_map(|cue| Some((cue.start_us, cue.image.as_ref()?))) | |
| 55 | + .and_then(|(start_us, image)| self.sub_picture(start_us, image, window)); | |
| 56 | + // A picture is fitted onto the whole region and a plate hangs off the | |
| 57 | + // bottom of it, and a track is one or the other -- so they are two | |
| 58 | + // shapes and not one with the parts switched off. | |
| 59 | + if let Some(image) = picture { | |
| 60 | + // A *flex* box with the canvas as its one growing item: a percentage | |
| 61 | + // size (`size_full`) inside an absolutely placed box has nothing to | |
| 62 | + // be a percentage of and lays the picture out to nothing, while a | |
| 63 | + // flex item is sized by the box itself. Fitted the way the picture | |
| 64 | + // above it is -- `Contain` over the same box -- so a canvas of the | |
| 65 | + // picture's own shape lands exactly on it. | |
| 66 | + return Some(div().absolute().inset_0().flex().child( | |
| 67 | + img(image).flex_1().h_full().object_fit(gpui::ObjectFit::Contain), | |
| 68 | + )); | |
| 69 | + } | |
| 70 | + Some( | |
| 71 | + div() | |
| 72 | + .absolute() | |
| 73 | + .left_0() | |
| 74 | + .right_0() | |
| 75 | + .bottom(px(SUB_BOTTOM)) | |
| 76 | + .flex() | |
| 77 | + .flex_col() | |
| 78 | + .items_center() | |
| 79 | + .gap(px(2.)) | |
| 80 | + // The plate takes no click: the picture behind it is still the | |
| 81 | + // drop target the whole window is. | |
| 82 | + .children(cues.into_iter().filter(|c| c.image.is_none()).map(|cue| { | |
| 83 | + div() | |
| 84 | + .max_w(relative(0.9)) | |
| 85 | + .px(px(6.)) | |
| 86 | + .rounded(px(3.)) | |
| 87 | + .bg(rgba(SUB_SHADE)) | |
| 88 | + .text_size(px(SUB_TEXT)) | |
| 89 | + .text_color(rgb(SUB_FG)) | |
| 90 | + .text_align(TextAlign::Center) | |
| 91 | + // A line of the cue is a line on screen: the break the | |
| 92 | + // parser kept is not whitespace to be re-flowed. What a | |
| 93 | + // *long* line does is wrap inside its own div, which is | |
| 94 | + // what the width cap above is for. | |
| 95 | + .children( | |
| 96 | + cue.text | |
| 97 | + .split('\n') | |
| 98 | + .map(|line| div().min_h(px(SUB_LINE_H)).child(line.to_string())), | |
| 99 | + ) | |
| 100 | + })), | |
| 101 | + ) | |
| 102 | + } | |
| 103 | + | |
| 104 | + /// The cue starting at `start_us` as a drawable picture, decoded on the | |
| 105 | + /// first repaint it is up for and kept until another cue takes its place | |
| 106 | + /// ([`Player::sub_image`]). `None` for a display set the decoder refuses, | |
| 107 | + /// which draws nothing rather than failing the frame. | |
| 108 | + /// | |
| 109 | + /// Its atlas tile is released as the video's is: every [`RenderImage`] gets | |
| 110 | + /// a fresh id and its own tile, so a film's worth of cues would grow the | |
| 111 | + /// sprite atlas by the whole film. | |
| 112 | + pub(crate) fn sub_picture( | |
| 113 | + &mut self, | |
| 114 | + start_us: i64, | |
| 115 | + image: &engine::subtitle::CueImage, | |
| 116 | + window: &mut Window, | |
| 117 | + ) -> Option<Arc<RenderImage>> { | |
| 118 | + let key = (self.sub_track, start_us); | |
| 119 | + if let Some((up, ready)) = &self.sub_image | |
| 120 | + && *up == key | |
| 121 | + { | |
| 122 | + return Some(ready.clone()); | |
| 123 | + } | |
| 124 | + let mut rgba = image.rgba()?; | |
| 125 | + // gpui's atlas is BGRA with straight alpha; PGS decodes to RGBA with | |
| 126 | + // straight alpha. The same swap the video frames get. | |
| 127 | + for pixel in rgba.chunks_exact_mut(4) { | |
| 128 | + pixel.swap(0, 2); | |
| 129 | + } | |
| 130 | + let buf = image::RgbaImage::from_raw(image.width, image.height, rgba)?; | |
| 131 | + let next = Arc::new(RenderImage::new(vec![image::Frame::new(buf)])); | |
| 132 | + self.drop_sub_image(window); | |
| 133 | + self.sub_image = Some((key, next.clone())); | |
| 134 | + Some(next) | |
| 135 | + } | |
| 136 | + | |
| 137 | + /// Lets go of the drawn cue and its atlas tile. Called where the cue stops | |
| 138 | + /// being on screen, which is every gap between two of them: an 8 MB tile | |
| 139 | + /// per cue is not a thing to leave behind a film. | |
| 140 | + pub(crate) fn drop_sub_image(&mut self, window: &mut Window) { | |
| 141 | + if let Some((_, old)) = self.sub_image.take() { | |
| 142 | + let _ = window.drop_image(old); | |
| 143 | + } | |
| 144 | + } | |
| 145 | + | |
| 146 | + /// What is decoding the picture right now, for the transport line: the | |
| 147 | + /// backend is the running worker's own (it is written where a hardware | |
| 148 | + /// session falls back to software, so this follows reality), and the codec | |
| 149 | + /// comes from the clip under the playhead. Empty when nothing is playing -- | |
| 150 | + /// the question is about what is happening, not about what would. | |
| 151 | + pub(crate) fn live_decode(&self, position: f64, playing: bool) -> String { | |
| 152 | + let Some(session) = self.session.as_ref().filter(|_| playing) else { | |
| 153 | + return String::new(); | |
| 154 | + }; | |
| 155 | + let backend = session.decode_backend(); | |
| 156 | + let codec = session | |
| 157 | + .video_clip_at(position) | |
| 158 | + .and_then(|(lane, idx)| session.lane_clips(lane).get(idx).map(|clip| clip.source)) | |
| 159 | + .and_then(|source| session.sources().get(source)) | |
| 160 | + .and_then(|source| self.decoders.get(&source.path).copied().flatten()) | |
| 161 | + .and_then(|(codec, _)| codec); | |
| 162 | + match backend { | |
| 163 | + // Neither is a decode, and saying "SW" of them would be a lie. | |
| 164 | + Backend::Gap => "gap · nothing to decode".to_string(), | |
| 165 | + Backend::Still => "still · one decode, held".to_string(), | |
| 166 | + _ => format!("{} decode", decode_label(codec, backend)), | |
| 167 | + } | |
| 168 | + } | |
| 169 | +} |
crates/app/src/ui/theme.rsadded+119 -0
| @@ -0,0 +1,119 @@ | ||
| 1 | +//! The one place this editor knows a colour. | |
| 2 | +//! | |
| 3 | +//! Every paint in every region reads a token from this table and nothing else: | |
| 4 | +//! a `0x` literal anywhere but this file is the bug the whole redesign is about | |
| 5 | +//! (`no_colour_is_written_outside_the_theme` is the guard). Names say the | |
| 6 | +//! *role*, never the shade -- `bg/panel`, not "the dark grey" -- so the palette | |
| 7 | +//! can be swapped whole without touching a single element. | |
| 8 | +//! | |
| 9 | +//! Family B: near-black ground, cool neutral chrome, one cyan accent, with the | |
| 10 | +//! clip bodies carrying the cross-NLE kind convention (video blue, audio green, | |
| 11 | +//! image teal, text purple) instead of four greys that differ by a hair. | |
| 12 | + | |
| 13 | +use engine::project::LaneKind; | |
| 14 | + | |
| 15 | +// -- surfaces ----------------------------------------------------------------- | |
| 16 | +/// The app's base, and the bed a picture is letterboxed against: darker than | |
| 17 | +/// every panel, so the picture is what the eye lands on. | |
| 18 | +pub const BG_CANVAS: u32 = 0x0b0d10; | |
| 19 | +/// The library, the inspector, the toolbar: the chrome the work sits between. | |
| 20 | +pub const BG_PANEL: u32 = 0x151a21; | |
| 21 | +/// Buttons, menu bodies, cards -- one plane up from the panel. Flat: the | |
| 22 | +/// separation is colour, never a shadow. | |
| 23 | +pub const BG_RAISED: u32 = 0x212936; | |
| 24 | +/// The lane bed, darker than the panel so a clip reads as an object on it. | |
| 25 | +pub const BG_TIMELINE: u32 = 0x0e1218; | |
| 26 | +/// One step lighter than whatever it sits on: the pointer's answer that this is | |
| 27 | +/// clickable. | |
| 28 | +pub const BG_HOVER: u32 = 0x2f3a4a; | |
| 29 | +/// The same answer for the things that stand on the panel rather than on a | |
| 30 | +/// button. | |
| 31 | +pub const BG_HOVER_DIM: u32 = 0x1d2531; | |
| 32 | +/// A picked row, a picked clip: the accent at surface brightness, so a | |
| 33 | +/// selection is tinted rather than lit up. | |
| 34 | +pub const BG_SELECTED: u32 = 0x0d4b5c; | |
| 35 | +/// What a card is floated over when it is genuinely modal (the export, the | |
| 36 | +/// actions list). Inspector sections never draw one -- they occlude nothing. | |
| 37 | +pub const SCRIM: u32 = 0x0b0d10cc; | |
| 38 | + | |
| 39 | +// -- strokes ------------------------------------------------------------------ | |
| 40 | +pub const STROKE_DIVIDER: u32 = 0x2a3442; | |
| 41 | +/// The keyboard's own ring, distinct from selection on purpose: focus is where | |
| 42 | +/// the next stroke lands, selection is what an edit acts on. | |
| 43 | +pub const STROKE_FOCUS: u32 = 0xffd166; | |
| 44 | +pub const STROKE_SELECTED: u32 = 0x22d3ee; | |
| 45 | + | |
| 46 | +// -- text --------------------------------------------------------------------- | |
| 47 | +pub const FG_PRIMARY: u32 = 0xe9eff7; | |
| 48 | +/// Shortcuts, dismissal hints, detail lines. Past 4.5:1 on every surface above. | |
| 49 | +pub const FG_SECONDARY: u32 = 0xa7b6c9; | |
| 50 | +pub const FG_DISABLED: u32 = 0x6c7a8b; | |
| 51 | + | |
| 52 | +// -- interaction -------------------------------------------------------------- | |
| 53 | +pub const ACCENT_PRIMARY: u32 = 0x22d3ee; | |
| 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. | |
| 56 | +pub const ACCENT_PLAYHEAD: u32 = 0xff4d6d; | |
| 57 | +/// The accent as a translucent wash, for the marks drawn over a clip body. | |
| 58 | +pub const ACCENT_WASH: u32 = 0x22d3eeaa; | |
| 59 | + | |
| 60 | +// -- clip kinds (cross-NLE convention) ---------------------------------------- | |
| 61 | +pub const CLIP_VIDEO: u32 = 0x2b5fa8; | |
| 62 | +pub const CLIP_AUDIO: u32 = 0x276b43; | |
| 63 | +pub const CLIP_IMAGE: u32 = 0x1a6a6a; | |
| 64 | +pub const CLIP_TEXT: u32 = 0x6b46c1; | |
| 65 | + | |
| 66 | +/// What a clip on `kind` is painted: the timeline's whole colour language in | |
| 67 | +/// one call, so a lane added later cannot invent a shade of its own. | |
| 68 | +pub const fn clip_kind(kind: LaneKind, image: bool) -> u32 { | |
| 69 | + match kind { | |
| 70 | + LaneKind::Audio => CLIP_AUDIO, | |
| 71 | + LaneKind::Video if image => CLIP_IMAGE, | |
| 72 | + LaneKind::Video => CLIP_VIDEO, | |
| 73 | + } | |
| 74 | +} | |
| 75 | + | |
| 76 | +/// One per source, so a clip that came from an imported file reads as coming | |
| 77 | +/// from somewhere else than its neighbour. The *kind* is the body colour now | |
| 78 | +/// ([`clip_kind`]); this is the identity stripe and the library swatch, and it | |
| 79 | +/// only has to be four things telling each other apart. | |
| 80 | +pub const SOURCE_TINTS: [u32; 4] = [0x4f8fd6, 0xd69a4f, 0x4fd6a8, 0xb14fd6]; | |
| 81 | + | |
| 82 | +// -- feedback ----------------------------------------------------------------- | |
| 83 | +pub const STATUS_ERROR: u32 = 0xef4444; | |
| 84 | +pub const STATUS_WARNING: u32 = 0xf59e0b; | |
| 85 | +pub const STATUS_SUCCESS: u32 = 0x34d399; | |
| 86 | +pub const STATUS_PROGRESS: u32 = ACCENT_PRIMARY; | |
| 87 | +/// The mirror of [`BG_SELECTED`]: a drop the lane will not take, tinting the | |
| 88 | +/// shadow the drag draws so a refusal is seen before the release. | |
| 89 | +pub const DROP_REFUSE: u32 = 0x8f2740; | |
| 90 | +/// How solid that shadow is (`0xRRGGBBAA`): enough to read as a box, little | |
| 91 | +/// enough that the clip under it is still legible. | |
| 92 | +pub const GHOST_ALPHA: u32 = 0x66; | |
| 93 | + | |
| 94 | +// -- subtitles (drawn over the picture, so they own their own contrast) -------- | |
| 95 | +pub const SUB_FG: u32 = 0xffffff; | |
| 96 | +pub const SUB_SHADE: u32 = 0x000000cc; | |
| 97 | + | |
| 98 | +// -- the equalizer graph and the histogram ------------------------------------ | |
| 99 | +pub const EQ_GRID: u32 = 0x2a3442; | |
| 100 | +pub const EQ_SPECTRUM_INK: u32 = 0x7f95ad66; | |
| 101 | +pub const EQ_FILL_INK: u32 = 0x22d3ee26; | |
| 102 | +pub const EQ_BELL_INK: u32 = 0x22d3ee66; | |
| 103 | +pub const HIST_INK: [u32; 3] = [0xE0_5A_5A, 0x5A_D0_7A, 0x5A_9A_E0]; | |
| 104 | + | |
| 105 | +// -- geometry the four regions are laid out on -------------------------------- | |
| 106 | +/// Compact density: 11-13 px text, 28 px controls, 8 px gutters. The floor the | |
| 107 | +/// whole window is measured at is 640x360, and airy spacing loses a region. | |
| 108 | +pub const INSPECTOR_MIN_W: f32 = 208.; | |
| 109 | +pub const INSPECTOR_MAX_W: f32 = 320.; | |
| 110 | +pub const INSPECTOR_FRAC: f32 = 0.24; | |
| 111 | + | |
| 112 | +/// The inspector's width at this window width, on the library's own rule: a | |
| 113 | +/// share of the window, clamped so the picture keeps the middle at every size. | |
| 114 | +pub fn inspector_w(window_w: f32) -> f32 { | |
| 115 | + (window_w * INSPECTOR_FRAC).clamp(INSPECTOR_MIN_W, INSPECTOR_MAX_W) | |
| 116 | +} | |
| 117 | +/// The lighter scrim: the picker list floats over a card that is still being | |
| 118 | +/// read, so it dims rather than hides. | |
| 119 | +pub const SCRIM_LIGHT: u32 = 0x0b0d1055; |
crates/app/src/ui/timeline.rsadded+1645 -0
| @@ -0,0 +1,1645 @@ | ||
| 1 | +//! The bottom region: the ruler, the lanes and the subtitle strip. | |
| 2 | + | |
| 3 | +use crate::*; | |
| 4 | +use crate::ui::widgets::*; | |
| 5 | + | |
| 6 | +impl Player { | |
| 7 | + /// Transport, edit and file buttons, timecode, playhead, clips lane. | |
| 8 | + pub(crate) fn panel( | |
| 9 | + &self, | |
| 10 | + position: f64, | |
| 11 | + duration: f64, | |
| 12 | + state: Transport, | |
| 13 | + cx: &mut Context<Self>, | |
| 14 | + ) -> impl IntoElement { | |
| 15 | + // Where the playhead is *on the bed*, in pixels from its left edge. | |
| 16 | + // Clamped to the bed because it is drawn as a width as well as an | |
| 17 | + // offset, and the view follows the playhead anyway, so it is never off | |
| 18 | + // the bed for long. | |
| 19 | + let bed_w = f32::from(self.ruler.get().size.width); | |
| 20 | + let filled = self.scale.px_at(position).clamp(0., bed_w); | |
| 21 | + // An export owns the hint slot and the ruler while it runs: the | |
| 22 | + // percentage and the accent bar are the same number, so the playhead | |
| 23 | + // fill doubles as the progress bar for free. | |
| 24 | + 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); | |
| 33 | + // 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. | |
| 35 | + let lanes = self | |
| 36 | + .session | |
| 37 | + .as_ref() | |
| 38 | + .map_or_else(|| vec![Lane::V1, Lane::A1], PlaybackSession::lanes); | |
| 39 | + // A loop rather than a `map`: each row takes `cx` in turn, where a | |
| 40 | + // closure would hold it for as long as the iterator lives. | |
| 41 | + let mut rows = Vec::new(); | |
| 42 | + for &lane in &lanes { | |
| 43 | + rows.push(self.lane_row(lane, filled, cx)); | |
| 44 | + } | |
| 45 | + // Built from the same playhead pixel the lanes are, and before the | |
| 46 | + // export takes `filled` over below: the strip is a picture of the | |
| 47 | + // timeline, not of an export's progress. | |
| 48 | + let strip = self.subtitle_strip(filled); | |
| 49 | + let strip_h = subtitle_strip_h(strip.is_some()); | |
| 50 | + let (hint, filled) = if let Some(export) = self.exporting() { | |
| 51 | + let progress = export.progress(); | |
| 52 | + let elapsed = self | |
| 53 | + .export_started | |
| 54 | + .map_or(0., |t| t.elapsed().as_secs_f32()); | |
| 55 | + // Two numbers that must both be honest: the one that counts up is | |
| 56 | + // measured, the one that counts down is a guess and says so. | |
| 57 | + let left = eta_secs(&self.export_marks, elapsed, progress).map_or_else( | |
| 58 | + || "estimating…".to_owned(), | |
| 59 | + |s| format!("~{} left", clock(s)), | |
| 60 | + ); | |
| 61 | + ( | |
| 62 | + format!( | |
| 63 | + // Clocks, then the way out, then what is encoding: at the | |
| 64 | + // 640 px floor the tail is what truncation eats, and the | |
| 65 | + // codec pair is the one part of this line the card already | |
| 66 | + // said. The escape must not be what goes missing. | |
| 67 | + "EXPORTING {}% · {} elapsed · {left} — {} cancels · {} · {}", | |
| 68 | + (progress * 100.) as u32, | |
| 69 | + clock(elapsed), | |
| 70 | + key(ActionId::CancelExport), | |
| 71 | + // The row that was picked; the engine's line below names the | |
| 72 | + // seats alone, since the library is what identifies a codec. | |
| 73 | + format_label(self.format), | |
| 74 | + // What the worker actually opened, so a fallback to the | |
| 75 | + // software encoder shows here rather than being invisible. | |
| 76 | + export | |
| 77 | + .encoders() | |
| 78 | + .unwrap_or_else(|| "opening the encoder".to_string()), | |
| 79 | + ), | |
| 80 | + progress, | |
| 81 | + ) | |
| 82 | + } else { | |
| 83 | + // The strokes no button carries; the rest ride on the buttons' | |
| 84 | + // tooltips. Keys first: at a 640 px window the tail is what a | |
| 85 | + // truncation eats, and the two hints at the end are also on the | |
| 86 | + // ruler's and Import's tooltips. | |
| 87 | + // While it plays, what is decoding it goes first: it is the | |
| 88 | + // answer that changes as the playhead crosses a cut, and the tail | |
| 89 | + // of this line is what a narrow window truncates. | |
| 90 | + ( | |
| 91 | + join_detail( | |
| 92 | + &self.live_decode(position, state.is_playing()), | |
| 93 | + &format!( | |
| 94 | + "{} copy · {} paste · {} undo · click the bar to seek · drop a file to \ | |
| 95 | + import", | |
| 96 | + key(ActionId::Copy), | |
| 97 | + key(ActionId::Paste), | |
| 98 | + key(ActionId::Undo) | |
| 99 | + ), | |
| 100 | + ), | |
| 101 | + filled, | |
| 102 | + ) | |
| 103 | + }; | |
| 104 | + div() | |
| 105 | + .flex_none() | |
| 106 | + .h(px(panel_h(lanes.len()) + strip_h)) | |
| 107 | + .flex() | |
| 108 | + .flex_col() | |
| 109 | + .gap(px(8.)) | |
| 110 | + .px(px(12.)) | |
| 111 | + .py(px(8.)) | |
| 112 | + .bg(rgb(BG_PANEL)) | |
| 113 | + // Transport | edit | file: three groups, so the eye can skip two of | |
| 114 | + // them. Every button says what it does; the tooltip adds its key. | |
| 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( | |
| 540 | + div() | |
| 541 | + .flex_none() | |
| 542 | + .flex() | |
| 543 | + .items_center() | |
| 544 | + .gap(px(12.)) | |
| 545 | + // Fixed width and one line: changing digits must not push | |
| 546 | + // the row around, nor wrap and change its height. | |
| 547 | + // The timeline's own length, never the drawn one: a tail | |
| 548 | + // being dragged inflates the bed to the room that edge has | |
| 549 | + // ([`Player::drawn_duration`]), and for a still that room is | |
| 550 | + // ten minutes -- a total that jumped to 10:00:00 the moment | |
| 551 | + // a picture's edge was pressed, and back on release. | |
| 552 | + .child(div().flex_none().w(px(TIME_W)).truncate().child(format!( | |
| 553 | + "{} / {}", | |
| 554 | + timecode(position, self.fps), | |
| 555 | + timecode( | |
| 556 | + self.session | |
| 557 | + .as_ref() | |
| 558 | + .map_or(0., PlaybackSession::timeline_duration), | |
| 559 | + self.fps | |
| 560 | + ) | |
| 561 | + ))) | |
| 562 | + .child( | |
| 563 | + div() | |
| 564 | + .flex_1() | |
| 565 | + .min_w(px(0.)) | |
| 566 | + .truncate() | |
| 567 | + .text_size(px(11.)) | |
| 568 | + .text_color(rgb(FG_SECONDARY)) | |
| 569 | + .child(hint), | |
| 570 | + ), | |
| 571 | + ) | |
| 572 | + // Press to seek, drag to scrub: the move and release halves live on | |
| 573 | + // the root, since the pointer leaves the bar immediately. The bar | |
| 574 | + // stays 6 px to look at; the strip that takes the click is 24, so | |
| 575 | + // it can be hit without aiming (WCAG 2.5.8). | |
| 576 | + .child( | |
| 577 | + div() | |
| 578 | + .flex_none() | |
| 579 | + .flex() | |
| 580 | + .gap(px(HEADER_GAP)) | |
| 581 | + // The lanes' header column, empty here: the ruler's own bar | |
| 582 | + // has to start where their beds start, or the playhead | |
| 583 | + // would point at a different moment in each row. | |
| 584 | + .child(div().flex_none().w(px(HEADER_W))) | |
| 585 | + .child( | |
| 586 | + div() | |
| 587 | + .id("ruler") | |
| 588 | + .flex_1() | |
| 589 | + .min_w(px(0.)) | |
| 590 | + .h(px(RULER_HIT_H)) | |
| 591 | + .flex() | |
| 592 | + .flex_col() | |
| 593 | + .justify_center() | |
| 594 | + .rounded(px(3.)) | |
| 595 | + .cursor_pointer() | |
| 596 | + .hover(|s| s.bg(rgb(BG_HOVER_DIM))) | |
| 597 | + // The strip carries no text, so the tooltip is the only | |
| 598 | + // place it can say what it is. | |
| 599 | + .tooltip(|_, cx| { | |
| 600 | + cx.new(|_| Tip("Seek — click or drag; ctrl+wheel zooms".into())) | |
| 601 | + .into() | |
| 602 | + }) | |
| 603 | + // Ctrl+wheel is what every timeline zooms with, and | |
| 604 | + // the point held still is the one under the pointer | |
| 605 | + // rather than the playhead. Only with ctrl: a bare | |
| 606 | + // wheel here is the window's to scroll, and the | |
| 607 | + // controls row above scrolls on exactly that. | |
| 608 | + .on_scroll_wheel(cx.listener( | |
| 609 | + |this, event: &ScrollWheelEvent, _, cx| { | |
| 610 | + if !event.modifiers.control { | |
| 611 | + return; | |
| 612 | + } | |
| 613 | + let dy = match event.delta { | |
| 614 | + ScrollDelta::Lines(d) => d.y, | |
| 615 | + ScrollDelta::Pixels(d) => f32::from(d.y), | |
| 616 | + }; | |
| 617 | + if dy == 0. { | |
| 618 | + return; | |
| 619 | + } | |
| 620 | + let anchor = px_along(event.position.x, this.ruler.get()); | |
| 621 | + let factor = if dy > 0. { ZOOM_STEP } else { 1. / ZOOM_STEP }; | |
| 622 | + this.zoom(factor, Some(anchor), cx); | |
| 623 | + }, | |
| 624 | + )) | |
| 625 | + .on_mouse_down( | |
| 626 | + MouseButton::Left, | |
| 627 | + cx.listener(|this, event: &MouseDownEvent, _, cx| { | |
| 628 | + this.scrubbing = true; | |
| 629 | + this.scrub_to(event.position.x, true, cx); | |
| 630 | + }), | |
| 631 | + ) | |
| 632 | + .child( | |
| 633 | + div() | |
| 634 | + .w_full() | |
| 635 | + .h(px(6.)) | |
| 636 | + .rounded(px(3.)) | |
| 637 | + .bg(rgb(BG_RAISED)) | |
| 638 | + .child(bounds_probe(self.ruler.clone())) | |
| 639 | + .child( | |
| 640 | + div() | |
| 641 | + .h_full() | |
| 642 | + .w(px(filled)) | |
| 643 | + .rounded(px(3.)) | |
| 644 | + .bg(rgb(ACCENT_PRIMARY)), | |
| 645 | + ), | |
| 646 | + ), | |
| 647 | + ), | |
| 648 | + ) | |
| 649 | + // Every lane the project has, in its own order -- and its own | |
| 650 | + // column, so a project with more lanes than the panel is tall | |
| 651 | + // scrolls its tracks instead of pushing the picture off the window. | |
| 652 | + // The gap is the panel's own, so two lanes lay out exactly as they | |
| 653 | + // did when they were two children of it. | |
| 654 | + .child( | |
| 655 | + div() | |
| 656 | + .id("lanes") | |
| 657 | + .flex_none() | |
| 658 | + .flex() | |
| 659 | + .flex_col() | |
| 660 | + .gap(px(8.)) | |
| 661 | + .max_h(px(lanes_h(LANES_MAX))) | |
| 662 | + .overflow_y_scroll() | |
| 663 | + .children(rows), | |
| 664 | + ) | |
| 665 | + // Under the tracks and outside their scrolling column: a subtitle is | |
| 666 | + // not a track -- nothing can be dropped on it and nothing dragged | |
| 667 | + // along it -- and a strip that scrolled away with the sixth lane | |
| 668 | + // would be a strip nobody could see while editing. | |
| 669 | + .children(strip) | |
| 670 | + } | |
| 671 | + | |
| 672 | + /// The subtitle tracks this timeline holds, under the media list: one row | |
| 673 | + /// each, the picked one marked, and a click makes another one the picked one | |
| 674 | + /// -- which is the whole of choosing between the two tracks of a film. A row | |
| 675 | + /// per track and no cycle: three of them is an ordinary number for a remux, | |
| 676 | + /// and a key that steps through three is a key nobody can aim. | |
| 677 | + /// | |
| 678 | + /// A track that could not be read is *here*, greyed and saying why, exactly | |
| 679 | + /// as a media row the timeline cannot take is: PGS subtitles are pictures, | |
| 680 | + /// and a film carrying four of them says so instead of listing nothing. | |
| 681 | + /// | |
| 682 | + /// Every row names the file it came out of itself, in words and in the tint | |
| 683 | + /// that file's clips wear on the lanes -- but only where there is more than | |
| 684 | + /// one file to tell apart, the way [`row_name`] numbers audio streams only | |
| 685 | + /// where a file gave several. Where the window is tall enough for it | |
| 686 | + /// ([`sub_headers_fit`]) each file's block is headed by its name as well: a | |
| 687 | + /// label and nothing more, no click and nothing to fold, so the rows under | |
| 688 | + /// it are the only things anybody has to aim at. At the 640x360 floor the | |
| 689 | + /// headers are gone and the rows still say whose they are. | |
| 690 | + /// | |
| 691 | + /// `None` when there are none -- an empty heading is a section about | |
| 692 | + /// nothing. | |
| 693 | + pub(crate) fn subtitle_section( | |
| 694 | + &self, | |
| 695 | + width: f32, | |
| 696 | + viewport_h: f32, | |
| 697 | + cx: &mut Context<Self>, | |
| 698 | + ) -> Option<impl IntoElement> { | |
| 699 | + let tracks = self.session.as_ref()?.subtitles(); | |
| 700 | + if tracks.is_empty() { | |
| 701 | + return None; | |
| 702 | + } | |
| 703 | + let groups = subtitle_rows(tracks); | |
| 704 | + // One file's tracks need no prefix saying which file: it is the only | |
| 705 | + // one, and every row would carry the same word. | |
| 706 | + let several_files = groups.len() > 1; | |
| 707 | + let headed = several_files && sub_headers_fit(viewport_h); | |
| 708 | + let text_w = row_text_w(width); | |
| 709 | + let rows: Vec<_> = groups | |
| 710 | + .into_iter() | |
| 711 | + .map(|SubGroup { name, path, rows }| { | |
| 712 | + // The file's own colour, the one its media rows and its clips | |
| 713 | + // wear -- and none at all for a standalone `.srt`, which came | |
| 714 | + // off no file on this timeline. | |
| 715 | + let tint = file_tint(self.sources(), &path); | |
| 716 | + let numbered = rows.len() > 1; | |
| 717 | + // The name twice over: all of it the header can hold, and the | |
| 718 | + // share of a row a prefix may take in front of the label. | |
| 719 | + let head = clip_middle(&name, text_w); | |
| 720 | + let prefix = clip_middle(&name, text_w * SUB_STEM_SHARE); | |
| 721 | + let rows: Vec<_> = rows | |
| 722 | + .into_iter() | |
| 723 | + .map(|row| { | |
| 724 | + let track = row.track; | |
| 725 | + let picked = track == self.sub_track; | |
| 726 | + let usable = row.refused.is_none(); | |
| 727 | + // Two tracks off one remux that both say "eng" are told | |
| 728 | + // apart by their number and by nothing else -- the same | |
| 729 | + // count [`sub_pick_name`] echoes. | |
| 730 | + let title = match numbered { | |
| 731 | + true => format!("{} {}", row.label, row.number), | |
| 732 | + false => row.label, | |
| 733 | + }; | |
| 734 | + // A standalone `.srt` is named after its own file, so | |
| 735 | + // the file in front of it says the same word twice | |
| 736 | + // ("Legend.of.… · Legend.of.…"). [`sub_pick_name`]'s | |
| 737 | + // rule, on the row it is about. | |
| 738 | + let owned = several_files && !title.starts_with(name.as_str()); | |
| 739 | + // The whole path, never clipped: the row says which | |
| 740 | + // file, and the tooltip says which one on disk. | |
| 741 | + let tip: SharedString = match &row.refused { | |
| 742 | + Some(why) => format!("{} — {why}", path.display()), | |
| 743 | + None => format!( | |
| 744 | + "{} — click to show this track over the picture", | |
| 745 | + path.display() | |
| 746 | + ), | |
| 747 | + } | |
| 748 | + .into(); | |
| 749 | + // Named, because a × is the same glyph on every row and | |
| 750 | + // the tooltip is what says which track it takes off. | |
| 751 | + let remove_tip: SharedString = | |
| 752 | + format!("Remove {title} — importing the file again brings it back") | |
| 753 | + .into(); | |
| 754 | + div() | |
| 755 | + // The *flat* index into the session's add-order | |
| 756 | + // list, which is what a pick is and what a save | |
| 757 | + // writes: the grouping moved the row on screen and | |
| 758 | + // never the track it stands for. | |
| 759 | + .id(("subtitle-track", track)) | |
| 760 | + .flex_none() | |
| 761 | + .h(px(ROW_H)) | |
| 762 | + .flex() | |
| 763 | + .items_center() | |
| 764 | + .gap(px(6.)) | |
| 765 | + .pr(px(6.)) | |
| 766 | + .rounded(px(3.)) | |
| 767 | + .when(!usable, |d| d.text_color(rgb(FG_SECONDARY)).opacity(0.55)) | |
| 768 | + .when(usable, |d| { | |
| 769 | + d.cursor_pointer() | |
| 770 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 771 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 772 | + this.sub_track = track; | |
| 773 | + // Picking a track is asking to see it: a | |
| 774 | + // click that changed nothing on screen | |
| 775 | + // because the toggle was off would read | |
| 776 | + // as a dead row. | |
| 777 | + this.subs_on = true; | |
| 778 | + cx.notify(); | |
| 779 | + })) | |
| 780 | + }) | |
| 781 | + .when(picked, |d| d.bg(rgb(BG_SELECTED))) | |
| 782 | + .tooltip(move |_, cx| cx.new(|_| Tip(tip.clone())).into()) | |
| 783 | + // The media rows' bar, same width and hard against | |
| 784 | + // the same edge: one association across the panel | |
| 785 | + // and the lanes. Kept as room rather than dropped | |
| 786 | + // where there is no tint, so a standalone `.srt` | |
| 787 | + // still lines its words up with the rest. | |
| 788 | + .child( | |
| 789 | + div() | |
| 790 | + .flex_none() | |
| 791 | + .w(px(SWATCH_W)) | |
| 792 | + .h_full() | |
| 793 | + .rounded(px(2.)) | |
| 794 | + .when_some(tint, |d, tint| d.bg(rgb(tint))), | |
| 795 | + ) | |
| 796 | + .child( | |
| 797 | + div() | |
| 798 | + .flex_1() | |
| 799 | + .min_w(px(0.)) | |
| 800 | + .flex() | |
| 801 | + .flex_col() | |
| 802 | + .child( | |
| 803 | + div() | |
| 804 | + .flex() | |
| 805 | + .text_size(px(11.)) | |
| 806 | + // In front, because the column | |
| 807 | + // truncates from the right: an | |
| 808 | + // ownership word at the end is a | |
| 809 | + // word the floor never shows. | |
| 810 | + .when(owned, |d| { | |
| 811 | + d.child( | |
| 812 | + div() | |
| 813 | + .flex_none() | |
| 814 | + // Said twice where a | |
| 815 | + // header says it above: | |
| 816 | + // still there, out of | |
| 817 | + // the way. | |
| 818 | + .when(headed, |d| { | |
| 819 | + d.text_color(rgb(FG_SECONDARY)) | |
| 820 | + }) | |
| 821 | + .child(format!("{prefix} · ")), | |
| 822 | + ) | |
| 823 | + }) | |
| 824 | + .child( | |
| 825 | + div() | |
| 826 | + .flex_1() | |
| 827 | + .min_w(px(0.)) | |
| 828 | + .truncate() | |
| 829 | + .child(title), | |
| 830 | + ), | |
| 831 | + ) | |
| 832 | + .child( | |
| 833 | + div() | |
| 834 | + .truncate() | |
| 835 | + .text_size(px(10.)) | |
| 836 | + .text_color(rgb(FG_SECONDARY)) | |
| 837 | + .child(row.detail), | |
| 838 | + ), | |
| 839 | + ) | |
| 840 | + // The way back off the timeline, on every row and on | |
| 841 | + // the last one too -- a list of subtitles is allowed | |
| 842 | + // to be empty, unlike a lane. A `HIT_MIN` target and | |
| 843 | + // never hidden, the lane header's ×, and it stops | |
| 844 | + // the click there: the row under it picks a track, | |
| 845 | + // and picking the track that has just gone would | |
| 846 | + // leave the pick naming nothing. | |
| 847 | + .child( | |
| 848 | + div() | |
| 849 | + .id(("subtitle-remove", track)) | |
| 850 | + .flex_none() | |
| 851 | + .w(px(HIT_MIN)) | |
| 852 | + .h_full() | |
| 853 | + .flex() | |
| 854 | + .items_center() | |
| 855 | + .justify_center() | |
| 856 | + .rounded(px(3.)) | |
| 857 | + .cursor_pointer() | |
| 858 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 859 | + .tooltip(move |_, cx| cx.new(|_| Tip(remove_tip.clone())).into()) | |
| 860 | + .on_click(cx.listener( | |
| 861 | + move |this, _: &ClickEvent, _, cx| { | |
| 862 | + cx.stop_propagation(); | |
| 863 | + this.remove_subtitle_track(track, cx); | |
| 864 | + }, | |
| 865 | + )) | |
| 866 | + .child("×"), | |
| 867 | + ) | |
| 868 | + }) | |
| 869 | + .collect(); | |
| 870 | + div() | |
| 871 | + .flex_none() | |
| 872 | + .flex() | |
| 873 | + .flex_col() | |
| 874 | + .gap(px(2.)) | |
| 875 | + // The header: which film these came out of, in words and not | |
| 876 | + // in colour alone. No id, no click, nothing to fold -- a | |
| 877 | + // label, which is why it is allowed under `HIT_MIN`. | |
| 878 | + .when(headed, |d| { | |
| 879 | + d.child( | |
| 880 | + div() | |
| 881 | + .flex_none() | |
| 882 | + .h(px(SUB_HEAD_H)) | |
| 883 | + .flex() | |
| 884 | + .items_center() | |
| 885 | + .gap(px(6.)) | |
| 886 | + .text_size(px(10.)) | |
| 887 | + .text_color(rgb(FG_SECONDARY)) | |
| 888 | + .when_some(tint, |d, tint| { | |
| 889 | + d.child( | |
| 890 | + div() | |
| 891 | + .flex_none() | |
| 892 | + .w(px(SWATCH_W)) | |
| 893 | + .h_full() | |
| 894 | + .rounded(px(2.)) | |
| 895 | + .bg(rgb(tint)), | |
| 896 | + ) | |
| 897 | + }) | |
| 898 | + .child(div().flex_1().min_w(px(0.)).truncate().child(head)), | |
| 899 | + ) | |
| 900 | + }) | |
| 901 | + .children(rows) | |
| 902 | + }) | |
| 903 | + .collect(); | |
| 904 | + Some( | |
| 905 | + div() | |
| 906 | + .flex_none() | |
| 907 | + .flex() | |
| 908 | + .flex_col() | |
| 909 | + .gap(px(2.)) | |
| 910 | + .child( | |
| 911 | + div() | |
| 912 | + .truncate() | |
| 913 | + .text_size(px(11.)) | |
| 914 | + .text_color(rgb(FG_SECONDARY)) | |
| 915 | + .child(match (self.subs_on, sub_pick_name(tracks, self.sub_track)) { | |
| 916 | + // Which of them is on screen, named by its film: | |
| 917 | + // the heading over a list of five is where the one | |
| 918 | + // being shown is worth saying out loud. | |
| 919 | + (true, Some(pick)) => format!("Subtitles — {pick}"), | |
| 920 | + (true, None) => "Subtitles".to_string(), | |
| 921 | + // The toggle's state where the tracks are listed: a | |
| 922 | + // list of subtitles nothing on screen is showing has | |
| 923 | + // to say that it is showing none. | |
| 924 | + (false, _) => "Subtitles — hidden".to_string(), | |
| 925 | + }), | |
| 926 | + ) | |
| 927 | + .child( | |
| 928 | + div() | |
| 929 | + .id("subtitle-rows") | |
| 930 | + .flex() | |
| 931 | + .flex_col() | |
| 932 | + .gap(px(2.)) | |
| 933 | + .max_h(px(SUB_ROWS_H)) | |
| 934 | + .overflow_y_scroll() | |
| 935 | + .children(rows), | |
| 936 | + ), | |
| 937 | + ) | |
| 938 | + } | |
| 939 | + | |
| 940 | + /// One lane of the edit list made visible: a fixed header saying which lane | |
| 941 | + /// it is, then a bed with a box per clip, placed and sized by its share of | |
| 942 | + /// the timeline. A cut adds a box without moving anything, a delete closes | |
| 943 | + /// the hole, a lift leaves one. A clip too narrow for its name says what it | |
| 944 | + /// is by its tint, and the tooltip is where every box says what clicking it | |
| 945 | + /// does. Never focusable, so the root keeps focus and the play binding still | |
| 946 | + /// works after a click (ledger:182). | |
| 947 | + /// The subtitle strip: where the picked track's cues are along the very same | |
| 948 | + /// bed the lanes are drawn on, through the very same [`Scale`], so a cue | |
| 949 | + /// lines up with the take it belongs to at every zoom. | |
| 950 | + /// | |
| 951 | + /// Display only -- no drag, no trim, no drop. What it is *for* is the | |
| 952 | + /// question "is there a subtitle here", which a timeline could not answer at | |
| 953 | + /// all before: the cues are the project's and are edited in the file they | |
| 954 | + /// came from. | |
| 955 | + /// | |
| 956 | + /// `None` with no track picked, so a timeline without subtitles is the panel | |
| 957 | + /// it has always been. | |
| 958 | + pub(crate) fn subtitle_strip(&self, filled: f32) -> Option<impl IntoElement + use<>> { | |
| 959 | + let track = self.subtitle_track()?; | |
| 960 | + let scale = self.scale; | |
| 961 | + // The pick with its film on it, not the raw tag: two films' "eng" | |
| 962 | + // tracks read alike otherwise, and a header saying "und" names a | |
| 963 | + // language nobody speaks. | |
| 964 | + let label = sub_pick_name(self.session.as_ref()?.subtitles(), self.sub_track)?; | |
| 965 | + // The colour the file's own rows and clips wear, so the strip says | |
| 966 | + // whose subtitles these are before the tooltip is asked. `None` for a | |
| 967 | + // standalone `.srt` -- nobody's stream, and the first film's colour | |
| 968 | + // would be a lie about where it came from. | |
| 969 | + let tint = file_tint(self.sources(), &track.path).unwrap_or(BG_RAISED); | |
| 970 | + // The whole of what the row says in words, since a 40 px column can hold | |
| 971 | + // three characters of it: which track of which file, how many cues, the | |
| 972 | + // file itself in full -- one stem is two films when they are two cuts of | |
| 973 | + // it -- and, for a track that could not be read, the engine's own reason, | |
| 974 | + // where the library row's grey already says the same thing. | |
| 975 | + let tip: SharedString = match track.refused.is_some() { | |
| 976 | + true => format!( | |
| 977 | + "Subtitles: {label} — {} — {}", | |
| 978 | + subtitle_detail(track), | |
| 979 | + track.path.display() | |
| 980 | + ), | |
| 981 | + false => format!( | |
| 982 | + "Subtitles: {label} — {}, {} hides them — {}", | |
| 983 | + subtitle_detail(track), | |
| 984 | + self.keymap.display(ActionId::ToggleSubtitles), | |
| 985 | + track.path.display() | |
| 986 | + ), | |
| 987 | + } | |
| 988 | + .into(); | |
| 989 | + // Where the cues are on *this* timeline and not in the file they came | |
| 990 | + // from ([`PlaybackSession::timeline_cues`]) -- the same map the plate | |
| 991 | + // over the picture and the export both go through, which is what keeps | |
| 992 | + // a mark under the take it is spoken over after a cut. | |
| 993 | + let cues: Vec<(f32, f32)> = self | |
| 994 | + .session | |
| 995 | + .as_ref()? | |
| 996 | + .timeline_cues(self.sub_track) | |
| 997 | + .iter() | |
| 998 | + .map(|cue| cue_box(scale, cue)) | |
| 999 | + .collect(); | |
| 1000 | + Some( | |
| 1001 | + div() | |
| 1002 | + .flex_none() | |
| 1003 | + .h(px(SUB_LANE_H)) | |
| 1004 | + .flex() | |
| 1005 | + .gap(px(HEADER_GAP)) | |
| 1006 | + .child( | |
| 1007 | + // Identified for the tooltip's sake and for nothing else: | |
| 1008 | + // the whole of what a 40 px column can say is three | |
| 1009 | + // characters, and the rest of it hangs off the hover. | |
| 1010 | + div() | |
| 1011 | + .id("subtitle-lane") | |
| 1012 | + .flex_none() | |
| 1013 | + .w(px(HEADER_W)) | |
| 1014 | + .h_full() | |
| 1015 | + .flex() | |
| 1016 | + .items_center() | |
| 1017 | + // From the left rather than centred, unlike a lane's | |
| 1018 | + // `V1`: a track label is a language or a file name, and | |
| 1019 | + // a centred truncation eats both of its ends. | |
| 1020 | + .px(px(2.)) | |
| 1021 | + .rounded(px(3.)) | |
| 1022 | + .bg(rgb(tint)) | |
| 1023 | + .text_size(px(9.)) | |
| 1024 | + .text_color(rgb(FG_SECONDARY)) | |
| 1025 | + .truncate() | |
| 1026 | + .tooltip(move |_, cx| cx.new(|_| Tip(tip.clone())).into()) | |
| 1027 | + .child(label), | |
| 1028 | + ) | |
| 1029 | + .child( | |
| 1030 | + div() | |
| 1031 | + .relative() | |
| 1032 | + .flex_1() | |
| 1033 | + .min_w(px(0.)) | |
| 1034 | + .h_full() | |
| 1035 | + .rounded(px(3.)) | |
| 1036 | + .bg(rgb(BG_CANVAS)) | |
| 1037 | + .overflow_hidden() | |
| 1038 | + .children(cues.into_iter().map(|(left, width)| { | |
| 1039 | + div() | |
| 1040 | + .absolute() | |
| 1041 | + .top_0() | |
| 1042 | + .h_full() | |
| 1043 | + .left(px(left)) | |
| 1044 | + .w(px(width)) | |
| 1045 | + .rounded(px(2.)) | |
| 1046 | + .bg(rgb(BG_SELECTED)) | |
| 1047 | + })) | |
| 1048 | + // The playhead again, last and in the lanes' own colour: | |
| 1049 | + // the strip is only worth anything beside them if it | |
| 1050 | + // reads as the same moment. | |
| 1051 | + .child( | |
| 1052 | + div() | |
| 1053 | + .absolute() | |
| 1054 | + .top_0() | |
| 1055 | + .h_full() | |
| 1056 | + .left(px(filled)) | |
| 1057 | + .w(px(1.)) | |
| 1058 | + .bg(rgb(ACCENT_PRIMARY)), | |
| 1059 | + ), | |
| 1060 | + ), | |
| 1061 | + ) | |
| 1062 | + } | |
| 1063 | + | |
| 1064 | + pub(crate) fn lane_row( | |
| 1065 | + &self, | |
| 1066 | + lane: Lane, | |
| 1067 | + // Where the playhead is on the bed, in pixels: worked out once by the | |
| 1068 | + // panel so the ruler's line and every lane's draw the same one. | |
| 1069 | + filled: f32, | |
| 1070 | + cx: &mut Context<Self>, | |
| 1071 | + // Borrows nothing it was given (`use<>`): the rows are built one after | |
| 1072 | + // another into a list, and a row still holding `cx` would be the only | |
| 1073 | + // one that could be built. | |
| 1074 | + ) -> impl IntoElement + use<> { | |
| 1075 | + // The mapping, copied out once: every box in the row is placed through | |
| 1076 | + // it, so all of them move together when it does. No bed width is needed | |
| 1077 | + // to place them any more -- a second is so many pixels wherever it is. | |
| 1078 | + let scale = self.scale; | |
| 1079 | + // How much bed there is to be seen on, measured off the ruler's own | |
| 1080 | + // probe like every other question about it: what a box draws *inside* | |
| 1081 | + // itself is clipped to this ([`visible_slice`]), because a box at a deep | |
| 1082 | + // zoom is far wider than the strip it is being watched through. | |
| 1083 | + let bed = f32::from(self.ruler.get().size.width); | |
| 1084 | + // Where the snap line stands, in the same pixels every box is placed | |
| 1085 | + // through -- and only while a gesture is actually live: gpui drops a | |
| 1086 | + // drag without telling anyone, so this asks whether one is in flight | |
| 1087 | + // (`App::has_active_drag`) rather than remembering that one was. | |
| 1088 | + let cue = self | |
| 1089 | + .snap_cue | |
| 1090 | + .filter(|_| self.trim.is_some() || cx.has_active_drag()) | |
| 1091 | + .map(|frame| scale.px_at(f64::from(frame) / self.fps)); | |
| 1092 | + // The shadow, on the one lane the pointer is over -- and, like the line, | |
| 1093 | + // only while the drag that asked for it is still in flight. | |
| 1094 | + let ghost = self | |
| 1095 | + .ghost | |
| 1096 | + .filter(|g| g.lane == lane && cx.has_active_drag()); | |
| 1097 | + let clips = self | |
| 1098 | + .session | |
| 1099 | + .as_ref() | |
| 1100 | + .map_or(&[][..], |session| session.lane_clips(lane)); | |
| 1101 | + // The group ids some *other* lane carries: a clip whose id is in here | |
| 1102 | + // has a half elsewhere, and one whose is not is a detached half however | |
| 1103 | + // many lanes there are. | |
| 1104 | + let others: Vec<u32> = self.session.as_ref().map_or_else(Vec::new, |session| { | |
| 1105 | + session | |
| 1106 | + .lanes() | |
| 1107 | + .into_iter() | |
| 1108 | + .filter(|&other| other != lane) | |
| 1109 | + .flat_map(|other| session.lane_clips(other)) | |
| 1110 | + .filter_map(|clip| clip.link) | |
| 1111 | + .collect() | |
| 1112 | + }); | |
| 1113 | + let name = lane.label(); | |
| 1114 | + let row_id: SharedString = format!("{name}-clip").into(); | |
| 1115 | + let remove_id: SharedString = format!("{name}-remove").into(); | |
| 1116 | + let remove_tip: SharedString = format!( | |
| 1117 | + "Remove {name} — it must be empty first, and {} brings it back", | |
| 1118 | + self.keymap.display(ActionId::Undo) | |
| 1119 | + ) | |
| 1120 | + .into(); | |
| 1121 | + let sources = self | |
| 1122 | + .session | |
| 1123 | + .as_ref() | |
| 1124 | + .map_or(&[][..], PlaybackSession::sources); | |
| 1125 | + let (sel, sel_link) = (self.selected, self.selected_link()); | |
| 1126 | + let audio = lane.kind == LaneKind::Audio; | |
| 1127 | + // What this track plays at, on the header it belongs to: shown only | |
| 1128 | + // when it is not unity, because a column 40 px wide has room for a | |
| 1129 | + // number or for a name, and the name is what a header is for. The | |
| 1130 | + // press opens the mix card on this very track. | |
| 1131 | + let gain_db = self | |
| 1132 | + .session | |
| 1133 | + .as_ref() | |
| 1134 | + .map_or(0., |session| session.lane_gain_db(lane)); | |
| 1135 | + let gain_tip: SharedString = format!( | |
| 1136 | + "{name} plays at {gain_db:+.0} dB — opens the mix ({}); the whole track, every frequency, unlike the equalizer", | |
| 1137 | + self.keymap.display(ActionId::Mix) | |
| 1138 | + ) | |
| 1139 | + .into(); | |
| 1140 | + let tip: SharedString = format!( | |
| 1141 | + "Select (or {} under the playhead, {}/{} along the lane) — drag it to move it, an end to trim, {} removes the take, {} leaves a gap, {} rejoins a cut", | |
| 1142 | + self.keymap.display(ActionId::Select), | |
| 1143 | + self.keymap.display(ActionId::SelectPrev), | |
| 1144 | + self.keymap.display(ActionId::SelectNext), | |
| 1145 | + self.keymap.display(ActionId::Delete), | |
| 1146 | + self.keymap.display(ActionId::Lift), | |
| 1147 | + self.keymap.display(ActionId::Regroup) | |
| 1148 | + ) | |
| 1149 | + .into(); | |
| 1150 | + div() | |
| 1151 | + .flex_none() | |
| 1152 | + .h(px(LANE_H)) | |
| 1153 | + .flex() | |
| 1154 | + .gap(px(HEADER_GAP)) | |
| 1155 | + // The fixed column the ruler above is offset by as well. Full lane | |
| 1156 | + // height, so it reads as the bed continuing rather than as a chip. | |
| 1157 | + .child( | |
| 1158 | + div() | |
| 1159 | + .flex_none() | |
| 1160 | + .w(px(HEADER_W)) | |
| 1161 | + .h_full() | |
| 1162 | + .flex() | |
| 1163 | + .flex_col() | |
| 1164 | + .items_center() | |
| 1165 | + .justify_center() | |
| 1166 | + .rounded(px(3.)) | |
| 1167 | + .bg(rgb(BG_RAISED)) | |
| 1168 | + .text_size(px(11.)) | |
| 1169 | + .text_color(rgb(FG_SECONDARY)) | |
| 1170 | + .child(match audio { | |
| 1171 | + // A button, not a label: the one setting a track has of | |
| 1172 | + // its own used to be reachable from nowhere. | |
| 1173 | + true => div() | |
| 1174 | + .id(("mix-lane", lane.ord)) | |
| 1175 | + .flex_1() | |
| 1176 | + .w_full() | |
| 1177 | + .flex() | |
| 1178 | + .items_center() | |
| 1179 | + .justify_center() | |
| 1180 | + .rounded(px(3.)) | |
| 1181 | + .cursor_pointer() | |
| 1182 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 1183 | + .tooltip(move |_, cx| cx.new(|_| Tip(gain_tip.clone())).into()) | |
| 1184 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 1185 | + this.open_mix(Some(lane), cx) | |
| 1186 | + })) | |
| 1187 | + .child(match gain_db == 0. { | |
| 1188 | + true => name.clone(), | |
| 1189 | + false => format!("{name} {gain_db:+.0}"), | |
| 1190 | + }) | |
| 1191 | + .into_any_element(), | |
| 1192 | + false => div() | |
| 1193 | + .flex_1() | |
| 1194 | + .flex() | |
| 1195 | + .items_center() | |
| 1196 | + .child(name.clone()) | |
| 1197 | + .into_any_element(), | |
| 1198 | + }) | |
| 1199 | + // The one thing a header does: take this track away again. | |
| 1200 | + // A `HIT_MIN` target rather than a glyph-sized one, and it | |
| 1201 | + // stays put on a track holding clips instead of hiding -- | |
| 1202 | + // the refusal names them, and a control that vanishes | |
| 1203 | + // teaches nothing. | |
| 1204 | + .child( | |
| 1205 | + div() | |
| 1206 | + .id(remove_id) | |
| 1207 | + .flex_none() | |
| 1208 | + .w_full() | |
| 1209 | + .h(px(HIT_MIN)) | |
| 1210 | + .flex() | |
| 1211 | + .items_center() | |
| 1212 | + .justify_center() | |
| 1213 | + .rounded(px(3.)) | |
| 1214 | + .cursor_pointer() | |
| 1215 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 1216 | + .tooltip(move |_, cx| cx.new(|_| Tip(remove_tip.clone())).into()) | |
| 1217 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 1218 | + this.remove_lane(lane, cx) | |
| 1219 | + })) | |
| 1220 | + .child("×"), | |
| 1221 | + ), | |
| 1222 | + ) | |
| 1223 | + .child( | |
| 1224 | + // Clips are placed at their own start rather than queued edge | |
| 1225 | + // to edge: a lift leaves a hole in the lane, and the bare bed | |
| 1226 | + // showing through it *is* how a gap looks. | |
| 1227 | + div() | |
| 1228 | + .relative() | |
| 1229 | + .flex_1() | |
| 1230 | + .min_w(px(0.)) | |
| 1231 | + .h_full() | |
| 1232 | + .rounded(px(3.)) | |
| 1233 | + .bg(rgb(BG_CANVAS)) | |
| 1234 | + .overflow_hidden() | |
| 1235 | + // A library row let go over a lane is the same insert the | |
| 1236 | + // Add button makes, through the same call -- but where the | |
| 1237 | + // pointer let it go, not at the playhead: a hand that | |
| 1238 | + // carried a file to a place on the bed named that place. | |
| 1239 | + // gpui hands a drop no event, so the pointer is read off | |
| 1240 | + // the window, which took it from the release that fired | |
| 1241 | + // this (gpui window.rs:3602). | |
| 1242 | + .on_drop(cx.listener(move |this, drag: &AssetDrag, window, cx| { | |
| 1243 | + // Onto the edges near it, exactly as a clip carried by | |
| 1244 | + // hand lands: the line drawn while it was in flight is | |
| 1245 | + // the frame it goes down on. | |
| 1246 | + let at = this.place_frame(window.mouse_position().x).0; | |
| 1247 | + this.insert_source(&drag.0.clone(), drag.1, Some(lane), Some(at), cx) | |
| 1248 | + })) | |
| 1249 | + .drag_over::<AssetDrag>(|s, _, _, _| s.bg(rgb(BG_HOVER_DIM))) | |
| 1250 | + // The shadow of the row in flight, drawn by the lane the | |
| 1251 | + // pointer is inside: `on_drag_move` fires on every painted | |
| 1252 | + // element while a drag of its type is live, wherever the | |
| 1253 | + // pointer is, and hands each one its own box -- which is how | |
| 1254 | + // a lane knows the pointer is over *it* (gpui div.rs:282). | |
| 1255 | + // The root cleared it a moment ago, so exactly one lane | |
| 1256 | + // draws one. | |
| 1257 | + .on_drag_move(cx.listener( | |
| 1258 | + move |this, event: &DragMoveEvent<AssetDrag>, _, cx| { | |
| 1259 | + if !event.bounds.contains(&event.event.position) { | |
| 1260 | + return; | |
| 1261 | + } | |
| 1262 | + let path = event.drag(cx).0.clone(); | |
| 1263 | + this.preview_ghost_asset(&path, lane, event.event.position.x, cx); | |
| 1264 | + }, | |
| 1265 | + )) | |
| 1266 | + // ...and a clip let go over a lane lands the same way: on | |
| 1267 | + // the track it was dropped on, at the frame it was carried | |
| 1268 | + // to -- its own included, which is the drag that moves a | |
| 1269 | + // take along its track. | |
| 1270 | + .on_drop(cx.listener(move |this, drag: &ClipDrag, window, cx| { | |
| 1271 | + // Against the lane as it is *now* ([`Player::dragged`]), | |
| 1272 | + // and then snapped by `move_clip` like any other drop: | |
| 1273 | + // which clip is being moved and where it lands are two | |
| 1274 | + // questions, and this is the first one. | |
| 1275 | + let Some(idx) = this.dragged(drag) else { | |
| 1276 | + return; | |
| 1277 | + }; | |
| 1278 | + this.move_clip(drag.lane, idx, lane, window.mouse_position().x, cx) | |
| 1279 | + })) | |
| 1280 | + .drag_over::<ClipDrag>(|s, _, _, _| s.bg(rgb(BG_HOVER_DIM))) | |
| 1281 | + // ...and the same shadow for the clip in the hand, seated on | |
| 1282 | + // this lane when the pointer is inside it. | |
| 1283 | + .on_drag_move(cx.listener( | |
| 1284 | + move |this, event: &DragMoveEvent<ClipDrag>, _, cx| { | |
| 1285 | + if !event.bounds.contains(&event.event.position) { | |
| 1286 | + return; | |
| 1287 | + } | |
| 1288 | + let drag = *event.drag(cx); | |
| 1289 | + this.preview_ghost(&drag, lane, event.event.position.x, cx); | |
| 1290 | + }, | |
| 1291 | + )) | |
| 1292 | + .children(clips.iter().enumerate().map(|(i, clip)| { | |
| 1293 | + // The clip as the lane holds it, for the drag payload: | |
| 1294 | + // what a drop looks itself up by has to be the placed | |
| 1295 | + // clip, never the preview an edge drag is drawing. | |
| 1296 | + let placed = *clip; | |
| 1297 | + // What a drag on an edge is showing, which is the clip | |
| 1298 | + // itself while nothing is being dragged. | |
| 1299 | + let clip = &self.trimmed(lane, i, *clip); | |
| 1300 | + // Its *timeline* length, which a speed halves or | |
| 1301 | + // quadruples: the box is as wide as the clip is long | |
| 1302 | + // where it sits, not as long as the source it reads. | |
| 1303 | + let (start, len) = ( | |
| 1304 | + f64::from(clip.start) / self.fps, | |
| 1305 | + f64::from(clip.frames()) / self.fps, | |
| 1306 | + ); | |
| 1307 | + let on = marked((lane, i), clip.link, sel, sel_link); | |
| 1308 | + // A group with a half in the other lane wears its tint; | |
| 1309 | + // one without is outlined, so a detached half is visible | |
| 1310 | + // as detached before anyone clicks it. | |
| 1311 | + let grouped = clip.link.is_some_and(|link| others.contains(&link)); | |
| 1312 | + // Tinted by *file*, not by source entry: two audio | |
| 1313 | + // streams of one file are two sources, and the library | |
| 1314 | + // gives them one swatch because they are one file. | |
| 1315 | + let tint = self.clip_tint(clip.source); | |
| 1316 | + // What the clip is worth in pixels, and how wide its box | |
| 1317 | + // is drawn -- the two part company on a take too short | |
| 1318 | + // to be hit at this zoom ([`clip_width`]). | |
| 1319 | + let span = scale.width_px(len); | |
| 1320 | + let width = clip_width(span); | |
| 1321 | + let left = scale.px_at(start); | |
| 1322 | + // The slice of this box that is on the bed: where its | |
| 1323 | + // name, its badge and its waveform go, so none of the | |
| 1324 | + // three is drawn out at a zoomed-in box's own edges. | |
| 1325 | + let (vis_x, vis_w) = visible_slice(left, width, bed); | |
| 1326 | + let label = sources.get(clip.source).map(|s| file_name(&s.path)); | |
| 1327 | + let wave = sources | |
| 1328 | + .get(clip.source) | |
| 1329 | + .and_then(|s| self.waves.get(&(s.path.clone(), s.audio_stream))) | |
| 1330 | + .cloned(); | |
| 1331 | + // The source seconds that slice plays -- not the clip's | |
| 1332 | + // whole range: the envelope is drawn for the part of the | |
| 1333 | + // box that can be seen, at the resolution of the pixels | |
| 1334 | + // it actually has, and never one column per two pixels | |
| 1335 | + // of a box millions of pixels wide. | |
| 1336 | + let along = |x: f32| match width > 0. { | |
| 1337 | + true => { | |
| 1338 | + f64::from(clip.in_frame) | |
| 1339 | + + f64::from(clip.out_frame - clip.in_frame) | |
| 1340 | + * f64::from(x / width) | |
| 1341 | + } | |
| 1342 | + false => f64::from(clip.in_frame), | |
| 1343 | + }; | |
| 1344 | + let (from, to) = (along(vis_x) / self.fps, along(vis_x + vis_w) / self.fps); | |
| 1345 | + let tip = tip.clone(); | |
| 1346 | + // What the pointer carries on the way to another lane: | |
| 1347 | + // the file the box is showing, the same ghost a library | |
| 1348 | + // row makes. A box too narrow for its own label still | |
| 1349 | + // says what is moving. | |
| 1350 | + let ghost: SharedString = | |
| 1351 | + label.clone().unwrap_or_else(|| lane.label()).into(); | |
| 1352 | + // Its head in frames, for the press below: the `start` | |
| 1353 | + // above is the same moment in seconds, which is what | |
| 1354 | + // the box is *drawn* from. | |
| 1355 | + let head = clip.start; | |
| 1356 | + div() | |
| 1357 | + // Named per lane: two rows numbering their clips | |
| 1358 | + // from zero would hand gpui the same id twice. | |
| 1359 | + .id((row_id.clone(), i)) | |
| 1360 | + .absolute() | |
| 1361 | + .top_0() | |
| 1362 | + .h_full() | |
| 1363 | + // Negative once the clip's head has been scrolled | |
| 1364 | + // off the left edge: the bed clips what hangs out | |
| 1365 | + // of it, so a half-visible clip is drawn as the | |
| 1366 | + // half of itself that is on screen. | |
| 1367 | + .left(px(left)) | |
| 1368 | + .w(px(width)) | |
| 1369 | + .overflow_hidden() | |
| 1370 | + .rounded(px(3.)) | |
| 1371 | + .border_1() | |
| 1372 | + .border_color(rgb(if on { | |
| 1373 | + ACCENT_PRIMARY | |
| 1374 | + } else if grouped { | |
| 1375 | + tint | |
| 1376 | + } else { | |
| 1377 | + FG_SECONDARY | |
| 1378 | + })) | |
| 1379 | + .bg(rgb(if on { BG_SELECTED } else { tint })) | |
| 1380 | + .cursor_pointer() | |
| 1381 | + .hover(|s| s.border_color(rgb(ACCENT_PRIMARY))) | |
| 1382 | + .tooltip(move |_, cx| cx.new(|_| Tip(tip.clone())).into()) | |
| 1383 | + // Dragged, it *moves*: to the frame it was let go on | |
| 1384 | + // and to the lane it was let go over. The click that | |
| 1385 | + // starts the drag still selects, so picking a clip | |
| 1386 | + // up and putting it back down where it was is | |
| 1387 | + // exactly a click. | |
| 1388 | + .on_drag( | |
| 1389 | + ClipDrag { | |
| 1390 | + lane, | |
| 1391 | + idx: i, | |
| 1392 | + clip: placed, | |
| 1393 | + }, | |
| 1394 | + move |_, _, _, cx| cx.new(|_| Tip(ghost.clone())), | |
| 1395 | + ) | |
| 1396 | + .on_mouse_down( | |
| 1397 | + MouseButton::Left, | |
| 1398 | + cx.listener(move |this, event: &MouseDownEvent, _, cx| { | |
| 1399 | + // Where in the box the hand took hold of it, | |
| 1400 | + // for the drag this press may become: the | |
| 1401 | + // clip has to move with the pointer rather | |
| 1402 | + // than jump its head under it. | |
| 1403 | + this.grab = | |
| 1404 | + this.frame_under(event.position.x).saturating_sub(head); | |
| 1405 | + this.select((lane, i), cx); | |
| 1406 | + }), | |
| 1407 | + ) | |
| 1408 | + // The right button selects exactly as the left one | |
| 1409 | + // does -- the menu acts on the clip it names, so | |
| 1410 | + // opening one has to pick it -- and then hangs the | |
| 1411 | + // menu at the pointer. | |
| 1412 | + .on_mouse_down( | |
| 1413 | + MouseButton::Right, | |
| 1414 | + cx.listener(move |this, event: &MouseDownEvent, _, cx| { | |
| 1415 | + this.open_menu(lane, i, event.position, cx); | |
| 1416 | + }), | |
| 1417 | + ) | |
| 1418 | + // The two strips a drag *lengthens* the clip by, | |
| 1419 | + // one at each end. They occlude the box behind | |
| 1420 | + // them, which is what keeps one gesture one thing: | |
| 1421 | + // a press here trims, a press anywhere else on the | |
| 1422 | + // box still starts the move to another lane. | |
| 1423 | + // | |
| 1424 | + // Asked of the clip's own width and not of the box's | |
| 1425 | + // floor: a take drawn at `HIT_MIN` because it is | |
| 1426 | + // shorter than that has no *pixels* to trim by -- one | |
| 1427 | + // would move it by seconds -- so it keeps all of its | |
| 1428 | + // padded box as a body to select and drag by, and is | |
| 1429 | + // trimmed after zooming in, exactly as [`trims`] says. | |
| 1430 | + .children( | |
| 1431 | + [Edge::Start, Edge::End] | |
| 1432 | + .into_iter() | |
| 1433 | + .filter(|_| trims(span)) | |
| 1434 | + .map(|edge| { | |
| 1435 | + let mut zone = div() | |
| 1436 | + .absolute() | |
| 1437 | + .top_0() | |
| 1438 | + .h_full() | |
| 1439 | + .w(px(EDGE_W)) | |
| 1440 | + .occlude() | |
| 1441 | + .cursor(CursorStyle::ResizeLeftRight) | |
| 1442 | + .hover(|s| s.bg(rgb(ACCENT_PRIMARY))) | |
| 1443 | + .on_mouse_down( | |
| 1444 | + MouseButton::Left, | |
| 1445 | + cx.listener( | |
| 1446 | + move |this, _: &MouseDownEvent, _, cx| { | |
| 1447 | + this.start_trim(lane, i, edge, cx); | |
| 1448 | + }, | |
| 1449 | + ), | |
| 1450 | + ) | |
| 1451 | + // Occluded, so the box's own right-button | |
| 1452 | + // listener never fires here: the menu is | |
| 1453 | + // the same menu, opened by the same call. | |
| 1454 | + .on_mouse_down( | |
| 1455 | + MouseButton::Right, | |
| 1456 | + cx.listener( | |
| 1457 | + move |this, event: &MouseDownEvent, _, cx| { | |
| 1458 | + this.open_menu(lane, i, event.position, cx); | |
| 1459 | + }, | |
| 1460 | + ), | |
| 1461 | + ); | |
| 1462 | + zone = match edge { | |
| 1463 | + Edge::Start => zone.left_0(), | |
| 1464 | + Edge::End => zone.right_0(), | |
| 1465 | + }; | |
| 1466 | + zone | |
| 1467 | + }), | |
| 1468 | + ) | |
| 1469 | + // Under the label row, never through it. | |
| 1470 | + .children(wave.filter(|_| audio && vis_w > 0.).and_then(|wave| { | |
| 1471 | + let inner: AnyElement = match wave { | |
| 1472 | + Wave::Peaks(peaks) => { | |
| 1473 | + waveform(peaks, from, to).into_any_element() | |
| 1474 | + } | |
| 1475 | + // A bed while the decode runs, and dimmer | |
| 1476 | + // than any waveform is drawn: a flat | |
| 1477 | + // `FG_SECONDARY` line here would be the shape a | |
| 1478 | + // silent file makes, which this file is not | |
| 1479 | + // known to be yet. | |
| 1480 | + Wave::Loading => div() | |
| 1481 | + .h_full() | |
| 1482 | + .flex() | |
| 1483 | + .items_center() | |
| 1484 | + .child(div().w_full().h(px(1.)).bg(rgb(BG_HOVER))) | |
| 1485 | + .into_any_element(), | |
| 1486 | + // No audio track: nothing, never a fake. | |
| 1487 | + Wave::Silent => return None, | |
| 1488 | + // Could not be read: a band that says so in | |
| 1489 | + // words, because the empty band a silent | |
| 1490 | + // file draws would claim this file has no | |
| 1491 | + // sound. The reason itself went to the log. | |
| 1492 | + Wave::Failed => div() | |
| 1493 | + .h_full() | |
| 1494 | + .flex() | |
| 1495 | + .items_center() | |
| 1496 | + .justify_center() | |
| 1497 | + .truncate() | |
| 1498 | + .text_size(px(9.)) | |
| 1499 | + .text_color(rgb(FG_SECONDARY)) | |
| 1500 | + .child("audio unreadable") | |
| 1501 | + .into_any_element(), | |
| 1502 | + }; | |
| 1503 | + Some( | |
| 1504 | + div() | |
| 1505 | + .absolute() | |
| 1506 | + .left(px(vis_x)) | |
| 1507 | + .w(px(vis_w)) | |
| 1508 | + .top(px(LABEL_H)) | |
| 1509 | + .bottom_0() | |
| 1510 | + .child(inner), | |
| 1511 | + ) | |
| 1512 | + })) | |
| 1513 | + // A speeded clip says so on the box, in the corner | |
| 1514 | + // the label does not reach: the box's width alone | |
| 1515 | + // cannot say whether a short clip is a trim or a | |
| 1516 | + // clip at 4x, and that is the difference between a | |
| 1517 | + // cut and a re-time. | |
| 1518 | + // Against the right edge of what is *visible* of the | |
| 1519 | + // box, not of the box: zoomed in, the box's own | |
| 1520 | + // right edge is off the screen and the badge with | |
| 1521 | + // it, which is a clip that stops saying it is | |
| 1522 | + // speeded exactly when it is being looked at | |
| 1523 | + // closely. | |
| 1524 | + .when(!clip.speed.is_normal() && vis_w > 0., |d| { | |
| 1525 | + d.child( | |
| 1526 | + div() | |
| 1527 | + .absolute() | |
| 1528 | + .top_0() | |
| 1529 | + .left(px(vis_x)) | |
| 1530 | + .w(px(vis_w)) | |
| 1531 | + .flex() | |
| 1532 | + .justify_end() | |
| 1533 | + .overflow_hidden() | |
| 1534 | + .child( | |
| 1535 | + div() | |
| 1536 | + .flex_none() | |
| 1537 | + .px(px(3.)) | |
| 1538 | + .rounded(px(3.)) | |
| 1539 | + .bg(rgb(ACCENT_PRIMARY)) | |
| 1540 | + .text_size(px(9.)) | |
| 1541 | + .text_color(rgb(BG_RAISED)) | |
| 1542 | + .child(format!("{}", clip.speed)), | |
| 1543 | + ), | |
| 1544 | + ) | |
| 1545 | + }) | |
| 1546 | + // ...and the name sits at the left edge of the same | |
| 1547 | + // slice, for the same reason: a box scrolled half | |
| 1548 | + // off names itself on the half that is on screen. | |
| 1549 | + .when_some(label.filter(|_| show_label(vis_w)), |d, label| { | |
| 1550 | + d.child( | |
| 1551 | + div() | |
| 1552 | + .absolute() | |
| 1553 | + .top_0() | |
| 1554 | + .left(px(vis_x)) | |
| 1555 | + .w(px(vis_w)) | |
| 1556 | + .h(px(LABEL_H)) | |
| 1557 | + .px(px(4.)) | |
| 1558 | + .truncate() | |
| 1559 | + .text_size(px(10.)) | |
| 1560 | + .child(label), | |
| 1561 | + ) | |
| 1562 | + }) | |
| 1563 | + })) | |
| 1564 | + // What the silence card found, over the clips it found them | |
| 1565 | + // in and over the waveform band that shows why: on the lane | |
| 1566 | + // the scan ran on and no other, because that is the only | |
| 1567 | + // lane whose sound was read. Drawn before anything is cut, | |
| 1568 | + // and replaced -- never stacked -- by every re-run. | |
| 1569 | + .children( | |
| 1570 | + self.silence_marks | |
| 1571 | + .iter() | |
| 1572 | + .filter(|_| self.silence_open.is_some_and(|(on, _)| on == lane)) | |
| 1573 | + .map(|&(at, len)| { | |
| 1574 | + div() | |
| 1575 | + .absolute() | |
| 1576 | + .top_0() | |
| 1577 | + .h_full() | |
| 1578 | + .left(px(scale.px_at(f64::from(at) / self.fps))) | |
| 1579 | + // Floored like a cue's mark and for the same | |
| 1580 | + // reason: a half-second silence on a zoomed- | |
| 1581 | + // out bed rounds to nothing, and a preview | |
| 1582 | + // that draws nothing reads as a scan that | |
| 1583 | + // found nothing. | |
| 1584 | + .w(px(scale | |
| 1585 | + .width_px(f64::from(len) / self.fps) | |
| 1586 | + .max(SUB_CUE_MIN_W))) | |
| 1587 | + .bg(rgba(ACCENT_WASH)) | |
| 1588 | + }), | |
| 1589 | + ) | |
| 1590 | + // Where the thing in the hand would come to rest, at the size | |
| 1591 | + // it would come to rest at: the shadow a proper editor draws | |
| 1592 | + // under a drag. Over the clips (it is translucent, so what | |
| 1593 | + // it would cover shows through) and under the line, which | |
| 1594 | + // marks the frame this box merely fills. | |
| 1595 | + .children(ghost.map(|g| { | |
| 1596 | + div() | |
| 1597 | + .absolute() | |
| 1598 | + .top_0() | |
| 1599 | + .h_full() | |
| 1600 | + .left(px(scale.px_at(f64::from(g.start) / self.fps))) | |
| 1601 | + // A row whose length the engine has not measured | |
| 1602 | + // draws a head marker rather than nothing: where it | |
| 1603 | + // lands is known, how long it is is not. | |
| 1604 | + .w(px(scale | |
| 1605 | + .width_px(f64::from(g.frames) / self.fps) | |
| 1606 | + .max(GHOST_MIN))) | |
| 1607 | + .rounded(px(3.)) | |
| 1608 | + .border_1() | |
| 1609 | + .border_color(rgb(if g.refused { DROP_REFUSE } else { FG_PRIMARY })) | |
| 1610 | + // The file's own swatch at a third of its weight, so | |
| 1611 | + // the box beneath is still legible through it -- and | |
| 1612 | + // the refusal red instead, for a lane that will not | |
| 1613 | + // take this drop at all. | |
| 1614 | + .bg(rgba( | |
| 1615 | + ((if g.refused { DROP_REFUSE } else { g.tint }) << 8) | GHOST_ALPHA, | |
| 1616 | + )) | |
| 1617 | + })) | |
| 1618 | + // What the gesture in flight is about to land on, drawn on | |
| 1619 | + // every lane so a clip lining up with a take one track over | |
| 1620 | + // can be seen to line up with it. Under the playhead's line | |
| 1621 | + // and in another colour, since the two mean different | |
| 1622 | + // things and often stand on the same pixel. | |
| 1623 | + .children(cue.map(|x| { | |
| 1624 | + div() | |
| 1625 | + .absolute() | |
| 1626 | + .top_0() | |
| 1627 | + .h_full() | |
| 1628 | + .left(px(x)) | |
| 1629 | + .w(px(1.)) | |
| 1630 | + .bg(rgb(FG_PRIMARY)) | |
| 1631 | + })) | |
| 1632 | + // Last, so it is over the clips: the same fraction in both | |
| 1633 | + // lanes, which is the playhead being one line. | |
| 1634 | + .child( | |
| 1635 | + div() | |
| 1636 | + .absolute() | |
| 1637 | + .top_0() | |
| 1638 | + .h_full() | |
| 1639 | + .left(px(filled)) | |
| 1640 | + .w(px(1.)) | |
| 1641 | + .bg(rgb(ACCENT_PRIMARY)), | |
| 1642 | + ), | |
| 1643 | + ) | |
| 1644 | + } | |
| 1645 | +} |
crates/app/src/ui/toolbar.rsadded+0 -0
crates/app/src/ui/widgets.rsadded+263 -0
| @@ -0,0 +1,263 @@ | ||
| 1 | +//! The small elements every region is built out of. | |
| 2 | + | |
| 3 | +use crate::*; | |
| 4 | + | |
| 5 | +/// One clip's audio, drawn as a filled min/max envelope inside whatever box it | |
| 6 | +/// is given. Peaks are the source's whole envelope; `from`/`to` are the source | |
| 7 | +/// seconds this clip plays, so a cut clip shows its own stretch of the file. | |
| 8 | +pub(crate) fn waveform(peaks: Arc<Vec<(f32, f32)>>, from: f64, to: f64) -> impl IntoElement { | |
| 9 | + canvas( | |
| 10 | + |_, _, _| (), | |
| 11 | + move |bounds, _, window, _| { | |
| 12 | + let (o, s) = (bounds.origin, bounds.size); | |
| 13 | + let cols = envelope(&peaks, from, to, f32::from(s.width), f32::from(s.height)); | |
| 14 | + if cols.len() < 2 { | |
| 15 | + return; | |
| 16 | + } | |
| 17 | + // Down the tops and back along the bottoms: one closed outline of | |
| 18 | + // the whole envelope, which is one path rather than a path a column. | |
| 19 | + let mut points: Vec<Point<Pixels>> = cols | |
| 20 | + .iter() | |
| 21 | + .map(|&(x, top, _)| point(o.x + px(x), o.y + px(top))) | |
| 22 | + .collect(); | |
| 23 | + points.extend( | |
| 24 | + cols.iter() | |
| 25 | + .rev() | |
| 26 | + .map(|&(x, _, bottom)| point(o.x + px(x), o.y + px(bottom))), | |
| 27 | + ); | |
| 28 | + let mut path = PathBuilder::fill(); | |
| 29 | + path.add_polygon(&points, true); | |
| 30 | + if let Ok(path) = path.build() { | |
| 31 | + window.paint_path(path, rgb(FG_SECONDARY)); | |
| 32 | + } | |
| 33 | + }, | |
| 34 | + ) | |
| 35 | + .size_full() | |
| 36 | +} | |
| 37 | + | |
| 38 | +/// A toolbar button: its glyph, its name, and its key on hover. `id` only buys | |
| 39 | +/// `on_click` and the tooltip -- it is still not focusable, so the root's own | |
| 40 | +/// key listener keeps working after a press, and the click lands on mouse-up | |
| 41 | +/// inside the button (a press that slides off does nothing). | |
| 42 | +/// | |
| 43 | +/// A button that would do nothing says so: dimmed, no pointer, no listener. | |
| 44 | +pub(crate) fn control( | |
| 45 | + id: &'static str, | |
| 46 | + glyph: Option<AnyElement>, | |
| 47 | + // Not `&'static str`: the volume button's label is its state. | |
| 48 | + label: impl Into<SharedString>, | |
| 49 | + shortcut: String, | |
| 50 | + enabled: bool, | |
| 51 | + on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static, | |
| 52 | +) -> impl IntoElement { | |
| 53 | + let label = label.into(); | |
| 54 | + let tip: SharedString = format!("{label} — {shortcut}").into(); | |
| 55 | + div() | |
| 56 | + .id(id) | |
| 57 | + .flex_none() | |
| 58 | + .h(px(CONTROL_H)) | |
| 59 | + .flex() | |
| 60 | + .items_center() | |
| 61 | + .gap(px(6.)) | |
| 62 | + .px(px(8.)) | |
| 63 | + .rounded(px(3.)) | |
| 64 | + .bg(rgb(BG_RAISED)) | |
| 65 | + .children(glyph) | |
| 66 | + .child(label) | |
| 67 | + .tooltip(move |_, cx| cx.new(|_| Tip(tip.clone())).into()) | |
| 68 | + .when(!enabled, |d| d.opacity(0.4).cursor_not_allowed()) | |
| 69 | + .when(enabled, |d| { | |
| 70 | + d.cursor_pointer() | |
| 71 | + .hover(|s| s.bg(rgb(BG_HOVER))) | |
| 72 | + .on_click(on_click) | |
| 73 | + }) | |
| 74 | +} | |
| 75 | + | |
| 76 | +/// The monitoring level as something to drag: 4 px of bar to look at and the | |
| 77 | +/// whole control's height to hit (WCAG 2.5.8), the split the speed bar and the | |
| 78 | +/// colour sliders both make. Only the level -- mute is the button beside it, so | |
| 79 | +/// a muted slider still shows what unmuting comes back to, drawn dim. | |
| 80 | +/// | |
| 81 | +/// Dimmed and inert without a timeline, like every other control that would | |
| 82 | +/// have nothing to act on. | |
| 83 | +pub(crate) fn volume_slider( | |
| 84 | + volume: Volume, | |
| 85 | + bar: Rc<Cell<Bounds<Pixels>>>, | |
| 86 | + enabled: bool, | |
| 87 | + cx: &mut Context<Player>, | |
| 88 | +) -> impl IntoElement { | |
| 89 | + div() | |
| 90 | + .id("volume-bar") | |
| 91 | + .relative() | |
| 92 | + .flex_none() | |
| 93 | + .w(px(VOLUME_W)) | |
| 94 | + .h(px(CONTROL_H)) | |
| 95 | + .flex() | |
| 96 | + .items_center() | |
| 97 | + .tooltip(|_, cx| { | |
| 98 | + cx.new(|_| Tip("Volume — drag to set the level; the button mutes".into())) | |
| 99 | + .into() | |
| 100 | + }) | |
| 101 | + .when(!enabled, |d| d.opacity(0.4).cursor_not_allowed()) | |
| 102 | + .when(enabled, |d| { | |
| 103 | + d.cursor_pointer() | |
| 104 | + .on_mouse_down( | |
| 105 | + MouseButton::Left, | |
| 106 | + cx.listener(|this, event: &MouseDownEvent, _, cx| { | |
| 107 | + this.volume_dragging = true; | |
| 108 | + this.drag_volume(event.position.x, cx); | |
| 109 | + }), | |
| 110 | + ) | |
| 111 | + .child(bounds_probe(bar)) | |
| 112 | + }) | |
| 113 | + .child( | |
| 114 | + div() | |
| 115 | + .w_full() | |
| 116 | + .h(px(4.)) | |
| 117 | + .rounded(px(2.)) | |
| 118 | + .bg(rgb(BG_RAISED)) | |
| 119 | + .child( | |
| 120 | + div() | |
| 121 | + .h_full() | |
| 122 | + .w(relative(volume.along())) | |
| 123 | + .rounded(px(2.)) | |
| 124 | + .bg(rgb(if volume.muted { FG_SECONDARY } else { ACCENT_PRIMARY })), | |
| 125 | + ), | |
| 126 | + ) | |
| 127 | +} | |
| 128 | + | |
| 129 | +/// The line between two groups of buttons. | |
| 130 | +pub(crate) fn separator() -> impl IntoElement { | |
| 131 | + div() | |
| 132 | + .flex_none() | |
| 133 | + .mx(px(4.)) | |
| 134 | + .w(px(1.)) | |
| 135 | + .h(px(18.)) | |
| 136 | + .bg(rgb(BG_HOVER)) | |
| 137 | +} | |
| 138 | + | |
| 139 | +/// Whether a card or a menu is drawn over the window, as the hover labels see | |
| 140 | +/// it: written once a frame by [`Player::render`], read by every [`Tip`] before | |
| 141 | +/// it paints. | |
| 142 | +/// | |
| 143 | +/// A tooltip already on screen when an overlay opens *stays* on screen in gpui: | |
| 144 | +/// occluding the surface under it does not take it back, because the check that | |
| 145 | +/// keeps it visible works off the element's absolute bounds and knows nothing | |
| 146 | +/// about what was painted over it (`div.rs::handle_tooltip_mouse_move`, its own | |
| 147 | +/// TODO). So the tip is what has to stand aside -- here, once, for every hover | |
| 148 | +/// label in this window, rather than at fifteen call sites of which the | |
| 149 | +/// sixteenth would be forgotten. | |
| 150 | +pub(crate) static OVERLAID: AtomicBool = AtomicBool::new(false); | |
| 151 | + | |
| 152 | +/// A tooltip is a view in gpui and nothing smaller, so this is the smallest one | |
| 153 | +/// that carries a line of text. It paints outside the window's element tree and | |
| 154 | +/// therefore owns its colours. | |
| 155 | +pub(crate) struct Tip(pub(crate) SharedString); | |
| 156 | + | |
| 157 | +impl Render for Tip { | |
| 158 | + fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement { | |
| 159 | + // A card or a menu is up: nothing. A line of text over the items of the | |
| 160 | + // menu that just opened under the pointer is the card being painted | |
| 161 | + // over by the window it covers. | |
| 162 | + if OVERLAID.load(Ordering::Relaxed) { | |
| 163 | + return div(); | |
| 164 | + } | |
| 165 | + div() | |
| 166 | + .px(px(6.)) | |
| 167 | + .py(px(3.)) | |
| 168 | + .rounded(px(3.)) | |
| 169 | + .border_1() | |
| 170 | + .border_color(rgb(BG_RAISED)) | |
| 171 | + .bg(rgb(BG_PANEL)) | |
| 172 | + .text_color(rgb(FG_PRIMARY)) | |
| 173 | + .text_size(px(12.)) | |
| 174 | + .child(self.0.clone()) | |
| 175 | + } | |
| 176 | +} | |
| 177 | + | |
| 178 | +/// Scissors: two blades crossed. Drawn this way and not as a split clip because | |
| 179 | +/// two bars is what the transport wears when it is playing -- the one glyph a | |
| 180 | +/// cut must never be mistaken for. | |
| 181 | +pub(crate) fn cut_glyph() -> impl IntoElement { | |
| 182 | + canvas( | |
| 183 | + |_, _, _| (), | |
| 184 | + |bounds, _, window, _| { | |
| 185 | + let (o, s) = (bounds.origin, bounds.size); | |
| 186 | + let mut path = PathBuilder::stroke(px(1.5)); | |
| 187 | + path.move_to(point(o.x + s.width * 0.15, o.y + s.height)); | |
| 188 | + path.line_to(point(o.x + s.width * 0.9, o.y + s.height * 0.1)); | |
| 189 | + path.move_to(point(o.x + s.width * 0.85, o.y + s.height)); | |
| 190 | + path.line_to(point(o.x + s.width * 0.1, o.y + s.height * 0.1)); | |
| 191 | + if let Ok(path) = path.build() { | |
| 192 | + window.paint_path(path, rgb(FG_PRIMARY)); | |
| 193 | + } | |
| 194 | + }, | |
| 195 | + ) | |
| 196 | + .w(px(13.)) | |
| 197 | + .h(px(13.)) | |
| 198 | +} | |
| 199 | + | |
| 200 | +/// A lid over a bin. | |
| 201 | +pub(crate) fn delete_glyph() -> impl IntoElement { | |
| 202 | + div() | |
| 203 | + .flex() | |
| 204 | + .flex_col() | |
| 205 | + .items_center() | |
| 206 | + .gap(px(2.)) | |
| 207 | + .child(div().w(px(13.)).h(px(2.)).bg(rgb(FG_PRIMARY))) | |
| 208 | + .child(div().w(px(9.)).h(px(9.)).bg(rgb(FG_PRIMARY))) | |
| 209 | +} | |
| 210 | + | |
| 211 | +/// What a window with no file open is waiting for. Both ways in are already | |
| 212 | +/// built -- the whole window is the drop target and the Import chooser takes a | |
| 213 | +/// project as readily as media -- so this only has to say so. | |
| 214 | +pub(crate) fn empty_hint() -> impl IntoElement { | |
| 215 | + div() | |
| 216 | + .flex() | |
| 217 | + .flex_col() | |
| 218 | + .items_center() | |
| 219 | + .gap(px(6.)) | |
| 220 | + .text_color(rgb(FG_SECONDARY)) | |
| 221 | + .child("Drop a video or an .edith project here") | |
| 222 | + .child( | |
| 223 | + div() | |
| 224 | + .text_size(px(11.)) | |
| 225 | + .child("or click Import in the media list"), | |
| 226 | + ) | |
| 227 | +} | |
| 228 | + | |
| 229 | +/// Two bars while playing, a triangle in every other state -- paused, nothing | |
| 230 | +/// open, and played out, where the button's next act is to start over rather | |
| 231 | +/// than to stop something. Drawn, so there is no icon font and no glyph | |
| 232 | +/// coverage to depend on. | |
| 233 | +pub(crate) fn transport_glyph(state: Transport) -> impl IntoElement { | |
| 234 | + let playing = state.is_playing(); | |
| 235 | + div() | |
| 236 | + .flex() | |
| 237 | + .items_center() | |
| 238 | + .gap(px(4.)) | |
| 239 | + .when(playing, |d| { | |
| 240 | + d.child(div().w(px(3.)).h(px(12.)).bg(rgb(FG_PRIMARY))) | |
| 241 | + .child(div().w(px(3.)).h(px(12.)).bg(rgb(FG_PRIMARY))) | |
| 242 | + }) | |
| 243 | + .when(!playing, |d| { | |
| 244 | + d.child( | |
| 245 | + canvas( | |
| 246 | + |_, _, _| (), | |
| 247 | + |bounds, _, window, _| { | |
| 248 | + let (o, s) = (bounds.origin, bounds.size); | |
| 249 | + let mut path = PathBuilder::fill(); | |
| 250 | + path.move_to(o); | |
| 251 | + path.line_to(point(o.x + s.width, o.y + s.height / 2.)); | |
| 252 | + path.line_to(point(o.x, o.y + s.height)); | |
| 253 | + path.close(); | |
| 254 | + if let Ok(path) = path.build() { | |
| 255 | + window.paint_path(path, rgb(FG_PRIMARY)); | |
| 256 | + } | |
| 257 | + }, | |
| 258 | + ) | |
| 259 | + .w(px(11.)) | |
| 260 | + .h(px(13.)), | |
| 261 | + ) | |
| 262 | + }) | |
| 263 | +} |