forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBef5832fTahinli3 months ago597 commits

render.rs812 lines, 43.8 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 // The recovery notice is the one bar that reads a key as more
211 // than "answered": `enter` loads the sidecar it named, and
212 // every other key declines it -- the way any other key
213 // dismisses any other notice. Asked before the generic
214 // dismiss below shares the same door with it, not instead of
215 // it: this recovers or declines, that pops the bar.
216 if this.recovery_sidecar.is_some() {
217 if key == "enter" {
218 this.recover_from_sidecar(cx);
219 } else if let Some(sidecar) = this.recovery_sidecar.take() {
220 Player::discard_sidecar(&sidecar);
221 }
222 }
223 // Any key answers the message on the bar and brings the next of
224 // them up, whatever it was -- and owes
225 // the repaint itself: a notice no longer keeps the render loop
226 // alive, and the arms below that do notify are not all of them
227 // (an unbound key, or the copy chord, changes nothing else).
228 if this.dismiss_notice() {
229 cx.notify();
230 }
231 // A row is waiting for a stroke, and while it is, that stroke is
232 // data: it means the binding and nothing else, which is why this
233 // answers before the export guard and before the keymap is
234 // consulted at all.
235 if let Some(action) = this.rebinding {
236 if key == ESCAPE {
237 this.rebinding = None;
238 } else if !is_bare_modifier(key) {
239 this.capture(action, key, ctrl);
240 }
241 cx.notify();
242 return;
243 }
244 // On linux gpui reports the copy chord as key "c" with the
245 // control modifier set (the control code is mapped back), which
246 // is why the keymap is keyed on the pair and never on the key
247 // alone.
248 let action = this.keymap.lookup(key, ctrl);
249 // An export is reading the edit list every other action here
250 // would change, so cancelling is the only one that means
251 // anything until it is over.
252 if this.exporting().is_some() {
253 if cancels_export(key, ctrl, action) {
254 this.cancel_export();
255 }
256 cx.notify();
257 return;
258 }
259 // The overlay owns the keyboard while it is up -- but it types
260 // now: a printable stroke is the search box's, which is why
261 // nothing here reaches the keymap. A waiting row is answered
262 // above and still wins, so a rebind onto "v" binds the key
263 // rather than typing it.
264 if this.keys_open {
265 if key == ESCAPE {
266 // Two steps out, the way a search box anywhere gets
267 // out: the filter first -- the whole list back --
268 // and the card only once there is no search to clear.
269 if this.keys_search.is_empty() {
270 this.keys_open = false;
271 } else {
272 this.keys_search.clear();
273 this.scroll_keys(None);
274 }
275 // The rows past the fold, without a wheel: forty actions
276 // are four times what the viewport shows, and the hand
277 // typing in the search box is already on the keyboard.
278 } else if key == "up" {
279 this.scroll_keys(Some(KEYS_ROW_H));
280 } else if key == "down" {
281 this.scroll_keys(Some(-KEYS_ROW_H));
282 } else if key == "backspace" {
283 this.keys_search.pop();
284 this.scroll_keys(None);
285 } else if let Some(c) = typed(key) {
286 this.keys_search.push(c);
287 this.scroll_keys(None);
288 }
289 cx.notify();
290 return;
291 }
292 // The export card owns it the same way, and for the same
293 // reason. Escape closes it -- nothing has been written yet, so
294 // there is nothing here to cancel -- and the card's own letters
295 // are its input: it has no widget that takes focus (nothing in
296 // it does), so this listener is its keyboard, exactly as it is
297 // a waiting row's.
298 if this.export_open {
299 // A list open over the card is the innermost thing on
300 // screen, so it is what a stroke closes first -- the rule
301 // every menu here follows, said before the card's own keys
302 // so escape does not take the card out from under it.
303 if this.picker.take().is_some() {
304 cx.notify();
305 return;
306 }
307 // A number being typed is the next thing in: while the
308 // field is open every stroke is text, which is what makes
309 // it a field and not a capture -- the card's letters cannot
310 // fire under it, and escape gives up the edit before it
311 // touches the card.
312 if let Some(edit) = &mut this.mbps_edit {
313 if key == ESCAPE {
314 this.mbps_edit = None;
315 } else if key == "enter" {
316 // Committed or refused in its own words; a refused
317 // one stays open on what was typed, so the number
318 // can be fixed rather than typed again.
319 if let Some(mbps) = edit.commit() {
320 this.custom_mbps = mbps;
321 this.quality = Quality::Custom;
322 this.mbps_edit = None;
323 }
324 } else if key == "backspace" {
325 edit.backspace();
326 } else if key == "up" {
327 edit.step(1);
328 } else if key == "down" {
329 edit.step(-1);
330 } else if let Ok(digit) = key.parse::<u32>() {
331 edit.digit(digit);
332 }
333 cx.notify();
334 return;
335 }
336 if key == ESCAPE {
337 this.export_open = false;
338 } else if key == "enter" {
339 // The card's own button, by keyboard: the one thing in
340 // it that writes a file must not be pointer-only either.
341 this.start_export(cx);
342 } else if let Some(format) = format_key(key, this.format) {
343 // The codec rows by their own letter, so the card can be
344 // driven without a mouse -- the same card-local input
345 // the typed bitrate is, and for the same reason: a
346 // choice reachable only by pointer is not reachable by
347 // everyone. Not a keymap binding: it means nothing
348 // outside this card, exactly like the digits.
349 this.set_format(format);
350 } else if key == "c" {
351 this.cycle_container();
352 } else if key == "q" {
353 this.cycle_quality();
354 } else if key == "b" {
355 // The sound's rate, `q`'s pair for the other half of
356 // the file. Not a digit: those are the picture's.
357 this.cycle_audio_kbps();
358 } else if key == "e" {
359 // Which encoder writes the picture, `b`'s neighbour for
360 // the other thing about the file a person picks rather
361 // than types. Card-local like the rest of these.
362 this.cycle_encoder(cx);
363 } else if key == "d" {
364 // The save dialog, which was the one row here a
365 // keyboard could not open.
366 this.pick_destination(cx);
367 } else if let Some(preset) = ExportPreset::ALL
368 .into_iter()
369 .find(|p| p.key() == key)
370 // `Custom` shares `s` with Advanced below, which already
371 // handles that key -- reaching it here too would only
372 // race the same assignment against itself.
373 .filter(|p| *p != ExportPreset::Custom)
374 {
375 this.pick_preset(preset);
376 } else if key == "g" {
377 this.export_grouped = !this.export_grouped;
378 } else if key == "r" {
379 this.export_refusals_inline = !this.export_refusals_inline;
380 } else if key == "s" {
381 // The Advanced pane, by keyboard: the primary pane's
382 // own row for it opens the same way a click does.
383 this.export_advanced_open = !this.export_advanced_open;
384 } else if key == "n" {
385 // The custom row's field, by keyboard. The digits used
386 // to do this from anywhere in the card, which meant a
387 // stray keystroke changed the bitrate with nothing on
388 // screen to say it had: now a digit outside the field
389 // means nothing at all, and this is the way in.
390 this.edit_mbps();
391 }
392 cx.notify();
393 return;
394 }
395 // And the equalizer card, the same way again. Its own strokes
396 // are the card's input, exactly as the export card's digits
397 // are: a band reachable only by dragging is a band a keyboard
398 // cannot move at all, and every one of them is listed in the
399 // keys menu (keymap.rs `FIXED`) rather than being a secret.
400 if this.eq_open.is_some() {
401 // Shift makes the two horizontal keys Q instead of
402 // frequency: both are the *width* of the same hump, so they
403 // sit on the same axis rather than on two keys nobody would
404 // guess. Wider is a lower Q, which is why left widens.
405 let shift = event.keystroke.modifiers.shift;
406 if key == ESCAPE {
407 // Nothing to undo: every change is already at the clip,
408 // and undo is undo's own key.
409 this.eq_open = None;
410 this.eq_dragging = false;
411 } else if key == "up" {
412 this.nudge_band(|b| b.gain_db += EQ_STEP, cx);
413 } else if key == "down" {
414 this.nudge_band(|b| b.gain_db -= EQ_STEP, cx);
415 } else if key == "left" && shift {
416 this.nudge_band(|b| b.q /= EQ_Q_STEP, cx);
417 } else if key == "right" && shift {
418 this.nudge_band(|b| b.q *= EQ_Q_STEP, cx);
419 } else if key == "left" {
420 this.nudge_band(|b| b.freq_hz /= EQ_FREQ_STEP, cx);
421 } else if key == "right" {
422 this.nudge_band(|b| b.freq_hz *= EQ_FREQ_STEP, cx);
423 } else if key == "r" {
424 for band in &mut this.eq_params.bands {
425 band.gain_db = 0.;
426 }
427 this.commit_eq(cx);
428 } else if key == "f" {
429 // This one band back to flat, which is the undo of one
430 // hand movement -- `r` is the undo of the whole card.
431 this.nudge_band(|b| b.gain_db = 0., cx);
432 } else if key == "a" {
433 this.add_band(cx);
434 } else if key == "x" {
435 this.remove_band(cx);
436 } else if key == "s" {
437 // The analyser off and on. Nothing is committed: it is
438 // what the card *shows*, so it survives no further than
439 // this window.
440 this.eq_spectrum = !this.eq_spectrum;
441 } else if let Ok(digit) = key.parse::<usize>() {
442 // As the keys are laid out: 1-9 then 0 for the tenth,
443 // which is the cap ([`EQ_BANDS_MAX`]). A digit past the
444 // last band picks nothing rather than panics.
445 let band = match digit {
446 0 => EQ_BANDS_MAX - 1,
447 n => n - 1,
448 };
449 if band < this.eq_params.bands.len() {
450 this.eq_band = band;
451 }
452 }
453 cx.notify();
454 return;
455 }
456 // The colour card owns the keyboard the same way the export
457 // card does, and its keys mean nothing outside it: the arrows
458 // pick a slider and move it, and `r` takes the grade off. Not
459 // keymap bindings for exactly that reason -- see `FIXED`, where
460 // the keys menu still lists them.
461 if this.color_open.is_some() {
462 match color_key(key) {
463 Some(ColorKey::Close) => {
464 this.color_open = None;
465 this.color_dragging = false;
466 }
467 Some(ColorKey::Band(step)) => {
468 this.color_band = (this.color_band + step) % COLOR_BANDS.len();
469 }
470 Some(ColorKey::Nudge(steps)) => this.nudge_color(steps, cx),
471 Some(ColorKey::Reset) => {
472 this.set_color(ColorParams::default(), cx);
473 }
474 None => {}
475 }
476 cx.notify();
477 return;
478 }
479 // The transform card, the same way again: the arrows pick a
480 // slider and move it, and `r` puts the placement back to
481 // identity. Card-local, [`ActionId::Color`]'s own reason (see
482 // `FIXED`, where the keys menu still lists them).
483 if this.transform_open.is_some() {
484 let n = TRANSFORM_BANDS.len();
485 if key == ESCAPE {
486 this.transform_open = None;
487 this.transform_dragging = false;
488 } else if key == "down" {
489 this.transform_band = (this.transform_band + 1) % n;
490 } else if key == "up" {
491 this.transform_band = (this.transform_band + n - 1) % n;
492 } else if key == "right" {
493 this.nudge_transform(1., cx);
494 } else if key == "left" {
495 this.nudge_transform(-1., cx);
496 } else if key == "r" {
497 this.set_transform(TransformParams::default(), cx);
498 }
499 cx.notify();
500 return;
501 }
502 // The speed card, the same way again: its arrows move the rate
503 // and `r` puts it back to real time, and neither means anything
504 // outside the card -- so neither is a binding (see `FIXED`,
505 // where the keys menu still lists them).
506 if this.speed_open.is_some() {
507 match color_key(key) {
508 Some(ColorKey::Close) => {
509 this.speed_open = None;
510 this.speed_dragging = false;
511 }
512 // The card has one value, so the pair that picks a
513 // slider on the colour card moves this one by a whole
514 // preset's worth instead of a step.
515 Some(ColorKey::Band(step)) => {
516 this.nudge_speed(if step == 1 { -2 } else { 2 }, cx)
517 }
518 Some(ColorKey::Nudge(steps)) => this.nudge_speed(steps as i32, cx),
519 Some(ColorKey::Reset) => this.set_speed(Speed::NORMAL, cx),
520 None => {}
521 }
522 cx.notify();
523 return;
524 }
525 // The silence card, the same way again: the arrows pick one of
526 // its rows and move it, and its two apply keys are the two
527 // things it can do to the timeline. Card-local, every one of
528 // them -- and listed in the keys menu (keymap.rs `FIXED`),
529 // because a key that cuts forty places at once is not a secret.
530 if this.silence_open.is_some() {
531 if key == ESCAPE {
532 // Nothing to undo: a preview is not an edit.
533 this.close_silence();
534 } else if key == "down" {
535 this.silence_field = (this.silence_field + 1) % SILENCE_ROWS;
536 } else if key == "up" {
537 this.silence_field = (this.silence_field + SILENCE_ROWS - 1) % SILENCE_ROWS;
538 } else if key == "right" {
539 this.nudge_silence(1);
540 } else if key == "left" {
541 this.nudge_silence(-1);
542 } else if key == "enter" {
543 this.cut_silences(cx);
544 } else if key == "f" {
545 this.speed_silences(cx);
546 }
547 cx.notify();
548 return;
549 }
550 // The mix card, the same way again: ↑↓ pick a row -- a track's
551 // fader, the limiter's ceiling or its switch -- and ←→ move it,
552 // held or pressed. Card-local like the four above it.
553 if this.mix_open {
554 let rows = this.mix_lanes().len() + MIX_MASTER_ROWS;
555 if key == ESCAPE {
556 this.mix_open = false;
557 } else if key == "down" {
558 this.mix_field = (this.mix_field + 1) % rows;
559 } else if key == "up" {
560 this.mix_field = (this.mix_field + rows - 1) % rows;
561 } else if key == "right" {
562 this.nudge_mix(1, cx);
563 } else if key == "left" {
564 this.nudge_mix(-1, cx);
565 }
566 cx.notify();
567 return;
568 }
569 // The subtitle style card, the same way again: row 0 is the
570 // size stepper (←→ moves it, held or pressed, the mix card's
571 // rule) and every row after it a family in
572 // `subtitle_fonts` -- ↑↓ walk the whole list and `enter`
573 // picks the one the arrows are on, since a hand with no
574 // mouse still has to be able to leave the platform default.
575 if this.subtitle_style_open {
576 // Row 0 is the size stepper, row 1 the platform default,
577 // and every row after it a family in `subtitle_fonts`.
578 let rows = 2 + this.subtitle_fonts.len();
579 if key == ESCAPE {
580 this.subtitle_style_open = false;
581 } else if key == "down" {
582 this.subtitle_style_field = (this.subtitle_style_field + 1) % rows;
583 } else if key == "up" {
584 this.subtitle_style_field =
585 (this.subtitle_style_field + rows - 1) % rows;
586 } else if key == "right" {
587 this.nudge_sub_size(1, cx);
588 } else if key == "left" {
589 this.nudge_sub_size(-1, cx);
590 } else if key == "enter" && this.subtitle_style_field == 1 {
591 this.set_sub_family(None, cx);
592 } else if key == "enter" && this.subtitle_style_field > 1 {
593 let family = this.subtitle_fonts[this.subtitle_style_field - 2].clone();
594 this.set_sub_family(Some(family), cx);
595 }
596 cx.notify();
597 return;
598 }
599 // A clip menu names an index, and every edit below moves
600 // indices -- so a stroke closes it before it acts. Escape means
601 // that and nothing else, which is the `esc` the keys menu
602 // already lists (keymap.rs `FIXED`).
603 // Both menus, taken rather than short-circuited: the library's
604 // one names a row the edits below can remove, so it closes on a
605 // stroke exactly as the clip menu does.
606 // A choice list goes the same way and for the same reason: it
607 // names a clip index too, and escape is the way out of it.
608 // An open list is the innermost thing on screen, so it takes
609 // the keys before anything under it does: ↑↓ walk it, enter
610 // takes the row, and escape falls through to the close below --
611 // the same three strokes every list in this editor answers.
612 // The picture-only layout is the outermost thing on screen --
613 // it is the chrome itself that is missing, not a card drawn
614 // over it -- so its own escape is answered before any menu or
615 // preview below gets a look at the stroke. Deliberate order:
616 // with a preview open *and* the player fullscreen, the first
617 // Escape only leaves fullscreen (the preview keeps playing,
618 // now behind the chrome again), and it takes a second Escape
619 // to stop the preview -- one stroke, one effect, same as
620 // every other card in this chain.
621 if escape_leaves_player_fullscreen(key, ctrl, this.player_fullscreen) {
622 this.player_fullscreen = false;
623 window.toggle_fullscreen();
624 cx.notify();
625 return;
626 }
627 if let Some(mut picker) = this.picker {
628 let rows = this.choices(picker.of);
629 if !rows.is_empty() && matches!(key, "up" | "down" | "enter") {
630 match key {
631 "down" => picker.sel = (picker.sel + 1) % rows.len(),
632 "up" => picker.sel = (picker.sel + rows.len() - 1) % rows.len(),
633 _ => {
634 let (choice, ..) = rows[picker.sel.min(rows.len() - 1)];
635 this.choose(choice, cx);
636 cx.notify();
637 return;
638 }
639 }
640 this.picker = Some(picker);
641 cx.notify();
642 return;
643 }
644 }
645 let clip_menu = this.context_menu.take().is_some();
646 let row_menu = this.library_menu.take().is_some();
647 let list = this.picker.take().is_some();
648 if clip_menu || row_menu || list {
649 cx.notify();
650 if key == ESCAPE {
651 return;
652 }
653 }
654 // The innermost thing left on screen once no menu is up: a
655 // preview takes the picture over the timeline's own, and
656 // escape is its own way out, same as every card above it.
657 if key == ESCAPE && !ctrl && this.preview_session.is_some() {
658 this.close_preview(cx);
659 return;
660 }
661 if let Some(action) = action {
662 this.act(action, window, cx);
663 }
664 }))
665 // The whole window is the drop target: gpui turns an external file
666 // drop into an `ExternalPaths` drag (window.rs:3626) delivered as a
667 // mouse-up to every hovered hitbox, and the root's is the only one
668 // that covers the picture as well as the panel.
669 .on_drop(cx.listener(|this, paths: &gpui::ExternalPaths, _, cx| {
670 // The overlay owns the pointer as well as the keyboard, and a
671 // drop is a click the scrim cannot swallow: gpui delivers it to
672 // the root's hitbox, which is under the scrim but is not a
673 // sibling it can stop. The export card is over the timeline for
674 // the same reason: importing under it would change the very
675 // edit list the card is about to write out.
676 if this.modal() {
677 return;
678 }
679 for path in paths.paths() {
680 // One queue for all of them, in arrival order: the fork --
681 // a project replaces the timeline, media joins the library
682 // -- is made when each one's worker starts ([`arrival`]),
683 // and neither is read on this thread.
684 this.import(path, cx);
685 }
686 }))
687 // A drop event carries no path of its own -- gpui only tells the
688 // target that something landed -- so the line that promises where
689 // it will land is fed by the drag's own moves, which do carry the
690 // pointer (gpui div.rs:282). On the root, because a drag crosses
691 // the window: it starts on a clip or on a library row and ends over
692 // a lane, and only an ancestor of both hears all of it.
693 .on_drag_move(cx.listener(|this, event: &DragMoveEvent<ClipDrag>, _, cx| {
694 // The clip the payload named, wherever an edit mid-drag has
695 // since put it ([`Player::dragged`]): the line has to promise a
696 // landing for the take actually in the hand.
697 let drag = *event.drag(cx);
698 if let Some(idx) = this.dragged(&drag) {
699 this.preview_drop(drag.lane, idx, event.event.position.x, cx);
700 }
701 // The shadow belongs to a *lane*, and which lane the pointer is
702 // over is the one thing this element cannot see. Cleared here
703 // and drawn again by the lane the pointer is actually inside
704 // (`lane_row`), which gpui runs straight after this one: the
705 // capture phase goes parent first, so a pointer over no lane at
706 // all -- up in the library, say -- promises nothing.
707 this.set_ghost(None, cx);
708 }))
709 .on_drag_move(
710 cx.listener(|this, event: &DragMoveEvent<AssetDrag>, _, cx| {
711 this.preview_place(event.event.position.x, cx);
712 this.set_ghost(None, cx);
713 }),
714 )
715 // The same pair for the two subtitle gestures, for the same reason:
716 // a palette row starts up in the library and a caption starts on a
717 // lane, and both are let go somewhere else entirely.
718 .on_drag_move(cx.listener(|this, event: &DragMoveEvent<SubPick>, _, cx| {
719 this.preview_place(event.event.position.x, cx);
720 this.set_ghost(None, cx);
721 }))
722 .on_drag_move(cx.listener(|this, event: &DragMoveEvent<SubDrag>, _, cx| {
723 // The placement gpui froze into the payload, whose *length* is
724 // all the line needs; which caption it is is the drop's
725 // question ([`Player::dragged_sub`]).
726 let (drag, x) = (*event.drag(cx), event.event.position.x);
727 let cue = this.sub_drop_frame(drag.sub, x).1;
728 this.set_cue(cue, x, cx);
729 this.set_ghost(None, cx);
730 }))
731 // Scrubbing is tracked on the root because the pointer leaves the
732 // 6 px ruler on the first drag and its own listeners then stop
733 // firing; the root's hitbox is the whole window.
734 .on_mouse_move(cx.listener(Self::drag_move))
735 .on_mouse_up(MouseButton::Left, cx.listener(Self::drag_release))
736 .size_full()
737 .flex()
738 .flex_col()
739 .bg(rgb(BG_CANVAS()))
740 .text_color(rgb(FG_PRIMARY()))
741 .text_size(px(12.))
742 // Four regions, the arrangement every consumer editor shares:
743 // library left, picture centre, inspector right, and the timeline
744 // full width along the bottom with its edit toolbar directly above
745 // it. Nothing here moves when the state changes -- the regions are
746 // fixed and the panels keep their room whether or not anything is
747 // open in them.
748 // Player fullscreen: the picture and nothing else -- what
749 // `Fullscreen` gives every consumer video player. The four-region
750 // layout is skipped rather than hidden under it (a hidden library
751 // and inspector would still lay out and take the split's own
752 // room), and the picture div itself is untouched either way --
753 // [`Player::picture_area`] is the same call in both arms.
754 .when(self.player_fullscreen, |d| {
755 d.child(self.picture_area(position, window, cx))
756 })
757 .when(!self.player_fullscreen, |d| {
758 d.child(self.topbar(window, cx))
759 .child(
760 div()
761 .flex_1()
762 .min_h(px(0.))
763 .flex()
764 .child(self.library(
765 self.split_px(Split::Library, window.viewport_size()),
766 cx,
767 ))
768 // The seams, one per pair of regions: what a hand
769 // drags to give a panel more room and its
770 // neighbour less ([`divider`]).
771 .child(divider(Split::Library, cx))
772 .child(
773 div()
774 .flex_1()
775 .min_w(px(0.))
776 .flex()
777 .flex_col()
778 .child(self.picture_area(position, window, cx))
779 .child(self.transport_bar(state, window.viewport_size(), cx)),
780 )
781 .child(divider(Split::Inspector, cx))
782 // The settings cards live in here rather than over
783 // the timeline: adjusting a clip must not hide the
784 // clip.
785 .child(self.inspector(window.viewport_size(), cx)),
786 )
787 // Above the toolbar rather than under it: the toolbar is
788 // a fixed strip belonging to the timeline, so the pair
789 // moves as one and the edge the hand is pulling is the
790 // edge under the pointer.
791 .child(divider(Split::Timeline, cx))
792 .child(self.toolbar(cx))
793 .child(self.timeline(position, state, window.viewport_size(), cx))
794 })
795 // Over the region they were opened on, and under the modal cards:
796 // they are only ever up while none of those is (`modal`).
797 .children(self.context_card(window.viewport_size(), cx))
798 .children(self.library_card(window.viewport_size(), cx))
799 // The two that are genuinely modal -- the whole registry, and the
800 // card that writes a file -- are the only sheets left over the
801 // window.
802 .children(self.keys_overlay(cx))
803 .children(self.export_card(window.viewport_size(), cx))
804 // The same sheet once the card has been answered: the running
805 // export is the one state in this window where nothing may be
806 // edited, so it is drawn as what it is rather than as a strip.
807 .children(self.export_progress_card(cx))
808 // Last, so it floats over whatever opened it -- an inspector row or
809 // a clip menu -- rather than under it.
810 .children(self.picker_card(window.viewport_size(), cx))
811 }
812}