A subtitle row says which film it came out of, and the film is named over its tracks
Browse files at this commitad9f1ba0d4598af41650a84512169a2323ee3586Parent: d5d7fdf- feat
- a subtitle row says which film it came out of, and the film is named over its tracks
1 changed file +364 -61
- crates/app/src/main.rs +364 -61
crates/app/src/main.rsmodified+364 -61
| @@ -198,6 +198,26 @@ const SUB_CUE_MIN_W: f32 = 2.; | ||
| 198 | 198 | /// How much of the subtitle list in the library column is on screen at once, |
| 199 | 199 | /// past which it scrolls -- the media list above it is what keeps the height. |
| 200 | 200 | const SUB_ROWS_H: f32 = 3. * ROW_H; |
| 201 | +/// The row naming the file a block of tracks came out of. Shorter than a track | |
| 202 | +/// row because nothing on it is clicked -- `HIT_MIN` binds targets and a header | |
| 203 | +/// is a label, not a way in -- and drawn at all only where the column has the | |
| 204 | +/// height to show tracks under it ([`sub_headers_fit`]). | |
| 205 | +const SUB_HEAD_H: f32 = 18.; | |
| 206 | +/// How much of the subtitle list is on screen at the 640x360 floor: one row, | |
| 207 | +/// measured -- the section's own heading and the Add button under it take the | |
| 208 | +/// rest of the 84 px the column has there. | |
| 209 | +const SUB_ROWS_AT_FLOOR: f32 = ROW_H; | |
| 210 | +/// How much of a subtitle row's width the file's name in front of the label may | |
| 211 | +/// take. Half: which file and which language are both worth reading, and a name | |
| 212 | +/// given the whole row is a row where the language is what gets truncated. | |
| 213 | +const SUB_STEM_SHARE: f32 = 0.5; | |
| 214 | +/// Roughly how wide one character of an 11 px list row is. Generous on purpose: | |
| 215 | +/// the element truncates for real, and a budget that overshoots would have the | |
| 216 | +/// element cut the tail off after [`clip_middle`] had already kept it. | |
| 217 | +const LIST_CHAR_W: f32 = 6.; | |
| 218 | +/// The fewest characters a clipped name is cut to, however narrow the column | |
| 219 | +/// gets: past this there is nothing on either side of the gap to read. | |
| 220 | +const LIST_CLIP_MIN: usize = 5; | |
| 201 | 221 | |
| 202 | 222 | /// The one key name this file still spells out, and gpui's spelling of it: it |
| 203 | 223 | /// is the way out of a capture and out of the overlay, and both have to work |
| @@ -4894,7 +4914,11 @@ impl Render for Player { | ||
| 4894 | 4914 | .flex_1() |
| 4895 | 4915 | .min_h(px(0.)) |
| 4896 | 4916 | .flex() |
| 4897 | - .child(self.library(library_w(f32::from(window.viewport_size().width)), cx)) | |
| 4917 | + .child(self.library( | |
| 4918 | + library_w(f32::from(window.viewport_size().width)), | |
| 4919 | + f32::from(window.viewport_size().height), | |
| 4920 | + cx, | |
| 4921 | + )) | |
| 4898 | 4922 | .child( |
| 4899 | 4923 | div() |
| 4900 | 4924 | .flex_1() |
| @@ -4970,7 +4994,7 @@ impl Player { | ||
| 4970 | 4994 | /// the rest of this window: nothing in it takes focus, so the root keeps |
| 4971 | 4995 | /// the keyboard and the play key still works after a row is clicked |
| 4972 | 4996 | /// (ledger:182). |
| 4973 | - fn library(&self, width: f32, cx: &mut Context<Self>) -> impl IntoElement { | |
| 4997 | + fn library(&self, width: f32, viewport_h: f32, cx: &mut Context<Self>) -> impl IntoElement { | |
| 4974 | 4998 | let exporting = self.exporting().is_some(); |
| 4975 | 4999 | let sources = self |
| 4976 | 5000 | .session |
| @@ -5142,7 +5166,15 @@ impl Player { | ||
| 5142 | 5166 | // Two lines rather than two columns: at the width |
| 5143 | 5167 | // this panel yields to, a name and a timecode side |
| 5144 | 5168 | // by side leave room for neither. |
| 5145 | - .child(div().truncate().text_size(px(11.)).child(name)) | |
| 5169 | + // Cut out of the middle, not the end: two episodes off | |
| 5170 | + // one release are the same words up to the number, and | |
| 5171 | + // the number is at the end. | |
| 5172 | + .child( | |
| 5173 | + div() | |
| 5174 | + .truncate() | |
| 5175 | + .text_size(px(11.)) | |
| 5176 | + .child(clip_middle(&name, row_text_w(width))), | |
| 5177 | + ) | |
| 5146 | 5178 | .child( |
| 5147 | 5179 | div() |
| 5148 | 5180 | .truncate() |
| @@ -5210,7 +5242,7 @@ impl Player { | ||
| 5210 | 5242 | // Under the media it belongs to: a subtitle track is not a source -- |
| 5211 | 5243 | // it goes on no lane and is dragged nowhere -- but it is a thing the |
| 5212 | 5244 | // timeline holds, and this is the list of those. |
| 5213 | - .children(self.subtitle_section(cx)) | |
| 5245 | + .children(self.subtitle_section(width, viewport_h, cx)) | |
| 5214 | 5246 | .child(control( |
| 5215 | 5247 | "add-asset", |
| 5216 | 5248 | None, |
| @@ -5244,65 +5276,188 @@ impl Player { | ||
| 5244 | 5276 | /// as a media row the timeline cannot take is: PGS subtitles are pictures, |
| 5245 | 5277 | /// and a film carrying four of them says so instead of listing nothing. |
| 5246 | 5278 | /// |
| 5279 | + /// Every row names the file it came out of itself, in words and in the tint | |
| 5280 | + /// that file's clips wear on the lanes -- but only where there is more than | |
| 5281 | + /// one file to tell apart, the way [`row_name`] numbers audio streams only | |
| 5282 | + /// where a file gave several. Where the window is tall enough for it | |
| 5283 | + /// ([`sub_headers_fit`]) each file's block is headed by its name as well: a | |
| 5284 | + /// label and nothing more, no click and nothing to fold, so the rows under | |
| 5285 | + /// it are the only things anybody has to aim at. At the 640x360 floor the | |
| 5286 | + /// headers are gone and the rows still say whose they are. | |
| 5287 | + /// | |
| 5247 | 5288 | /// `None` when there are none -- an empty heading is a section about |
| 5248 | 5289 | /// nothing. |
| 5249 | - fn subtitle_section(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> { | |
| 5290 | + fn subtitle_section( | |
| 5291 | + &self, | |
| 5292 | + width: f32, | |
| 5293 | + viewport_h: f32, | |
| 5294 | + cx: &mut Context<Self>, | |
| 5295 | + ) -> Option<impl IntoElement> { | |
| 5250 | 5296 | let tracks = self.session.as_ref()?.subtitles(); |
| 5251 | 5297 | if tracks.is_empty() { |
| 5252 | 5298 | return None; |
| 5253 | 5299 | } |
| 5254 | - let rows: Vec<_> = tracks | |
| 5255 | - .iter() | |
| 5256 | - .enumerate() | |
| 5257 | - .map(|(i, track)| { | |
| 5258 | - let picked = i == self.sub_track; | |
| 5259 | - let usable = track.refused.is_none(); | |
| 5260 | - let under = subtitle_detail(track); | |
| 5261 | - let tip: SharedString = match &track.refused { | |
| 5262 | - Some(why) => format!("{} — {why}", track.path.display()), | |
| 5263 | - None => format!( | |
| 5264 | - "{} — click to show this track over the picture", | |
| 5265 | - track.path.display() | |
| 5266 | - ), | |
| 5267 | - } | |
| 5268 | - .into(); | |
| 5300 | + let groups = subtitle_rows(tracks); | |
| 5301 | + // One file's tracks need no prefix saying which file: it is the only | |
| 5302 | + // one, and every row would carry the same word. | |
| 5303 | + let several_files = groups.len() > 1; | |
| 5304 | + let headed = several_files && sub_headers_fit(viewport_h); | |
| 5305 | + let text_w = row_text_w(width); | |
| 5306 | + let rows: Vec<_> = groups | |
| 5307 | + .into_iter() | |
| 5308 | + .map(|SubGroup { name, path, rows }| { | |
| 5309 | + // The file's own colour, the one its media rows and its clips | |
| 5310 | + // wear -- and none at all for a standalone `.srt`, which came | |
| 5311 | + // off no file on this timeline. | |
| 5312 | + let tint = file_tint(self.sources(), &path); | |
| 5313 | + let numbered = rows.len() > 1; | |
| 5314 | + // The name twice over: all of it the header can hold, and the | |
| 5315 | + // share of a row a prefix may take in front of the label. | |
| 5316 | + let head = clip_middle(&name, text_w); | |
| 5317 | + let prefix = clip_middle(&name, text_w * SUB_STEM_SHARE); | |
| 5318 | + let rows: Vec<_> = rows | |
| 5319 | + .into_iter() | |
| 5320 | + .map(|row| { | |
| 5321 | + let track = row.track; | |
| 5322 | + let picked = track == self.sub_track; | |
| 5323 | + let usable = row.refused.is_none(); | |
| 5324 | + // Two tracks off one remux that both say "eng" are told | |
| 5325 | + // apart by their number and by nothing else -- the same | |
| 5326 | + // count [`sub_pick_name`] echoes. | |
| 5327 | + let title = match numbered { | |
| 5328 | + true => format!("{} {}", row.label, row.number), | |
| 5329 | + false => row.label, | |
| 5330 | + }; | |
| 5331 | + // The whole path, never clipped: the row says which | |
| 5332 | + // file, and the tooltip says which one on disk. | |
| 5333 | + let tip: SharedString = match &row.refused { | |
| 5334 | + Some(why) => format!("{} — {why}", path.display()), | |
| 5335 | + None => format!( | |
| 5336 | + "{} — click to show this track over the picture", | |
| 5337 | + path.display() | |
| 5338 | + ), | |
| 5339 | + } | |
| 5340 | + .into(); | |
| 5341 | + div() | |
| 5342 | + // The *flat* index into the session's add-order | |
| 5343 | + // list, which is what a pick is and what a save | |
| 5344 | + // writes: the grouping moved the row on screen and | |
| 5345 | + // never the track it stands for. | |
| 5346 | + .id(("subtitle-track", track)) | |
| 5347 | + .flex_none() | |
| 5348 | + .h(px(ROW_H)) | |
| 5349 | + .flex() | |
| 5350 | + .items_center() | |
| 5351 | + .gap(px(6.)) | |
| 5352 | + .pr(px(6.)) | |
| 5353 | + .rounded(px(3.)) | |
| 5354 | + .when(!usable, |d| d.text_color(rgb(INK_DIM)).opacity(0.55)) | |
| 5355 | + .when(usable, |d| { | |
| 5356 | + d.cursor_pointer() | |
| 5357 | + .hover(|s| s.bg(rgb(HOVER))) | |
| 5358 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 5359 | + this.sub_track = track; | |
| 5360 | + // Picking a track is asking to see it: a | |
| 5361 | + // click that changed nothing on screen | |
| 5362 | + // because the toggle was off would read | |
| 5363 | + // as a dead row. | |
| 5364 | + this.subs_on = true; | |
| 5365 | + cx.notify(); | |
| 5366 | + })) | |
| 5367 | + }) | |
| 5368 | + .when(picked, |d| d.bg(rgb(SELECTED))) | |
| 5369 | + .tooltip(move |_, cx| cx.new(|_| Tip(tip.clone())).into()) | |
| 5370 | + // The media rows' bar, same width and hard against | |
| 5371 | + // the same edge: one association across the panel | |
| 5372 | + // and the lanes. Kept as room rather than dropped | |
| 5373 | + // where there is no tint, so a standalone `.srt` | |
| 5374 | + // still lines its words up with the rest. | |
| 5375 | + .child( | |
| 5376 | + div() | |
| 5377 | + .flex_none() | |
| 5378 | + .w(px(SWATCH_W)) | |
| 5379 | + .h_full() | |
| 5380 | + .rounded(px(2.)) | |
| 5381 | + .when_some(tint, |d, tint| d.bg(rgb(tint))), | |
| 5382 | + ) | |
| 5383 | + .child( | |
| 5384 | + div() | |
| 5385 | + .flex_1() | |
| 5386 | + .min_w(px(0.)) | |
| 5387 | + .flex() | |
| 5388 | + .flex_col() | |
| 5389 | + .child( | |
| 5390 | + div() | |
| 5391 | + .flex() | |
| 5392 | + .text_size(px(11.)) | |
| 5393 | + // In front, because the column | |
| 5394 | + // truncates from the right: an | |
| 5395 | + // ownership word at the end is a | |
| 5396 | + // word the floor never shows. | |
| 5397 | + .when(several_files, |d| { | |
| 5398 | + d.child( | |
| 5399 | + div() | |
| 5400 | + .flex_none() | |
| 5401 | + // Said twice where a | |
| 5402 | + // header says it above: | |
| 5403 | + // still there, out of | |
| 5404 | + // the way. | |
| 5405 | + .when(headed, |d| { | |
| 5406 | + d.text_color(rgb(INK_DIM)) | |
| 5407 | + }) | |
| 5408 | + .child(format!("{prefix} · ")), | |
| 5409 | + ) | |
| 5410 | + }) | |
| 5411 | + .child( | |
| 5412 | + div() | |
| 5413 | + .flex_1() | |
| 5414 | + .min_w(px(0.)) | |
| 5415 | + .truncate() | |
| 5416 | + .child(title), | |
| 5417 | + ), | |
| 5418 | + ) | |
| 5419 | + .child( | |
| 5420 | + div() | |
| 5421 | + .truncate() | |
| 5422 | + .text_size(px(10.)) | |
| 5423 | + .text_color(rgb(INK_DIM)) | |
| 5424 | + .child(row.detail), | |
| 5425 | + ), | |
| 5426 | + ) | |
| 5427 | + }) | |
| 5428 | + .collect(); | |
| 5269 | 5429 | div() |
| 5270 | - .id(("subtitle-track", i)) | |
| 5271 | 5430 | .flex_none() |
| 5272 | - .h(px(ROW_H)) | |
| 5273 | 5431 | .flex() |
| 5274 | 5432 | .flex_col() |
| 5275 | - .justify_center() | |
| 5276 | - .px(px(6.)) | |
| 5277 | - .rounded(px(3.)) | |
| 5278 | - .when(!usable, |d| d.text_color(rgb(INK_DIM)).opacity(0.55)) | |
| 5279 | - .when(usable, |d| { | |
| 5280 | - d.cursor_pointer() | |
| 5281 | - .hover(|s| s.bg(rgb(HOVER))) | |
| 5282 | - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 5283 | - this.sub_track = i; | |
| 5284 | - // Picking a track is asking to see it: a click | |
| 5285 | - // that changed nothing on screen because the | |
| 5286 | - // toggle was off would read as a dead row. | |
| 5287 | - this.subs_on = true; | |
| 5288 | - cx.notify(); | |
| 5289 | - })) | |
| 5433 | + .gap(px(2.)) | |
| 5434 | + // The header: which film these came out of, in words and not | |
| 5435 | + // in colour alone. No id, no click, nothing to fold -- a | |
| 5436 | + // label, which is why it is allowed under `HIT_MIN`. | |
| 5437 | + .when(headed, |d| { | |
| 5438 | + d.child( | |
| 5439 | + div() | |
| 5440 | + .flex_none() | |
| 5441 | + .h(px(SUB_HEAD_H)) | |
| 5442 | + .flex() | |
| 5443 | + .items_center() | |
| 5444 | + .gap(px(6.)) | |
| 5445 | + .text_size(px(10.)) | |
| 5446 | + .text_color(rgb(INK_DIM)) | |
| 5447 | + .when_some(tint, |d, tint| { | |
| 5448 | + d.child( | |
| 5449 | + div() | |
| 5450 | + .flex_none() | |
| 5451 | + .w(px(SWATCH_W)) | |
| 5452 | + .h_full() | |
| 5453 | + .rounded(px(2.)) | |
| 5454 | + .bg(rgb(tint)), | |
| 5455 | + ) | |
| 5456 | + }) | |
| 5457 | + .child(div().flex_1().min_w(px(0.)).truncate().child(head)), | |
| 5458 | + ) | |
| 5290 | 5459 | }) |
| 5291 | - .when(picked, |d| d.bg(rgb(SELECTED))) | |
| 5292 | - .tooltip(move |_, cx| cx.new(|_| Tip(tip.clone())).into()) | |
| 5293 | - .child( | |
| 5294 | - div() | |
| 5295 | - .truncate() | |
| 5296 | - .text_size(px(11.)) | |
| 5297 | - .child(track.label.clone()), | |
| 5298 | - ) | |
| 5299 | - .child( | |
| 5300 | - div() | |
| 5301 | - .truncate() | |
| 5302 | - .text_size(px(10.)) | |
| 5303 | - .text_color(rgb(INK_DIM)) | |
| 5304 | - .child(under), | |
| 5305 | - ) | |
| 5460 | + .children(rows) | |
| 5306 | 5461 | }) |
| 5307 | 5462 | .collect(); |
| 5308 | 5463 | Some( |
| @@ -9373,12 +9528,10 @@ fn subtitle_detail(track: &engine::subtitle::SubtitleTrack) -> String { | ||
| 9373 | 9528 | /// before anything is drawn -- the grouping is the branchy part and it is the |
| 9374 | 9529 | /// same answer whatever a styling puts around it. |
| 9375 | 9530 | /// |
| 9376 | -/// ponytail: only [`sub_pick_name`] reads these -- [`Player::subtitle_section`] | |
| 9377 | -/// still *lists* the flat rows, so the grouping shows in what the headers say | |
| 9378 | -/// and not yet in how the list is laid out. The upgrade is that section | |
| 9379 | -/// rendering groups instead. | |
| 9531 | +/// [`Player::subtitle_section`] draws one block per group of these, and | |
| 9532 | +/// [`sub_pick_name`] names the pick out of the same answer -- so what a heading | |
| 9533 | +/// says and what a row a person clicked says cannot disagree. | |
| 9380 | 9534 | #[derive(Debug, PartialEq)] |
| 9381 | -#[allow(dead_code)] | |
| 9382 | 9535 | struct SubGroup { |
| 9383 | 9536 | /// What the group is called: the file without its extension, which is what |
| 9384 | 9537 | /// a person named the film even when the subtitles came out of a remux. |
| @@ -9392,7 +9545,6 @@ struct SubGroup { | ||
| 9392 | 9545 | |
| 9393 | 9546 | /// One subtitle track, as a row shows it. |
| 9394 | 9547 | #[derive(Debug, PartialEq)] |
| 9395 | -#[allow(dead_code)] | |
| 9396 | 9548 | struct SubRow { |
| 9397 | 9549 | /// Which track of the session's list this row is: the *flat* index into the |
| 9398 | 9550 | /// add-order Vec `PlaybackSession::subtitles` hands back, which is what a |
| @@ -9418,7 +9570,6 @@ struct SubRow { | ||
| 9418 | 9570 | /// distinct path, in the order the files first appear, and each file's tracks |
| 9419 | 9571 | /// in the order they were added. Two remuxes' tracks arriving interleaved -- |
| 9420 | 9572 | /// which is what importing a second film does -- still read as two films. |
| 9421 | -#[allow(dead_code)] | |
| 9422 | 9573 | fn subtitle_rows(tracks: &[engine::subtitle::SubtitleTrack]) -> Vec<SubGroup> { |
| 9423 | 9574 | let mut groups: Vec<SubGroup> = Vec::new(); |
| 9424 | 9575 | for (track, sub) in tracks.iter().enumerate() { |
| @@ -10033,6 +10184,55 @@ fn library_w(window_w: f32) -> f32 { | ||
| 10033 | 10184 | .min(window_w / 3.) |
| 10034 | 10185 | } |
| 10035 | 10186 | |
| 10187 | +/// What is left of a library column this wide for a row's *words*: the panel's | |
| 10188 | +/// padding on both sides, the tint bar, the gap after it and the row's own right | |
| 10189 | +/// inset. Every row in the column -- media and subtitle -- is built to this | |
| 10190 | +/// shape, so one number answers for both. | |
| 10191 | +fn row_text_w(width: f32) -> f32 { | |
| 10192 | + // 8 px of panel padding each side, then the bar, the gap after it and the | |
| 10193 | + // row's own right inset -- the numbers the rows are built with. | |
| 10194 | + width - 16. - SWATCH_W - 6. - 6. | |
| 10195 | +} | |
| 10196 | + | |
| 10197 | +/// A name cut to what a column this wide can hold, out of the *middle*. Two | |
| 10198 | +/// files off one release differ in their last characters and nowhere else -- | |
| 10199 | +/// "…Episode 01" against "…02" -- so a name cut from the right is the same | |
| 10200 | +/// name twice and the list stops naming anything. The width decides how much | |
| 10201 | +/// survives, not a number of characters somebody guessed: a wider window spells | |
| 10202 | +/// more of the file out, and the floor still keeps both ends. | |
| 10203 | +/// | |
| 10204 | +/// The element truncates for real; this only decides where what is lost comes | |
| 10205 | +/// out of. | |
| 10206 | +fn clip_middle(name: &str, width: f32) -> String { | |
| 10207 | + let budget = ((width / LIST_CHAR_W) as usize).max(LIST_CLIP_MIN); | |
| 10208 | + let chars: Vec<char> = name.chars().collect(); | |
| 10209 | + if chars.len() <= budget { | |
| 10210 | + return name.to_string(); | |
| 10211 | + } | |
| 10212 | + // The gap costs a character, and what is left of the odd one goes to the | |
| 10213 | + // tail: the tail is the half that tells two of them apart. | |
| 10214 | + let head = (budget - 1) / 2; | |
| 10215 | + let tail = budget - 1 - head; | |
| 10216 | + format!( | |
| 10217 | + "{}…{}", | |
| 10218 | + chars[..head].iter().collect::<String>(), | |
| 10219 | + chars[chars.len() - tail..].iter().collect::<String>() | |
| 10220 | + ) | |
| 10221 | +} | |
| 10222 | + | |
| 10223 | +/// Whether the subtitle list has the height to name each file over its tracks. | |
| 10224 | +/// A header is worth its own height only where there are still tracks under it | |
| 10225 | +/// to read: at the 640x360 floor the list is one row tall, and a header there | |
| 10226 | +/// would name a film and show none of it -- so at the floor there are no | |
| 10227 | +/// headers and the rows say which file they came from themselves. | |
| 10228 | +/// | |
| 10229 | +/// The window's height answers it on its own: the row above the picture and the | |
| 10230 | +/// panel under it are fixed, so every pixel the window gains past the floor is a | |
| 10231 | +/// pixel this column gains. | |
| 10232 | +fn sub_headers_fit(viewport_h: f32) -> bool { | |
| 10233 | + SUB_ROWS_AT_FLOOR + (viewport_h - 360.).max(0.) >= SUB_HEAD_H + 2. * ROW_H | |
| 10234 | +} | |
| 10235 | + | |
| 10036 | 10236 | /// What the window is called: the program, and what is open in it. The name is |
| 10037 | 10237 | /// what the header shows, so an empty window says the program alone rather than |
| 10038 | 10238 | /// "no file open — edith". |
| @@ -12087,8 +12287,10 @@ mod tests { | ||
| 12087 | 12287 | visible_slice, |
| 12088 | 12288 | }; |
| 12089 | 12289 | use super::{ |
| 12090 | - SUB_BOTTOM, SUB_CUE_MIN_W, SUB_INK, SUB_LANE_H, SUB_LINE_H, SUB_ROWS_H, SUB_TEXT, cue_box, | |
| 12091 | - cues_at, file_tint, is_matroska, is_subtitle, lang_human, subtitle_detail, subtitle_notice, | |
| 12290 | + SUB_BOTTOM, SUB_CUE_MIN_W, SUB_HEAD_H, SUB_INK, SUB_LANE_H, SUB_LINE_H, SUB_ROWS_H, | |
| 12291 | + SUB_STEM_SHARE, SUB_TEXT, clip_middle, cue_box, | |
| 12292 | + cues_at, file_tint, is_matroska, is_subtitle, lang_human, row_text_w, sub_headers_fit, | |
| 12293 | + subtitle_detail, subtitle_notice, | |
| 12092 | 12294 | sub_pick_name, subtitle_rows, subtitle_strip_h, |
| 12093 | 12295 | }; |
| 12094 | 12296 | |
| @@ -15610,6 +15812,61 @@ mod tests { | ||
| 15610 | 15812 | // taking the media list's room. |
| 15611 | 15813 | assert_eq!(SUB_ROWS_H / ROW_H, 3.); |
| 15612 | 15814 | assert!(ROW_H >= HIT_MIN, "a subtitle row is clicked to pick it"); |
| 15815 | + // At the floor there are no group headers at all: the list is one row | |
| 15816 | + // tall there, and a header would name a film and then show none of it. | |
| 15817 | + // The rows go on naming their own file, so nothing is lost by it. | |
| 15818 | + assert!(!sub_headers_fit(360.), "a header at the floor eats the track"); | |
| 15819 | + // At the size the window opens on there is room for a header and the | |
| 15820 | + // tracks under it, which is the only condition it is drawn on. | |
| 15821 | + assert!(sub_headers_fit(720.)); | |
| 15822 | + // ...and where it is drawn it fits inside the same capped list, header | |
| 15823 | + // and two rows under it, without the tracks losing their budget. | |
| 15824 | + assert!(SUB_HEAD_H + 2. * ROW_H <= SUB_ROWS_H); | |
| 15825 | + // A header takes no click -- there is nothing to fold and nothing to | |
| 15826 | + // aim at -- which is the only reason it may be under `HIT_MIN`. | |
| 15827 | + assert!(SUB_HEAD_H < HIT_MIN && SUB_HEAD_H > 0.); | |
| 15828 | + } | |
| 15829 | + | |
| 15830 | + /// What the rows of both lists do with a name too long for the column: two | |
| 15831 | + /// episodes off one release differ in their last two characters, and a name | |
| 15832 | + /// cut from the right is the same row twice. | |
| 15833 | + #[test] | |
| 15834 | + fn a_long_name_is_cut_out_of_its_middle_so_two_episodes_stay_two_rows() { | |
| 15835 | + let (a, b) = ( | |
| 15836 | + "A Long Release Name Of A Series 01", | |
| 15837 | + "A Long Release Name Of A Series 02", | |
| 15838 | + ); | |
| 15839 | + // The two call sites at the narrowest the column ever is: a media row's | |
| 15840 | + // name gets the row's whole width, a subtitle row's file prefix gets a | |
| 15841 | + // share of it because the language has to fit beside it. | |
| 15842 | + let media = row_text_w(LIBRARY_MIN_W); | |
| 15843 | + let prefix = media * SUB_STEM_SHARE; | |
| 15844 | + for width in [media, prefix] { | |
| 15845 | + assert!(width > 0., "the floor leaves a row no words at all"); | |
| 15846 | + assert_ne!( | |
| 15847 | + clip_middle(a, width), | |
| 15848 | + clip_middle(b, width), | |
| 15849 | + "{width}px: two episodes read as one row" | |
| 15850 | + ); | |
| 15851 | + // Both ends survive: the release's name at the front, the number | |
| 15852 | + // that tells them apart at the back. | |
| 15853 | + assert!(clip_middle(a, width).starts_with('F')); | |
| 15854 | + assert!(clip_middle(a, width).ends_with("01")); | |
| 15855 | + assert!(clip_middle(a, width).contains('…')); | |
| 15856 | + // Never wider than the column can hold, gap included. | |
| 15857 | + assert!(clip_middle(a, width).chars().count() <= (width / 6.) as usize + 1); | |
| 15858 | + } | |
| 15859 | + // A name the width holds is left exactly as it is -- no gap, nothing | |
| 15860 | + // dropped -- and so is a name at any width once the column is wide. | |
| 15861 | + assert_eq!(clip_middle("eng.srt", 400.), "eng.srt"); | |
| 15862 | + assert_eq!(clip_middle(a, 4000.), a); | |
| 15863 | + // Nothing panics at a width no column ever has, and something of both | |
| 15864 | + // ends is still there. | |
| 15865 | + assert_eq!(clip_middle(a, 0.).chars().count(), 5); | |
| 15866 | + assert!(clip_middle(a, 0.).ends_with('1')); | |
| 15867 | + // Counted in characters and not bytes: a name in another script is cut | |
| 15868 | + // between its letters, not through one. | |
| 15869 | + assert_eq!(clip_middle("ααααααααααααααα", 24.), "αα…αα"); | |
| 15613 | 15870 | } |
| 15614 | 15871 | |
| 15615 | 15872 | /// The two doors subtitles arrive through, end to end on the fixtures: a |
| @@ -16302,6 +16559,52 @@ mod tests { | ||
| 16302 | 16559 | assert_eq!(groups[0].rows[1].track, 2); |
| 16303 | 16560 | } |
| 16304 | 16561 | |
| 16562 | + /// The same claim from the click's end, on the order imports actually | |
| 16563 | + /// arrive in: two films opened one after the other and an `.srt` dropped | |
| 16564 | + /// last interleave in the flat list, and the display reorders them. What a | |
| 16565 | + /// click sets is the row's own `track`, so the *n*th row on screen has to | |
| 16566 | + /// pick the track it shows and the echoes have to name that same file. | |
| 16567 | + #[test] | |
| 16568 | + fn a_click_on_a_regrouped_row_picks_the_track_that_row_shows() { | |
| 16569 | + let tracks = [ | |
| 16570 | + sub("/films/a.mkv", Some(1), "eng"), | |
| 16571 | + sub("/films/b.mkv", Some(1), "eng"), | |
| 16572 | + sub("/films/a.mkv", Some(2), "fre"), | |
| 16573 | + sub("/subs/late.srt", None, "late.srt"), | |
| 16574 | + sub("/films/b.mkv", Some(3), "ger"), | |
| 16575 | + ]; | |
| 16576 | + let rows: Vec<_> = subtitle_rows(&tracks) | |
| 16577 | + .into_iter() | |
| 16578 | + .flat_map(|group| { | |
| 16579 | + group | |
| 16580 | + .rows | |
| 16581 | + .into_iter() | |
| 16582 | + .map(move |row| (group.path.clone(), row)) | |
| 16583 | + }) | |
| 16584 | + .collect(); | |
| 16585 | + // Read top to bottom, the rows are no longer in add order... | |
| 16586 | + assert_eq!( | |
| 16587 | + rows.iter().map(|(_, row)| row.track).collect::<Vec<_>>(), | |
| 16588 | + [0, 2, 1, 4, 3] | |
| 16589 | + ); | |
| 16590 | + for (path, row) in &rows { | |
| 16591 | + // ...and what the click writes into `sub_track` -- and a save into | |
| 16592 | + // the `.edith` -- still lands on the track the row is showing. | |
| 16593 | + let picked = &tracks[row.track]; | |
| 16594 | + assert_eq!(&picked.path, path, "row {} picks another file", row.track); | |
| 16595 | + assert_eq!(lang_human(&picked.label), row.label); | |
| 16596 | + // And the heading, the strip and the notice name that same file | |
| 16597 | + // back, so a click cannot leave the echoes pointing elsewhere. | |
| 16598 | + let echo = sub_pick_name(&tracks, row.track).expect("the row's own track"); | |
| 16599 | + let stem = path.file_stem().expect("a fixture path").to_string_lossy(); | |
| 16600 | + assert!( | |
| 16601 | + echo.contains(&*stem), | |
| 16602 | + "picked {}, echoed {echo}", | |
| 16603 | + path.display() | |
| 16604 | + ); | |
| 16605 | + } | |
| 16606 | + } | |
| 16607 | + | |
| 16305 | 16608 | /// "und" is what a muxer writes when nobody said what the language is. A |
| 16306 | 16609 | /// row showing it verbatim names a language nobody speaks. |
| 16307 | 16610 | #[test] |