Visible file controls, labeled buttons, persistent notices
Browse files at this commita981d4af94fee0078b83b01848f18354adf1c317Parent: 3adbaf7- feat
- visible file controls, labeled buttons, persistent notices
1 changed file +337 -92
- crates/app/src/main.rs +337 -92
crates/app/src/main.rsmodified+337 -92
| @@ -6,10 +6,10 @@ use std::time::{Duration, Instant}; | |||
| 6 | 6 | ||
| 7 | use engine::{Clip, ExportHandle, Frame, PlaybackSession}; | 7 | use engine::{Clip, ExportHandle, Frame, PlaybackSession}; |
| 8 | use gpui::{ | 8 | use gpui::{ |
| 9 | - App, Application, Bounds, Context, FocusHandle, KeyDownEvent, MouseButton, MouseDownEvent, | 9 | + AnyElement, App, Application, Bounds, ClickEvent, Context, FocusHandle, KeyDownEvent, |
| 10 | - MouseMoveEvent, MouseUpEvent, PathBuilder, Pixels, RenderImage, SharedString, TitlebarOptions, | 10 | + MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, PathBuilder, Pixels, RenderImage, |
| 11 | - Window, WindowBounds, WindowOptions, canvas, div, img, point, prelude::*, px, relative, rgb, | 11 | + SharedString, TitlebarOptions, Window, WindowBounds, WindowOptions, canvas, div, img, point, |
| 12 | - size, | 12 | + prelude::*, px, relative, rgb, size, |
| 13 | }; | 13 | }; |
| 14 | 14 | ||
| 15 | /// Editor chrome: three grays and one accent, all darker than the picture so the | 15 | /// Editor chrome: three grays and one accent, all darker than the picture so the |
| @@ -26,15 +26,36 @@ const SELECTED: u32 = 0x2a4a6b; | |||
| 26 | /// the lane stays in the dark family the rest of the chrome lives in | 26 | /// the lane stays in the dark family the rest of the chrome lives in |
| 27 | /// (ledger:187), and the first source keeps `SURFACE` exactly. | 27 | /// (ledger:187), and the first source keeps `SURFACE` exactly. |
| 28 | const SOURCE_TINTS: [u32; 4] = [SURFACE, 0x3b3329, 0x293b33, 0x33293b]; | 28 | const SOURCE_TINTS: [u32; 4] = [SURFACE, 0x3b3329, 0x293b33, 0x33293b]; |
| 29 | +/// One step lighter than whatever it sits on: the pointer's answer that this is | ||
| 30 | +/// clickable. Two of them, because buttons stand on `SURFACE` and the scrub | ||
| 31 | +/// strip stands on `CHROME`. | ||
| 32 | +const HOVER: u32 = 0x3f3f3f; | ||
| 33 | +const HOVER_DIM: u32 = 0x2c2c2c; | ||
| 34 | +/// Secondary text -- shortcuts, dismissal hints. Dimmer than `INK` and still | ||
| 35 | +/// past 4.5:1 on both `SURFACE` and `CHROME`. | ||
| 36 | +const INK_DIM: u32 = 0xa0a0a0; | ||
| 29 | 37 | ||
| 30 | /// Fixed so the video region takes every pixel the window gains and the controls | 38 | /// Fixed so the video region takes every pixel the window gains and the controls |
| 31 | /// never clip at 640x360. | 39 | /// never clip at 640x360. |
| 32 | const HEADER_H: f32 = 32.; | 40 | const HEADER_H: f32 = 32.; |
| 33 | -const PANEL_H: f32 = 180.; | 41 | +// 28 button row + 24 scrub strip + two 48 lanes + the timecode line + the gaps |
| 42 | +// between them, with a few px of slack so a taller text line cannot push a lane | ||
| 43 | +// off the bottom. | ||
| 44 | +const PANEL_H: f32 = 220.; | ||
| 34 | const LANE_H: f32 = 48.; | 45 | const LANE_H: f32 = 48.; |
| 46 | +/// WCAG 2.5.8: nothing clickable is smaller than this. The scrub bar stays 6 px | ||
| 47 | +/// to look at -- `RULER_HIT_H` is the strip that has to be hit. | ||
| 48 | +const HIT_MIN: f32 = 24.; | ||
| 49 | +const CONTROL_H: f32 = 28.; | ||
| 50 | +const RULER_HIT_H: f32 = HIT_MIN; | ||
| 35 | /// Wide enough for `HH:MM:SS:FF / HH:MM:SS:FF`, and fixed so changing digits | 51 | /// Wide enough for `HH:MM:SS:FF / HH:MM:SS:FF`, and fixed so changing digits |
| 36 | /// cannot push the layout around. | 52 | /// cannot push the layout around. |
| 37 | const TIME_W: f32 = 200.; | 53 | const TIME_W: f32 = 200.; |
| 54 | +/// The shortcuts no button carries; the rest ride on the buttons' tooltips. | ||
| 55 | +/// Keys first: at a 640 px window the tail is what a truncation eats, and the | ||
| 56 | +/// two hints at the end are also on the ruler's and Import's tooltips. | ||
| 57 | +const KEY_HINTS: &str = | ||
| 58 | + "ctrl+c copy · ctrl+v paste · z undo · click the bar to seek · drop a file to import"; | ||
| 38 | 59 | ||
| 39 | struct Player { | 60 | struct Player { |
| 40 | session: PlaybackSession, | 61 | session: PlaybackSession, |
| @@ -82,9 +103,10 @@ struct Player { | |||
| 82 | /// one derived beside the media it started as. Saving twice overwrites the | 103 | /// one derived beside the media it started as. Saving twice overwrites the |
| 83 | /// same file rather than making a second one. | 104 | /// same file rather than making a second one. |
| 84 | project_path: PathBuf, | 105 | project_path: PathBuf, |
| 85 | - /// What the last export left in the timecode slot, and when. Cleared by | 106 | + /// What the last file action had to say. Holds its own bar above the panel |
| 86 | - /// `NOTICE` passing or by the next key, whichever comes first. | 107 | + /// until it is answered -- any key retires it, so does a click on it -- so a |
| 87 | - notice: Option<(SharedString, Instant)>, | 108 | + /// failure is read in full instead of blinking past. |
| 109 | + notice: Option<SharedString>, | ||
| 88 | displayed: u32, | 110 | displayed: u32, |
| 89 | dropped: u32, | 111 | dropped: u32, |
| 90 | /// Wall clock of the first displayed frame -- the real-speed measurement. | 112 | /// Wall clock of the first displayed frame -- the real-speed measurement. |
| @@ -238,10 +260,39 @@ impl Player { | |||
| 238 | Err(e) => format!("IMPORT FAILED: {e}"), | 260 | Err(e) => format!("IMPORT FAILED: {e}"), |
| 239 | }; | 261 | }; |
| 240 | eprintln!("{text}"); | 262 | eprintln!("{text}"); |
| 241 | - self.notice = Some((text.into(), Instant::now())); | 263 | + self.notice = Some(text.into()); |
| 242 | cx.notify(); | 264 | cx.notify(); |
| 243 | } | 265 | } |
| 244 | 266 | ||
| 267 | + /// The Import button: asks the desktop for a path and takes it the same way | ||
| 268 | + /// a drop would. The chooser is another process and the user may sit in it, | ||
| 269 | + /// so it runs on a background thread -- blocking here would freeze the | ||
| 270 | + /// window behind the dialog. | ||
| 271 | + fn pick_and_import(&mut self, cx: &mut Context<Self>) { | ||
| 272 | + if self.exporting().is_some() { | ||
| 273 | + return; | ||
| 274 | + } | ||
| 275 | + let picked = cx.background_executor().spawn(async { pick_file() }); | ||
| 276 | + cx.spawn(async move |this, cx| { | ||
| 277 | + let picked = picked.await; | ||
| 278 | + this.update(cx, |this, cx| match picked { | ||
| 279 | + // The same fork the drop handler makes: a project replaces the | ||
| 280 | + // timeline, media is appended to it. | ||
| 281 | + Ok(Some(path)) if is_project(&path) => this.load_project(&path, cx), | ||
| 282 | + Ok(Some(path)) => this.import(&path, cx), | ||
| 283 | + // Cancelled: the user already knows what happened. | ||
| 284 | + Ok(None) => {} | ||
| 285 | + Err(text) => { | ||
| 286 | + eprintln!("{text}"); | ||
| 287 | + this.notice = Some(text.into()); | ||
| 288 | + cx.notify(); | ||
| 289 | + } | ||
| 290 | + }) | ||
| 291 | + .ok(); | ||
| 292 | + }) | ||
| 293 | + .detach(); | ||
| 294 | + } | ||
| 295 | + | ||
| 245 | /// Swaps the whole timeline for one restored from a `.edith`. Like an | 296 | /// Swaps the whole timeline for one restored from a `.edith`. Like an |
| 246 | /// import this arrives by drop and so checks the export guard for itself. | 297 | /// import this arrives by drop and so checks the export guard for itself. |
| 247 | /// The new session is built before anything is replaced, so a refusal is | 298 | /// The new session is built before anything is replaced, so a refusal is |
| @@ -277,7 +328,7 @@ impl Player { | |||
| 277 | Err(e) => format!("OPEN FAILED: {e}"), | 328 | Err(e) => format!("OPEN FAILED: {e}"), |
| 278 | }; | 329 | }; |
| 279 | eprintln!("{text}"); | 330 | eprintln!("{text}"); |
| 280 | - self.notice = Some((text.into(), Instant::now())); | 331 | + self.notice = Some(text.into()); |
| 281 | cx.notify(); | 332 | cx.notify(); |
| 282 | } | 333 | } |
| 283 | 334 | ||
| @@ -289,7 +340,7 @@ impl Player { | |||
| 289 | Err(e) => format!("SAVE FAILED: {e}"), | 340 | Err(e) => format!("SAVE FAILED: {e}"), |
| 290 | }; | 341 | }; |
| 291 | eprintln!("{text}"); | 342 | eprintln!("{text}"); |
| 292 | - self.notice = Some((text.into(), Instant::now())); | 343 | + self.notice = Some(text.into()); |
| 293 | cx.notify(); | 344 | cx.notify(); |
| 294 | } | 345 | } |
| 295 | 346 | ||
| @@ -376,7 +427,7 @@ impl Player { | |||
| 376 | Err(e) => format!("EXPORT FAILED: {e}"), | 427 | Err(e) => format!("EXPORT FAILED: {e}"), |
| 377 | }; | 428 | }; |
| 378 | eprintln!("{text}"); | 429 | eprintln!("{text}"); |
| 379 | - self.notice = Some((text.into(), Instant::now())); | 430 | + self.notice = Some(text.into()); |
| 380 | } | 431 | } |
| 381 | } | 432 | } |
| 382 | 433 | ||
| @@ -391,25 +442,16 @@ impl Render for Player { | |||
| 391 | self.session.tick(); | 442 | self.session.tick(); |
| 392 | self.pump(window); | 443 | self.pump(window); |
| 393 | self.poll_export(); | 444 | self.poll_export(); |
| 394 | - if self | ||
| 395 | - .notice | ||
| 396 | - .as_ref() | ||
| 397 | - .is_some_and(|(_, at)| at.elapsed() >= NOTICE) | ||
| 398 | - { | ||
| 399 | - self.notice = None; | ||
| 400 | - } | ||
| 401 | // No shadow flag: the clock is the only truth about play state. | 445 | // No shadow flag: the clock is the only truth about play state. |
| 402 | let playing = self.session.is_playing(); | 446 | let playing = self.session.is_playing(); |
| 403 | // A paused timeline has nothing to animate; the toggle handlers notify, | 447 | // A paused timeline has nothing to animate; the toggle handlers notify, |
| 404 | // which is what starts the loop again. A paused seek keeps the loop | 448 | // which is what starts the loop again. A paused seek keeps the loop |
| 405 | // running by itself until `pump` has the frame it asked for. An export | 449 | // running by itself until `pump` has the frame it asked for. An export |
| 406 | - // pauses playback and still needs the loop: its progress, and the | 450 | + // pauses playback and still needs the loop: its progress only reaches |
| 407 | - // message it leaves behind, only reach the screen on a repaint. | 451 | + // the screen on a repaint. A notice does not: it waits to be dismissed |
| 408 | - if (playing && !self.done) | 452 | + // rather than for a clock, so keeping the loop alive for it would spin |
| 409 | - || self.pending_seek | 453 | + // the GPU until someone answered it. |
| 410 | - || self.export.is_some() | 454 | + if (playing && !self.done) || self.pending_seek || self.export.is_some() { |
| 411 | - || self.notice.is_some() | ||
| 412 | - { | ||
| 413 | window.request_animation_frame(); | 455 | window.request_animation_frame(); |
| 414 | } | 456 | } |
| 415 | 457 | ||
| @@ -433,8 +475,13 @@ impl Render for Player { | |||
| 433 | if event.is_held { | 475 | if event.is_held { |
| 434 | return; | 476 | return; |
| 435 | } | 477 | } |
| 436 | - // Any key retires the last export's message, whatever it was. | 478 | + // Any key retires the last message, whatever it was -- and owes |
| 437 | - this.notice = None; | 479 | + // the repaint itself: a notice no longer keeps the render loop |
| 480 | + // alive, and the arms below that do notify are not all of them | ||
| 481 | + // (an unbound key, or ctrl+c, changes nothing else). | ||
| 482 | + if this.notice.take().is_some() { | ||
| 483 | + cx.notify(); | ||
| 484 | + } | ||
| 438 | // An export is reading the edit list every other key here would | 485 | // An export is reading the edit list every other key here would |
| 439 | // change, so escape is the only one that means anything until | 486 | // change, so escape is the only one that means anything until |
| 440 | // it is over. | 487 | // it is over. |
| @@ -531,12 +578,15 @@ impl Render for Player { | |||
| 531 | .map(|i| img(i).size_full().object_fit(gpui::ObjectFit::Contain)), | 578 | .map(|i| img(i).size_full().object_fit(gpui::ObjectFit::Contain)), |
| 532 | ), | 579 | ), |
| 533 | ) | 580 | ) |
| 581 | + // Above the panel and only when there is one to show, so it costs | ||
| 582 | + // the picture nothing the rest of the time. | ||
| 583 | + .children(self.notice_bar(cx)) | ||
| 534 | .child(self.panel(position, duration, playing, cx)) | 584 | .child(self.panel(position, duration, playing, cx)) |
| 535 | } | 585 | } |
| 536 | } | 586 | } |
| 537 | 587 | ||
| 538 | impl Player { | 588 | impl Player { |
| 539 | - /// Transport, timecode, playhead, clips lane. | 589 | + /// Transport, edit and file buttons, timecode, playhead, clips lane. |
| 540 | fn panel( | 590 | fn panel( |
| 541 | &self, | 591 | &self, |
| 542 | position: f64, | 592 | position: f64, |
| @@ -549,26 +599,18 @@ impl Player { | |||
| 549 | } else { | 599 | } else { |
| 550 | 0. | 600 | 0. |
| 551 | }; | 601 | }; |
| 552 | - // An export owns the timecode slot and the ruler while it runs: the | 602 | + // An export owns the hint slot and the ruler while it runs: the |
| 553 | // percentage and the accent bar are the same number, so the playhead | 603 | // percentage and the accent bar are the same number, so the playhead |
| 554 | // fill doubles as the progress bar for free. | 604 | // fill doubles as the progress bar for free. |
| 555 | - let (label, filled) = if let Some(export) = self.exporting() { | 605 | + let exporting = self.exporting().is_some(); |
| 606 | + let (hint, filled) = if let Some(export) = self.exporting() { | ||
| 556 | let progress = export.progress(); | 607 | let progress = export.progress(); |
| 557 | ( | 608 | ( |
| 558 | - format!("EXPORT {}% — esc cancels", (progress * 100.) as u32), | 609 | + format!("EXPORTING {}% — esc cancels", (progress * 100.) as u32), |
| 559 | progress, | 610 | progress, |
| 560 | ) | 611 | ) |
| 561 | - } else if let Some((notice, _)) = &self.notice { | ||
| 562 | - (notice.to_string(), filled) | ||
| 563 | } else { | 612 | } else { |
| 564 | - ( | 613 | + (KEY_HINTS.to_string(), filled) |
| 565 | - format!( | ||
| 566 | - "{} / {}", | ||
| 567 | - timecode(position, self.fps), | ||
| 568 | - timecode(duration, self.fps) | ||
| 569 | - ), | ||
| 570 | - filled, | ||
| 571 | - ) | ||
| 572 | }; | 614 | }; |
| 573 | div() | 615 | div() |
| 574 | .flex_none() | 616 | .flex_none() |
| @@ -579,43 +621,110 @@ impl Player { | |||
| 579 | .px(px(12.)) | 621 | .px(px(12.)) |
| 580 | .py(px(8.)) | 622 | .py(px(8.)) |
| 581 | .bg(rgb(CHROME)) | 623 | .bg(rgb(CHROME)) |
| 624 | + // Transport | edit | file: three groups, so the eye can skip two of | ||
| 625 | + // them. Every button says what it does; the tooltip adds its key. | ||
| 582 | .child( | 626 | .child( |
| 583 | div() | 627 | div() |
| 628 | + .flex_none() | ||
| 584 | .flex() | 629 | .flex() |
| 585 | .items_center() | 630 | .items_center() |
| 586 | - .gap(px(12.)) | 631 | + .gap(px(8.)) |
| 587 | .child(control( | 632 | .child(control( |
| 588 | - transport_glyph(playing), | 633 | + "transport", |
| 589 | - cx.listener(|this, _: &MouseDownEvent, _, cx| { | 634 | + Some(transport_glyph(playing).into_any_element()), |
| 590 | - this.toggle_or_restart(cx); | 635 | + if playing { "Pause" } else { "Play" }, |
| 591 | - }), | 636 | + "space", |
| 637 | + !exporting, | ||
| 638 | + cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_or_restart(cx)), | ||
| 592 | )) | 639 | )) |
| 640 | + .child(separator()) | ||
| 593 | .child(control( | 641 | .child(control( |
| 594 | - cut_glyph(), | 642 | + "cut", |
| 595 | - cx.listener(|this, _: &MouseDownEvent, _, cx| this.cut(cx)), | 643 | + Some(cut_glyph().into_any_element()), |
| 644 | + "Cut", | ||
| 645 | + "c — splits the clip under the playhead", | ||
| 646 | + !exporting, | ||
| 647 | + cx.listener(|this, _: &ClickEvent, _, cx| this.cut(cx)), | ||
| 596 | )) | 648 | )) |
| 597 | .child(control( | 649 | .child(control( |
| 598 | - delete_glyph(), | 650 | + "delete", |
| 599 | - cx.listener(|this, _: &MouseDownEvent, _, cx| this.delete_selected(cx)), | 651 | + Some(delete_glyph().into_any_element()), |
| 652 | + "Delete", | ||
| 653 | + if self.selected.is_some() { | ||
| 654 | + "x or delete" | ||
| 655 | + } else { | ||
| 656 | + "x or delete — click a clip below first" | ||
| 657 | + }, | ||
| 658 | + !exporting && self.selected.is_some(), | ||
| 659 | + cx.listener(|this, _: &ClickEvent, _, cx| this.delete_selected(cx)), | ||
| 600 | )) | 660 | )) |
| 601 | - // Fixed width and one line whatever it says: an export | 661 | + .child(separator()) |
| 602 | - // label is longer than a timecode and must not push the | 662 | + .child(control( |
| 603 | - // row around, nor wrap and change its height. | 663 | + "import", |
| 604 | - // | 664 | + None, |
| 605 | - // ponytail: a long file name is ellipsized at TIME_W -- | 665 | + "Import", |
| 606 | - // the whole path is on stderr. Upgrade path is a status | 666 | + "opens a file chooser — or drop a file on the window", |
| 607 | - // line of its own under the ruler, not a wider slot. | 667 | + !exporting, |
| 608 | - .child(div().flex_none().w(px(TIME_W)).truncate().child(label)), | 668 | + cx.listener(|this, _: &ClickEvent, _, cx| this.pick_and_import(cx)), |
| 669 | + )) | ||
| 670 | + .child(control( | ||
| 671 | + "export", | ||
| 672 | + None, | ||
| 673 | + "Export", | ||
| 674 | + "e — writes the timeline out beside the source", | ||
| 675 | + self.export.is_none(), | ||
| 676 | + cx.listener(|this, _: &ClickEvent, _, cx| this.start_export(cx)), | ||
| 677 | + )) | ||
| 678 | + .child(control( | ||
| 679 | + "save", | ||
| 680 | + None, | ||
| 681 | + "Save", | ||
| 682 | + "ctrl+s — writes the project file", | ||
| 683 | + !exporting, | ||
| 684 | + cx.listener(|this, _: &ClickEvent, _, cx| this.save_project(cx)), | ||
| 685 | + )), | ||
| 686 | + ) | ||
| 687 | + .child( | ||
| 688 | + div() | ||
| 689 | + .flex_none() | ||
| 690 | + .flex() | ||
| 691 | + .items_center() | ||
| 692 | + .gap(px(12.)) | ||
| 693 | + // Fixed width and one line: changing digits must not push | ||
| 694 | + // the row around, nor wrap and change its height. | ||
| 695 | + .child(div().flex_none().w(px(TIME_W)).truncate().child(format!( | ||
| 696 | + "{} / {}", | ||
| 697 | + timecode(position, self.fps), | ||
| 698 | + timecode(duration, self.fps) | ||
| 699 | + ))) | ||
| 700 | + .child( | ||
| 701 | + div() | ||
| 702 | + .flex_1() | ||
| 703 | + .min_w(px(0.)) | ||
| 704 | + .truncate() | ||
| 705 | + .text_size(px(11.)) | ||
| 706 | + .text_color(rgb(INK_DIM)) | ||
| 707 | + .child(hint), | ||
| 708 | + ), | ||
| 609 | ) | 709 | ) |
| 610 | // Press to seek, drag to scrub: the move and release halves live on | 710 | // Press to seek, drag to scrub: the move and release halves live on |
| 611 | - // the root, since the pointer leaves this 6 px strip immediately. | 711 | + // the root, since the pointer leaves the bar immediately. The bar |
| 712 | + // stays 6 px to look at; the strip that takes the click is 24, so | ||
| 713 | + // it can be hit without aiming (WCAG 2.5.8). | ||
| 612 | .child( | 714 | .child( |
| 613 | div() | 715 | div() |
| 716 | + .id("ruler") | ||
| 614 | .flex_none() | 717 | .flex_none() |
| 615 | - .h(px(6.)) | 718 | + .h(px(RULER_HIT_H)) |
| 719 | + .flex() | ||
| 720 | + .flex_col() | ||
| 721 | + .justify_center() | ||
| 616 | .rounded(px(3.)) | 722 | .rounded(px(3.)) |
| 617 | - .bg(rgb(SURFACE)) | ||
| 618 | .cursor_pointer() | 723 | .cursor_pointer() |
| 724 | + .hover(|s| s.bg(rgb(HOVER_DIM))) | ||
| 725 | + // The strip carries no text, so the tooltip is the only | ||
| 726 | + // place it can say what it is. | ||
| 727 | + .tooltip(|_, cx| cx.new(|_| Tip("Seek — click or drag".into())).into()) | ||
| 619 | .on_mouse_down( | 728 | .on_mouse_down( |
| 620 | MouseButton::Left, | 729 | MouseButton::Left, |
| 621 | cx.listener(|this, event: &MouseDownEvent, _, cx| { | 730 | cx.listener(|this, event: &MouseDownEvent, _, cx| { |
| @@ -623,23 +732,64 @@ impl Player { | |||
| 623 | this.scrub_to(event.position.x, true, cx); | 732 | this.scrub_to(event.position.x, true, cx); |
| 624 | }), | 733 | }), |
| 625 | ) | 734 | ) |
| 626 | - .child(bounds_probe(self.ruler.clone())) | ||
| 627 | .child( | 735 | .child( |
| 628 | div() | 736 | div() |
| 629 | - .h_full() | 737 | + .w_full() |
| 630 | - .w(relative(filled)) | 738 | + .h(px(6.)) |
| 631 | .rounded(px(3.)) | 739 | .rounded(px(3.)) |
| 632 | - .bg(rgb(ACCENT)), | 740 | + .bg(rgb(SURFACE)) |
| 741 | + .child(bounds_probe(self.ruler.clone())) | ||
| 742 | + .child( | ||
| 743 | + div() | ||
| 744 | + .h_full() | ||
| 745 | + .w(relative(filled)) | ||
| 746 | + .rounded(px(3.)) | ||
| 747 | + .bg(rgb(ACCENT)), | ||
| 748 | + ), | ||
| 633 | ), | 749 | ), |
| 634 | ) | 750 | ) |
| 635 | .child(self.clips_lane(duration, cx)) | 751 | .child(self.clips_lane(duration, cx)) |
| 636 | .child(track_lane()) | 752 | .child(track_lane()) |
| 637 | } | 753 | } |
| 638 | 754 | ||
| 755 | + /// A notice holds its own bar, full width, until it is answered: any key | ||
| 756 | + /// retires it (the key handler) and so does a click on it. Its own surface | ||
| 757 | + /// because the message is the point -- a failure cut to the timecode's slot | ||
| 758 | + /// is a failure nobody read. | ||
| 759 | + fn notice_bar(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> { | ||
| 760 | + let notice = self.notice.clone()?; | ||
| 761 | + Some( | ||
| 762 | + div() | ||
| 763 | + .id("notice") | ||
| 764 | + .flex_none() | ||
| 765 | + .flex() | ||
| 766 | + .items_start() | ||
| 767 | + .gap(px(12.)) | ||
| 768 | + .px(px(12.)) | ||
| 769 | + .py(px(6.)) | ||
| 770 | + .bg(rgb(SURFACE)) | ||
| 771 | + .cursor_pointer() | ||
| 772 | + .hover(|s| s.bg(rgb(HOVER))) | ||
| 773 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { | ||
| 774 | + this.notice = None; | ||
| 775 | + cx.notify(); | ||
| 776 | + })) | ||
| 777 | + .child(div().flex_1().min_w(px(0.)).child(notice)) | ||
| 778 | + .child( | ||
| 779 | + div() | ||
| 780 | + .flex_none() | ||
| 781 | + .text_size(px(11.)) | ||
| 782 | + .text_color(rgb(INK_DIM)) | ||
| 783 | + .child("click or press any key to dismiss"), | ||
| 784 | + ), | ||
| 785 | + ) | ||
| 786 | + } | ||
| 787 | + | ||
| 639 | /// The edit list made visible: one box per clip, sized by its share of the | 788 | /// The edit list made visible: one box per clip, sized by its share of the |
| 640 | /// timeline. A cut adds a box without moving anything, a delete closes the | 789 | /// timeline. A cut adds a box without moving anything, a delete closes the |
| 641 | - /// gap. Plain divs, so the root keeps focus and space still works after a | 790 | + /// gap. A box has no room for a label at four clips, so the tooltip is where |
| 642 | - /// click (ledger:182). | 791 | + /// it says what clicking it does. Never focusable, so the root keeps focus |
| 792 | + /// and space still works after a click (ledger:182). | ||
| 643 | fn clips_lane(&self, duration: f64, cx: &mut Context<Self>) -> impl IntoElement { | 793 | fn clips_lane(&self, duration: f64, cx: &mut Context<Self>) -> impl IntoElement { |
| 644 | div() | 794 | div() |
| 645 | .flex_none() | 795 | .flex_none() |
| @@ -656,6 +806,7 @@ impl Player { | |||
| 656 | let selected = self.selected == Some(i); | 806 | let selected = self.selected == Some(i); |
| 657 | let tint = source_tint(source); | 807 | let tint = source_tint(source); |
| 658 | div() | 808 | div() |
| 809 | + .id(("clip", i)) | ||
| 659 | .h_full() | 810 | .h_full() |
| 660 | .w(relative(width_frac(len, duration))) | 811 | .w(relative(width_frac(len, duration))) |
| 661 | .rounded(px(3.)) | 812 | .rounded(px(3.)) |
| @@ -663,6 +814,11 @@ impl Player { | |||
| 663 | .border_color(rgb(if selected { ACCENT } else { tint })) | 814 | .border_color(rgb(if selected { ACCENT } else { tint })) |
| 664 | .bg(rgb(if selected { SELECTED } else { tint })) | 815 | .bg(rgb(if selected { SELECTED } else { tint })) |
| 665 | .cursor_pointer() | 816 | .cursor_pointer() |
| 817 | + .hover(|s| s.border_color(rgb(ACCENT))) | ||
| 818 | + .tooltip(|_, cx| { | ||
| 819 | + cx.new(|_| Tip("Select clip — Delete removes it".into())) | ||
| 820 | + .into() | ||
| 821 | + }) | ||
| 666 | .on_mouse_down( | 822 | .on_mouse_down( |
| 667 | MouseButton::Left, | 823 | MouseButton::Left, |
| 668 | cx.listener(move |this, _: &MouseDownEvent, _, cx| { | 824 | cx.listener(move |this, _: &MouseDownEvent, _, cx| { |
| @@ -684,8 +840,30 @@ fn scrub_due(target: u32, last_target: u32, since: Duration) -> bool { | |||
| 684 | target != last_target && since >= SCRUB_GAP | 840 | target != last_target && since >= SCRUB_GAP |
| 685 | } | 841 | } |
| 686 | 842 | ||
| 687 | -/// How long a finished export's message holds the timecode slot. | 843 | +/// The desktop's own file choosers, best first. Asked for by name because gpui |
| 688 | -const NOTICE: Duration = Duration::from_secs(2); | 844 | +/// 0.2 has no file dialog of its own and none of these is worth a dependency. |
| 845 | +const PICKERS: [(&str, &[&str]); 2] = [ | ||
| 846 | + ("zenity", &["--file-selection", "--title=edith — import"]), | ||
| 847 | + ("kdialog", &["--getopenfilename"]), | ||
| 848 | +]; | ||
| 849 | + | ||
| 850 | +/// Runs the first chooser that is installed. `Ok(None)` is a cancelled dialog; | ||
| 851 | +/// the error is for a machine with no chooser at all, which still has the drop | ||
| 852 | +/// target -- the import path that never depended on another program. | ||
| 853 | +fn pick_file() -> Result<Option<PathBuf>, &'static str> { | ||
| 854 | + for (bin, args) in PICKERS { | ||
| 855 | + // Not installed: try the next one. Anything else (a cancel, a refusal) | ||
| 856 | + // is that chooser's answer and is taken as final. | ||
| 857 | + let Ok(out) = std::process::Command::new(bin).args(args).output() else { | ||
| 858 | + continue; | ||
| 859 | + }; | ||
| 860 | + let path = String::from_utf8_lossy(&out.stdout).trim().to_string(); | ||
| 861 | + return Ok((!path.is_empty()).then(|| PathBuf::from(path))); | ||
| 862 | + } | ||
| 863 | + Err( | ||
| 864 | + "NO FILE CHOOSER — install zenity or kdialog, or drag the file onto this window to import it", | ||
| 865 | + ) | ||
| 866 | +} | ||
| 689 | 867 | ||
| 690 | /// Where an export goes: the source path with `.export.mp4` for an extension, | 868 | /// Where an export goes: the source path with `.export.mp4` for an extension, |
| 691 | /// so it lands beside the original and can never be the original. | 869 | /// so it lands beside the original and can never be the original. |
| @@ -734,34 +912,92 @@ fn width_frac(len: f64, total: f64) -> f32 { | |||
| 734 | if total > 0. { (len / total) as f32 } else { 1. } | 912 | if total > 0. { (len / total) as f32 } else { 1. } |
| 735 | } | 913 | } |
| 736 | 914 | ||
| 737 | -/// The 32x28 control shape shared by transport, cut and delete. A plain div: | 915 | +/// A toolbar button: its glyph, its name, and its key on hover. `id` only buys |
| 738 | -/// nothing here tracks focus, so the root's own key listener keeps working | 916 | +/// `on_click` and the tooltip -- it is still not focusable, so the root's own |
| 739 | -/// after a press. | 917 | +/// key listener keeps working after a press, and the click lands on mouse-up |
| 918 | +/// inside the button (a press that slides off does nothing). | ||
| 919 | +/// | ||
| 920 | +/// A button that would do nothing says so: dimmed, no pointer, no listener. | ||
| 740 | fn control( | 921 | fn control( |
| 741 | - glyph: impl IntoElement, | 922 | + id: &'static str, |
| 742 | - on_press: impl Fn(&MouseDownEvent, &mut Window, &mut App) + 'static, | 923 | + glyph: Option<AnyElement>, |
| 924 | + label: &'static str, | ||
| 925 | + shortcut: &'static str, | ||
| 926 | + enabled: bool, | ||
| 927 | + on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static, | ||
| 743 | ) -> impl IntoElement { | 928 | ) -> impl IntoElement { |
| 929 | + let tip: SharedString = format!("{label} — {shortcut}").into(); | ||
| 744 | div() | 930 | div() |
| 745 | - .w(px(32.)) | 931 | + .id(id) |
| 746 | - .h(px(28.)) | 932 | + .flex_none() |
| 933 | + .h(px(CONTROL_H)) | ||
| 747 | .flex() | 934 | .flex() |
| 748 | - .justify_center() | ||
| 749 | .items_center() | 935 | .items_center() |
| 936 | + .gap(px(6.)) | ||
| 937 | + .px(px(8.)) | ||
| 750 | .rounded(px(3.)) | 938 | .rounded(px(3.)) |
| 751 | .bg(rgb(SURFACE)) | 939 | .bg(rgb(SURFACE)) |
| 752 | - .cursor_pointer() | 940 | + .children(glyph) |
| 753 | - .on_mouse_down(MouseButton::Left, on_press) | 941 | + .child(label) |
| 754 | - .child(glyph) | 942 | + .tooltip(move |_, cx| cx.new(|_| Tip(tip.clone())).into()) |
| 943 | + .when(!enabled, |d| d.opacity(0.4).cursor_not_allowed()) | ||
| 944 | + .when(enabled, |d| { | ||
| 945 | + d.cursor_pointer() | ||
| 946 | + .hover(|s| s.bg(rgb(HOVER))) | ||
| 947 | + .on_click(on_click) | ||
| 948 | + }) | ||
| 755 | } | 949 | } |
| 756 | 950 | ||
| 757 | -/// A clip split in two -- the gap is the cut. Drawn, like every glyph here. | 951 | +/// The line between two groups of buttons. |
| 758 | -fn cut_glyph() -> impl IntoElement { | 952 | +fn separator() -> impl IntoElement { |
| 759 | div() | 953 | div() |
| 760 | - .flex() | 954 | + .flex_none() |
| 761 | - .items_center() | 955 | + .mx(px(4.)) |
| 762 | - .gap(px(3.)) | 956 | + .w(px(1.)) |
| 763 | - .child(div().w(px(5.)).h(px(13.)).bg(rgb(INK))) | 957 | + .h(px(18.)) |
| 764 | - .child(div().w(px(5.)).h(px(13.)).bg(rgb(INK))) | 958 | + .bg(rgb(HOVER)) |
| 959 | +} | ||
| 960 | + | ||
| 961 | +/// A tooltip is a view in gpui and nothing smaller, so this is the smallest one | ||
| 962 | +/// that carries a line of text. It paints outside the window's element tree and | ||
| 963 | +/// therefore owns its colours. | ||
| 964 | +struct Tip(SharedString); | ||
| 965 | + | ||
| 966 | +impl Render for Tip { | ||
| 967 | + fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement { | ||
| 968 | + div() | ||
| 969 | + .px(px(6.)) | ||
| 970 | + .py(px(3.)) | ||
| 971 | + .rounded(px(3.)) | ||
| 972 | + .border_1() | ||
| 973 | + .border_color(rgb(SURFACE)) | ||
| 974 | + .bg(rgb(CHROME)) | ||
| 975 | + .text_color(rgb(INK)) | ||
| 976 | + .text_size(px(12.)) | ||
| 977 | + .child(self.0.clone()) | ||
| 978 | + } | ||
| 979 | +} | ||
| 980 | + | ||
| 981 | +/// Scissors: two blades crossed. Drawn this way and not as a split clip because | ||
| 982 | +/// two bars is what the transport wears when it is playing -- the one glyph a | ||
| 983 | +/// cut must never be mistaken for. | ||
| 984 | +fn cut_glyph() -> impl IntoElement { | ||
| 985 | + canvas( | ||
| 986 | + |_, _, _| (), | ||
| 987 | + |bounds, _, window, _| { | ||
| 988 | + let (o, s) = (bounds.origin, bounds.size); | ||
| 989 | + let mut path = PathBuilder::stroke(px(1.5)); | ||
| 990 | + path.move_to(point(o.x + s.width * 0.15, o.y + s.height)); | ||
| 991 | + path.line_to(point(o.x + s.width * 0.9, o.y + s.height * 0.1)); | ||
| 992 | + path.move_to(point(o.x + s.width * 0.85, o.y + s.height)); | ||
| 993 | + path.line_to(point(o.x + s.width * 0.1, o.y + s.height * 0.1)); | ||
| 994 | + if let Ok(path) = path.build() { | ||
| 995 | + window.paint_path(path, rgb(INK)); | ||
| 996 | + } | ||
| 997 | + }, | ||
| 998 | + ) | ||
| 999 | + .w(px(13.)) | ||
| 1000 | + .h(px(13.)) | ||
| 765 | } | 1001 | } |
| 766 | 1002 | ||
| 767 | /// A lid over a bin. | 1003 | /// A lid over a bin. |
| @@ -853,8 +1089,8 @@ fn timecode(t: f64, fps: f64) -> String { | |||
| 853 | #[cfg(test)] | 1089 | #[cfg(test)] |
| 854 | mod tests { | 1090 | mod tests { |
| 855 | use super::{ | 1091 | use super::{ |
| 856 | - SOURCE_TINTS, SURFACE, export_path, frac_along, is_project, project_path, scrub_due, | 1092 | + CONTROL_H, HIT_MIN, LANE_H, RULER_HIT_H, SOURCE_TINTS, SURFACE, export_path, frac_along, |
| 857 | - source_tint, timecode, width_frac, | 1093 | + is_project, project_path, scrub_due, source_tint, timecode, width_frac, |
| 858 | }; | 1094 | }; |
| 859 | use gpui::{Bounds, Pixels, point, px, size}; | 1095 | use gpui::{Bounds, Pixels, point, px, size}; |
| 860 | use std::time::Duration; | 1096 | use std::time::Duration; |
| @@ -963,6 +1199,15 @@ mod tests { | |||
| 963 | assert_eq!(width_frac(0., 0.), 1.); | 1199 | assert_eq!(width_frac(0., 0.), 1.); |
| 964 | } | 1200 | } |
| 965 | 1201 | ||
| 1202 | + #[test] | ||
| 1203 | + fn nothing_clickable_is_smaller_than_the_wcag_minimum() { | ||
| 1204 | + // Every hit target in the panel, including the scrub strip -- whose bar | ||
| 1205 | + // is 6 px to look at and whose click area must not be. | ||
| 1206 | + assert!(CONTROL_H >= HIT_MIN); | ||
| 1207 | + assert!(RULER_HIT_H >= HIT_MIN); | ||
| 1208 | + assert!(LANE_H >= HIT_MIN); | ||
| 1209 | + } | ||
| 1210 | + | ||
| 966 | #[test] | 1211 | #[test] |
| 967 | fn source_tints_differ_per_source_and_cycle() { | 1212 | fn source_tints_differ_per_source_and_cycle() { |
| 968 | // The file the session opened with is the unchanged lane colour. | 1213 | // The file the session opened with is the unchanged lane colour. |
| @@ -1036,7 +1281,7 @@ fn main() { | |||
| 1036 | WindowOptions { | 1281 | WindowOptions { |
| 1037 | window_bounds: Some(WindowBounds::Windowed(bounds)), | 1282 | window_bounds: Some(WindowBounds::Windowed(bounds)), |
| 1038 | titlebar: Some(TitlebarOptions { | 1283 | titlebar: Some(TitlebarOptions { |
| 1039 | - title: Some("video_editor".into()), | 1284 | + title: Some("edith".into()), |
| 1040 | ..Default::default() | 1285 | ..Default::default() |
| 1041 | }), | 1286 | }), |
| 1042 | ..Default::default() | 1287 | ..Default::default() |
| @@ -1062,7 +1307,7 @@ fn main() { | |||
| 1062 | cancelling: false, | 1307 | cancelling: false, |
| 1063 | export_path: out.clone(), | 1308 | export_path: out.clone(), |
| 1064 | project_path: project.clone(), | 1309 | project_path: project.clone(), |
| 1065 | - notice: notice.clone().map(|text| (text.into(), Instant::now())), | 1310 | + notice: notice.clone().map(SharedString::from), |
| 1066 | displayed: 0, | 1311 | displayed: 0, |
| 1067 | dropped: 0, | 1312 | dropped: 0, |
| 1068 | started: None, | 1313 | started: None, |