Add Darkroom subtitle palette
Browse files at this commit447ec3979adb8b9276313e0d6298481b3379e3cfParent: 3e04aeb- feat
- add Darkroom subtitle palette
2 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 | /// A source's group header in the library must not vanish on a short | 1414 | /// A source's group header in the library must not vanish on a short |
| 1384 | /// window: it is drawn whenever there is more than one source | 1415 | /// window: it is drawn whenever there is more than one source |
| 1385 | /// (`several_files`), never gated on the viewport's height, and the list | 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 | //! still supply the row facts ([`library_rows`], [`source_tint`], | 11 | //! still supply the row facts ([`library_rows`], [`source_tint`], |
| 12 | //! [`clip_middle`]...), only the anatomy around them is new. | 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 | use crate::*; | 15 | use crate::*; |
| 16 | use gpui::FontWeight; | 16 | use gpui::FontWeight; |
| 17 | 17 | ||
| @@ -401,6 +401,182 @@ fn source_row( | |||
| 401 | }) | 401 | }) |
| 402 | } | 402 | } |
| 403 | 403 | ||
| 404 | +/// Imported subtitle tracks, grouped by their source. A row selects and drags | ||
| 405 | +/// its track; its header folds that source's rows without becoming a cycle. | ||
| 406 | +fn subtitle_palette(player: &Player, cx: &mut Context<Player>) -> Option<AnyElement> { | ||
| 407 | + let groups = subtitle_rows(player.session.as_ref()?.subtitles()); | ||
| 408 | + if groups.is_empty() { | ||
| 409 | + return None; | ||
| 410 | + } | ||
| 411 | + let count: usize = groups.iter().map(|group| group.rows.len()).sum(); | ||
| 412 | + let rows: Vec<_> = groups | ||
| 413 | + .into_iter() | ||
| 414 | + .enumerate() | ||
| 415 | + .map(|(group_ord, group)| { | ||
| 416 | + let folded = player.sub_folded.contains(&group.path); | ||
| 417 | + let fold_path = group.path.clone(); | ||
| 418 | + let tint = file_tint(player.sources(), &group.path); | ||
| 419 | + let track_count = group.rows.len(); | ||
| 420 | + let tracks: Vec<_> = group | ||
| 421 | + .rows | ||
| 422 | + .into_iter() | ||
| 423 | + .map(|row| { | ||
| 424 | + let track = row.track; | ||
| 425 | + let picked = track == player.sub_track; | ||
| 426 | + let usable = row.refused.is_none(); | ||
| 427 | + let title: SharedString = match track_count { | ||
| 428 | + 1 => row.label, | ||
| 429 | + _ => format!("{} {}", row.label, row.number), | ||
| 430 | + } | ||
| 431 | + .into(); | ||
| 432 | + let detail: SharedString = row | ||
| 433 | + .refused | ||
| 434 | + .unwrap_or_else(|| "drag onto an S lane to place".to_string()) | ||
| 435 | + .into(); | ||
| 436 | + let ghost = title.clone(); | ||
| 437 | + div() | ||
| 438 | + .id(("dock-subtitle-track", track)) | ||
| 439 | + .flex_none() | ||
| 440 | + .h(px(CONTROL_H)) | ||
| 441 | + .flex() | ||
| 442 | + .items_center() | ||
| 443 | + .gap(px(6.)) | ||
| 444 | + .px(px(8.)) | ||
| 445 | + .rounded(px(3.)) | ||
| 446 | + .when(picked, |d| d.border_1().border_color(rgb(INK1()))) | ||
| 447 | + .when(!usable, |d| d.opacity(0.5)) | ||
| 448 | + .when(usable, |d| { | ||
| 449 | + d.cursor_pointer() | ||
| 450 | + .hover(|s| s.bg(rgb(DARK_RAISED()))) | ||
| 451 | + .on_drag(SubPick(track), move |_, _, _, cx| { | ||
| 452 | + cx.new(|_| Tip(ghost.clone())) | ||
| 453 | + }) | ||
| 454 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | ||
| 455 | + this.sub_track = track; | ||
| 456 | + cx.notify(); | ||
| 457 | + })) | ||
| 458 | + }) | ||
| 459 | + .child( | ||
| 460 | + div() | ||
| 461 | + .flex_none() | ||
| 462 | + .w(px(4.)) | ||
| 463 | + .h(px(16.)) | ||
| 464 | + .rounded(px(2.)) | ||
| 465 | + .when_some(tint, |d, tint| d.bg(rgb(tint))), | ||
| 466 | + ) | ||
| 467 | + .child( | ||
| 468 | + div() | ||
| 469 | + .flex_1() | ||
| 470 | + .min_w(px(0.)) | ||
| 471 | + .truncate() | ||
| 472 | + .type_style(mono( | ||
| 473 | + type_scale::CHORD_METADATA_MIN_PX, | ||
| 474 | + FontWeight::MEDIUM, | ||
| 475 | + )) | ||
| 476 | + .text_color(rgb(INK2())) | ||
| 477 | + .child(title), | ||
| 478 | + ) | ||
| 479 | + .child( | ||
| 480 | + div() | ||
| 481 | + .flex_none() | ||
| 482 | + .truncate() | ||
| 483 | + .type_style(mono(type_scale::FLOOR_PX, FontWeight::MEDIUM)) | ||
| 484 | + .text_color(rgb(INK3())) | ||
| 485 | + .child(detail), | ||
| 486 | + ) | ||
| 487 | + .child( | ||
| 488 | + div() | ||
| 489 | + .id(("dock-subtitle-remove", track)) | ||
| 490 | + .flex_none() | ||
| 491 | + .w(px(HIT_MIN)) | ||
| 492 | + .h_full() | ||
| 493 | + .flex() | ||
| 494 | + .items_center() | ||
| 495 | + .justify_center() | ||
| 496 | + .rounded(px(3.)) | ||
| 497 | + .cursor_pointer() | ||
| 498 | + .hover(|s| s.bg(rgb(DARK_RAISED())).text_color(rgb(INK1()))) | ||
| 499 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | ||
| 500 | + cx.stop_propagation(); | ||
| 501 | + this.remove_subtitle_track(track, cx); | ||
| 502 | + })) | ||
| 503 | + .child("×"), | ||
| 504 | + ) | ||
| 505 | + }) | ||
| 506 | + .collect(); | ||
| 507 | + div() | ||
| 508 | + .flex_none() | ||
| 509 | + .flex() | ||
| 510 | + .flex_col() | ||
| 511 | + .gap(px(2.)) | ||
| 512 | + .child( | ||
| 513 | + div() | ||
| 514 | + .id(("dock-subtitle-group", group_ord)) | ||
| 515 | + .flex_none() | ||
| 516 | + .h(px(CONTROL_H)) | ||
| 517 | + .flex() | ||
| 518 | + .items_center() | ||
| 519 | + .gap(px(6.)) | ||
| 520 | + .px(px(8.)) | ||
| 521 | + .rounded(px(3.)) | ||
| 522 | + .cursor_pointer() | ||
| 523 | + .hover(|s| s.bg(rgb(DARK_RAISED()))) | ||
| 524 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | ||
| 525 | + if !this.sub_folded.remove(&fold_path) { | ||
| 526 | + this.sub_folded.insert(fold_path.clone()); | ||
| 527 | + } | ||
| 528 | + cx.notify(); | ||
| 529 | + })) | ||
| 530 | + .child(if folded { "▸" } else { "▾" }) | ||
| 531 | + .when_some(tint, |d, tint| { | ||
| 532 | + d.child( | ||
| 533 | + div() | ||
| 534 | + .flex_none() | ||
| 535 | + .w(px(4.)) | ||
| 536 | + .h(px(16.)) | ||
| 537 | + .rounded(px(2.)) | ||
| 538 | + .bg(rgb(tint)), | ||
| 539 | + ) | ||
| 540 | + }) | ||
| 541 | + .child( | ||
| 542 | + div() | ||
| 543 | + .flex_1() | ||
| 544 | + .min_w(px(0.)) | ||
| 545 | + .truncate() | ||
| 546 | + .type_style(label(type_scale::LABEL_ROW_PX, FontWeight::MEDIUM)) | ||
| 547 | + .text_color(rgb(INK2())) | ||
| 548 | + .child(group.name), | ||
| 549 | + ) | ||
| 550 | + .child( | ||
| 551 | + div() | ||
| 552 | + .flex_none() | ||
| 553 | + .type_style(mono( | ||
| 554 | + type_scale::CHORD_METADATA_MIN_PX, | ||
| 555 | + FontWeight::MEDIUM, | ||
| 556 | + )) | ||
| 557 | + .text_color(rgb(INK3())) | ||
| 558 | + .child(format!( | ||
| 559 | + "{track_count} track{}", | ||
| 560 | + if track_count == 1 { "" } else { "s" } | ||
| 561 | + )), | ||
| 562 | + ), | ||
| 563 | + ) | ||
| 564 | + .when(!folded, |d| d.children(tracks)) | ||
| 565 | + }) | ||
| 566 | + .collect(); | ||
| 567 | + Some( | ||
| 568 | + div() | ||
| 569 | + .id("dock-subtitle-palette") | ||
| 570 | + .flex_none() | ||
| 571 | + .flex() | ||
| 572 | + .flex_col() | ||
| 573 | + .gap(px(2.)) | ||
| 574 | + .child(section_head(format!("SUBTITLES · {count}"))) | ||
| 575 | + .children(rows) | ||
| 576 | + .into_any_element(), | ||
| 577 | + ) | ||
| 578 | +} | ||
| 579 | + | ||
| 404 | /// The Sources tab, built off MOCK-SPEC.md's "Dock" section: count line, | 580 | /// The Sources tab, built off MOCK-SPEC.md's "Dock" section: count line, |
| 405 | /// filter, sort chips, rows, IMPORT, hint -- none of it the legacy | 581 | /// filter, sort chips, rows, IMPORT, hint -- none of it the legacy |
| 406 | /// Media/Audio/Text panel `library.rs` draws. That panel's row facts | 582 | /// Media/Audio/Text panel `library.rs` draws. That panel's row facts |
| @@ -551,6 +727,7 @@ fn sources_tab(player: &Player, cx: &mut Context<Player>) -> impl IntoElement { | |||
| 551 | elements | 727 | elements |
| 552 | }), | 728 | }), |
| 553 | ) | 729 | ) |
| 730 | + .children(subtitle_palette(player, cx)) | ||
| 554 | .child(section_head("IMPORT")) | 731 | .child(section_head("IMPORT")) |
| 555 | .child( | 732 | .child( |
| 556 | div() | 733 | div() |