forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

track_height.rs126 lines, 5.8 KiBHistoryRawDownload
1//! Track heights: the three sizes a lane can be set to, the menus and keys that set them, and
2//! the y-to-lane arithmetic a column of mixed heights has to get right.
3
4use super::*;
5use crate::ui::bench_stance::{
6 LANE_MAX_H, LANE_MIN_H, TrackSize, lane_at_y, lane_bands, set_track_size, size_h, snap_lane_h,
7};
8use crate::ui::menubar::Title;
9use keymap::ActionId;
10
11/// Small is the floor, Medium is the kind's own default, Large is taller than Medium and within
12/// the ceiling a dragged lane may reach; the subtitle lane's Small and Medium are one height.
13#[test]
14fn the_three_sizes_order_by_height_within_the_lane_range() {
15 for kind in [LaneKind::Video, LaneKind::Audio, LaneKind::Subtitle] {
16 let (small, medium, large) = (
17 size_h(kind, TrackSize::Small),
18 size_h(kind, TrackSize::Medium),
19 size_h(kind, TrackSize::Large),
20 );
21 assert_eq!(small, LANE_MIN_H, "{kind:?}");
22 assert!(small <= medium && medium < large, "{kind:?}: {small} {medium} {large}");
23 assert!(large <= LANE_MAX_H, "{kind:?}: {large}");
24 }
25 assert_eq!(size_h(LaneKind::Video, TrackSize::Medium), 52.);
26 assert_eq!(size_h(LaneKind::Audio, TrackSize::Medium), 40.);
27}
28
29/// Steps move one size at a time and hold at the ends.
30#[test]
31fn a_step_moves_one_size_and_holds_at_the_ends() {
32 use TrackSize::{Large, Medium, Small};
33 assert_eq!(Small.step(true), Medium);
34 assert_eq!(Medium.step(true), Large);
35 assert_eq!(Large.step(true), Large);
36 assert_eq!(Large.step(false), Medium);
37 assert_eq!(Medium.step(false), Small);
38 assert_eq!(Small.step(false), Small);
39 assert_eq!([Small, Medium, Large].map(TrackSize::word), ["Small", "Medium", "Large"]);
40}
41
42/// A size written to a lane saves its height; Medium forgets it, so the lane goes back to following
43/// the window. Other lanes are not touched.
44#[test]
45fn a_size_sets_its_own_lane_and_medium_forgets_it() {
46 let mut saved = Vec::new();
47 set_track_size(&mut saved, Lane::V1, TrackSize::Large);
48 set_track_size(&mut saved, Lane::A1, TrackSize::Small);
49 assert_eq!(saved, vec![("v1".to_string(), 96.), ("a1".to_string(), LANE_MIN_H)]);
50 set_track_size(&mut saved, Lane::V1, TrackSize::Medium);
51 assert_eq!(saved, vec![("a1".to_string(), LANE_MIN_H)]);
52 set_track_size(&mut saved, Lane::A1, TrackSize::Large);
53 assert_eq!(saved, vec![("a1".to_string(), 72.)], "a key is replaced, not repeated");
54}
55
56/// A drag that lands within a few pixels of a size lands on it; one that does not keeps its height.
57#[test]
58fn a_dragged_height_snaps_to_a_size_it_is_next_to() {
59 assert_eq!(snap_lane_h(LaneKind::Video, 50.), 52.);
60 assert_eq!(snap_lane_h(LaneKind::Video, 56.), 52.);
61 assert_eq!(snap_lane_h(LaneKind::Video, 70.), 70.);
62 assert_eq!(snap_lane_h(LaneKind::Audio, 74.), 72.);
63 assert_eq!(snap_lane_h(LaneKind::Audio, LANE_MIN_H + 1.), LANE_MIN_H);
64}
65
66/// A mixed stack (video 96, audio 40, a small audio 28, video 52, rows apart by the 2px gap): each
67/// y belongs to the lane whose own band holds it, and the gap between two lanes belongs to neither.
68#[test]
69fn a_y_lands_on_the_lane_whose_own_height_holds_it_in_a_mixed_stack() {
70 let v1 = Lane::V1;
71 let a1 = Lane::A1;
72 let a2 = Lane::new(LaneKind::Audio, 1);
73 let v2 = Lane::new(LaneKind::Video, 1);
74 let bands = lane_bands(&[(v1, 96.), (a1, 40.), (a2, 28.), (v2, 52.)]);
75 assert_eq!(bands[1], (a1, 98., 138.));
76 assert_eq!(bands[2], (a2, 140., 168.));
77 assert_eq!(bands[3], (v2, 170., 222.));
78 assert_eq!(lane_at_y(&bands, 0.), Some(v1));
79 assert_eq!(lane_at_y(&bands, 95.9), Some(v1));
80 assert_eq!(lane_at_y(&bands, 97.), None, "the gap under V1 is no lane");
81 assert_eq!(lane_at_y(&bands, 98.), Some(a1));
82 assert_eq!(lane_at_y(&bands, 137.), Some(a1));
83 assert_eq!(lane_at_y(&bands, 139.), None, "the gap under A1 is no lane");
84 assert_eq!(lane_at_y(&bands, 141.), Some(a2));
85 assert_eq!(lane_at_y(&bands, 167.9), Some(a2));
86 assert_eq!(lane_at_y(&bands, 170.), Some(v2));
87 assert_eq!(lane_at_y(&bands, 222.), None, "below the last lane");
88 assert_eq!(lane_at_y(&bands, -1.), None, "above the first lane");
89}
90
91/// The header's menu offers the three heights as rows, before the rule that leads to the removes,
92/// and they are enabled on every kind of lane.
93#[test]
94fn the_head_menu_offers_three_heights_before_the_removes() {
95 for lane in [Lane::V1, Lane::A1, Lane::S1] {
96 let items = lane_items(lane);
97 let remove = items.iter().position(|&a| destructive(a)).unwrap_or(items.len());
98 for size in [ActionId::TrackSmall, ActionId::TrackMedium, ActionId::TrackLarge] {
99 let at = items.iter().position(|&a| a == size).expect("a height row");
100 assert!(at < remove, "{lane:?}: {size:?} before the removes");
101 assert!(matches!(enable_lane(size, lane, Ctx::default()), Enable::Yes));
102 }
103 }
104}
105
106/// The Timeline menu carries the three all-track rows and the two steps; the keys for the steps
107/// are the ones the keymap binds, and the labels are the words a person reads.
108#[test]
109fn the_timeline_menu_and_keys_set_every_track_height() {
110 let timeline: Vec<ActionId> = Title::Timeline.entries().into_iter().filter_map(|e| e.action()).collect();
111 for action in [
112 ActionId::TrackSmall,
113 ActionId::TrackMedium,
114 ActionId::TrackLarge,
115 ActionId::TracksSmaller,
116 ActionId::TracksLarger,
117 ] {
118 assert!(timeline.contains(&action), "{action:?} in the Timeline menu");
119 }
120 assert_eq!(ActionId::TrackSmall.label(), "All tracks: Small");
121 assert_eq!(ActionId::TracksSmaller.label(), "Make tracks smaller");
122 assert_eq!(ActionId::TracksLarger.label(), "Make tracks larger");
123 let keys = keymap::Keymap::defaults();
124 assert_eq!(keys.display(ActionId::TracksLarger), "Alt+=");
125 assert_eq!(keys.display(ActionId::TracksSmaller), "Alt+-");
126}