forge
Explore
Log in

Don't you dare go Hollow

The subtitles toggle says what is placed, not what is picked

Browse files at this commit

d6c0e923464106eaff250d487d8a8ab7120f0aa9Ahmet Kaan GümüşParent: 563161a
  • chore
    • the subtitles toggle says what is placed, not what is picked
Show full message
🧹 chore(app): the subtitles toggle says what is placed, not what is picked

Under lanes the picture reads the subtitle lanes, so the toggle's notice
naming the palette row named a track the stroke never touches: it now counts
the captions actually placed, and so does the toolbar's own label ('No subs'
for a palette full of tracks nobody dragged anywhere).

- actions.rs: toggle_subtitles words itself off placed captions; subtitle_track
  (the last pick-shows-it reader) gone, placed_captions in its place.
- toolbar.rs: the subs control reads placed captions.
- subs.rs/export.rs: docs that still said a pick draws.
crates/app/src/player/actions.rsmodified+23 -22
@@ -166,33 +166,34 @@ impl Player {
166 self.keys_scroll.set_offset(point(px(0.), px(at)));166 self.keys_scroll.set_offset(point(px(0.), px(at)));
167 }167 }
168 168
169- /// The cues over the picture, off and on. Says which it is now *and* what is169+ /// The cues over the picture, off and on. Says which it is now *and* how
170- /// on screen while they are on: a toggle whose answer is invisible when the170+ /// much is placed underneath: a toggle whose answer is invisible -- the
171- /// playhead happens to sit between two cues would read as broken.171+ /// playhead between two cues, or a palette full of tracks nobody dragged
172+ /// onto a lane -- would read as broken.
172 pub(crate) fn toggle_subtitles(&mut self, cx: &mut Context<Self>) {173 pub(crate) fn toggle_subtitles(&mut self, cx: &mut Context<Self>) {
173 self.subs_on = !self.subs_on;174 self.subs_on = !self.subs_on;
174- // Named with its film here too: a notice saying "SUBTITLES ON — eng"175+ // Lane facts and not the picked row: what draws is what is *placed*
175- // over a timeline holding two films' eng tracks names neither.176+ // ([`Player::subtitle_overlay`]), so naming the palette selection here
176- let label = self177+ // named a track the toggle never touched.
177- .session178+ let placed = self.placed_captions();
178- .as_ref()179+ self.notify_user(subtitle_toggle_notice(self.subs_on, placed).into());
179- .and_then(|session| sub_pick_name(session.subtitles(), self.sub_track))
180- .unwrap_or_else(|| "nothing imported".to_string());
181- self.notify_user(
182- match self.subs_on {
183- true => format!("SUBTITLES ON — {label}"),
184- false => format!("SUBTITLES OFF — {label} is still on the timeline"),
185- }
186- .into(),
187- );
188 cx.notify();180 cx.notify();
189 }181 }
190 182
191- /// The subtitle track the overlay and the strip are showing: the one a183+ /// How many captions the subtitle lanes hold, all lanes together: what the
192- /// library row picked, or the first there is. `None` with no timeline and184+ /// toggle and the toolbar's own label are about, now that the picture reads
193- /// for an index left over from one that is gone.185+ /// the lanes rather than a pick ([`Player::subtitle_overlay`]). Zero with no
194- pub(crate) fn subtitle_track(&self) -> Option<&engine::subtitle::SubtitleTrack> {186+ /// timeline, and zero for a palette full of tracks nobody placed -- both
195- self.session.as_ref()?.subtitles().get(self.sub_track)187+ /// show nothing, so both read "No subs".
188+ pub(crate) fn placed_captions(&self) -> usize {
189+ let Some(session) = self.session.as_ref() else {
190+ return 0;
191+ };
192+ session
193+ .subtitle_lanes()
194+ .into_iter()
195+ .map(|lane| session.sub_lane(lane).len())
196+ .sum()
196 }197 }
197 198
198 /// Whether the editor can be asked for `action` right now, and why not when199 /// Whether the editor can be asked for `action` right now, and why not when
crates/app/src/player/export.rsmodified+2 -2
@@ -517,8 +517,8 @@ impl Player {
517 /// Worked out from the cues each time rather than kept as a pick, which is517 /// Worked out from the cues each time rather than kept as a pick, which is
518 /// what makes it impossible to desync: a row added or taken off shifts every518 /// what makes it impossible to desync: a row added or taken off shifts every
519 /// index after it, and a stored list would then name tracks nobody chose.519 /// index after it, and a stored list would then name tracks nobody chose.
520- /// `Player::sub_track` stays what it always was -- which track the *overlay*520+ /// `Player::sub_track` stays what it always was -- which palette row the
521- /// draws -- and has no say here.521+ /// list *marks* -- and has no say here.
522 ///522 ///
523 /// The honest input and not the final answer: the engine filters it again523 /// The honest input and not the final answer: the engine filters it again
524 /// per track (a track that could not be read, a picture one) and says so in524 /// per track (a track that could not be read, a picture one) and says so in
crates/app/src/subs.rsmodified+20 -1
@@ -257,6 +257,24 @@ pub(crate) fn subtitle_tail(session: &mut PlaybackSession, subs: Subs) -> Option
257 }257 }
258 }258 }
259 259
260+/// What the subtitles toggle says it just did ([`Player::toggle_subtitles`]),
261+/// worded off the lanes: `placed` is every caption on every subtitle lane
262+/// ([`Player::placed_captions`]), because that -- and never the palette row the
263+/// list marks -- is what the toggle covers and uncovers.
264+///
265+/// Nothing placed is its own sentence: "SUBTITLES SHOWN — 0 caption(s)" over an
266+/// unchanged picture reads as a broken toggle, so it says the move that would
267+/// put words there instead.
268+pub(crate) fn subtitle_toggle_notice(on: bool, placed: usize) -> String {
269+ match (on, placed) {
270+ (true, 0) => {
271+ "SUBTITLES SHOWN — nothing placed yet: drag a track onto a subtitle track".to_string()
272+ }
273+ (true, n) => format!("SUBTITLES SHOWN — {n} caption(s) on the timeline"),
274+ (false, n) => format!("SUBTITLES HIDDEN — {n} caption(s) still placed"),
275+ }
276+}
277+
260 /// The push both deliberate add-subtitles doors end on -- `+ S` and its key278 /// The push both deliberate add-subtitles doors end on -- `+ S` and its key
261 /// ([`Player::add_subtitles`]) and a dropped or argv'd subtitle file279 /// ([`Player::add_subtitles`]) and a dropped or argv'd subtitle file
262 /// ([`Player::take_subtitles`]) -- so the two cannot come to word the same file280 /// ([`Player::take_subtitles`]) -- so the two cannot come to word the same file
@@ -423,7 +441,8 @@ pub(crate) struct SubGroup {
423 pub(crate) struct SubRow {441 pub(crate) struct SubRow {
424 /// Which track of the session's list this row is: the *flat* index into the442 /// Which track of the session's list this row is: the *flat* index into the
425 /// add-order Vec `PlaybackSession::subtitles` hands back, which is what a443 /// add-order Vec `PlaybackSession::subtitles` hands back, which is what a
426- /// click sets `sub_track` to and what a save writes into the `.edith`.444+ /// click sets `sub_track` to and what a caption placed on a subtitle lane
445+ /// names, so it is what a save writes into the `.edith` for that caption.
427 /// Grouping moves rows around on screen and never touches this number.446 /// Grouping moves rows around on screen and never touches this number.
428 pub(crate) track: usize,447 pub(crate) track: usize,
429 /// Which of *this file's* tracks it is, counted from 1 -- the numbering448 /// Which of *this file's* tracks it is, counted from 1 -- the numbering
crates/app/src/tests/layout.rsmodified+23 -1
@@ -882,11 +882,33 @@ fn the_picked_subtitle_is_named_with_the_film_it_came_out_of() {
882 // A standalone `.srt` is its own file and its label already says so:882 // A standalone `.srt` is its own file and its label already says so:
883 // one track, so no number, and no stem after it saying it again.883 // one track, so no number, and no stem after it saying it again.
884 assert_eq!(name(4), "late.srt");884 assert_eq!(name(4), "late.srt");
885- // The silence `subtitle_track` gives at the same moment.885+ // The silence a row left over from a timeline that is gone gets.
886 assert_eq!(sub_pick_name(&tracks, 5), None);886 assert_eq!(sub_pick_name(&tracks, 5), None);
887 assert_eq!(sub_pick_name(&[], 0), None);887 assert_eq!(sub_pick_name(&[], 0), None);
888 }888 }
889 889
890+/// What the toggle covers is what is *placed*, so what it says is a lane fact:
891+/// naming the palette row the list happens to mark named a track the stroke
892+/// never touched ("SUBTITLES OFF — one.srt is still on the timeline" for a
893+/// one.srt nobody dragged anywhere).
894+#[test]
895+fn the_subtitles_toggle_says_what_is_placed_and_never_the_picked_row() {
896+ for on in [true, false] {
897+ let text = subtitle_toggle_notice(on, 2);
898+ assert!(text.contains('2'), "{text} counts the captions placed");
899+ assert!(
900+ !text.contains("track(s)") && !text.contains(" — a"),
901+ "{text} names no palette row"
902+ );
903+ }
904+ // Off leaves them on the lanes; that is the half a person needs told.
905+ assert!(subtitle_toggle_notice(false, 2).contains("still placed"));
906+ // An empty timeline says the move instead of a count that reads as broken.
907+ let none = subtitle_toggle_notice(true, 0);
908+ assert!(!none.contains('0'), "{none} counts nothing at nothing");
909+ assert!(none.contains("drag"), "{none} says the next move");
910+}
911+
890 /// The door this editor answers "don't make me import the film again" with,912 /// The door this editor answers "don't make me import the film again" with,
891 /// and it is in the panel where the tracks it adds are listed: the Text913 /// and it is in the panel where the tracks it adds are listed: the Text
892 /// tab's own button reads a file's subtitle tracks onto the open timeline914 /// tab's own button reads a file's subtitle tracks onto the open timeline
crates/app/src/tests/mod.rsmodified+1 -1
@@ -58,7 +58,7 @@ use super::{
58 SUB_STEM_SHARE, SUB_TEXT, clip_middle, cue_box, sub_bottom,58 SUB_STEM_SHARE, SUB_TEXT, clip_middle, cue_box, sub_bottom,
59 carries_subtitles, cues_at, file_tint, is_subtitle, lang_human, row_text_w, sub_headers_fit,59 carries_subtitles, cues_at, file_tint, is_subtitle, lang_human, row_text_w, sub_headers_fit,
60 Subs, subtitle_detail, subtitle_notice, subtitle_tail,60 Subs, subtitle_detail, subtitle_notice, subtitle_tail,
61- sub_pick_name, subtitle_rows, walk_subtitles,61+ sub_pick_name, subtitle_rows, subtitle_toggle_notice, walk_subtitles,
62 };62 };
63 63
64 use engine::PlaybackSession;64 use engine::PlaybackSession;
crates/app/src/ui/toolbar.rsmodified+1 -1
@@ -341,7 +341,7 @@ impl Player {
341 SNAP_SLOT_W,341 SNAP_SLOT_W,
342 BG_RAISED(),342 BG_RAISED(),
343 None,343 None,
344- match (self.subtitle_track().is_some(), self.subs_on) {344+ match (self.placed_captions() > 0, self.subs_on) {
345 (false, _) => "No subs",345 (false, _) => "No subs",
346 (true, true) => "Subs on",346 (true, true) => "Subs on",
347 (true, false) => "Subs off",347 (true, false) => "Subs off",