forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiB33ae7d9Tahinli3 months ago699 commits

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