forge
Explore
Log in

Don't you dare go Hollow

Options card before the export starts

Browse files at this commit

935d5f0509ef224ed7c04e9c960dfe0c5c59d468Ahmet Kaan GümüşParent: 24d9b93
  • feat
    • options card before the export starts
Show full message
✨ feat(export): options card before the export starts

Export no longer writes the moment it is asked: the action and the button
open a card first. Quality rows (Auto/Low/Medium/High/Custom Mbps) map to
engine ExportSettings and go out through export_to_with; the destination
comes from the desktop save dialog, and with no chooser installed the
default path beside the source still stands. Codec, container and moov
placement are stated rather than offered -- they are what edith can write.

One card at a time: opening either the keys overlay or this one closes the
other. Escape closes the card; a running export's escape is untouched.
crates/app/src/main.rsmodified+422 -31
@@ -8,6 +8,7 @@ use std::rc::Rc;
8 use std::sync::Arc;8 use std::sync::Arc;
9 use std::time::{Duration, Instant};9 use std::time::{Duration, Instant};
10 10
11+use engine::export::ExportSettings;
11 use engine::{Clip, ExportHandle, Frame, PlaybackSession};12 use engine::{Clip, ExportHandle, Frame, PlaybackSession};
12 use gpui::{13 use gpui::{
13 AnyElement, App, Application, Bounds, ClickEvent, Context, FocusHandle, KeyDownEvent,14 AnyElement, App, Application, Bounds, ClickEvent, Context, FocusHandle, KeyDownEvent,
@@ -120,6 +121,16 @@ struct Player {
120 /// pointer: a stroke or a click meant for a row must not also cut the121 /// pointer: a stroke or a click meant for a row must not also cut the
121 /// timeline.122 /// timeline.
122 keys_open: bool,123 keys_open: bool,
124+ /// The export options card is up: what the export action opens now, so
125+ /// nothing is written until the card's own button says so. One card at a
126+ /// time -- opening either closes the other, since both are the whole window
127+ /// and two stacked scrims say nothing about which one is listening.
128+ export_open: bool,
129+ /// Which quality row the card has picked, and the megabits typed against
130+ /// the custom one. Kept across closes, so a second export offers what the
131+ /// first one chose.
132+ quality: Quality,
133+ custom_mbps: u32,
123 /// The action whose row is waiting for a stroke. The next key that is134 /// The action whose row is waiting for a stroke. The next key that is
124 /// neither escape nor a lone modifier becomes the whole of what reaches it.135 /// neither escape nor a lone modifier becomes the whole of what reaches it.
125 rebinding: Option<ActionId>,136 rebinding: Option<ActionId>,
@@ -483,24 +494,82 @@ impl Player {
483 self.export.as_ref().filter(|_| !self.cancelling)494 self.export.as_ref().filter(|_| !self.cancelling)
484 }495 }
485 496
486- /// Writes the edit list out beside the source. Playback stops first: the497+ /// What the export action does now: opens the card, which is where the
487- /// exporter opens its own decoder -- and, on the hardware path, an encoder --498+ /// quality, the destination and the decision to write at all are. Nothing
488- /// so a running player would only compete with it for the GPU. A cancelled499+ /// is encoded until the button in it is pressed.
489- /// export still winding down holds this off for the frame it takes to500+ fn open_export(&mut self, cx: &mut Context<Self>) {
490- /// notice, which is what keeps its `remove_file` off the new output.
491- fn start_export(&mut self, cx: &mut Context<Self>) {
492 if self.export.is_some() {501 if self.export.is_some() {
493 return;502 return;
494 }503 }
495- // Nothing to write out, and a refusal rather than a silent button: the504+ // Nothing to write out, and a refusal rather than a card about it: the
496 // window is empty and the export path is not even chosen yet.505 // window is empty and the export path is not even chosen yet.
506+ if self.session.is_none() {
507+ self.notice = Some("NOTHING TO EXPORT — open a file first".into());
508+ cx.notify();
509+ return;
510+ }
511+ self.export_open = true;
512+ // One card at a time, and a waiting row must not outlive the card it
513+ // was waiting in.
514+ self.keys_open = false;
515+ self.rebinding = None;
516+ cx.notify();
517+ }
518+
519+ /// The card's Destination row: the desktop's save dialog, on a background
520+ /// thread like the import chooser -- the user may sit in it and the window
521+ /// behind must not freeze. No chooser at all leaves the default path, which
522+ /// is what the refusal says.
523+ fn pick_destination(&mut self, cx: &mut Context<Self>) {
524+ let default = self.export_path.clone();
525+ let picked = cx
526+ .background_executor()
527+ .spawn(async move { pick_save(&default) });
528+ cx.spawn(async move |this, cx| {
529+ let picked = picked.await;
530+ this.update(cx, |this, cx| {
531+ // The dialog outlives the card: an export started meanwhile
532+ // took the old path and its notice must name what it wrote.
533+ if this.export.is_some() {
534+ return;
535+ }
536+ match picked {
537+ Ok(Some(path)) => this.export_path = path,
538+ // Cancelled: the default stands, as it did before.
539+ Ok(None) => {}
540+ Err(text) => {
541+ eprintln!("{text}");
542+ this.notice = Some(text.into());
543+ }
544+ }
545+ cx.notify();
546+ })
547+ .ok();
548+ })
549+ .detach();
550+ }
551+
552+ /// Writes the edit list out, at the settings the card was left at. Playback
553+ /// stops first: the exporter opens its own decoder -- and, on the hardware
554+ /// path, an encoder -- so a running player would only compete with it for
555+ /// the GPU. A cancelled export still winding down holds this off for the
556+ /// frame it takes to notice, which is what keeps its `remove_file` off the
557+ /// new output.
558+ fn start_export(&mut self, cx: &mut Context<Self>) {
559+ if self.export.is_some() {
560+ return;
561+ }
562+ let settings = export_settings(self.quality, self.custom_mbps);
497 let Some(session) = &mut self.session else {563 let Some(session) = &mut self.session else {
498 self.notice = Some("NOTHING TO EXPORT — open a file first".into());564 self.notice = Some("NOTHING TO EXPORT — open a file first".into());
499 cx.notify();565 cx.notify();
500 return;566 return;
501 };567 };
502 session.pause();568 session.pause();
503- self.export = Some(session.export_to(&self.export_path));569+ self.export = Some(session.export_to_with(&self.export_path, &settings));
570+ // The card has been answered; the progress line takes the panel from
571+ // here, and it is the running export's escape that matters now.
572+ self.export_open = false;
504 cx.notify();573 cx.notify();
505 }574 }
506 575
@@ -632,9 +701,28 @@ impl Render for Player {
632 }701 }
633 return;702 return;
634 }703 }
704+ // The export card owns it the same way, and for the same
705+ // reason. Escape closes it -- nothing has been written yet, so
706+ // there is nothing here to cancel -- and a digit is the custom
707+ // bitrate being typed: the card has no text field (nothing in
708+ // it takes focus, ledger:182) so this listener is its input,
709+ // exactly as it is a waiting row's.
710+ if this.export_open {
711+ if key == ESCAPE {
712+ this.export_open = false;
713+ } else if let Ok(digit) = key.parse::<u32>() {
714+ this.custom_mbps = push_digit(this.custom_mbps, digit);
715+ this.quality = Quality::Custom;
716+ } else if key == "backspace" {
717+ this.custom_mbps /= 10;
718+ this.quality = Quality::Custom;
719+ }
720+ cx.notify();
721+ return;
722+ }
635 match action {723 match action {
636 Some(ActionId::Play) => this.toggle_or_restart(cx),724 Some(ActionId::Play) => this.toggle_or_restart(cx),
637- Some(ActionId::Export) => this.start_export(cx),725+ Some(ActionId::Export) => this.open_export(cx),
638 Some(ActionId::Save) => this.save_project(cx),726 Some(ActionId::Save) => this.save_project(cx),
639 Some(ActionId::Copy) => this.copy_selected(),727 Some(ActionId::Copy) => this.copy_selected(),
640 Some(ActionId::Paste) => this.paste(cx),728 Some(ActionId::Paste) => this.paste(cx),
@@ -653,8 +741,10 @@ impl Render for Player {
653 // The overlay owns the pointer as well as the keyboard, and a741 // The overlay owns the pointer as well as the keyboard, and a
654 // drop is a click the scrim cannot swallow: gpui delivers it to742 // drop is a click the scrim cannot swallow: gpui delivers it to
655 // the root's hitbox, which is under the scrim but is not a743 // the root's hitbox, which is under the scrim but is not a
656- // sibling it can stop.744+ // sibling it can stop. The export card is over the timeline for
657- if this.keys_open {745+ // the same reason: importing under it would change the very
746+ // edit list the card is about to write out.
747+ if this.keys_open || this.export_open {
658 return;748 return;
659 }749 }
660 for path in paths.paths() {750 for path in paths.paths() {
@@ -738,8 +828,10 @@ impl Render for Player {
738 // the picture nothing the rest of the time.828 // the picture nothing the rest of the time.
739 .children(self.notice_bar(cx))829 .children(self.notice_bar(cx))
740 .child(self.panel(position, duration, playing, cx))830 .child(self.panel(position, duration, playing, cx))
741- // Last, so it is over everything -- it takes no room in the column.831+ // Last, so they are over everything -- they take no room in the
832+ // column, and only one of the two is ever up.
742 .children(self.keys_overlay(cx))833 .children(self.keys_overlay(cx))
834+ .children(self.export_card(cx))
743 }835 }
744 }836 }
745 837
@@ -853,11 +945,11 @@ impl Player {
853 None,945 None,
854 "Export",946 "Export",
855 format!(947 format!(
856- "{} — writes the timeline out beside the source",948+ "{} — quality and destination, then writes the timeline out",
857 key(ActionId::Export)949 key(ActionId::Export)
858 ),950 ),
859 live && self.export.is_none(),951 live && self.export.is_none(),
860- cx.listener(|this, _: &ClickEvent, _, cx| this.start_export(cx)),952+ cx.listener(|this, _: &ClickEvent, _, cx| this.open_export(cx)),
861 ))953 ))
862 .child(control(954 .child(control(
863 "save",955 "save",
@@ -879,6 +971,8 @@ impl Player {
879 cx.listener(|this, _: &ClickEvent, _, cx| {971 cx.listener(|this, _: &ClickEvent, _, cx| {
880 this.keys_open = !this.keys_open;972 this.keys_open = !this.keys_open;
881 this.rebinding = None;973 this.rebinding = None;
974+ // One card at a time, both ways round.
975+ this.export_open = false;
882 cx.notify();976 cx.notify();
883 }),977 }),
884 )),978 )),
@@ -1090,6 +1184,133 @@ impl Player {
1090 )1184 )
1091 }1185 }
1092 1186
1187+ /// What an export is going to be, before there is one: the destination, the
1188+ /// quality rows, and the two things that are not a choice at all. The same
1189+ /// scrim, width and row shape as the keybindings overlay -- two cards of
1190+ /// different builds over one window read as two different programs -- and
1191+ /// the same plain divs, so the root keeps the keyboard and a typed digit
1192+ /// reaches the custom row.
1193+ fn export_card(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> {
1194+ if !self.export_open {
1195+ return None;
1196+ }
1197+ let row = |id: (&'static str, usize)| {
1198+ div()
1199+ .id(id)
1200+ .flex()
1201+ // The floor, not the height: the destination's path wraps on a
1202+ // long name and must not paint over the row under it.
1203+ .min_h(px(KEYS_ROW_H))
1204+ .items_center()
1205+ .justify_between()
1206+ .gap(px(12.))
1207+ .px(px(6.))
1208+ .rounded(px(3.))
1209+ .cursor_pointer()
1210+ .hover(|s| s.bg(rgb(HOVER)))
1211+ };
1212+ let rows: Vec<_> = Quality::ALL
1213+ .into_iter()
1214+ .enumerate()
1215+ .map(|(i, quality)| {
1216+ row(("quality", i))
1217+ .when(self.quality == quality, |d| d.bg(rgb(SELECTED)))
1218+ .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
1219+ this.quality = quality;
1220+ cx.notify();
1221+ }))
1222+ .child(quality.label())
1223+ .child(
1224+ div()
1225+ .text_size(px(11.))
1226+ .text_color(rgb(INK_DIM))
1227+ .child(quality.detail(self.custom_mbps)),
1228+ )
1229+ })
1230+ .collect();
1231+ Some(
1232+ div()
1233+ .absolute()
1234+ .inset_0()
1235+ .flex()
1236+ .justify_center()
1237+ .items_center()
1238+ .bg(rgba(0x101010cc))
1239+ .on_mouse_down(MouseButton::Left, |_: &MouseDownEvent, _, cx| {
1240+ cx.stop_propagation()
1241+ })
1242+ .child(
1243+ div()
1244+ .w(px(KEYS_W))
1245+ .flex()
1246+ .flex_col()
1247+ .gap(px(2.))
1248+ .p(px(12.))
1249+ .rounded(px(6.))
1250+ .bg(rgb(SURFACE))
1251+ .child(div().flex_none().px(px(6.)).child("Export"))
1252+ // The status line, where a refusal from the save dialog
1253+ // lands: the notice bar it would otherwise take is under
1254+ // the scrim.
1255+ .child(
1256+ div()
1257+ .flex_none()
1258+ .px(px(6.))
1259+ .text_size(px(11.))
1260+ .text_color(rgb(INK_DIM))
1261+ .child(self.notice.clone().unwrap_or_else(|| {
1262+ "pick a quality, then Export — esc closes".into()
1263+ })),
1264+ )
1265+ .child(
1266+ row(("destination", 0))
1267+ .on_click(cx.listener(|this, _: &ClickEvent, _, cx| {
1268+ this.pick_destination(cx)
1269+ }))
1270+ .child("Destination")
1271+ .child(
1272+ div()
1273+ .text_size(px(11.))
1274+ .text_color(rgb(INK_DIM))
1275+ .child(file_name(&self.export_path)),
1276+ ),
1277+ )
1278+ .children(rows)
1279+ // Not offered, so said: these are what this program can
1280+ // write, and a menu of one is a lie about the other
1281+ // entries. `moov` last is the muxer's own shape -- the
1282+ // file is playable only once it is finished.
1283+ .child(
1284+ div()
1285+ .flex_none()
1286+ .px(px(6.))
1287+ .text_size(px(11.))
1288+ .text_color(rgb(INK_DIM))
1289+ .child("H.264 · MP4 · moov at end"),
1290+ )
1291+ .child(
1292+ div()
1293+ .id("export-confirm")
1294+ .mt(px(4.))
1295+ .flex()
1296+ .h(px(CONTROL_H))
1297+ .items_center()
1298+ .justify_center()
1299+ .rounded(px(3.))
1300+ .bg(rgb(SELECTED))
1301+ .cursor_pointer()
1302+ .hover(|s| s.bg(rgb(HOVER)))
1303+ .on_click(
1304+ cx.listener(|this, _: &ClickEvent, _, cx| {
1305+ this.start_export(cx)
1306+ }),
1307+ )
1308+ .child("Export"),
1309+ ),
1310+ ),
1311+ )
1312+ }
1313+
1093 /// The edit list made visible: one box per clip, sized by its share of the1314 /// The edit list made visible: one box per clip, sized by its share of the
1094 /// timeline. A cut adds a box without moving anything, a delete closes the1315 /// timeline. A cut adds a box without moving anything, a delete closes the
1095 /// gap. A box has no room for a label at four clips, so the tooltip is where1316 /// gap. A box has no room for a label at four clips, so the tooltip is where
@@ -1147,31 +1368,62 @@ fn scrub_due(target: u32, last_target: u32, since: Duration) -> bool {
1147 target != last_target && since >= SCRUB_GAP1368 target != last_target && since >= SCRUB_GAP
1148 }1369 }
1149 1370
1150-/// The desktop's own file choosers, best first. Asked for by name because gpui1371+/// Runs the first chooser that is installed. `Some(None)` is a cancelled
1151-/// 0.2 has no file dialog of its own and none of these is worth a dependency.1372+/// dialog; `None` is a machine with no chooser at all, and what still works
1152-const PICKERS: [(&str, &[&str]); 2] = [1373+/// without one differs per dialog, so the caller words that refusal.
1153- ("zenity", &["--file-selection", "--title=edith — import"]),1374+///
1154- ("kdialog", &["--getopenfilename"]),1375+/// The desktop's own choosers, asked for by name because gpui 0.2 has no file
1155-];1376+/// dialog of its own and none of these is worth a dependency.
1156-1377+fn run_picker(pickers: [(&str, Vec<String>); 2]) -> Option<Option<PathBuf>> {
1157-/// Runs the first chooser that is installed. `Ok(None)` is a cancelled dialog;1378+ for (bin, args) in pickers {
1158-/// the error is for a machine with no chooser at all, which still has the drop
1159-/// target -- the import path that never depended on another program.
1160-fn pick_file() -> Result<Option<PathBuf>, &'static str> {
1161- for (bin, args) in PICKERS {
1162 // Not installed: try the next one. Anything else (a cancel, a refusal)1379 // Not installed: try the next one. Anything else (a cancel, a refusal)
1163 // is that chooser's answer and is taken as final.1380 // is that chooser's answer and is taken as final.
1164 let Ok(out) = std::process::Command::new(bin).args(args).output() else {1381 let Ok(out) = std::process::Command::new(bin).args(args).output() else {
1165 continue;1382 continue;
1166 };1383 };
1167 let path = String::from_utf8_lossy(&out.stdout).trim().to_string();1384 let path = String::from_utf8_lossy(&out.stdout).trim().to_string();
1168- return Ok((!path.is_empty()).then(|| PathBuf::from(path)));1385+ return Some((!path.is_empty()).then(|| PathBuf::from(path)));
1169 }1386 }
1170- Err(1387+ None
1388+}
1389+
1390+fn pick_file() -> Result<Option<PathBuf>, &'static str> {
1391+ run_picker([
1392+ (
1393+ "zenity",
1394+ vec!["--file-selection".into(), "--title=edith — import".into()],
1395+ ),
1396+ ("kdialog", vec!["--getopenfilename".into()]),
1397+ ])
1398+ .ok_or(
1171 "NO FILE CHOOSER — install zenity or kdialog, or drag the file onto this window to import it",1399 "NO FILE CHOOSER — install zenity or kdialog, or drag the file onto this window to import it",
1172 )1400 )
1173 }1401 }
1174 1402
1403+/// The save-side dialog, opened on where the export would land anyway: with no
1404+/// chooser installed that default is still what gets written, so this refusal
1405+/// costs the export nothing and says so.
1406+fn pick_save(default: &std::path::Path) -> Result<Option<PathBuf>, &'static str> {
1407+ let default = default.to_string_lossy().into_owned();
1408+ run_picker([
1409+ (
1410+ "zenity",
1411+ vec![
1412+ "--file-selection".into(),
1413+ // No `--confirm-overwrite`: zenity 4.2 lists it as deprecated
1414+ // and does the confirming itself.
1415+ "--save".into(),
1416+ "--title=edith — export to".into(),
1417+ format!("--filename={default}"),
1418+ ],
1419+ ),
1420+ ("kdialog", vec!["--getsavefilename".into(), default]),
1421+ ])
1422+ .ok_or(
1423+ "NO FILE CHOOSER — install zenity or kdialog to choose where; exporting beside the source",
1424+ )
1425+}
1426+
1175 /// Where an export goes: the source path with `.export.mp4` for an extension,1427 /// Where an export goes: the source path with `.export.mp4` for an extension,
1176 /// so it lands beside the original and can never be the original.1428 /// so it lands beside the original and can never be the original.
1177 fn export_path(source: impl Into<PathBuf>) -> PathBuf {1429 fn export_path(source: impl Into<PathBuf>) -> PathBuf {
@@ -1213,6 +1465,81 @@ fn source_tint(source: usize) -> u32 {
1213 SOURCE_TINTS[source % SOURCE_TINTS.len()]1465 SOURCE_TINTS[source % SOURCE_TINTS.len()]
1214 }1466 }
1215 1467
1468+/// What the export card offers, top to bottom. Bitrate is the only thing the
1469+/// encoder actually takes: the codec and the container are what this program
1470+/// can write and nothing else, so the card states them rather than offering
1471+/// them.
1472+#[derive(Clone, Copy, PartialEq, Debug)]
1473+enum Quality {
1474+ Auto,
1475+ Low,
1476+ Medium,
1477+ High,
1478+ Custom,
1479+}
1480+
1481+impl Quality {
1482+ const ALL: [Quality; 5] = [
1483+ Quality::Auto,
1484+ Quality::Low,
1485+ Quality::Medium,
1486+ Quality::High,
1487+ Quality::Custom,
1488+ ];
1489+
1490+ fn label(self) -> &'static str {
1491+ match self {
1492+ Quality::Auto => "Auto",
1493+ Quality::Low => "Low",
1494+ Quality::Medium => "Medium",
1495+ Quality::High => "High",
1496+ Quality::Custom => "Custom",
1497+ }
1498+ }
1499+
1500+ /// The figure the row stands for, said in the units the row is chosen by.
1501+ fn detail(self, custom_mbps: u32) -> String {
1502+ match self {
1503+ Quality::Auto => "from the picture size and frame rate".to_string(),
1504+ Quality::Custom => format!("{custom_mbps} Mbps — type a number, 1–20"),
1505+ other => format!(
1506+ "{} Mbps",
1507+ export_settings(other, 0).bitrate.unwrap_or_default() / 1_000_000
1508+ ),
1509+ }
1510+ }
1511+}
1512+
1513+/// The card's rows as the engine takes them. `Auto` leaves the bitrate to the
1514+/// exporter, which derives it from the picture; the fixed rows are figures that
1515+/// hold from 720p to 1080p, and a typed one is passed exactly as typed -- the
1516+/// engine clamps every explicit bitrate to 1..20 Mbps (export.rs:290), so this
1517+/// must not clamp it a second time and disagree about where the edge is.
1518+fn export_settings(quality: Quality, custom_mbps: u32) -> ExportSettings {
1519+ ExportSettings {
1520+ bitrate: match quality {
1521+ Quality::Auto => None,
1522+ Quality::Low => Some(2_000_000),
1523+ Quality::Medium => Some(6_000_000),
1524+ Quality::High => Some(12_000_000),
1525+ Quality::Custom => Some(u64::from(custom_mbps) * 1_000_000),
1526+ },
1527+ // No row of its own: the software pin is for a driver that encodes
1528+ // badly, which is a thing about the machine and not about the output --
1529+ // `VE_SW_ENC` already says it, and to the whole run rather than once.
1530+ force_sw: false,
1531+ }
1532+}
1533+
1534+/// A digit typed against the custom row, appended to what is already there.
1535+/// Refused rather than truncated past two digits: the engine's ceiling is
1536+/// 20 Mbps, so a third digit can only be a mistake, and a silently dropped one
1537+/// would leave the card showing a number nobody typed.
1538+fn push_digit(mbps: u32, digit: u32) -> u32 {
1539+ let next = mbps * 10 + digit;
1540+ if next <= 99 { next } else { mbps }
1541+}
1542+
1216 /// Whether a stroke gets out of a running export. Escape does, whatever1543 /// Whether a stroke gets out of a running export. Escape does, whatever
1217 /// modifiers are held with it, for the same reason it gets out of a capture and1544 /// modifiers are held with it, for the same reason it gets out of a capture and
1218 /// out of the overlay: it is this window's way out, and a way out that only1545 /// out of the overlay: it is this window's way out, and a way out that only
@@ -1435,9 +1762,9 @@ fn timecode(t: f64, fps: f64) -> String {
1435 #[cfg(test)]1762 #[cfg(test)]
1436 mod tests {1763 mod tests {
1437 use super::{1764 use super::{
1438- CONTROL_H, HIT_MIN, KEYS_ROW_H, KEYS_W, LANE_H, RULER_HIT_H, SOURCE_TINTS, SURFACE,1765+ CONTROL_H, HIT_MIN, KEYS_ROW_H, KEYS_W, LANE_H, Quality, RULER_HIT_H, SOURCE_TINTS,
1439- cancels_export, export_path, frac_along, is_bare_modifier, is_project, keymap,1766+ SURFACE, cancels_export, export_path, export_settings, frac_along, is_bare_modifier,
1440- project_path, scrub_due, source_tint, timecode, width_frac,1767+ is_project, keymap, project_path, push_digit, scrub_due, source_tint, timecode, width_frac,
1441 };1768 };
1442 use gpui::{Bounds, Pixels, point, px, size};1769 use gpui::{Bounds, Pixels, point, px, size};
1443 use std::time::Duration;1770 use std::time::Duration;
@@ -1599,6 +1926,65 @@ mod tests {
1599 assert!(KEYS_ROW_H >= HIT_MIN);1926 assert!(KEYS_ROW_H >= HIT_MIN);
1600 }1927 }
1601 1928
1929+ #[test]
1930+ fn a_quality_row_is_the_bitrate_it_promises() {
1931+ // Auto is the one row that says nothing: the exporter derives it, and
1932+ // a number typed against the custom row must not leak into it.
1933+ assert_eq!(export_settings(Quality::Auto, 7).bitrate, None);
1934+ assert_eq!(export_settings(Quality::Low, 0).bitrate, Some(2_000_000));
1935+ assert_eq!(export_settings(Quality::Medium, 0).bitrate, Some(6_000_000));
1936+ assert_eq!(export_settings(Quality::High, 0).bitrate, Some(12_000_000));
1937+ // Megabits as typed, and as the row says it back.
1938+ assert_eq!(export_settings(Quality::Custom, 7).bitrate, Some(7_000_000));
1939+ assert_eq!(Quality::Low.detail(0), "2 Mbps");
1940+ // Every fixed row sits inside the engine's clamp (export.rs:290), so no
1941+ // row can promise a bitrate the exporter silently changes.
1942+ for quality in Quality::ALL {
1943+ let settings = export_settings(quality, 7);
1944+ if let Some(bitrate) = settings.bitrate {
1945+ assert!(
1946+ (1_000_000..=20_000_000).contains(&bitrate),
1947+ "{quality:?} outside the engine clamp"
1948+ );
1949+ }
1950+ // The software pin is the environment's to set, never a row's.
1951+ assert!(!settings.force_sw);
1952+ }
1953+ }
1954+
1955+ #[test]
1956+ fn a_typed_bitrate_stops_at_two_digits() {
1957+ assert_eq!(push_digit(0, 8), 8);
1958+ assert_eq!(push_digit(1, 2), 12);
1959+ // A third digit is refused whole: the ceiling is 20 Mbps, so it can
1960+ // only be a mistake, and dropping it silently would leave the card
1961+ // showing a number nobody typed.
1962+ assert_eq!(push_digit(12, 3), 12);
1963+ assert_eq!(push_digit(99, 9), 99);
1964+ // Never past what the clamp can take back to a real bitrate.
1965+ assert!(u64::from(push_digit(99, 9)) * 1_000_000 < u64::from(u32::MAX));
1966+ }
1967+
1968+ #[test]
1969+ fn the_export_card_fits_the_smallest_window() {
1970+ // Same 640x360 floor the keybindings card is measured against: a
1971+ // destination row, one row per quality, the fixed-format line and the
1972+ // confirm button, under a title and a status line.
1973+ let rows = Quality::ALL.len() as f32 + 1.;
1974+ let title = 17.;
1975+ let status = 28.;
1976+ let fixed = 17.;
1977+ let gaps = (rows + 3.) * 2.;
1978+ let padding = 24.;
1979+ assert!(
1980+ title + status + rows * KEYS_ROW_H + fixed + CONTROL_H + 4. + gaps + padding <= 360.,
1981+ "card too tall"
1982+ );
1983+ // Clickable rows, so WCAG 2.5.8 binds them as it binds the panel's.
1984+ assert!(KEYS_ROW_H >= HIT_MIN);
1985+ assert!(CONTROL_H >= HIT_MIN);
1986+ }
1987+
1602 #[test]1988 #[test]
1603 fn nothing_clickable_is_smaller_than_the_wcag_minimum() {1989 fn nothing_clickable_is_smaller_than_the_wcag_minimum() {
1604 // Every hit target in the panel, including the scrub strip -- whose bar1990 // Every hit target in the panel, including the scrub strip -- whose bar
@@ -1740,6 +2126,11 @@ fn main() {
1740 project_path: project.clone(),2126 project_path: project.clone(),
1741 keymap: keymap.clone(),2127 keymap: keymap.clone(),
1742 keys_open: false,2128 keys_open: false,
2129+ export_open: false,
2130+ // What an export is until someone says otherwise: the
2131+ // bitrate the picture asks for.
2132+ quality: Quality::Auto,
2133+ custom_mbps: 0,
1743 rebinding: None,2134 rebinding: None,
1744 notice: notice.clone().map(SharedString::from),2135 notice: notice.clone().map(SharedString::from),
1745 displayed: 0,2136 displayed: 0,