forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiB6dae2b4Tahinli3 months ago555 commits

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