forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

capsel.rs54 lines, 2.7 KiBHistoryRawDownload
1//! The caption panel of the Clip tab: a selected caption is the tab's own panel (header, words,
2//! start and end that scrub or type, a read-only length, its three actions, then the style
3//! section), and its number drags one whole frame at a time, one cue edit on the release.
4
5use super::*;
6use crate::player::caption_cues::{cue_secs, scrubbed_us};
7
8#[test]
9fn a_scrubbed_caption_number_moves_by_frames_and_clamps() {
10 // Two seconds at 25 fps: 100 px at 0.02 s a pixel is two seconds more, on whole frames.
11 assert_eq!(scrubbed_us(2_000_000, 0., false, 25.), 2_000_000);
12 assert_eq!(scrubbed_us(2_000_000, 50., false, 25.), 3_000_000);
13 // A fine drag (shift) moves a tenth as far: 100 px is 0.2 s.
14 assert_eq!(scrubbed_us(2_000_000, 100., true, 25.), 2_200_000);
15 // A value never goes below zero, nor past ten hours.
16 assert_eq!(scrubbed_us(100_000, -1_000., false, 25.), 0);
17 assert_eq!(scrubbed_us(35_000_000_000, 1_000_000., false, 25.), 36_000_000_000);
18 // A frame rate that is not usable falls back to 25 fps rather than dividing by it.
19 assert_eq!(scrubbed_us(2_000_000, 50., false, 0.), 3_000_000);
20}
21
22#[test]
23fn a_caption_number_reads_in_seconds_with_two_places() {
24 assert_eq!(cue_secs(1_840_000), "1.84");
25 assert_eq!(cue_secs(0), "0.00");
26}
27
28#[test]
29fn a_selected_caption_panel_has_its_actions_and_read_only_length() {
30 let card = src_text("ui/cards/caption.rs");
31 for label in ["Split at playhead", "Merge with next", "Delete", "Caption {} of {}"] {
32 assert!(card.contains(label), "{label}");
33 }
34 // The three actions are the caption menu's own, so a reason shows the same way.
35 for run in ["split_cue_at_playhead", "merge_cue_with_next", "delete_cue_at"] {
36 assert!(card.contains(run), "{run}");
37 }
38 // The length is read off the two numbers: no number field of its own.
39 assert!(!card.contains("num(\"caption-length\""), "length is read-only");
40 // A number that is dragged is written through the caption ops, one edit each.
41 let cues = src_text("player/caption_cues.rs");
42 assert!(cues.contains("fn cue_num_scrub_end") && cues.contains("set_cue_times"));
43}
44
45#[test]
46fn the_empty_clip_hero_waits_for_nothing_selected() {
47 let dock = src_text("ui/dock_stance.rs");
48 // The hero is the empty state only: a selected caption (`cue_up`) keeps the tab off it.
49 assert!(dock.contains("let empty = anchor.is_none() && !player.clip_card_open() && !title_up && !cue_up;"));
50 // A selected caption shows its panel and the style section only, none of a clip's sections.
51 let at = dock.find("if cue_up {").expect("the caption branch");
52 let branch = &dock[at..at + 260];
53 assert!(branch.contains("player.caption_card(cx)") && branch.contains("subtitle_style_card"), "{branch}");
54}