forge
Explore
Log in

Don't you dare go Hollow

Subtitle cue font and size are the user's to choose

Browse files at this commit

dd4bbea11c6abf972d585481bd937cbff890854bAhmet Kaan GümüşParent: 803b8e6
  • feat
    • subtitle cue font and size are the user's to choose
Show full message
✨ feat(app): subtitle cue font and size are the user's to choose

A subtitle-style file beside the theme holds a family and a size
(10-28, default 14); the cue plate reads them live and the line height
scales on the stock ratio. New card lists every system family plus the
platform default, opened from the inspector's Font control or y. A file
the format could not have written falls back whole to the defaults.
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
@@ -510,6 +510,27 @@ struct Player {
510 /// or its switch. The card's own focus, since nothing in it takes gpui's510 /// or its switch. The card's own focus, since nothing in it takes gpui's
511 /// (ledger:182).511 /// (ledger:182).
512 mix_field: usize,512 mix_field: usize,
513+ /// The cue plate's own size, in force this session and kept in
514+ /// `~/.config/edith/subtitle-style` beside the keybindings -- an
515+ /// app-global preference like the theme, since export never burns
516+ /// subtitles into the picture. [`SUB_TEXT`] is the default it opens at,
517+ /// never the value read at paint; [`sub_line_h`](Player::sub_line_h) is
518+ /// what preview.rs reads for the line height, derived from this.
519+ sub_text: f32,
520+ /// Which family the cue plate draws in, or the platform default with
521+ /// nothing picked -- `None` calls no [`gpui::Styled::font_family`] at
522+ /// all, which is what leaves the window's own choice in force.
523+ sub_family: Option<String>,
524+ /// The subtitle style card is up.
525+ subtitle_style_open: bool,
526+ /// Which of its rows the arrow keys move: 0 is the size stepper, every
527+ /// row after it a family in [`Self::subtitle_fonts`]. The card's own
528+ /// focus, since nothing in it takes gpui's (ledger:182).
529+ subtitle_style_field: usize,
530+ /// Every family the platform can draw, asked for once when the card
531+ /// opens and kept for as long as it is up: [`gpui::TextSystem::all_font_names`]
532+ /// walks the whole font registry, which is not a repaint's business.
533+ subtitle_fonts: Vec<String>,
513 /// The silence card is up on this clip -- the lane it is on and its index534 /// The silence card is up on this clip -- the lane it is on and its index
514 /// there, exactly as the speed card's handle is.535 /// there, exactly as the speed card's handle is.
515 silence_open: Option<(Lane, usize)>,536 silence_open: Option<(Lane, usize)>,
@@ -628,6 +649,9 @@ fn main() {
628 // itself. Silent on a missing or unreadable file -- the default is a whole649 // itself. Silent on a missing or unreadable file -- the default is a whole
629 // answer, and nothing of the user's is lost by it.650 // answer, and nothing of the user's is lost by it.
630 ui::theme::load();651 ui::theme::load();
652+ // The subtitle style the last session picked, same silence on a missing
653+ // or unreadable file.
654+ let (sub_family, sub_text) = load_subtitle_style();
631 // Nothing named on the command line is read here. The first file makes the655 // Nothing named on the command line is read here. The first file makes the
632 // timeline -- a `.edith` restores a whole one, anything else *is* one --656 // timeline -- a `.edith` restores a whole one, anything else *is* one --
633 // and the rest are imports like any other: rows in the library, dragged657 // and the rest are imports like any other: rows in the library, dragged
@@ -778,6 +802,11 @@ fn main() {
778 pending_speed: None,802 pending_speed: None,
779 mix_open: false,803 mix_open: false,
780 mix_field: 0,804 mix_field: 0,
805+ sub_text,
806+ sub_family,
807+ subtitle_style_open: false,
808+ subtitle_style_field: 0,
809+ subtitle_fonts: Vec::new(),
781 silence_open: None,810 silence_open: None,
782 // The conservative defaults the engine documents: a first811 // The conservative defaults the engine documents: a first
783 // scan that leaves a little too much is one nobody undoes.812 // 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
@@ -658,6 +658,57 @@ impl Player {
658 cx.notify();658 cx.notify();
659 }659 }
660 660
661+ /// Opens the subtitle style card: the platform's font list, asked for
662+ /// once and kept while the card is up, and the size stepper beside it.
663+ /// Nothing here is a clip's or even the project's -- it never reaches the
664+ /// export, which never burns a cue into the picture -- so like the mix
665+ /// card it opens with no timeline required and nothing to refuse.
666+ pub(crate) fn open_subtitle_style(&mut self, cx: &mut Context<Self>) {
667+ self.subtitle_fonts = cx.text_system().all_font_names();
668+ self.subtitle_style_open = true;
669+ self.subtitle_style_field = 0;
670+ // One card at a time, the rule the other five follow.
671+ self.keys_open = false;
672+ self.export_open = false;
673+ self.eq_open = None;
674+ self.color_open = None;
675+ self.speed_open = None;
676+ self.mix_open = false;
677+ self.close_silence();
678+ self.context_menu = None;
679+ cx.notify();
680+ }
681+
682+ /// Picks a family outright -- a click on a row, the card's rule for a
683+ /// list rather than a stepper. `None` is the top row, the platform's own
684+ /// choice, which is what a family nobody can spell as a fallback would
685+ /// leave silently wrong instead.
686+ pub(crate) fn set_sub_family(&mut self, family: Option<String>, cx: &mut Context<Self>) {
687+ self.sub_family = family;
688+ self.keep_subtitle_style(cx);
689+ }
690+
691+ /// One [`SUB_SIZE_STEP`] per keystroke or stepper press, clamped to
692+ /// [`SUB_SIZE_RANGE`].
693+ pub(crate) fn nudge_sub_size(&mut self, steps: i32, cx: &mut Context<Self>) {
694+ self.sub_text = (self.sub_text + steps as f32 * SUB_SIZE_STEP)
695+ .clamp(SUB_SIZE_RANGE.0, SUB_SIZE_RANGE.1);
696+ self.keep_subtitle_style(cx);
697+ }
698+
699+ /// Writes the style to disk and repaints: every change to either field
700+ /// goes through here, so the file on disk and the plate on screen never
701+ /// disagree about which session's edit is in force.
702+ fn keep_subtitle_style(&mut self, cx: &mut Context<Self>) {
703+ if let Err(e) = save_subtitle_style(self.sub_family.as_deref(), self.sub_text) {
704+ let path = subtitle_style_path();
705+ self.notify_user(
706+ format!("SUBTITLE STYLE COULD NOT BE KEPT — {} — {e}", path.display()).into(),
707+ );
708+ }
709+ cx.notify();
710+ }
711+
661 /// Closes it and drops the preview with it: marks left on the lane after712 /// Closes it and drops the preview with it: marks left on the lane after
662 /// the card is gone would name frames the next edit has already moved.713 /// the card is gone would name frames the next edit has already moved.
663 pub(crate) fn close_silence(&mut self) {714 pub(crate) fn close_silence(&mut self) {
@@ -1012,6 +1063,7 @@ impl Player {
1012 || self.speed_open.is_some()1063 || self.speed_open.is_some()
1013 || self.silence_open.is_some()1064 || self.silence_open.is_some()
1014 || self.mix_open1065 || self.mix_open
1066+ || self.subtitle_style_open
1015 || self.exporting().is_some()1067 || self.exporting().is_some()
1016 }1068 }
1017 1069
@@ -1042,6 +1094,7 @@ impl Player {
1042 self.close_silence();1094 self.close_silence();
1043 }1095 }
1044 self.mix_open = false;1096 self.mix_open = false;
1097+ self.subtitle_style_open = false;
1045 }1098 }
1046 1099
1047 /// Opens the equalizer on the selected clip. Audio only, and it says so1100 /// 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
@@ -367,6 +368,16 @@ impl Player {
367 "a fader per track and the limiter over the sum of them",368 "a fader per track and the limiter over the sum of them",
368 ActionId::Mix,369 ActionId::Mix,
369 cx.listener(|this, _: &ClickEvent, _, cx| this.open_mix(None, cx)),370 cx.listener(|this, _: &ClickEvent, _, cx| this.open_mix(None, cx)),
371+ ))
372+ .child(self.action_control(
373+ "inspect-subtitle-style",
374+ 0.,
375+ BG_RAISED(),
376+ None,
377+ "Font",
378+ "the cue plate's own font and size",
379+ ActionId::SubtitleStyle,
380+ cx.listener(|this, _: &ClickEvent, _, cx| this.open_subtitle_style(cx)),
370 )),381 )),
371 )382 )
372 }383 }
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 }