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