forge
Explore
Log in

Don't you dare go Hollow

The subtitle cue dresses to the user's taste

Browse files at this commit

0bee605205e8c9a32a36f8830c90e81c528e632bAhmet Kaan GümüşParent: 79d189bdd4bbea
  • feat
    • the subtitle cue dresses to the user's taste
Show full message
✨ feat(app): the subtitle cue dresses to the user's taste
crates/app/src/keymap.rsmodified+14 -1
@@ -146,6 +146,9 @@ actions! {
146 /// own picture or a library preview's, since both write through the one146 /// own picture or a library preview's, since both write through the one
147 /// `self.image` the atlas already holds.147 /// `self.image` the atlas already holds.
148 Screenshot,148 Screenshot,
149+ /// The cue plate's font and size -- a person's own preference, kept
150+ /// beside the theme and not the project, and opened the same way.
151+ SubtitleStyle,
149 }152 }
150 153
151 impl ActionId {154 impl ActionId {
@@ -208,6 +211,7 @@ impl ActionId {
208 ActionId::CancelExport => "Cancel export",211 ActionId::CancelExport => "Cancel export",
209 ActionId::ShowActions => "All actions and their keys…",212 ActionId::ShowActions => "All actions and their keys…",
210 ActionId::Screenshot => "Save the frame on screen as a PNG",213 ActionId::Screenshot => "Save the frame on screen as a PNG",
214+ ActionId::SubtitleStyle => "Subtitle style: font and size…",
211 }215 }
212 }216 }
213 217
@@ -268,6 +272,7 @@ impl ActionId {
268 ActionId::CancelExport => "cancel-export",272 ActionId::CancelExport => "cancel-export",
269 ActionId::ShowActions => "show-actions",273 ActionId::ShowActions => "show-actions",
270 ActionId::Screenshot => "screenshot",274 ActionId::Screenshot => "screenshot",
275+ ActionId::SubtitleStyle => "subtitle-style",
271 }276 }
272 }277 }
273 278
@@ -329,6 +334,9 @@ impl ActionId {
329 // ...and what the whole window is painted in: it edits nothing at334 // ...and what the whole window is painted in: it edits nothing at
330 // all, it is what one is looking *with*.335 // all, it is what one is looking *with*.
331 | ActionId::Theme336 | ActionId::Theme
337+ // ...and what the cue plate is drawn in: a person's own reading
338+ // preference, same as the theme beside it.
339+ | ActionId::SubtitleStyle
332 // ...and whether that window fills the screen: a way of looking,340 // ...and whether that window fills the screen: a way of looking,
333 // same as the zoom and the theme beside it.341 // same as the zoom and the theme beside it.
334 | ActionId::Fullscreen => Category::View,342 | ActionId::Fullscreen => Category::View,
@@ -944,6 +952,10 @@ impl Keymap {
944 // "w" is free entirely, bare and ctrl both -- nothing else in952 // "w" is free entirely, bare and ctrl both -- nothing else in
945 // this table answers to it.953 // this table answers to it.
946 b(ActionId::Screenshot, "w", false),954 b(ActionId::Screenshot, "w", false),
955+ // Bare "y" is free entirely, and unshifted: a preference
956+ // opened as often as the theme, not a switch thrown once a
957+ // session.
958+ b(ActionId::SubtitleStyle, "y", false),
947 ],959 ],
948 }960 }
949 }961 }
@@ -1207,9 +1219,10 @@ mod tests {
1207 #[test]1219 #[test]
1208 fn every_default_stroke_reaches_its_action() {1220 fn every_default_stroke_reaches_its_action() {
1209 let k = Keymap::defaults();1221 let k = Keymap::defaults();
1210- assert_eq!(k.entries().len(), 55);1222+ assert_eq!(k.entries().len(), 56);
1211 assert_eq!(k.lookup("f11", false), Some(ActionId::Fullscreen));1223 assert_eq!(k.lookup("f11", false), Some(ActionId::Fullscreen));
1212 assert_eq!(k.lookup("w", false), Some(ActionId::Screenshot));1224 assert_eq!(k.lookup("w", false), Some(ActionId::Screenshot));
1225+ assert_eq!(k.lookup("y", false), Some(ActionId::SubtitleStyle));
1213 assert_eq!(k.lookup("p", true), Some(ActionId::ToggleProxies));1226 assert_eq!(k.lookup("p", true), Some(ActionId::ToggleProxies));
1214 assert_eq!(k.lookup("o", true), Some(ActionId::ToggleAutoProxies));1227 assert_eq!(k.lookup("o", true), Some(ActionId::ToggleAutoProxies));
1215 assert_eq!(k.lookup("f1", false), Some(ActionId::ShowActions));1228 assert_eq!(k.lookup("f1", false), Some(ActionId::ShowActions));
crates/app/src/main.rsmodified+29 -0
@@ -519,6 +519,27 @@ struct Player {
519 /// or its switch. The card's own focus, since nothing in it takes gpui's519 /// or its switch. The card's own focus, since nothing in it takes gpui's
520 /// (ledger:182).520 /// (ledger:182).
521 mix_field: usize,521 mix_field: usize,
522+ /// The cue plate's own size, in force this session and kept in
523+ /// `~/.config/edith/subtitle-style` beside the keybindings -- an
524+ /// app-global preference like the theme, since export never burns
525+ /// subtitles into the picture. [`SUB_TEXT`] is the default it opens at,
526+ /// never the value read at paint; [`sub_line_h`](Player::sub_line_h) is
527+ /// what preview.rs reads for the line height, derived from this.
528+ sub_text: f32,
529+ /// Which family the cue plate draws in, or the platform default with
530+ /// nothing picked -- `None` calls no [`gpui::Styled::font_family`] at
531+ /// all, which is what leaves the window's own choice in force.
532+ sub_family: Option<String>,
533+ /// The subtitle style card is up.
534+ subtitle_style_open: bool,
535+ /// Which of its rows the arrow keys move: 0 is the size stepper, every
536+ /// row after it a family in [`Self::subtitle_fonts`]. The card's own
537+ /// focus, since nothing in it takes gpui's (ledger:182).
538+ subtitle_style_field: usize,
539+ /// Every family the platform can draw, asked for once when the card
540+ /// opens and kept for as long as it is up: [`gpui::TextSystem::all_font_names`]
541+ /// walks the whole font registry, which is not a repaint's business.
542+ subtitle_fonts: Vec<String>,
522 /// The silence card is up on this clip -- the lane it is on and its index543 /// The silence card is up on this clip -- the lane it is on and its index
523 /// there, exactly as the speed card's handle is.544 /// there, exactly as the speed card's handle is.
524 silence_open: Option<(Lane, usize)>,545 silence_open: Option<(Lane, usize)>,
@@ -637,6 +658,9 @@ fn main() {
637 // itself. Silent on a missing or unreadable file -- the default is a whole658 // itself. Silent on a missing or unreadable file -- the default is a whole
638 // answer, and nothing of the user's is lost by it.659 // answer, and nothing of the user's is lost by it.
639 ui::theme::load();660 ui::theme::load();
661+ // The subtitle style the last session picked, same silence on a missing
662+ // or unreadable file.
663+ let (sub_family, sub_text) = load_subtitle_style();
640 // Nothing named on the command line is read here. The first file makes the664 // Nothing named on the command line is read here. The first file makes the
641 // timeline -- a `.edith` restores a whole one, anything else *is* one --665 // timeline -- a `.edith` restores a whole one, anything else *is* one --
642 // and the rest are imports like any other: rows in the library, dragged666 // and the rest are imports like any other: rows in the library, dragged
@@ -788,6 +812,11 @@ fn main() {
788 pending_speed: None,812 pending_speed: None,
789 mix_open: false,813 mix_open: false,
790 mix_field: 0,814 mix_field: 0,
815+ sub_text,
816+ sub_family,
817+ subtitle_style_open: false,
818+ subtitle_style_field: 0,
819+ subtitle_fonts: Vec::new(),
791 silence_open: None,820 silence_open: None,
792 // The conservative defaults the engine documents: a first821 // The conservative defaults the engine documents: a first
793 // scan that leaves a little too much is one nobody undoes.822 // scan that leaves a little too much is one nobody undoes.
crates/app/src/oracle.rsmodified+3 -1
@@ -100,7 +100,9 @@ pub(crate) fn enable(action: ActionId, ctx: Ctx) -> Enable {
100 // reading one, which is the only state that dims the list above.100 // reading one, which is the only state that dims the list above.
101 // ...and whether that window fills the screen: also always there, also101 // ...and whether that window fills the screen: also always there, also
102 // touching no timeline, live through an export the same way.102 // touching no timeline, live through an export the same way.
103- if action == ActionId::Theme || action == ActionId::Fullscreen {103+ // ...and the cue plate's own font and size: a reading preference like the
104+ // theme, never burned into an export, live the same way.
105+ if action == ActionId::Theme || action == ActionId::Fullscreen || action == ActionId::SubtitleStyle {
104 return Enable::Yes;106 return Enable::Yes;
105 }107 }
106 if action == ActionId::ShowActions {108 if action == ActionId::ShowActions {
crates/app/src/player/actions.rsmodified+1 -0
@@ -89,6 +89,7 @@ impl Player {
89 ActionId::Speed => self.open_speed(cx),89 ActionId::Speed => self.open_speed(cx),
90 ActionId::Silence => self.open_silence(cx),90 ActionId::Silence => self.open_silence(cx),
91 ActionId::Mix => self.open_mix(None, cx),91 ActionId::Mix => self.open_mix(None, cx),
92+ ActionId::SubtitleStyle => self.open_subtitle_style(cx),
92 ActionId::ToggleSnap => self.toggle_snap(cx),93 ActionId::ToggleSnap => self.toggle_snap(cx),
93 ActionId::ToggleSubtitles => self.toggle_subtitles(cx),94 ActionId::ToggleSubtitles => self.toggle_subtitles(cx),
94 ActionId::ToggleProxies => self.toggle_proxies(cx),95 ActionId::ToggleProxies => self.toggle_proxies(cx),
crates/app/src/player/cards.rsmodified+53 -0
@@ -691,6 +691,57 @@ impl Player {
691 cx.notify();691 cx.notify();
692 }692 }
693 693
694+ /// Opens the subtitle style card: the platform's font list, asked for
695+ /// once and kept while the card is up, and the size stepper beside it.
696+ /// Nothing here is a clip's or even the project's -- it never reaches the
697+ /// export, which never burns a cue into the picture -- so like the mix
698+ /// card it opens with no timeline required and nothing to refuse.
699+ pub(crate) fn open_subtitle_style(&mut self, cx: &mut Context<Self>) {
700+ self.subtitle_fonts = cx.text_system().all_font_names();
701+ self.subtitle_style_open = true;
702+ self.subtitle_style_field = 0;
703+ // One card at a time, the rule the other five follow.
704+ self.keys_open = false;
705+ self.export_open = false;
706+ self.eq_open = None;
707+ self.color_open = None;
708+ self.speed_open = None;
709+ self.mix_open = false;
710+ self.close_silence();
711+ self.context_menu = None;
712+ cx.notify();
713+ }
714+
715+ /// Picks a family outright -- a click on a row, the card's rule for a
716+ /// list rather than a stepper. `None` is the top row, the platform's own
717+ /// choice, which is what a family nobody can spell as a fallback would
718+ /// leave silently wrong instead.
719+ pub(crate) fn set_sub_family(&mut self, family: Option<String>, cx: &mut Context<Self>) {
720+ self.sub_family = family;
721+ self.keep_subtitle_style(cx);
722+ }
723+
724+ /// One [`SUB_SIZE_STEP`] per keystroke or stepper press, clamped to
725+ /// [`SUB_SIZE_RANGE`].
726+ pub(crate) fn nudge_sub_size(&mut self, steps: i32, cx: &mut Context<Self>) {
727+ self.sub_text = (self.sub_text + steps as f32 * SUB_SIZE_STEP)
728+ .clamp(SUB_SIZE_RANGE.0, SUB_SIZE_RANGE.1);
729+ self.keep_subtitle_style(cx);
730+ }
731+
732+ /// Writes the style to disk and repaints: every change to either field
733+ /// goes through here, so the file on disk and the plate on screen never
734+ /// disagree about which session's edit is in force.
735+ fn keep_subtitle_style(&mut self, cx: &mut Context<Self>) {
736+ if let Err(e) = save_subtitle_style(self.sub_family.as_deref(), self.sub_text) {
737+ let path = subtitle_style_path();
738+ self.notify_user(
739+ format!("SUBTITLE STYLE COULD NOT BE KEPT — {} — {e}", path.display()).into(),
740+ );
741+ }
742+ cx.notify();
743+ }
744+
694 /// Closes it and drops the preview with it: marks left on the lane after745 /// Closes it and drops the preview with it: marks left on the lane after
695 /// the card is gone would name frames the next edit has already moved.746 /// the card is gone would name frames the next edit has already moved.
696 pub(crate) fn close_silence(&mut self) {747 pub(crate) fn close_silence(&mut self) {
@@ -1045,6 +1096,7 @@ impl Player {
1045 || self.speed_open.is_some()1096 || self.speed_open.is_some()
1046 || self.silence_open.is_some()1097 || self.silence_open.is_some()
1047 || self.mix_open1098 || self.mix_open
1099+ || self.subtitle_style_open
1048 || self.exporting().is_some()1100 || self.exporting().is_some()
1049 }1101 }
1050 1102
@@ -1075,6 +1127,7 @@ impl Player {
1075 self.close_silence();1127 self.close_silence();
1076 }1128 }
1077 self.mix_open = false;1129 self.mix_open = false;
1130+ self.subtitle_style_open = false;
1078 }1131 }
1079 1132
1080 /// Opens the equalizer on the selected clip. Audio only, and it says so1133 /// Opens the equalizer on the selected clip. Audio only, and it says so
crates/app/src/render.rsmodified+30 -0
@@ -434,6 +434,36 @@ impl Render for Player {
434 cx.notify();434 cx.notify();
435 return;435 return;
436 }436 }
437+ // The subtitle style card, the same way again: row 0 is the
438+ // size stepper (←→ moves it, held or pressed, the mix card's
439+ // rule) and every row after it a family in
440+ // `subtitle_fonts` -- ↑↓ walk the whole list and `enter`
441+ // picks the one the arrows are on, since a hand with no
442+ // mouse still has to be able to leave the platform default.
443+ if this.subtitle_style_open {
444+ // Row 0 is the size stepper, row 1 the platform default,
445+ // and every row after it a family in `subtitle_fonts`.
446+ let rows = 2 + this.subtitle_fonts.len();
447+ if key == ESCAPE {
448+ this.subtitle_style_open = false;
449+ } else if key == "down" {
450+ this.subtitle_style_field = (this.subtitle_style_field + 1) % rows;
451+ } else if key == "up" {
452+ this.subtitle_style_field =
453+ (this.subtitle_style_field + rows - 1) % rows;
454+ } else if key == "right" {
455+ this.nudge_sub_size(1, cx);
456+ } else if key == "left" {
457+ this.nudge_sub_size(-1, cx);
458+ } else if key == "enter" && this.subtitle_style_field == 1 {
459+ this.set_sub_family(None, cx);
460+ } else if key == "enter" && this.subtitle_style_field > 1 {
461+ let family = this.subtitle_fonts[this.subtitle_style_field - 2].clone();
462+ this.set_sub_family(Some(family), cx);
463+ }
464+ cx.notify();
465+ return;
466+ }
437 // A clip menu names an index, and every edit below moves467 // A clip menu names an index, and every edit below moves
438 // indices -- so a stroke closes it before it acts. Escape means468 // indices -- so a stroke closes it before it acts. Escape means
439 // that and nothing else, which is the `esc` the keys menu469 // that and nothing else, which is the `esc` the keys menu
crates/app/src/subs.rsmodified+51 -0
@@ -2,6 +2,57 @@
2 2
3 use crate::*;3 use crate::*;
4 4
5+/// One press of the size stepper, and how far it may be pushed: below
6+/// [`SUB_SIZE_RANGE`].0 a plate is unreadable, above its top it eats the
7+/// smallest picture the layout floor promises ([`the_subtitle_plate_and_lanes_fit_the_smallest_window`]).
8+pub(crate) const SUB_SIZE_STEP: f32 = 1.;
9+pub(crate) const SUB_SIZE_RANGE: (f32, f32) = (10., 28.);
10+
11+/// The cue's line height at `size`, on the ratio the defaults draw at
12+/// ([`SUB_LINE_H`] over [`SUB_TEXT`]): a bigger cue wants a taller line, not
13+/// just bigger letters on the old one.
14+pub(crate) fn sub_line_h_for(size: f32) -> f32 {
15+ size * SUB_LINE_H / SUB_TEXT
16+}
17+
18+/// Where the subtitle style survives: beside the keybindings and the theme,
19+/// same corner-cut persistence -- a torn write costs the style and nothing
20+/// else, and [`load_subtitle_style`] falls back to the defaults on one.
21+pub(crate) fn subtitle_style_path() -> PathBuf {
22+ crate::keymap::Keymap::config_path().with_file_name("subtitle-style")
23+}
24+
25+/// Two lines: the family (empty for the system default) and the size.
26+/// Anything unreadable, missing or out of range leaves the defaults in
27+/// force -- a subtitle style file is not the user's work, so a bad one is
28+/// worth no message at startup, exactly as [`ui::theme::load`].
29+pub(crate) fn load_subtitle_style() -> (Option<String>, f32) {
30+ let Ok(text) = std::fs::read_to_string(subtitle_style_path()) else {
31+ return (None, SUB_TEXT);
32+ };
33+ let mut lines = text.lines();
34+ let family = lines.next().filter(|l| !l.is_empty()).map(str::to_string);
35+ // A size this format could not have written means the file is not this
36+ // format at all -- the family line is then noise too, not a font.
37+ let Some(size) = lines
38+ .next()
39+ .and_then(|l| l.trim().parse::<f32>().ok())
40+ .filter(|s| (SUB_SIZE_RANGE.0..=SUB_SIZE_RANGE.1).contains(s))
41+ else {
42+ return (None, SUB_TEXT);
43+ };
44+ (family, size)
45+}
46+
47+/// Writes the style whole, the way [`ui::theme::save`] writes the palette.
48+pub(crate) fn save_subtitle_style(family: Option<&str>, size: f32) -> std::io::Result<()> {
49+ let path = subtitle_style_path();
50+ if let Some(dir) = path.parent() {
51+ std::fs::create_dir_all(dir)?;
52+ }
53+ std::fs::write(path, format!("{}\n{size}\n", family.unwrap_or("")))
54+}
55+
5 /// Whether a dropped or named path is a subtitle file rather than media: the56 /// Whether a dropped or named path is a subtitle file rather than media: the
6 /// formats `engine::subtitle` parses, lowercased, for [`engine::is_audio`]'s57 /// formats `engine::subtitle` parses, lowercased, for [`engine::is_audio`]'s
7 /// reason -- the import door has to know which of the engine's two doors a file58 /// reason -- the import door has to know which of the engine's two doors a file
crates/app/src/tests/editing.rsmodified+3 -1
@@ -890,7 +890,8 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() {
890 // edit list either.890 // edit list either.
891 let allowed = action == ActionId::CancelExport891 let allowed = action == ActionId::CancelExport
892 || action == ActionId::Theme892 || action == ActionId::Theme
893- || action == ActionId::Fullscreen;893+ || action == ActionId::Fullscreen
894+ || action == ActionId::SubtitleStyle;
894 assert_eq!(895 assert_eq!(
895 whole(action, busy).yes(),896 whole(action, busy).yes(),
896 allowed,897 allowed,
@@ -1206,6 +1207,7 @@ fn every_card_closes_without_the_keyboard() {
1206 "speed_card",1207 "speed_card",
1207 "mix_card",1208 "mix_card",
1208 "silence_card",1209 "silence_card",
1210+ "subtitle_style_card",
1209 ] {1211 ] {
1210 let src = fn_body(card);1212 let src = fn_body(card);
1211 assert!(1213 assert!(
crates/app/src/tests/layout.rsmodified+1 -1
@@ -175,7 +175,7 @@ fn an_inspector_section_occludes_no_timeline() {
175 // leave this rule reading a file the render is no longer in.175 // leave this rule reading a file the render is no longer in.
176 let render = source_from("impl Render for Player");176 let render = source_from("impl Render for Player");
177 for card in [177 for card in [
178- "eq_card", "color_card", "speed_card", "silence_card", "mix_card",178+ "eq_card", "color_card", "speed_card", "silence_card", "mix_card", "subtitle_style_card",
179 ] {179 ] {
180 assert!(180 assert!(
181 inspector.contains(&format!("self.{card}(")),181 inspector.contains(&format!("self.{card}(")),
crates/app/src/tests/media.rsmodified+65 -0
@@ -2,6 +2,9 @@
2 //! command line, the scans, the codecs offered, and the subtitles found.2 //! command line, the scans, the codecs offered, and the subtitles found.
3 3
4 use super::*;4 use super::*;
5+use crate::subs::{
6+ load_subtitle_style, save_subtitle_style, sub_line_h_for, subtitle_style_path, SUB_SIZE_RANGE,
7+};
5 use crate::ui::preview::{bgra_to_rgba, screenshot_path};8 use crate::ui::preview::{bgra_to_rgba, screenshot_path};
6 9
7 /// The import line's own state machine, driven the way a repaint drives10 /// The import line's own state machine, driven the way a repaint drives
@@ -901,6 +904,68 @@ fn the_subtitle_plate_and_lanes_fit_the_smallest_window() {
901 assert!(SUB_HEAD_H >= HIT_MIN);904 assert!(SUB_HEAD_H >= HIT_MIN);
902 }905 }
903 906
907+/// The subtitle style file, round-tripped through a scratch config directory
908+/// -- the same corner-cut persistence as the theme and the keybindings, kept
909+/// to the same test the load/save pair earns: a save followed by a load reads
910+/// back what was written, a file that never existed leaves the defaults in
911+/// force, and a file that exists but says nothing readable does too rather
912+/// than crashing a startup on someone else's edit of the file.
913+#[test]
914+fn the_subtitle_style_file_round_trips_or_falls_back_to_defaults() {
915+ let dir = std::env::temp_dir().join(format!(
916+ "edith-subtitle-style-test-{}-{}",
917+ std::process::id(),
918+ std::time::SystemTime::now()
919+ .duration_since(std::time::UNIX_EPOCH)
920+ .unwrap()
921+ .as_nanos()
922+ ));
923+ std::fs::create_dir_all(&dir).unwrap();
924+ // Scoped to this test alone: no other test reads XDG_CONFIG_HOME or the
925+ // subtitle-style file it names, so this narrow, restored mutation of the
926+ // process environment cannot race another test's own file.
927+ unsafe { std::env::set_var("XDG_CONFIG_HOME", &dir) };
928+
929+ // Nothing written yet: the defaults, not a crash on a missing file.
930+ assert_eq!(load_subtitle_style(), (None, SUB_TEXT));
931+
932+ // A save, read back whole: family and size both.
933+ save_subtitle_style(Some("Iosevka"), 22.).unwrap();
934+ assert_eq!(
935+ load_subtitle_style(),
936+ (Some("Iosevka".to_string()), 22.)
937+ );
938+
939+ // The platform default (`None`) round-trips too, and is not a family
940+ // called "".
941+ save_subtitle_style(None, 14.).unwrap();
942+ assert_eq!(load_subtitle_style(), (None, 14.));
943+
944+ // A file present but unreadable as this format -- a stray edit, or bytes
945+ // from a future version -- leaves the defaults in force rather than
946+ // failing the window that opens over it.
947+ std::fs::write(subtitle_style_path(), "not a number\n9999\n").unwrap();
948+ assert_eq!(load_subtitle_style(), (None, SUB_TEXT));
949+
950+ unsafe { std::env::remove_var("XDG_CONFIG_HOME") };
951+ std::fs::remove_dir_all(&dir).ok();
952+}
953+
954+/// The cue's line height scales with its size, on the same ratio the defaults
955+/// draw at -- a bigger plate wants more room per line, not letters growing
956+/// inside an unchanged one.
957+#[test]
958+fn the_cue_line_height_scales_with_its_size() {
959+ assert_eq!(sub_line_h_for(SUB_TEXT), SUB_LINE_H);
960+ // Twice the size is twice the line height, on the same ratio.
961+ assert_eq!(sub_line_h_for(SUB_TEXT * 2.), SUB_LINE_H * 2.);
962+ // Always at least the text itself, across the whole size range: a line
963+ // shorter than its own text would clip it.
964+ for size in [SUB_SIZE_RANGE.0, SUB_TEXT, SUB_SIZE_RANGE.1] {
965+ assert!(sub_line_h_for(size) >= size);
966+ }
967+}
968+
904 /// What the rows of both lists do with a name too long for the column: two969 /// What the rows of both lists do with a name too long for the column: two
905 /// episodes off one release differ in their last two characters, and a name970 /// episodes off one release differ in their last two characters, and a name
906 /// cut from the right is the same row twice.971 /// cut from the right is the same row twice.
crates/app/src/ui/cards.rsmodified+153 -0
@@ -1818,6 +1818,159 @@ impl Player {
1818 )1818 )
1819 }1819 }
1820 1820
1821+ /// The subtitle style card: the size stepper on top, the platform's own
1822+ /// font list scrolling under it -- a picker's rows and not a cycle, so a
1823+ /// hundred-odd families are each one click and not a hundred presses of
1824+ /// the same key. Nothing here is a clip's or the project's, the mix
1825+ /// card's shape for the same reason: app-global, kept in a file beside
1826+ /// the theme, and drawn straight off `self.sub_text` / `self.sub_family`
1827+ /// so a change is on the cue underneath before the card is closed.
1828+ pub(crate) fn subtitle_style_card(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> {
1829+ if !self.subtitle_style_open {
1830+ return None;
1831+ }
1832+ let size_row = div()
1833+ .id("subtitle-size-row")
1834+ .flex()
1835+ .flex_none()
1836+ .min_h(px(KEYS_ROW_H))
1837+ .items_center()
1838+ .justify_between()
1839+ .px(px(6.))
1840+ .rounded(px(3.))
1841+ .bg(rgb(match self.subtitle_style_field == 0 {
1842+ true => BG_SELECTED(),
1843+ false => BG_PANEL(),
1844+ }))
1845+ .child(div().text_color(rgb(FG_SECONDARY())).child("Size"))
1846+ .child(
1847+ div()
1848+ .flex()
1849+ .items_center()
1850+ .gap(px(4.))
1851+ .child(format!("{:.0}px", self.sub_text))
1852+ .children([-1, 1].map(|steps: i32| {
1853+ div()
1854+ .id(("subtitle-size-step", usize::from(steps > 0)))
1855+ .flex_none()
1856+ .w(px(HIT_MIN))
1857+ .h(px(KEYS_ROW_H))
1858+ .flex()
1859+ .items_center()
1860+ .justify_center()
1861+ .rounded(px(3.))
1862+ .bg(rgb(BG_PANEL()))
1863+ .cursor_pointer()
1864+ .hover(|s| s.bg(rgb(BG_HOVER())))
1865+ .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
1866+ this.subtitle_style_field = 0;
1867+ this.nudge_sub_size(steps, cx);
1868+ }))
1869+ .child(match steps > 0 {
1870+ true => "+",
1871+ false => "−",
1872+ })
1873+ })),
1874+ );
1875+ let default_row = div()
1876+ .id("subtitle-family-row-default")
1877+ .flex()
1878+ .flex_none()
1879+ .min_h(px(KEYS_ROW_H))
1880+ .items_center()
1881+ .px(px(6.))
1882+ .rounded(px(3.))
1883+ .bg(rgb(match self.subtitle_style_field == 1 {
1884+ true => BG_SELECTED(),
1885+ false => BG_PANEL(),
1886+ }))
1887+ .cursor_pointer()
1888+ .hover(|s| s.bg(rgb(BG_HOVER())))
1889+ .on_click(cx.listener(|this, _: &ClickEvent, _, cx| {
1890+ this.set_sub_family(None, cx);
1891+ }))
1892+ .child("System default");
1893+ let family_rows = self.subtitle_fonts.iter().enumerate().map(|(n, name)| {
1894+ div()
1895+ .id(("subtitle-family-row", n))
1896+ .flex()
1897+ .flex_none()
1898+ .min_h(px(KEYS_ROW_H))
1899+ .items_center()
1900+ .px(px(6.))
1901+ .rounded(px(3.))
1902+ .bg(rgb(
1903+ match (self.subtitle_style_field == n + 2, self.sub_family.as_deref() == Some(name.as_str())) {
1904+ (true, _) | (false, true) => BG_SELECTED(),
1905+ _ => BG_PANEL(),
1906+ },
1907+ ))
1908+ .cursor_pointer()
1909+ .hover(|s| s.bg(rgb(BG_HOVER())))
1910+ .on_click(cx.listener({
1911+ let name = name.clone();
1912+ move |this, _: &ClickEvent, _, cx| {
1913+ this.set_sub_family(Some(name.clone()), cx);
1914+ }
1915+ }))
1916+ .child(name.clone())
1917+ });
1918+ Some(
1919+ scrim()
1920+ .flex()
1921+ .justify_center()
1922+ .items_center()
1923+ .bg(rgba(SCRIM()))
1924+ .on_mouse_down(
1925+ MouseButton::Left,
1926+ cx.listener(|this, _: &MouseDownEvent, _, cx| {
1927+ this.close_card();
1928+ cx.notify();
1929+ cx.stop_propagation();
1930+ }),
1931+ )
1932+ .child(
1933+ div()
1934+ .w_full()
1935+ .max_w(px(COLOR_W))
1936+ .on_mouse_down(MouseButton::Left, swallow)
1937+ .max_h(px(360. - 24.))
1938+ .flex()
1939+ .flex_col()
1940+ .gap(px(6.))
1941+ .p(px(12.))
1942+ .rounded(px(6.))
1943+ .bg(rgb(BG_RAISED()))
1944+ .child(
1945+ div()
1946+ .flex_none()
1947+ .px(px(6.))
1948+ .child("Subtitle style — font and size of the cue plate"),
1949+ )
1950+ .child(
1951+ div()
1952+ .flex_none()
1953+ .px(px(6.))
1954+ .text_size(px(11.))
1955+ .text_color(rgb(FG_SECONDARY()))
1956+ .child(
1957+ "− and + move the size, or ↑↓ picks a row and ←→ moves it (held or pressed); a family row picks it outright — a click away or esc closes",
1958+ ),
1959+ )
1960+ .child(size_row)
1961+ .child(
1962+ div()
1963+ .id("subtitle-family-rows")
1964+ .flex()
1965+ .flex_col()
1966+ .overflow_y_scroll()
1967+ .child(default_row)
1968+ .children(family_rows),
1969+ ),
1970+ ),
1971+ )
1972+ }
1973+
1821 /// The silence card: what the scan is looking for, what it found, and the1974 /// The silence card: what the scan is looking for, what it found, and the
1822 /// two things that can be done about it.1975 /// two things that can be done about it.
1823 ///1976 ///
crates/app/src/ui/inspector.rsmodified+11 -0
@@ -84,6 +84,7 @@ impl Player {
84 .children(self.speed_card(cx))84 .children(self.speed_card(cx))
85 .children(self.silence_card(cx))85 .children(self.silence_card(cx))
86 .children(self.mix_card(cx))86 .children(self.mix_card(cx))
87+ .children(self.subtitle_style_card(cx))
87 }88 }
88 89
89 /// What is marked, and the settings that belong to *it*. A dump of every90 /// What is marked, and the settings that belong to *it*. A dump of every
@@ -371,6 +372,16 @@ impl Player {
371 "a fader per track and the limiter over the sum of them",372 "a fader per track and the limiter over the sum of them",
372 ActionId::Mix,373 ActionId::Mix,
373 cx.listener(|this, _: &ClickEvent, _, cx| this.open_mix(None, cx)),374 cx.listener(|this, _: &ClickEvent, _, cx| this.open_mix(None, cx)),
375+ ))
376+ .child(self.action_control(
377+ "inspect-subtitle-style",
378+ 0.,
379+ BG_RAISED(),
380+ None,
381+ "Font",
382+ "the cue plate's own font and size",
383+ ActionId::SubtitleStyle,
384+ cx.listener(|this, _: &ClickEvent, _, cx| this.open_subtitle_style(cx)),
374 )),385 )),
375 )386 )
376 }387 }
crates/app/src/ui/preview.rsmodified+7 -6
@@ -190,18 +190,19 @@ impl Player {
190 .px(px(6.))190 .px(px(6.))
191 .rounded(px(3.))191 .rounded(px(3.))
192 .bg(rgba(SUB_SHADE()))192 .bg(rgba(SUB_SHADE()))
193- .text_size(px(SUB_TEXT))193+ .text_size(px(self.sub_text))
194 .text_color(rgb(SUB_FG()))194 .text_color(rgb(SUB_FG()))
195 .text_align(TextAlign::Center)195 .text_align(TextAlign::Center)
196+ .when_some(self.sub_family.clone(), |el, fam| el.font_family(fam))
196 // A line of the cue is a line on screen: the break the197 // A line of the cue is a line on screen: the break the
197 // parser kept is not whitespace to be re-flowed. What a198 // parser kept is not whitespace to be re-flowed. What a
198 // *long* line does is wrap inside its own div, which is199 // *long* line does is wrap inside its own div, which is
199 // what the width cap above is for.200 // what the width cap above is for.
200- .children(201+ .children(cue.text.split('\n').map(|line| {
201- cue.text202+ div()
202- .split('\n')203+ .min_h(px(sub_line_h_for(self.sub_text)))
203- .map(|line| div().min_h(px(SUB_LINE_H)).child(line.to_string())),204+ .child(line.to_string())
204- )205+ }))
205 })),206 })),
206 )207 )
207 }208 }