merge oldui-subs
Browse files at this commit2 changed files +209 -1
crates/app/src/tests/layout.rsmodified+31 -0
| @@ -1380,6 +1380,37 @@ fn the_text_tab_carries_the_add_subtitles_door() { | ||
| 1380 | 1380 | ); |
| 1381 | 1381 | } |
| 1382 | 1382 | |
| 1383 | +/// The Darkroom keeps imported subtitle tracks in the Sources dock, where a | |
| 1384 | +/// row can be selected, folded with its source, removed, and dragged to the | |
| 1385 | +/// bench's existing subtitle-lane target. | |
| 1386 | +#[test] | |
| 1387 | +fn the_darkroom_subtitle_palette_drags_tracks_to_subtitle_lanes() { | |
| 1388 | + let dock = src_text("ui/dock_stance.rs"); | |
| 1389 | + let palette = &dock[dock | |
| 1390 | + .find("fn subtitle_palette") | |
| 1391 | + .expect("no Darkroom subtitle palette")..]; | |
| 1392 | + for required in [ | |
| 1393 | + "subtitle_rows", | |
| 1394 | + "dock-subtitle-group", | |
| 1395 | + "sub_folded.remove", | |
| 1396 | + "sub_folded.insert", | |
| 1397 | + "this.sub_track = track", | |
| 1398 | + ".on_drag(SubPick(track)", | |
| 1399 | + "remove_subtitle_track(track", | |
| 1400 | + ] { | |
| 1401 | + assert!(palette.contains(required), "palette lost {required}"); | |
| 1402 | + } | |
| 1403 | + let bench = src_text("ui/bench_stance.rs"); | |
| 1404 | + let drop_at = bench | |
| 1405 | + .find(".drag_over::<SubPick>") | |
| 1406 | + .expect("no subtitle-track lane target"); | |
| 1407 | + let drop = &bench[drop_at..(drop_at + 500).min(bench.len())]; | |
| 1408 | + assert!( | |
| 1409 | + drop.contains("this.place_sub(drag.0, lane"), | |
| 1410 | + "a dock subtitle drag does not place on the lane: {drop}" | |
| 1411 | + ); | |
| 1412 | +} | |
| 1413 | + | |
| 1383 | 1414 | /// A source's group header in the library must not vanish on a short |
| 1384 | 1415 | /// window: it is drawn whenever there is more than one source |
| 1385 | 1416 | /// (`several_files`), never gated on the viewport's height, and the list |
crates/app/src/ui/dock_stance.rsmodified+178 -1
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | //! still supply the row facts ([`library_rows`], [`source_tint`], |
| 12 | 12 | //! [`clip_middle`]...), only the anatomy around them is new. |
| 13 | 13 | |
| 14 | -use crate::ui::type_scale::{self, head, label, mono}; | |
| 14 | +use crate::ui::type_scale::{self, Typeset, head, label, mono}; | |
| 15 | 15 | use crate::*; |
| 16 | 16 | use gpui::FontWeight; |
| 17 | 17 | |
| @@ -546,6 +546,182 @@ fn source_row( | ||
| 546 | 546 | }) |
| 547 | 547 | } |
| 548 | 548 | |
| 549 | +/// Imported subtitle tracks, grouped by their source. A row selects and drags | |
| 550 | +/// its track; its header folds that source's rows without becoming a cycle. | |
| 551 | +fn subtitle_palette(player: &Player, cx: &mut Context<Player>) -> Option<AnyElement> { | |
| 552 | + let groups = subtitle_rows(player.session.as_ref()?.subtitles()); | |
| 553 | + if groups.is_empty() { | |
| 554 | + return None; | |
| 555 | + } | |
| 556 | + let count: usize = groups.iter().map(|group| group.rows.len()).sum(); | |
| 557 | + let rows: Vec<_> = groups | |
| 558 | + .into_iter() | |
| 559 | + .enumerate() | |
| 560 | + .map(|(group_ord, group)| { | |
| 561 | + let folded = player.sub_folded.contains(&group.path); | |
| 562 | + let fold_path = group.path.clone(); | |
| 563 | + let tint = file_tint(player.sources(), &group.path); | |
| 564 | + let track_count = group.rows.len(); | |
| 565 | + let tracks: Vec<_> = group | |
| 566 | + .rows | |
| 567 | + .into_iter() | |
| 568 | + .map(|row| { | |
| 569 | + let track = row.track; | |
| 570 | + let picked = track == player.sub_track; | |
| 571 | + let usable = row.refused.is_none(); | |
| 572 | + let title: SharedString = match track_count { | |
| 573 | + 1 => row.label, | |
| 574 | + _ => format!("{} {}", row.label, row.number), | |
| 575 | + } | |
| 576 | + .into(); | |
| 577 | + let detail: SharedString = row | |
| 578 | + .refused | |
| 579 | + .unwrap_or_else(|| "drag onto an S lane to place".to_string()) | |
| 580 | + .into(); | |
| 581 | + let ghost = title.clone(); | |
| 582 | + div() | |
| 583 | + .id(("dock-subtitle-track", track)) | |
| 584 | + .flex_none() | |
| 585 | + .h(px(CONTROL_H)) | |
| 586 | + .flex() | |
| 587 | + .items_center() | |
| 588 | + .gap(px(6.)) | |
| 589 | + .px(px(8.)) | |
| 590 | + .rounded(px(3.)) | |
| 591 | + .when(picked, |d| d.border_1().border_color(rgb(INK1()))) | |
| 592 | + .when(!usable, |d| d.opacity(0.5)) | |
| 593 | + .when(usable, |d| { | |
| 594 | + d.cursor_pointer() | |
| 595 | + .hover(|s| s.bg(rgb(DARK_RAISED()))) | |
| 596 | + .on_drag(SubPick(track), move |_, _, _, cx| { | |
| 597 | + cx.new(|_| Tip(ghost.clone())) | |
| 598 | + }) | |
| 599 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 600 | + this.sub_track = track; | |
| 601 | + cx.notify(); | |
| 602 | + })) | |
| 603 | + }) | |
| 604 | + .child( | |
| 605 | + div() | |
| 606 | + .flex_none() | |
| 607 | + .w(px(4.)) | |
| 608 | + .h(px(16.)) | |
| 609 | + .rounded(px(2.)) | |
| 610 | + .when_some(tint, |d, tint| d.bg(rgb(tint))), | |
| 611 | + ) | |
| 612 | + .child( | |
| 613 | + div() | |
| 614 | + .flex_1() | |
| 615 | + .min_w(px(0.)) | |
| 616 | + .truncate() | |
| 617 | + .type_style(mono( | |
| 618 | + type_scale::CHORD_METADATA_MIN_PX, | |
| 619 | + FontWeight::MEDIUM, | |
| 620 | + )) | |
| 621 | + .text_color(rgb(INK2())) | |
| 622 | + .child(title), | |
| 623 | + ) | |
| 624 | + .child( | |
| 625 | + div() | |
| 626 | + .flex_none() | |
| 627 | + .truncate() | |
| 628 | + .type_style(mono(type_scale::FLOOR_PX, FontWeight::MEDIUM)) | |
| 629 | + .text_color(rgb(INK3())) | |
| 630 | + .child(detail), | |
| 631 | + ) | |
| 632 | + .child( | |
| 633 | + div() | |
| 634 | + .id(("dock-subtitle-remove", track)) | |
| 635 | + .flex_none() | |
| 636 | + .w(px(HIT_MIN)) | |
| 637 | + .h_full() | |
| 638 | + .flex() | |
| 639 | + .items_center() | |
| 640 | + .justify_center() | |
| 641 | + .rounded(px(3.)) | |
| 642 | + .cursor_pointer() | |
| 643 | + .hover(|s| s.bg(rgb(DARK_RAISED())).text_color(rgb(INK1()))) | |
| 644 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 645 | + cx.stop_propagation(); | |
| 646 | + this.remove_subtitle_track(track, cx); | |
| 647 | + })) | |
| 648 | + .child("×"), | |
| 649 | + ) | |
| 650 | + }) | |
| 651 | + .collect(); | |
| 652 | + div() | |
| 653 | + .flex_none() | |
| 654 | + .flex() | |
| 655 | + .flex_col() | |
| 656 | + .gap(px(2.)) | |
| 657 | + .child( | |
| 658 | + div() | |
| 659 | + .id(("dock-subtitle-group", group_ord)) | |
| 660 | + .flex_none() | |
| 661 | + .h(px(CONTROL_H)) | |
| 662 | + .flex() | |
| 663 | + .items_center() | |
| 664 | + .gap(px(6.)) | |
| 665 | + .px(px(8.)) | |
| 666 | + .rounded(px(3.)) | |
| 667 | + .cursor_pointer() | |
| 668 | + .hover(|s| s.bg(rgb(DARK_RAISED()))) | |
| 669 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 670 | + if !this.sub_folded.remove(&fold_path) { | |
| 671 | + this.sub_folded.insert(fold_path.clone()); | |
| 672 | + } | |
| 673 | + cx.notify(); | |
| 674 | + })) | |
| 675 | + .child(if folded { "▸" } else { "▾" }) | |
| 676 | + .when_some(tint, |d, tint| { | |
| 677 | + d.child( | |
| 678 | + div() | |
| 679 | + .flex_none() | |
| 680 | + .w(px(4.)) | |
| 681 | + .h(px(16.)) | |
| 682 | + .rounded(px(2.)) | |
| 683 | + .bg(rgb(tint)), | |
| 684 | + ) | |
| 685 | + }) | |
| 686 | + .child( | |
| 687 | + div() | |
| 688 | + .flex_1() | |
| 689 | + .min_w(px(0.)) | |
| 690 | + .truncate() | |
| 691 | + .type_style(label(type_scale::LABEL_ROW_PX, FontWeight::MEDIUM)) | |
| 692 | + .text_color(rgb(INK2())) | |
| 693 | + .child(group.name), | |
| 694 | + ) | |
| 695 | + .child( | |
| 696 | + div() | |
| 697 | + .flex_none() | |
| 698 | + .type_style(mono( | |
| 699 | + type_scale::CHORD_METADATA_MIN_PX, | |
| 700 | + FontWeight::MEDIUM, | |
| 701 | + )) | |
| 702 | + .text_color(rgb(INK3())) | |
| 703 | + .child(format!( | |
| 704 | + "{track_count} track{}", | |
| 705 | + if track_count == 1 { "" } else { "s" } | |
| 706 | + )), | |
| 707 | + ), | |
| 708 | + ) | |
| 709 | + .when(!folded, |d| d.children(tracks)) | |
| 710 | + }) | |
| 711 | + .collect(); | |
| 712 | + Some( | |
| 713 | + div() | |
| 714 | + .id("dock-subtitle-palette") | |
| 715 | + .flex_none() | |
| 716 | + .flex() | |
| 717 | + .flex_col() | |
| 718 | + .gap(px(2.)) | |
| 719 | + .child(section_head(format!("SUBTITLES · {count}"))) | |
| 720 | + .children(rows) | |
| 721 | + .into_any_element(), | |
| 722 | + ) | |
| 723 | +} | |
| 724 | + | |
| 549 | 725 | /// The Sources tab, built off MOCK-SPEC.md's "Dock" section: count line, |
| 550 | 726 | /// filter, sort chips, rows, IMPORT, hint -- none of it the legacy |
| 551 | 727 | /// Media/Audio/Text panel `library.rs` draws. That panel's row facts |
| @@ -725,6 +901,7 @@ fn sources_tab(player: &Player, cx: &mut Context<Player>) -> impl IntoElement { | ||
| 725 | 901 | elements |
| 726 | 902 | }), |
| 727 | 903 | ) |
| 904 | + .children(subtitle_palette(player, cx)) | |
| 728 | 905 | .child(section_head("IMPORT")) |
| 729 | 906 | .child( |
| 730 | 907 | div() |