From d6c0e923464106eaff250d487d8a8ab7120f0aa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 14 Aug 2026 06:47:13 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20chore(app):=20the=20subtitles=20?= =?UTF-8?q?toggle=20says=20what=20is=20placed,=20not=20what=20is=20picked?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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.rs | 45 ++++++++++++++++---------------- crates/app/src/player/export.rs | 4 +-- crates/app/src/subs.rs | 21 ++++++++++++++- crates/app/src/tests/layout.rs | 24 ++++++++++++++++- crates/app/src/tests/mod.rs | 2 +- crates/app/src/ui/toolbar.rs | 2 +- 6 files changed, 70 insertions(+), 28 deletions(-) diff --git a/crates/app/src/player/actions.rs b/crates/app/src/player/actions.rs index 2ee049d..aa893c8 100644 --- a/crates/app/src/player/actions.rs +++ b/crates/app/src/player/actions.rs @@ -166,33 +166,34 @@ impl Player { self.keys_scroll.set_offset(point(px(0.), px(at))); } - /// The cues over the picture, off and on. Says which it is now *and* what is - /// on screen while they are on: a toggle whose answer is invisible when the - /// playhead happens to sit between two cues would read as broken. + /// The cues over the picture, off and on. Says which it is now *and* how + /// much is placed underneath: a toggle whose answer is invisible -- the + /// playhead between two cues, or a palette full of tracks nobody dragged + /// onto a lane -- would read as broken. pub(crate) fn toggle_subtitles(&mut self, cx: &mut Context) { self.subs_on = !self.subs_on; - // Named with its film here too: a notice saying "SUBTITLES ON — eng" - // over a timeline holding two films' eng tracks names neither. - let label = self - .session - .as_ref() - .and_then(|session| sub_pick_name(session.subtitles(), self.sub_track)) - .unwrap_or_else(|| "nothing imported".to_string()); - self.notify_user( - match self.subs_on { - true => format!("SUBTITLES ON — {label}"), - false => format!("SUBTITLES OFF — {label} is still on the timeline"), - } - .into(), - ); + // Lane facts and not the picked row: what draws is what is *placed* + // ([`Player::subtitle_overlay`]), so naming the palette selection here + // named a track the toggle never touched. + let placed = self.placed_captions(); + self.notify_user(subtitle_toggle_notice(self.subs_on, placed).into()); cx.notify(); } - /// The subtitle track the overlay and the strip are showing: the one a - /// library row picked, or the first there is. `None` with no timeline and - /// for an index left over from one that is gone. - pub(crate) fn subtitle_track(&self) -> Option<&engine::subtitle::SubtitleTrack> { - self.session.as_ref()?.subtitles().get(self.sub_track) + /// How many captions the subtitle lanes hold, all lanes together: what the + /// toggle and the toolbar's own label are about, now that the picture reads + /// the lanes rather than a pick ([`Player::subtitle_overlay`]). Zero with no + /// timeline, and zero for a palette full of tracks nobody placed -- both + /// show nothing, so both read "No subs". + pub(crate) fn placed_captions(&self) -> usize { + let Some(session) = self.session.as_ref() else { + return 0; + }; + session + .subtitle_lanes() + .into_iter() + .map(|lane| session.sub_lane(lane).len()) + .sum() } /// Whether the editor can be asked for `action` right now, and why not when diff --git a/crates/app/src/player/export.rs b/crates/app/src/player/export.rs index 9666185..34a600f 100644 --- a/crates/app/src/player/export.rs +++ b/crates/app/src/player/export.rs @@ -517,8 +517,8 @@ impl Player { /// Worked out from the cues each time rather than kept as a pick, which is /// what makes it impossible to desync: a row added or taken off shifts every /// index after it, and a stored list would then name tracks nobody chose. - /// `Player::sub_track` stays what it always was -- which track the *overlay* - /// draws -- and has no say here. + /// `Player::sub_track` stays what it always was -- which palette row the + /// list *marks* -- and has no say here. /// /// The honest input and not the final answer: the engine filters it again /// per track (a track that could not be read, a picture one) and says so in diff --git a/crates/app/src/subs.rs b/crates/app/src/subs.rs index 7788964..dfdc4d4 100644 --- a/crates/app/src/subs.rs +++ b/crates/app/src/subs.rs @@ -257,6 +257,24 @@ pub(crate) fn subtitle_tail(session: &mut PlaybackSession, subs: Subs) -> Option } } +/// What the subtitles toggle says it just did ([`Player::toggle_subtitles`]), +/// worded off the lanes: `placed` is every caption on every subtitle lane +/// ([`Player::placed_captions`]), because that -- and never the palette row the +/// list marks -- is what the toggle covers and uncovers. +/// +/// Nothing placed is its own sentence: "SUBTITLES SHOWN — 0 caption(s)" over an +/// unchanged picture reads as a broken toggle, so it says the move that would +/// put words there instead. +pub(crate) fn subtitle_toggle_notice(on: bool, placed: usize) -> String { + match (on, placed) { + (true, 0) => { + "SUBTITLES SHOWN — nothing placed yet: drag a track onto a subtitle track".to_string() + } + (true, n) => format!("SUBTITLES SHOWN — {n} caption(s) on the timeline"), + (false, n) => format!("SUBTITLES HIDDEN — {n} caption(s) still placed"), + } +} + /// The push both deliberate add-subtitles doors end on -- `+ S` and its key /// ([`Player::add_subtitles`]) and a dropped or argv'd subtitle file /// ([`Player::take_subtitles`]) -- so the two cannot come to word the same file @@ -423,7 +441,8 @@ pub(crate) struct SubGroup { pub(crate) struct SubRow { /// Which track of the session's list this row is: the *flat* index into the /// add-order Vec `PlaybackSession::subtitles` hands back, which is what a - /// click sets `sub_track` to and what a save writes into the `.edith`. + /// click sets `sub_track` to and what a caption placed on a subtitle lane + /// names, so it is what a save writes into the `.edith` for that caption. /// Grouping moves rows around on screen and never touches this number. pub(crate) track: usize, /// Which of *this file's* tracks it is, counted from 1 -- the numbering diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index de2b254..692a993 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -882,11 +882,33 @@ fn the_picked_subtitle_is_named_with_the_film_it_came_out_of() { // A standalone `.srt` is its own file and its label already says so: // one track, so no number, and no stem after it saying it again. assert_eq!(name(4), "late.srt"); - // The silence `subtitle_track` gives at the same moment. + // The silence a row left over from a timeline that is gone gets. assert_eq!(sub_pick_name(&tracks, 5), None); assert_eq!(sub_pick_name(&[], 0), None); } +/// What the toggle covers is what is *placed*, so what it says is a lane fact: +/// naming the palette row the list happens to mark named a track the stroke +/// never touched ("SUBTITLES OFF — one.srt is still on the timeline" for a +/// one.srt nobody dragged anywhere). +#[test] +fn the_subtitles_toggle_says_what_is_placed_and_never_the_picked_row() { + for on in [true, false] { + let text = subtitle_toggle_notice(on, 2); + assert!(text.contains('2'), "{text} counts the captions placed"); + assert!( + !text.contains("track(s)") && !text.contains(" — a"), + "{text} names no palette row" + ); + } + // Off leaves them on the lanes; that is the half a person needs told. + assert!(subtitle_toggle_notice(false, 2).contains("still placed")); + // An empty timeline says the move instead of a count that reads as broken. + let none = subtitle_toggle_notice(true, 0); + assert!(!none.contains('0'), "{none} counts nothing at nothing"); + assert!(none.contains("drag"), "{none} says the next move"); +} + /// The door this editor answers "don't make me import the film again" with, /// and it is in the panel where the tracks it adds are listed: the Text /// tab's own button reads a file's subtitle tracks onto the open timeline diff --git a/crates/app/src/tests/mod.rs b/crates/app/src/tests/mod.rs index 85be6a3..a5d942f 100644 --- a/crates/app/src/tests/mod.rs +++ b/crates/app/src/tests/mod.rs @@ -58,7 +58,7 @@ use super::{ SUB_STEM_SHARE, SUB_TEXT, clip_middle, cue_box, sub_bottom, carries_subtitles, cues_at, file_tint, is_subtitle, lang_human, row_text_w, sub_headers_fit, Subs, subtitle_detail, subtitle_notice, subtitle_tail, - sub_pick_name, subtitle_rows, walk_subtitles, + sub_pick_name, subtitle_rows, subtitle_toggle_notice, walk_subtitles, }; use engine::PlaybackSession; diff --git a/crates/app/src/ui/toolbar.rs b/crates/app/src/ui/toolbar.rs index 7273ca5..93a5a34 100644 --- a/crates/app/src/ui/toolbar.rs +++ b/crates/app/src/ui/toolbar.rs @@ -341,7 +341,7 @@ impl Player { SNAP_SLOT_W, BG_RAISED(), None, - match (self.subtitle_track().is_some(), self.subs_on) { + match (self.placed_captions() > 0, self.subs_on) { (false, _) => "No subs", (true, true) => "Subs on", (true, false) => "Subs off",