edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching·0 forks·Rust·18.3 MiB·7f487c1·Tahinli·3 months ago·659 commits
| 1 | //! What the window looks like this frame: the one `render` the whole |
| 2 | //! interface hangs off, root to overlays. |
| 3 | |
| 4 | use crate::*; |
| 5 | |
| 6 | /// Whether a stroke leaves player fullscreen. Bare escape does, the same |
| 7 | /// stroke every card and menu in this window answers to -- and it is |
| 8 | /// answered *first*: the picture-only layout is the chrome itself missing, |
| 9 | /// not a card drawn over it, so it goes before a menu close or a preview |
| 10 | /// close gets a look at the same key. See the call site in [`Player::render`] |
| 11 | /// for the deliberate order this buys with a preview open underneath. |
| 12 | pub(crate) fn escape_leaves_player_fullscreen(key: &str, ctrl: bool, player_fullscreen: bool) -> bool { |
| 13 | key == ESCAPE && !ctrl && player_fullscreen |
| 14 | } |
| 15 | |
| 16 | /// The frame `image`, letterboxed/pillarboxed into whatever box it is given, |
| 17 | /// filling that box on its own axis and leaving the other bare -- the bare |
| 18 | /// strip is the box's own background (`BG_CANVAS`), never painted here, which |
| 19 | /// is why every caller sits this on a div already carrying that colour. |
| 20 | /// |
| 21 | /// `Img::object_fit(Contain)` reads right (verified by hand against |
| 22 | /// `ObjectFit::Contain::get_bounds`) but only when taffy has already given the |
| 23 | /// element a real size to fit *into* -- and for a plain `img()` with both axes |
| 24 | /// `Auto` (`size_full()`/`max_w_full().max_h_full()` both resolve that way in |
| 25 | /// this pin), it resolves to the image's own native size first and object-fit |
| 26 | /// never gets a box smaller than the frame to shrink into, so the frame reads |
| 27 | /// through un-fitted. A `canvas()` element carries no such precompute -- its |
| 28 | /// `request_layout` is a plain `Style` read, so it is sized by its parent |
| 29 | /// exactly as a `div()` would be -- and its `paint` callback is handed the |
| 30 | /// real resolved `bounds`, which is all `Contain::get_bounds` needs. |
| 31 | /// |
| 32 | /// `.absolute()` with all four insets zero, not `.size_full()` in flex flow: |
| 33 | /// a flex item under `justify_center()`/`items_center()` (see `picture_area` |
| 34 | /// below) never resolves a percentage cross-axis size for a plain-`Style` |
| 35 | /// element like `canvas()`, which is a taffy circularity and not this |
| 36 | /// element's own bug (confirmed live: bounds handed to `paint` came back |
| 37 | /// `944px x 0px`, main axis right, cross axis collapsed). An absolutely |
| 38 | /// positioned box is sized against its containing block directly instead -- |
| 39 | /// the nearest `.relative()` ancestor, which every caller here already sits |
| 40 | /// this on -- so it never asks taffy's flex algorithm for a cross-axis size |
| 41 | /// at all. |
| 42 | /// |
| 43 | /// That containing block still has to have a real size of its own, though: |
| 44 | /// gpui's default `display` is `Block` (`Style::default()`), not `Flex`, and |
| 45 | /// a `Block` box with height `auto` is sized by its *normal-flow* children -- |
| 46 | /// an `.absolute()` one, this, takes no part in that (confirmed live: with |
| 47 | /// the box lacking its own `.flex()`, this canvas's own bounds came back |
| 48 | /// `944px x 0px` even though its containing block, measured independently, |
| 49 | /// was a real `944px x 335px`). Every `.relative()` ancestor this sits on |
| 50 | /// must also be `.flex()` (see `ui::stance::screen`'s `stance-picture`) for |
| 51 | /// exactly this reason. |
| 52 | pub(crate) fn letterboxed_image(image: Arc<RenderImage>) -> impl IntoElement + Styled { |
| 53 | canvas( |
| 54 | |_, _, _| (), |
| 55 | move |bounds, _, window, _| { |
| 56 | let fitted = gpui::ObjectFit::Contain.get_bounds(bounds, image.size(0)); |
| 57 | let _ = window.paint_image(fitted, Corners::default(), image, 0, false); |
| 58 | }, |
| 59 | ) |
| 60 | .absolute() |
| 61 | .top_0() |
| 62 | .bottom_0() |
| 63 | .left_0() |
| 64 | .right_0() |
| 65 | .size_full() |
| 66 | } |
| 67 | |
| 68 | impl Player { |
| 69 | /// The picture region alone: the image, the subtitle cue plate, the |
| 70 | /// preview badge and the three transient bars over its bottom edge. |
| 71 | /// Its own method so player fullscreen ([`Player::act`]) can stand it up |
| 72 | /// as the window's only child without a second copy of what it draws -- |
| 73 | /// and so the darkroom's own screen region (DESIGN.md §5, |
| 74 | /// `ui::stance::screen`) draws the same picture rather than a second one. |
| 75 | pub(crate) fn picture_area( |
| 76 | &mut self, |
| 77 | position: f64, |
| 78 | window: &mut Window, |
| 79 | cx: &mut Context<Self>, |
| 80 | ) -> impl IntoElement { |
| 81 | div() |
| 82 | .flex_1() |
| 83 | .min_h(px(0.)) |
| 84 | .overflow_hidden() |
| 85 | // The bed the cue plate is placed against: it hangs off the |
| 86 | // bottom of the picture region, which is the one box that is the |
| 87 | // picture and nothing else. |
| 88 | .relative() |
| 89 | .flex() |
| 90 | .justify_center() |
| 91 | .items_center() |
| 92 | .bg(rgb(BG_CANVAS())) |
| 93 | .children( |
| 94 | self.image |
| 95 | .clone() |
| 96 | .map(|i| letterboxed_image(i).into_any_element()) |
| 97 | // With no file open the letterbox is the whole region, |
| 98 | // and a black rectangle says only that something is |
| 99 | // broken -- so it says what it wants instead. The window |
| 100 | // is already the drop target. |
| 101 | .or_else(|| { |
| 102 | (self.active_session().is_none()) |
| 103 | .then(|| empty_hint().into_any_element()) |
| 104 | }), |
| 105 | ) |
| 106 | // After the picture, so the plate is drawn over it rather than |
| 107 | // under. |
| 108 | .children(self.subtitle_overlay(position, window)) |
| 109 | .children(self.preview_badge(cx)) |
| 110 | // The three transient lines hang off the bottom of the picture |
| 111 | // rather than taking a row of the column: a notice that arrives |
| 112 | // must not push the transport, the toolbar and the timeline down |
| 113 | // by its own height -- which is a control moving with state, on |
| 114 | // every control below it at once. |
| 115 | .child( |
| 116 | div() |
| 117 | .absolute() |
| 118 | .bottom_0() |
| 119 | .left_0() |
| 120 | .right_0() |
| 121 | .flex() |
| 122 | .flex_col() |
| 123 | .gap(px(2.)) |
| 124 | .children(self.import_bar(cx)) |
| 125 | .children(self.seek_bar()) |
| 126 | // DESIGN §8: no full-width bar over the picture, ever. |
| 127 | // The darkroom stance has its own §8-conformant notice |
| 128 | // plate above the ledger (`ui::stance::notice_plate`) -- |
| 129 | // this legacy bar would otherwise paint a second, |
| 130 | // picture-covering copy of the same notice underneath |
| 131 | // it. The legacy (non-darkroom) room keeps this bar |
| 132 | // exactly as it was. |
| 133 | .children((!self.darkroom).then(|| self.notice_bar(cx)).flatten()) |
| 134 | // How tall the lot came out, for the cue plate above to |
| 135 | // step over ([`sub_bottom`]) -- the bars are over the |
| 136 | // picture, and a message drawn across the line being |
| 137 | // read loses both of them. Zero with no bar up, since |
| 138 | // this box is then empty. |
| 139 | .child(height_probe(self.notice_h.clone())), |
| 140 | ) |
| 141 | // The preview's scrub bar, drawn LAST: the notice box above shares |
| 142 | // its bottom edge, and a bar under the "PREVIEWING ..." plate was |
| 143 | // invisible for exactly the moment it matters. |
| 144 | .children(self.preview_scrub_bar(cx)) |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | impl Render for Player { |
| 149 | fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { |
| 150 | // A file that has just been opened sits on its first frame with the |
| 151 | // clock stopped: opening is not playing, whichever way the file |
| 152 | // arrived. The play binding and the transport button start it. |
| 153 | if let Some(session) = self.active_session_mut() { |
| 154 | session.tick(); |
| 155 | } |
| 156 | self.pump(window); |
| 157 | // What every hover label asks before it paints: a card or a menu is |
| 158 | // drawn over whatever the pointer is resting on. |
| 159 | OVERLAID.store(self.overlaid(), Ordering::Relaxed); |
| 160 | // A cleared seek is a frame delivered, which is the one readiness signal |
| 161 | // there is: whatever a slider drag held back is written here. |
| 162 | if self.seek_since.is_none() { |
| 163 | self.flush_drag(cx); |
| 164 | } |
| 165 | self.poll_export(); |
| 166 | self.poll_import(cx); |
| 167 | self.poll_silence(); |
| 168 | self.poll_proxies(cx); |
| 169 | // Every way a source can arrive -- argv, an import, a project load -- |
| 170 | // has been through a repaint by the time its clips are drawn, so this |
| 171 | // is the one place that has to notice a new one. |
| 172 | self.cache_media(cx); |
| 173 | self.cache_export_seat(cx); |
| 174 | self.cache_hw_caps(cx); |
| 175 | // What the compositor calls this window. Pushed only when it changes: |
| 176 | // it is a protocol round trip and this runs at vsync. |
| 177 | let title = window_title(&self.name); |
| 178 | if title != self.titled { |
| 179 | window.set_window_title(&title); |
| 180 | self.titled = title; |
| 181 | } |
| 182 | // A compositor keybind (the window manager's own fullscreen, not |
| 183 | // ours) can drop `window.is_fullscreen()` without ever going through |
| 184 | // [`Player::act`] -- the picture-only layout below must not survive |
| 185 | // that on its own, or the chrome never comes back. Only the *leaving* |
| 186 | // direction is reconciled here: the platform going fullscreen behind |
| 187 | // our back is not this editor asking for the picture-only layout, so |
| 188 | // it is left alone rather than guessed at. |
| 189 | if self.player_fullscreen && !window.is_fullscreen() { |
| 190 | self.player_fullscreen = false; |
| 191 | } |
| 192 | // No shadow flag: the session is the only truth about play state, and |
| 193 | // [`Player::transport`] is the one place it is read. |
| 194 | let state = self.transport(); |
| 195 | // A paused timeline has nothing to animate; the toggle handlers notify, |
| 196 | // which is what starts the loop again. A paused seek keeps the loop |
| 197 | // running by itself until `pump` has the frame it asked for. An export |
| 198 | // pauses playback and still needs the loop: its progress only reaches |
| 199 | // the screen on a repaint. A notice does not: it waits to be dismissed |
| 200 | // rather than for a clock, so keeping the loop alive for it would spin |
| 201 | // the GPU until someone answered it. |
| 202 | // An import does too, and for the same reason: its clock and its sweep |
| 203 | // only reach the screen on a repaint, and a still line is the very |
| 204 | // thing it exists to disprove. |
| 205 | if state.is_playing() |
| 206 | || self.seek_since.is_some() |
| 207 | || self.export.is_some() |
| 208 | || self.importing.is_some() |
| 209 | // A silence scan too: its progress and its two clocks only reach |
| 210 | // the screen on a repaint, and a still line is the very thing this |
| 211 | // card was rewritten to disprove. |
| 212 | || self.silence_scan.is_some() |
| 213 | // ...and a stand-in being made: its percentage on the library row |
| 214 | // only reaches the screen on a repaint, and a bar that never moves |
| 215 | // is exactly what a person reads as a hung encode. |
| 216 | || self.making_proxies() |
| 217 | { |
| 218 | window.request_animation_frame(); |
| 219 | } |
| 220 | |
| 221 | // Read per render, never cached: a delete shortens the timeline and the |
| 222 | // timecode, the ruler and the clamp below all have to follow it -- and |
| 223 | // so does the room a tail being dragged needs to grow into. |
| 224 | let duration = self.drawn_duration(); |
| 225 | let position = self.playhead(duration); |
| 226 | // Re-settled every frame against the duration this one is drawing: an |
| 227 | // edit that shortens the timeline moves the far end of the view, and a |
| 228 | // playhead that has run off the bed pulls the view after it -- which is |
| 229 | // what makes a zoomed-in timeline scroll while it plays. |
| 230 | // ...but only a playhead that is *going* somewhere pulls it: following |
| 231 | // is what a moving one does, during playback and through a seek. A view |
| 232 | // yanked back to a playhead nobody moved is a hand's own scroll undone |
| 233 | // by the very next frame, which is what made the wheel look dead. |
| 234 | // ...and a hand that scrolled the view away from the head keeps it |
| 235 | // ([`Player::panned`]): a follow that centres the head again would undo |
| 236 | // the notch before it was seen, which is what made the wheel look dead |
| 237 | // while playing. It is given straight back below, the moment the head |
| 238 | // is on the bed a person chose to look at -- so the scroll wins now and |
| 239 | // the follow resumes by itself, with nothing to press. |
| 240 | self.scale = match (state.is_playing() || self.seek_since.is_some()) && !self.panned { |
| 241 | true => self.view().following(position), |
| 242 | false => self.view().settled(), |
| 243 | }; |
| 244 | if self.panned && self.view().shows(position) { |
| 245 | self.panned = false; |
| 246 | } |
| 247 | |
| 248 | // DESIGN.md §12 step 2: the stance skeleton, on by default now |
| 249 | // (`OLD_GUI=1` opts back into the tree below). |
| 250 | // `.into_any_element()` on both arms is the one thing this branch |
| 251 | // costs the legacy tree below -- an `impl IntoElement` return can |
| 252 | // only be one concrete type, and the two trees are not the same one. |
| 253 | if self.darkroom { |
| 254 | return ui::stance::render(self, window, cx).into_any_element(); |
| 255 | } |
| 256 | |
| 257 | (div() |
| 258 | .track_focus(&self.focus) |
| 259 | .on_key_down(cx.listener(|this, event: &KeyDownEvent, window, cx| { |
| 260 | let key = event.keystroke.key.as_str(); |
| 261 | let ctrl = event.keystroke.modifiers.control; |
| 262 | // `is_held` is the auto-repeat, and a value is the one thing |
| 263 | // worth running on it: a held arrow on a card moves the slider |
| 264 | // it picked, and a held volume key runs the volume. Everything |
| 265 | // else is filtered exactly as it always was -- a repeat that |
| 266 | // toggled playback, or cut the timeline, many times a second is |
| 267 | // what this guard is for, and a row waiting for a stroke takes |
| 268 | // none of it either (it would bind the key, then fire what it |
| 269 | // just bound). See [`repeats`]. |
| 270 | if event.is_held |
| 271 | && !repeats(this.repeat_scope(), key, this.keymap.lookup(key, ctrl)) |
| 272 | { |
| 273 | return; |
| 274 | } |
| 275 | // The recovery notice is the one bar that reads a key as more |
| 276 | // than "answered": `enter` loads the sidecar it named, and |
| 277 | // every other key declines it -- the way any other key |
| 278 | // dismisses any other notice. Asked before the generic |
| 279 | // dismiss below shares the same door with it, not instead of |
| 280 | // it: this recovers or declines, that pops the bar. |
| 281 | if this.recovery_sidecar.is_some() { |
| 282 | if key == "enter" { |
| 283 | this.recover_from_sidecar(cx); |
| 284 | } else if let Some(sidecar) = this.recovery_sidecar.take() { |
| 285 | Player::discard_sidecar(&sidecar); |
| 286 | } |
| 287 | } |
| 288 | // Any key answers the message on the bar and brings the next of |
| 289 | // them up, whatever it was -- and owes |
| 290 | // the repaint itself: a notice no longer keeps the render loop |
| 291 | // alive, and the arms below that do notify are not all of them |
| 292 | // (an unbound key, or the copy chord, changes nothing else). |
| 293 | if this.dismiss_notice() { |
| 294 | cx.notify(); |
| 295 | } |
| 296 | // A row is waiting for a stroke, and while it is, that stroke is |
| 297 | // data: it means the binding and nothing else, which is why this |
| 298 | // answers before the export guard and before the keymap is |
| 299 | // consulted at all. |
| 300 | if let Some(action) = this.rebinding { |
| 301 | if key == ESCAPE { |
| 302 | this.rebinding = None; |
| 303 | } else if !is_bare_modifier(key) { |
| 304 | this.capture(action, key, ctrl); |
| 305 | } |
| 306 | cx.notify(); |
| 307 | return; |
| 308 | } |
| 309 | // On linux gpui reports the copy chord as key "c" with the |
| 310 | // control modifier set (the control code is mapped back), which |
| 311 | // is why the keymap is keyed on the pair and never on the key |
| 312 | // alone. |
| 313 | let action = this.keymap.lookup(key, ctrl); |
| 314 | // An export is reading the edit list every other action here |
| 315 | // would change, so cancelling is the only one that means |
| 316 | // anything until it is over. |
| 317 | if this.exporting().is_some() { |
| 318 | if cancels_export(key, ctrl, action) { |
| 319 | this.cancel_export(); |
| 320 | } |
| 321 | cx.notify(); |
| 322 | return; |
| 323 | } |
| 324 | // The overlay owns the keyboard while it is up -- but it types |
| 325 | // now: a printable stroke is the search box's, which is why |
| 326 | // nothing here reaches the keymap. A waiting row is answered |
| 327 | // above and still wins, so a rebind onto "v" binds the key |
| 328 | // rather than typing it. |
| 329 | if this.keys_open { |
| 330 | if key == ESCAPE { |
| 331 | // Two steps out, the way a search box anywhere gets |
| 332 | // out: the filter first -- the whole list back -- |
| 333 | // and the card only once there is no search to clear. |
| 334 | if this.keys_search.is_empty() { |
| 335 | this.keys_open = false; |
| 336 | } else { |
| 337 | this.keys_search.clear(); |
| 338 | this.scroll_keys(None); |
| 339 | } |
| 340 | // The rows past the fold, without a wheel: forty actions |
| 341 | // are four times what the viewport shows, and the hand |
| 342 | // typing in the search box is already on the keyboard. |
| 343 | } else if key == "up" { |
| 344 | this.scroll_keys(Some(KEYS_ROW_H)); |
| 345 | } else if key == "down" { |
| 346 | this.scroll_keys(Some(-KEYS_ROW_H)); |
| 347 | } else if key == "backspace" { |
| 348 | this.keys_search.pop(); |
| 349 | this.scroll_keys(None); |
| 350 | } else if let Some(c) = typed(key) { |
| 351 | this.keys_search.push(c); |
| 352 | this.scroll_keys(None); |
| 353 | } |
| 354 | cx.notify(); |
| 355 | return; |
| 356 | } |
| 357 | // The dock's Sources filter (MOCK-SPEC "Dock" §2): owns the |
| 358 | // keyboard only while it was clicked into, exactly the |
| 359 | // `keys_search` shape above -- a letter typed anywhere else in |
| 360 | // the room still means what the spine says it means. |
| 361 | if this.dock_filter_edit { |
| 362 | if key == "escape" || key == "enter" { |
| 363 | this.dock_filter_edit = false; |
| 364 | } else if key == "backspace" { |
| 365 | this.dock_filter.pop(); |
| 366 | } else if let Some(c) = typed(key) { |
| 367 | this.dock_filter.push(c); |
| 368 | } |
| 369 | cx.notify(); |
| 370 | return; |
| 371 | } |
| 372 | // `↵` adds the picked source at the playhead (MOCK-SPEC "Dock" |
| 373 | // hint paragraph, gesture 2) -- the keyboard door beside the |
| 374 | // legacy "Add at playhead" button's pointer one, live only |
| 375 | // where a row is actually picked so a bare enter elsewhere |
| 376 | // keeps meaning whatever it already means below. |
| 377 | if key == "enter" && this.dock_src_active && this.selected_asset.is_some() && this.exporting().is_none() { |
| 378 | if let Some((path, stream)) = this.selected_asset.clone() { |
| 379 | this.insert_source(&path, stream, None, None, cx); |
| 380 | } |
| 381 | cx.notify(); |
| 382 | return; |
| 383 | } |
| 384 | // The export card owns it the same way, and for the same |
| 385 | // reason. Escape closes it -- nothing has been written yet, so |
| 386 | // there is nothing here to cancel -- and the card's own letters |
| 387 | // are its input: it has no widget that takes focus (nothing in |
| 388 | // it does), so this listener is its keyboard, exactly as it is |
| 389 | // a waiting row's. |
| 390 | if this.export_open { |
| 391 | // A list open over the card is the innermost thing on |
| 392 | // screen, so it is what a stroke closes first -- the rule |
| 393 | // every menu here follows, said before the card's own keys |
| 394 | // so escape does not take the card out from under it. |
| 395 | if this.picker.take().is_some() { |
| 396 | cx.notify(); |
| 397 | return; |
| 398 | } |
| 399 | // A number being typed is the next thing in: while the |
| 400 | // field is open every stroke is text, which is what makes |
| 401 | // it a field and not a capture -- the card's letters cannot |
| 402 | // fire under it, and escape gives up the edit before it |
| 403 | // touches the card. |
| 404 | if let Some(edit) = &mut this.mbps_edit { |
| 405 | if key == ESCAPE { |
| 406 | this.mbps_edit = None; |
| 407 | } else if key == "enter" { |
| 408 | // Committed or refused in its own words; a refused |
| 409 | // one stays open on what was typed, so the number |
| 410 | // can be fixed rather than typed again. |
| 411 | if let Some(mbps) = edit.commit() { |
| 412 | this.custom_mbps = mbps; |
| 413 | this.quality = Quality::Custom; |
| 414 | this.mbps_edit = None; |
| 415 | } |
| 416 | } else if key == "backspace" { |
| 417 | edit.backspace(); |
| 418 | } else if key == "up" { |
| 419 | edit.step(1); |
| 420 | } else if key == "down" { |
| 421 | edit.step(-1); |
| 422 | } else if let Ok(digit) = key.parse::<u32>() { |
| 423 | edit.digit(digit); |
| 424 | } |
| 425 | cx.notify(); |
| 426 | return; |
| 427 | } |
| 428 | if key == ESCAPE { |
| 429 | this.export_open = false; |
| 430 | } else if key == "enter" { |
| 431 | // The card's own button, by keyboard: the one thing in |
| 432 | // it that writes a file must not be pointer-only either. |
| 433 | this.start_export(cx); |
| 434 | } else if let Some(format) = format_key(key, this.format) { |
| 435 | // The codec rows by their own letter, so the card can be |
| 436 | // driven without a mouse -- the same card-local input |
| 437 | // the typed bitrate is, and for the same reason: a |
| 438 | // choice reachable only by pointer is not reachable by |
| 439 | // everyone. Not a keymap binding: it means nothing |
| 440 | // outside this card, exactly like the digits. |
| 441 | this.set_format(format); |
| 442 | } else if key == "c" { |
| 443 | this.cycle_container(); |
| 444 | } else if key == "q" { |
| 445 | this.cycle_quality(); |
| 446 | } else if key == "b" { |
| 447 | // The sound's rate, `q`'s pair for the other half of |
| 448 | // the file. Not a digit: those are the picture's. |
| 449 | this.cycle_audio_kbps(); |
| 450 | } else if key == "e" { |
| 451 | // Which encoder writes the picture, `b`'s neighbour for |
| 452 | // the other thing about the file a person picks rather |
| 453 | // than types. Card-local like the rest of these. |
| 454 | this.cycle_encoder(cx); |
| 455 | } else if key == "d" { |
| 456 | // The save dialog, which was the one row here a |
| 457 | // keyboard could not open. |
| 458 | this.pick_destination(cx); |
| 459 | } else if let Some(preset) = ExportPreset::ALL |
| 460 | .into_iter() |
| 461 | .find(|p| p.key() == key) |
| 462 | // `Custom` shares `s` with Advanced below, which already |
| 463 | // handles that key -- reaching it here too would only |
| 464 | // race the same assignment against itself. |
| 465 | .filter(|p| *p != ExportPreset::Custom) |
| 466 | { |
| 467 | this.pick_preset(preset); |
| 468 | } else if key == "g" { |
| 469 | this.export_grouped = !this.export_grouped; |
| 470 | } else if key == "r" { |
| 471 | this.export_refusals_inline = !this.export_refusals_inline; |
| 472 | } else if key == "s" { |
| 473 | // The Advanced pane, by keyboard: the primary pane's |
| 474 | // own row for it opens the same way a click does. |
| 475 | this.export_advanced_open = !this.export_advanced_open; |
| 476 | } else if key == "n" { |
| 477 | // The custom row's field, by keyboard. The digits used |
| 478 | // to do this from anywhere in the card, which meant a |
| 479 | // stray keystroke changed the bitrate with nothing on |
| 480 | // screen to say it had: now a digit outside the field |
| 481 | // means nothing at all, and this is the way in. |
| 482 | this.edit_mbps(); |
| 483 | } |
| 484 | cx.notify(); |
| 485 | return; |
| 486 | } |
| 487 | // Every param card's own key branch, factored into |
| 488 | // `Player::param_card_key` (`player/cards.rs`) so this tree and |
| 489 | // the darkroom stance drive the same logic rather than a |
| 490 | // second, divergent copy. |
| 491 | if this.param_card_key(key, event.keystroke.modifiers.shift, cx) { |
| 492 | cx.notify(); |
| 493 | return; |
| 494 | } |
| 495 | // A clip menu names an index, and every edit below moves |
| 496 | // indices -- so a stroke closes it before it acts. Escape means |
| 497 | // that and nothing else, which is the `esc` the keys menu |
| 498 | // already lists (keymap.rs `FIXED`). |
| 499 | // Both menus, taken rather than short-circuited: the library's |
| 500 | // one names a row the edits below can remove, so it closes on a |
| 501 | // stroke exactly as the clip menu does. |
| 502 | // A choice list goes the same way and for the same reason: it |
| 503 | // names a clip index too, and escape is the way out of it. |
| 504 | // An open list is the innermost thing on screen, so it takes |
| 505 | // the keys before anything under it does: ↑↓ walk it, enter |
| 506 | // takes the row, and escape falls through to the close below -- |
| 507 | // the same three strokes every list in this editor answers. |
| 508 | // The picture-only layout is the outermost thing on screen -- |
| 509 | // it is the chrome itself that is missing, not a card drawn |
| 510 | // over it -- so its own escape is answered before any menu or |
| 511 | // preview below gets a look at the stroke. Deliberate order: |
| 512 | // with a preview open *and* the player fullscreen, the first |
| 513 | // Escape only leaves fullscreen (the preview keeps playing, |
| 514 | // now behind the chrome again), and it takes a second Escape |
| 515 | // to stop the preview -- one stroke, one effect, same as |
| 516 | // every other card in this chain. |
| 517 | if escape_leaves_player_fullscreen(key, ctrl, this.player_fullscreen) { |
| 518 | this.player_fullscreen = false; |
| 519 | window.toggle_fullscreen(); |
| 520 | cx.notify(); |
| 521 | return; |
| 522 | } |
| 523 | if let Some(mut picker) = this.picker { |
| 524 | let rows = this.choices(picker.of); |
| 525 | if !rows.is_empty() && matches!(key, "up" | "down" | "enter") { |
| 526 | match key { |
| 527 | "down" => picker.sel = (picker.sel + 1) % rows.len(), |
| 528 | "up" => picker.sel = (picker.sel + rows.len() - 1) % rows.len(), |
| 529 | _ => { |
| 530 | let (choice, ..) = rows[picker.sel.min(rows.len() - 1)]; |
| 531 | this.choose(choice, cx); |
| 532 | cx.notify(); |
| 533 | return; |
| 534 | } |
| 535 | } |
| 536 | this.picker = Some(picker); |
| 537 | cx.notify(); |
| 538 | return; |
| 539 | } |
| 540 | } |
| 541 | let clip_menu = this.context_menu.take().is_some(); |
| 542 | let row_menu = this.library_menu.take().is_some(); |
| 543 | let list = this.picker.take().is_some(); |
| 544 | if clip_menu || row_menu || list { |
| 545 | cx.notify(); |
| 546 | if key == ESCAPE { |
| 547 | return; |
| 548 | } |
| 549 | } |
| 550 | // The innermost thing left on screen once no menu is up: a |
| 551 | // preview takes the picture over the timeline's own, and |
| 552 | // escape is its own way out, same as every card above it. |
| 553 | if key == ESCAPE && !ctrl && this.preview_session.is_some() { |
| 554 | this.close_preview(cx); |
| 555 | return; |
| 556 | } |
| 557 | if let Some(action) = action { |
| 558 | this.act(action, window, cx); |
| 559 | } |
| 560 | })) |
| 561 | // The whole window is the drop target: gpui turns an external file |
| 562 | // drop into an `ExternalPaths` drag (window.rs:3626) delivered as a |
| 563 | // mouse-up to every hovered hitbox, and the root's is the only one |
| 564 | // that covers the picture as well as the panel. |
| 565 | .on_drop(cx.listener(|this, paths: &gpui::ExternalPaths, _, cx| { |
| 566 | // The overlay owns the pointer as well as the keyboard, and a |
| 567 | // drop is a click the scrim cannot swallow: gpui delivers it to |
| 568 | // the root's hitbox, which is under the scrim but is not a |
| 569 | // sibling it can stop. The export card is over the timeline for |
| 570 | // the same reason: importing under it would change the very |
| 571 | // edit list the card is about to write out. |
| 572 | if this.modal() { |
| 573 | return; |
| 574 | } |
| 575 | for path in paths.paths() { |
| 576 | // One queue for all of them, in arrival order: the fork -- |
| 577 | // a project replaces the timeline, media joins the library |
| 578 | // -- is made when each one's worker starts ([`arrival`]), |
| 579 | // and neither is read on this thread. |
| 580 | this.import(path, cx); |
| 581 | } |
| 582 | })) |
| 583 | // A drop event carries no path of its own -- gpui only tells the |
| 584 | // target that something landed -- so the line that promises where |
| 585 | // it will land is fed by the drag's own moves, which do carry the |
| 586 | // pointer (gpui div.rs:282). On the root, because a drag crosses |
| 587 | // the window: it starts on a clip or on a library row and ends over |
| 588 | // a lane, and only an ancestor of both hears all of it. |
| 589 | .on_drag_move(cx.listener(|this, event: &DragMoveEvent<ClipDrag>, _, cx| { |
| 590 | // The clip the payload named, wherever an edit mid-drag has |
| 591 | // since put it ([`Player::dragged`]): the line has to promise a |
| 592 | // landing for the take actually in the hand. |
| 593 | let drag = *event.drag(cx); |
| 594 | if let Some(idx) = this.dragged(&drag) { |
| 595 | this.preview_drop(drag.lane, idx, event.event.position.x, cx); |
| 596 | } |
| 597 | // The shadow belongs to a *lane*, and which lane the pointer is |
| 598 | // over is the one thing this element cannot see. Cleared here |
| 599 | // and drawn again by the lane the pointer is actually inside |
| 600 | // (`lane_row`), which gpui runs straight after this one: the |
| 601 | // capture phase goes parent first, so a pointer over no lane at |
| 602 | // all -- up in the library, say -- promises nothing. |
| 603 | this.set_ghost(None, cx); |
| 604 | })) |
| 605 | .on_drag_move( |
| 606 | cx.listener(|this, event: &DragMoveEvent<AssetDrag>, _, cx| { |
| 607 | this.preview_place(event.event.position.x, cx); |
| 608 | this.set_ghost(None, cx); |
| 609 | }), |
| 610 | ) |
| 611 | // The same pair for the two subtitle gestures, for the same reason: |
| 612 | // a palette row starts up in the library and a caption starts on a |
| 613 | // lane, and both are let go somewhere else entirely. |
| 614 | .on_drag_move(cx.listener(|this, event: &DragMoveEvent<SubPick>, _, cx| { |
| 615 | this.preview_place(event.event.position.x, cx); |
| 616 | this.set_ghost(None, cx); |
| 617 | })) |
| 618 | .on_drag_move(cx.listener(|this, event: &DragMoveEvent<SubDrag>, _, cx| { |
| 619 | // The placement gpui froze into the payload, whose *length* is |
| 620 | // all the line needs; which caption it is is the drop's |
| 621 | // question ([`Player::dragged_sub`]). |
| 622 | let (drag, x) = (*event.drag(cx), event.event.position.x); |
| 623 | let cue = this.sub_drop_frame(drag.sub, x).1; |
| 624 | this.set_cue(cue, x, cx); |
| 625 | this.set_ghost(None, cx); |
| 626 | })) |
| 627 | // Scrubbing is tracked on the root because the pointer leaves the |
| 628 | // 6 px ruler on the first drag and its own listeners then stop |
| 629 | // firing; the root's hitbox is the whole window. |
| 630 | .on_mouse_move(cx.listener(Self::drag_move)) |
| 631 | .on_mouse_up(MouseButton::Left, cx.listener(Self::drag_release)) |
| 632 | .size_full() |
| 633 | .flex() |
| 634 | .flex_col() |
| 635 | .bg(rgb(BG_CANVAS())) |
| 636 | .text_color(rgb(FG_PRIMARY())) |
| 637 | .text_size(px(12.)) |
| 638 | // Four regions, the arrangement every consumer editor shares: |
| 639 | // library left, picture centre, inspector right, and the timeline |
| 640 | // full width along the bottom with its edit toolbar directly above |
| 641 | // it. Nothing here moves when the state changes -- the regions are |
| 642 | // fixed and the panels keep their room whether or not anything is |
| 643 | // open in them. |
| 644 | // Player fullscreen: the picture and nothing else -- what |
| 645 | // `Fullscreen` gives every consumer video player. The four-region |
| 646 | // layout is skipped rather than hidden under it (a hidden library |
| 647 | // and inspector would still lay out and take the split's own |
| 648 | // room), and the picture div itself is untouched either way -- |
| 649 | // [`Player::picture_area`] is the same call in both arms. |
| 650 | .when(self.player_fullscreen, |d| { |
| 651 | d.child(self.picture_area(position, window, cx)) |
| 652 | }) |
| 653 | .when(!self.player_fullscreen, |d| { |
| 654 | d.child(self.topbar(window, cx)) |
| 655 | .child( |
| 656 | div() |
| 657 | .flex_1() |
| 658 | .min_h(px(0.)) |
| 659 | .flex() |
| 660 | .child(self.library( |
| 661 | self.split_px(Split::Library, window.viewport_size()), |
| 662 | cx, |
| 663 | )) |
| 664 | // The seams, one per pair of regions: what a hand |
| 665 | // drags to give a panel more room and its |
| 666 | // neighbour less ([`divider`]). |
| 667 | .child(divider(Split::Library, cx)) |
| 668 | .child( |
| 669 | div() |
| 670 | .flex_1() |
| 671 | .min_w(px(0.)) |
| 672 | .flex() |
| 673 | .flex_col() |
| 674 | .child(self.picture_area(position, window, cx)) |
| 675 | .child(self.transport_bar(state, window.viewport_size(), cx)), |
| 676 | ) |
| 677 | .child(divider(Split::Inspector, cx)) |
| 678 | // The settings cards live in here rather than over |
| 679 | // the timeline: adjusting a clip must not hide the |
| 680 | // clip. |
| 681 | .child(self.inspector(window.viewport_size(), cx)), |
| 682 | ) |
| 683 | // Above the toolbar rather than under it: the toolbar is |
| 684 | // a fixed strip belonging to the timeline, so the pair |
| 685 | // moves as one and the edge the hand is pulling is the |
| 686 | // edge under the pointer. |
| 687 | .child(divider(Split::Timeline, cx)) |
| 688 | .child(self.toolbar(cx)) |
| 689 | .child(self.timeline(position, state, window.viewport_size(), cx)) |
| 690 | }) |
| 691 | // Over the region they were opened on, and under the modal cards: |
| 692 | // they are only ever up while none of those is (`modal`). |
| 693 | .children(self.context_card(window.viewport_size(), cx)) |
| 694 | .children(self.library_card(window.viewport_size(), cx)) |
| 695 | // The two that are genuinely modal -- the whole registry, and the |
| 696 | // card that writes a file -- are the only sheets left over the |
| 697 | // window. |
| 698 | .children(self.keys_overlay(cx)) |
| 699 | .children(self.export_card(window.viewport_size(), cx)) |
| 700 | // The same sheet once the card has been answered: the running |
| 701 | // export is the one state in this window where nothing may be |
| 702 | // edited, so it is drawn as what it is rather than as a strip. |
| 703 | .children(self.export_progress_card(cx)) |
| 704 | // Last, so it floats over whatever opened it -- an inspector row or |
| 705 | // a clip menu -- rather than under it. |
| 706 | .children(self.picker_card(window.viewport_size(), cx))) |
| 707 | .into_any_element() |
| 708 | } |
| 709 | } |