🔀 merge(E4): the bitrate is typed into a field, not clicked into existence — caret, validation, refusals in words
Browse files at this commit2 changed files +307 -58
- crates/app/src/keymap.rs +9 -4
- crates/app/src/main.rs +298 -54
crates/app/src/keymap.rsmodified+9 -4
| @@ -353,7 +353,7 @@ pub struct Fixed { | ||
| 353 | 353 | pub category: Category, |
| 354 | 354 | } |
| 355 | 355 | |
| 356 | -pub const FIXED: [Fixed; 27] = [ | |
| 356 | +pub const FIXED: [Fixed; 28] = [ | |
| 357 | 357 | // Not a chord at all but a way of pressing one, and the only place the |
| 358 | 358 | // editor can say so: holding a key that moves a *value* runs it, and |
| 359 | 359 | // holding anything else still does what one press did. |
| @@ -367,9 +367,14 @@ pub const FIXED: [Fixed; 27] = [ | ||
| 367 | 367 | label: "Close this card or menu, or cancel a capture", |
| 368 | 368 | category: Category::View, |
| 369 | 369 | }, |
| 370 | + Fixed { | |
| 371 | + chord: "n", | |
| 372 | + label: "Open the custom export bitrate field — ↑↓ step it", | |
| 373 | + category: Category::File, | |
| 374 | + }, | |
| 370 | 375 | Fixed { |
| 371 | 376 | chord: "0–9", |
| 372 | - label: "Type a custom export bitrate", | |
| 377 | + label: "Type into that field — nothing outside it", | |
| 373 | 378 | category: Category::File, |
| 374 | 379 | }, |
| 375 | 380 | Fixed { |
| @@ -414,12 +419,12 @@ pub const FIXED: [Fixed; 27] = [ | ||
| 414 | 419 | }, |
| 415 | 420 | Fixed { |
| 416 | 421 | chord: "enter", |
| 417 | - label: "Start the export the card is set to", | |
| 422 | + label: "Start the export — or commit the bitrate field", | |
| 418 | 423 | category: Category::File, |
| 419 | 424 | }, |
| 420 | 425 | Fixed { |
| 421 | 426 | chord: "backspace", |
| 422 | - label: "Erase a bitrate digit", | |
| 427 | + label: "Erase a digit in the bitrate field", | |
| 423 | 428 | category: Category::File, |
| 424 | 429 | }, |
| 425 | 430 | // The equalizer card's own input, for the same reason the export card has |
crates/app/src/main.rsmodified+298 -54
| @@ -1100,6 +1100,14 @@ struct Player { | ||
| 1100 | 1100 | /// first one chose. |
| 1101 | 1101 | quality: Quality, |
| 1102 | 1102 | custom_mbps: u32, |
| 1103 | + /// The custom row's number *while it is being typed*, or `None` when nobody | |
| 1104 | + /// is typing one. A field with a caret in it and not a key capture: digits | |
| 1105 | + /// used to change the bitrate from anywhere in the card, with no caret to | |
| 1106 | + /// say where they were landing and nothing to look at before the number | |
| 1107 | + /// took effect. Nothing in this card takes gpui focus (the root keeps the | |
| 1108 | + /// keyboard), so the field is a modal state on the player exactly as a | |
| 1109 | + /// waiting rebind row is, and the root's handler is what types into it. | |
| 1110 | + mbps_edit: Option<NumberEdit>, | |
| 1103 | 1111 | /// What the *sound* is coded at, in kbps, for every format that encodes it |
| 1104 | 1112 | /// -- the AAC inside a video export as much as an MP3. Kept across closes |
| 1105 | 1113 | /// like the picture's quality, and starts at the figure this program wrote |
| @@ -2338,7 +2346,12 @@ impl Player { | ||
| 2338 | 2346 | /// exactly the ones that answer differently from the keys menu and the |
| 2339 | 2347 | /// export card. |
| 2340 | 2348 | fn repeat_scope(&self) -> Repeat { |
| 2341 | - if self.rebinding.is_some() | |
| 2349 | + // A number being typed is a value under the arrows, exactly as a card's | |
| 2350 | + // slider is -- so a held arrow runs it. Asked before the export card | |
| 2351 | + // below, which otherwise repeats nothing. | |
| 2352 | + if self.mbps_edit.is_some() { | |
| 2353 | + Repeat::Card | |
| 2354 | + } else if self.rebinding.is_some() | |
| 2342 | 2355 | || self.keys_open |
| 2343 | 2356 | || self.export_open |
| 2344 | 2357 | || self.exporting().is_some() |
| @@ -4015,9 +4028,11 @@ impl Player { | ||
| 4015 | 4028 | } |
| 4016 | 4029 | self.export_open = true; |
| 4017 | 4030 | // One card at a time, and a waiting row must not outlive the card it |
| 4018 | - // was waiting in. | |
| 4031 | + // was waiting in. Nor may a half-typed number: the card opens on the | |
| 4032 | + // bitrate it will write, never on digits left behind by a closed one. | |
| 4019 | 4033 | self.keys_open = false; |
| 4020 | 4034 | self.rebinding = None; |
| 4035 | + self.mbps_edit = None; | |
| 4021 | 4036 | cx.notify(); |
| 4022 | 4037 | } |
| 4023 | 4038 | |
| @@ -4090,8 +4105,19 @@ impl Player { | ||
| 4090 | 4105 | /// (the engine's own 1..20 Mbps), and picking the row is part of the step -- |
| 4091 | 4106 | /// a stepper that moves a number nobody is using would move nothing. |
| 4092 | 4107 | fn nudge_mbps(&mut self, step: i32) { |
| 4093 | - self.custom_mbps = (self.custom_mbps as i32 + step).clamp(1, 20) as u32; | |
| 4108 | + self.custom_mbps = | |
| 4109 | + (self.custom_mbps as i32 + step).clamp(MBPS_MIN as i32, MBPS_MAX as i32) as u32; | |
| 4110 | + self.quality = Quality::Custom; | |
| 4111 | + } | |
| 4112 | + | |
| 4113 | + /// Opens the custom bitrate's field on the number the row is carrying, and | |
| 4114 | + /// picks the row while it is at it: a field typed into is the row being | |
| 4115 | + /// chosen, and a number nobody is using would be a number typed at nothing. | |
| 4116 | + /// Nothing is committed here -- until enter, the card still exports at the | |
| 4117 | + /// bitrate it had. | |
| 4118 | + fn edit_mbps(&mut self) { | |
| 4094 | 4119 | self.quality = Quality::Custom; |
| 4120 | + self.mbps_edit = Some(NumberEdit::new(self.custom_mbps)); | |
| 4095 | 4121 | } |
| 4096 | 4122 | |
| 4097 | 4123 | /// The card's Destination row: the desktop's save dialog, on a background |
| @@ -4361,10 +4387,10 @@ impl Render for Player { | ||
| 4361 | 4387 | } |
| 4362 | 4388 | // The export card owns it the same way, and for the same |
| 4363 | 4389 | // reason. Escape closes it -- nothing has been written yet, so |
| 4364 | - // there is nothing here to cancel -- and a digit is the custom | |
| 4365 | - // bitrate being typed: the card has no text field (nothing in | |
| 4366 | - // it takes focus, ledger:182) so this listener is its input, | |
| 4367 | - // exactly as it is a waiting row's. | |
| 4390 | + // there is nothing here to cancel -- and the card's own letters | |
| 4391 | + // are its input: it has no widget that takes focus (nothing in | |
| 4392 | + // it does), so this listener is its keyboard, exactly as it is | |
| 4393 | + // a waiting row's. | |
| 4368 | 4394 | if this.export_open { |
| 4369 | 4395 | // A list open over the card is the innermost thing on |
| 4370 | 4396 | // screen, so it is what a stroke closes first -- the rule |
| @@ -4374,6 +4400,35 @@ impl Render for Player { | ||
| 4374 | 4400 | cx.notify(); |
| 4375 | 4401 | return; |
| 4376 | 4402 | } |
| 4403 | + // A number being typed is the next thing in: while the | |
| 4404 | + // field is open every stroke is text, which is what makes | |
| 4405 | + // it a field and not a capture -- the card's letters cannot | |
| 4406 | + // fire under it, and escape gives up the edit before it | |
| 4407 | + // touches the card. | |
| 4408 | + if let Some(edit) = &mut this.mbps_edit { | |
| 4409 | + if key == ESCAPE { | |
| 4410 | + this.mbps_edit = None; | |
| 4411 | + } else if key == "enter" { | |
| 4412 | + // Committed or refused in its own words; a refused | |
| 4413 | + // one stays open on what was typed, so the number | |
| 4414 | + // can be fixed rather than typed again. | |
| 4415 | + if let Some(mbps) = edit.commit() { | |
| 4416 | + this.custom_mbps = mbps; | |
| 4417 | + this.quality = Quality::Custom; | |
| 4418 | + this.mbps_edit = None; | |
| 4419 | + } | |
| 4420 | + } else if key == "backspace" { | |
| 4421 | + edit.backspace(); | |
| 4422 | + } else if key == "up" { | |
| 4423 | + edit.step(1); | |
| 4424 | + } else if key == "down" { | |
| 4425 | + edit.step(-1); | |
| 4426 | + } else if let Ok(digit) = key.parse::<u32>() { | |
| 4427 | + edit.digit(digit); | |
| 4428 | + } | |
| 4429 | + cx.notify(); | |
| 4430 | + return; | |
| 4431 | + } | |
| 4377 | 4432 | if key == ESCAPE { |
| 4378 | 4433 | this.export_open = false; |
| 4379 | 4434 | } else if key == "enter" { |
| @@ -4404,19 +4459,13 @@ impl Render for Player { | ||
| 4404 | 4459 | this.export_grouped = !this.export_grouped; |
| 4405 | 4460 | } else if key == "r" { |
| 4406 | 4461 | this.export_refusals_inline = !this.export_refusals_inline; |
| 4407 | - } else if let Ok(digit) = key.parse::<u32>() { | |
| 4408 | - let next = push_digit(this.custom_mbps, digit); | |
| 4409 | - // A refused third digit says so: it used to be dropped | |
| 4410 | - // in silence, which left the card showing a number the | |
| 4411 | - // user had already typed past. | |
| 4412 | - if next == this.custom_mbps && this.custom_mbps > 0 { | |
| 4413 | - this.notice = Some("1–20 Mbps — a third digit is refused".into()); | |
| 4414 | - } | |
| 4415 | - this.custom_mbps = next; | |
| 4416 | - this.quality = Quality::Custom; | |
| 4417 | - } else if key == "backspace" { | |
| 4418 | - this.custom_mbps /= 10; | |
| 4419 | - this.quality = Quality::Custom; | |
| 4462 | + } else if key == "n" { | |
| 4463 | + // The custom row's field, by keyboard. The digits used | |
| 4464 | + // to do this from anywhere in the card, which meant a | |
| 4465 | + // stray keystroke changed the bitrate with nothing on | |
| 4466 | + // screen to say it had: now a digit outside the field | |
| 4467 | + // means nothing at all, and this is the way in. | |
| 4468 | + this.edit_mbps(); | |
| 4420 | 4469 | } |
| 4421 | 4470 | cx.notify(); |
| 4422 | 4471 | return; |
| @@ -6110,7 +6159,7 @@ impl Player { | ||
| 6110 | 6159 | ) |
| 6111 | 6160 | // The search box: no focus and no text field -- the |
| 6112 | 6161 | // card's key handler is the field, exactly as the |
| 6113 | - // export card's digits are typed into it. Its own line | |
| 6162 | + // export card's bitrate is typed into it. Its own line | |
| 6114 | 6163 | // above the list, so the rows below it are always the |
| 6115 | 6164 | // answer to what it says. |
| 6116 | 6165 | .child( |
| @@ -6147,7 +6196,8 @@ impl Player { | ||
| 6147 | 6196 | /// two lines that state the file all of that adds up to. The same scrim and |
| 6148 | 6197 | /// row shape as the keybindings overlay (two cards of different builds over |
| 6149 | 6198 | /// one window read as two different programs) and the same plain divs, so |
| 6150 | - /// the root keeps the keyboard and a typed digit reaches the custom row. | |
| 6199 | + /// the root keeps the keyboard and the custom row's field is typed into | |
| 6200 | + /// through it ([`NumberEdit`]). | |
| 6151 | 6201 | /// |
| 6152 | 6202 | /// Every row carries the key that picks it, so the card is drivable end to |
| 6153 | 6203 | /// end without a pointer *and* without a legend to memorise -- and every |
| @@ -6342,22 +6392,31 @@ impl Player { | ||
| 6342 | 6392 | ), |
| 6343 | 6393 | None => { |
| 6344 | 6394 | for (i, quality) in Quality::ALL.into_iter().enumerate() { |
| 6395 | + // The custom row is a field: `n` opens it, a click in it | |
| 6396 | + // opens it too, and while it is open the row shows what is | |
| 6397 | + // being typed with a caret in it rather than the number in | |
| 6398 | + // force. The other four are picked whole. | |
| 6399 | + let field = self.mbps_edit.as_ref().filter(|_| quality == Quality::Custom); | |
| 6345 | 6400 | let mut r = entry( |
| 6346 | 6401 | ("quality", i), |
| 6347 | 6402 | match quality { |
| 6348 | - // The one row a key does not step to but types | |
| 6349 | - // into, which is what its key column says. | |
| 6350 | - Quality::Custom => "0–9", | |
| 6403 | + Quality::Custom => "n", | |
| 6351 | 6404 | _ => "q", |
| 6352 | 6405 | }, |
| 6353 | 6406 | quality.label().into(), |
| 6354 | - quality.detail(self.custom_mbps).into(), | |
| 6407 | + match field { | |
| 6408 | + Some(edit) => edit.detail().into(), | |
| 6409 | + None => quality.detail(self.custom_mbps).into(), | |
| 6410 | + }, | |
| 6355 | 6411 | self.quality == quality, |
| 6356 | 6412 | true, |
| 6357 | 6413 | ) |
| 6358 | 6414 | .on_click(cx.listener( |
| 6359 | 6415 | move |this, _: &ClickEvent, _, cx| { |
| 6360 | - this.quality = quality; | |
| 6416 | + match quality { | |
| 6417 | + Quality::Custom => this.edit_mbps(), | |
| 6418 | + _ => this.quality = quality, | |
| 6419 | + } | |
| 6361 | 6420 | cx.notify(); |
| 6362 | 6421 | }, |
| 6363 | 6422 | )); |
| @@ -6523,11 +6582,22 @@ impl Player { | ||
| 6523 | 6582 | .px(px(6.)) |
| 6524 | 6583 | .text_size(px(11.)) |
| 6525 | 6584 | .text_color(rgb(INK_DIM)) |
| 6526 | - .child(self.notice.clone().unwrap_or_else(|| { | |
| 6527 | - "the keys are on the rows · enter exports · esc closes · \ | |
| 6528 | - g/r change the layout" | |
| 6529 | - .into() | |
| 6530 | - })), | |
| 6585 | + .child(match (&self.mbps_edit, &self.notice) { | |
| 6586 | + // A field being typed into says so here as | |
| 6587 | + // well as in its row: this line is outside | |
| 6588 | + // the scrolling list and on screen at every | |
| 6589 | + // window size, and at 360 px the custom row | |
| 6590 | + // itself can be below the fold -- a number | |
| 6591 | + // typed where it cannot be seen is the | |
| 6592 | + // blind capture this field replaced. | |
| 6593 | + (Some(edit), _) => { | |
| 6594 | + SharedString::from(format!("Custom bitrate {}", edit.detail())) | |
| 6595 | + } | |
| 6596 | + (None, Some(notice)) => notice.clone(), | |
| 6597 | + (None, None) => "the keys are on the rows · enter exports · \ | |
| 6598 | + esc closes · g/r change the layout" | |
| 6599 | + .into(), | |
| 6600 | + }), | |
| 6531 | 6601 | ) |
| 6532 | 6602 | // Capped and scrolling like the keybindings list: the |
| 6533 | 6603 | // rows are more than a 360 px window has room for, and |
| @@ -9662,7 +9732,9 @@ impl Quality { | ||
| 9662 | 9732 | fn detail(self, custom_mbps: u32) -> String { |
| 9663 | 9733 | match self { |
| 9664 | 9734 | Quality::Auto => "from the picture size and frame rate".to_string(), |
| 9665 | - Quality::Custom => format!("{custom_mbps} Mbps — type a number, 1–20"), | |
| 9735 | + Quality::Custom => { | |
| 9736 | + format!("{custom_mbps} Mbps — n types a number, {MBPS_MIN}–{MBPS_MAX}") | |
| 9737 | + } | |
| 9666 | 9738 | other => format!( |
| 9667 | 9739 | "{} Mbps", |
| 9668 | 9740 | export_settings(other, 0, Format::Mp4, DEFAULT_AUDIO_KBPS) |
| @@ -9728,7 +9800,7 @@ const FORMATS: [(&[Format], &str, &str, &str); 8] = [ | ||
| 9728 | 9800 | /// `a` after an mp4 gives AV1 *in mp4*, because a box decided once is not a |
| 9729 | 9801 | /// question again. A letter of the row's own name, spelled out in the table |
| 9730 | 9802 | /// rather than taken from the initial (`MP4` and `MP3` share one). Never a |
| 9731 | -/// digit -- those are the bitrate's. `None` for every other stroke, the rows | |
| 9803 | +/// digit -- those are the bitrate field's. `None` for every other stroke, the rows | |
| 9732 | 9804 | /// that cannot be picked included. |
| 9733 | 9805 | fn format_key(key: &str, current: Format) -> Option<Format> { |
| 9734 | 9806 | FORMATS |
| @@ -10129,13 +10201,118 @@ fn export_settings( | ||
| 10129 | 10201 | } |
| 10130 | 10202 | } |
| 10131 | 10203 | |
| 10132 | -/// A digit typed against the custom row, appended to what is already there. | |
| 10133 | -/// Refused rather than truncated past two digits: the engine's ceiling is | |
| 10134 | -/// 20 Mbps, so a third digit can only be a mistake, and a silently dropped one | |
| 10135 | -/// would leave the card showing a number nobody typed. | |
| 10136 | -fn push_digit(mbps: u32, digit: u32) -> u32 { | |
| 10137 | - let next = mbps * 10 + digit; | |
| 10138 | - if next <= 99 { next } else { mbps } | |
| 10204 | +/// What the engine will code an explicit bitrate at, in whole Mbps: outside | |
| 10205 | +/// this it clamps (`export.rs` `MIN_BITRATE`/`MAX_BITRATE`), so a number typed | |
| 10206 | +/// past either end would be written as a different one. The field refuses it | |
| 10207 | +/// instead of clamping quietly -- a card that changes the user's number without | |
| 10208 | +/// saying so is the one thing a field like this must never do. | |
| 10209 | +const MBPS_MIN: u32 = 1; | |
| 10210 | +const MBPS_MAX: u32 = 20; | |
| 10211 | + | |
| 10212 | +/// How many digits the field takes. Two reach the ceiling; the third is there so | |
| 10213 | +/// a number *past* it can be typed whole and refused in its own words, rather | |
| 10214 | +/// than being dropped keystroke by keystroke. | |
| 10215 | +const MBPS_DIGITS: usize = 3; | |
| 10216 | + | |
| 10217 | +/// A number being typed into a card row: the digits so far and, once a commit | |
| 10218 | +/// has been refused, why. Text-field semantics on a card that has no text field | |
| 10219 | +/// -- typing, backspace, arrows that step, enter that commits and escape that | |
| 10220 | +/// gives up -- held as state and driven by the root's key handler, since | |
| 10221 | +/// nothing in these cards takes gpui focus. | |
| 10222 | +#[derive(Clone, Debug, Default, PartialEq, Eq)] | |
| 10223 | +struct NumberEdit { | |
| 10224 | + text: String, | |
| 10225 | + refusal: Option<String>, | |
| 10226 | +} | |
| 10227 | + | |
| 10228 | +impl NumberEdit { | |
| 10229 | + /// Starts on the number the row already carries, so backspace edits it | |
| 10230 | + /// rather than the field opening empty over a value that is still in force. | |
| 10231 | + /// Zero is no number at all -- it is what the card opens at, before anyone | |
| 10232 | + /// has typed one. | |
| 10233 | + fn new(value: u32) -> Self { | |
| 10234 | + NumberEdit { | |
| 10235 | + text: match value { | |
| 10236 | + 0 => String::new(), | |
| 10237 | + v => v.to_string(), | |
| 10238 | + }, | |
| 10239 | + refusal: None, | |
| 10240 | + } | |
| 10241 | + } | |
| 10242 | + | |
| 10243 | + /// A digit against what is there. The one past [`MBPS_DIGITS`] is refused | |
| 10244 | + /// *out loud*: a keystroke dropped in silence is how the old digit capture | |
| 10245 | + /// left the card showing a number the user had already typed past. | |
| 10246 | + fn digit(&mut self, digit: u32) { | |
| 10247 | + if self.text.chars().count() >= MBPS_DIGITS { | |
| 10248 | + self.refusal = Some(format!("{MBPS_DIGITS} digits is already past the ceiling")); | |
| 10249 | + return; | |
| 10250 | + } | |
| 10251 | + match char::from_digit(digit, 10) { | |
| 10252 | + Some(c) => { | |
| 10253 | + self.text.push(c); | |
| 10254 | + self.refusal = None; | |
| 10255 | + } | |
| 10256 | + None => self.refusal = Some("digits only".into()), | |
| 10257 | + } | |
| 10258 | + } | |
| 10259 | + | |
| 10260 | + /// Erases the last digit, and the refusal with it: the number on screen has | |
| 10261 | + /// changed, so the reason the old one was refused no longer describes it. | |
| 10262 | + fn backspace(&mut self) { | |
| 10263 | + self.text.pop(); | |
| 10264 | + self.refusal = None; | |
| 10265 | + } | |
| 10266 | + | |
| 10267 | + /// The arrows, which is how a number gets picked rather than typed. Steps | |
| 10268 | + /// from what is in the field -- an empty one starts at the floor, so the | |
| 10269 | + /// first press up is `MBPS_MIN` and not a jump to some remembered value -- | |
| 10270 | + /// and stays inside the range, because a step is a walk through the legal | |
| 10271 | + /// numbers rather than a way out of them. | |
| 10272 | + fn step(&mut self, by: i32) { | |
| 10273 | + let at = self.text.parse::<i32>().unwrap_or(MBPS_MIN as i32 - by.signum()); | |
| 10274 | + self.text = (at + by) | |
| 10275 | + .clamp(MBPS_MIN as i32, MBPS_MAX as i32) | |
| 10276 | + .to_string(); | |
| 10277 | + self.refusal = None; | |
| 10278 | + } | |
| 10279 | + | |
| 10280 | + /// The number, or `None` with the reason recorded where the row will read | |
| 10281 | + /// it. Never clamped: 45 committed as 20 is a number the user did not type. | |
| 10282 | + fn commit(&mut self) -> Option<u32> { | |
| 10283 | + match commit_mbps(&self.text) { | |
| 10284 | + Ok(mbps) => Some(mbps), | |
| 10285 | + Err(why) => { | |
| 10286 | + self.refusal = Some(why); | |
| 10287 | + None | |
| 10288 | + } | |
| 10289 | + } | |
| 10290 | + } | |
| 10291 | + | |
| 10292 | + /// What the row shows while it is being typed into: the digits, the caret | |
| 10293 | + /// that says they are landing *here*, and either the refusal or the two | |
| 10294 | + /// keys that end the edit. | |
| 10295 | + fn detail(&self) -> String { | |
| 10296 | + format!( | |
| 10297 | + "{}▏ Mbps — {}", | |
| 10298 | + self.text, | |
| 10299 | + match &self.refusal { | |
| 10300 | + Some(why) => why.as_str(), | |
| 10301 | + None => "enter commits · esc cancels", | |
| 10302 | + } | |
| 10303 | + ) | |
| 10304 | + } | |
| 10305 | +} | |
| 10306 | + | |
| 10307 | +/// A typed bitrate as the card takes it, or the reason it is not one. The words | |
| 10308 | +/// are the row's: they are what the field shows in place of its hint. | |
| 10309 | +fn commit_mbps(text: &str) -> Result<u32, String> { | |
| 10310 | + match text.parse::<u32>() { | |
| 10311 | + Ok(mbps) if (MBPS_MIN..=MBPS_MAX).contains(&mbps) => Ok(mbps), | |
| 10312 | + Ok(0) => Err(format!("0 is not a rate — {MBPS_MIN}–{MBPS_MAX} Mbps")), | |
| 10313 | + Ok(mbps) => Err(format!("{mbps} is past the {MBPS_MAX} Mbps ceiling")), | |
| 10314 | + Err(_) => Err(format!("type a number — {MBPS_MIN}–{MBPS_MAX} Mbps")), | |
| 10315 | + } | |
| 10139 | 10316 | } |
| 10140 | 10317 | |
| 10141 | 10318 | /// Whether a stroke gets out of a running export. Escape does, whatever |
| @@ -11439,16 +11616,18 @@ mod tests { | ||
| 11439 | 11616 | Format, HEADER_GAP, HEADER_H, HEADER_W, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, INK, |
| 11440 | 11617 | INK_DIM, KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, KeyRow, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX, |
| 11441 | 11618 | LETTERBOX, LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_PAD, MENU_ROW_H, |
| 11442 | - MENU_ROWS_H, MENU_W, NO_FILE, PANEL_H, Quality, ROW_H, RULER_HIT_H, SELECTED, SILENCE_ROWS, | |
| 11619 | + MBPS_DIGITS, MBPS_MAX, MBPS_MIN, MENU_ROWS_H, MENU_W, NO_FILE, NumberEdit, PANEL_H, | |
| 11620 | + Quality, ROW_H, RULER_HIT_H, SELECTED, SILENCE_ROWS, | |
| 11443 | 11621 | SOURCE_TINTS, SPEED_PRESETS, SPEED_STEP, SURFACE, SWATCH_W, Source, Speed, StreamInfo, |
| 11444 | 11622 | Transport, VOLUME_W, Volume, WAVE_BPS, WAVE_COL, WAVE_COLS_MAX, Wave, band_label, |
| 11445 | - bitrate_refusal, can_add, cancels_export, clipboard_after_remove, color_snap, containers, | |
| 11623 | + bitrate_refusal, can_add, cancels_export, clipboard_after_remove, color_snap, commit_mbps, | |
| 11624 | + containers, | |
| 11446 | 11625 | enable, envelope, eq_card_w, eq_freq, eq_freq_label, eq_spectrum, eq_x, eq_y, |
| 11447 | 11626 | estimated_mb, export_path, export_settings, format_key, |
| 11448 | 11627 | format_line, format_refusal, fps_label, frac_along, frac_down, frame_at, histogram, |
| 11449 | 11628 | inserted_band, is_bare_modifier, is_project, keymap, keys_filter, keys_rows, lanes_h, |
| 11450 | 11629 | marked, menu_at, next_audio_kbps, next_container, normalise, nothing_to_play, panel_h, project_path, |
| 11451 | - push_digit, retarget, scrub_due, show_label, silence_rate, snap_cue, snap_marks, snapped, | |
| 11630 | + retarget, scrub_due, show_label, silence_rate, snap_cue, snap_marks, snapped, | |
| 11452 | 11631 | source_tint, span_partner, speed_at, summary_head, summary_tail, timecode, transport, |
| 11453 | 11632 | typed, unseen_paths, unseen_sources, |
| 11454 | 11633 | whole_take, window_title, |
| @@ -14142,16 +14321,80 @@ mod tests { | ||
| 14142 | 14321 | } |
| 14143 | 14322 | |
| 14144 | 14323 | #[test] |
| 14145 | - fn a_typed_bitrate_stops_at_two_digits() { | |
| 14146 | - assert_eq!(push_digit(0, 8), 8); | |
| 14147 | - assert_eq!(push_digit(1, 2), 12); | |
| 14148 | - // A third digit is refused whole: the ceiling is 20 Mbps, so it can | |
| 14149 | - // only be a mistake, and dropping it silently would leave the card | |
| 14150 | - // showing a number nobody typed. | |
| 14151 | - assert_eq!(push_digit(12, 3), 12); | |
| 14152 | - assert_eq!(push_digit(99, 9), 99); | |
| 14153 | - // Never past what the clamp can take back to a real bitrate. | |
| 14154 | - assert!(u64::from(push_digit(99, 9)) * 1_000_000 < u64::from(u32::MAX)); | |
| 14324 | + fn a_typed_bitrate_is_a_field_and_not_a_key_capture() { | |
| 14325 | + // It opens on the number in force, so backspace edits that number | |
| 14326 | + // rather than the field starting empty over a bitrate still being used. | |
| 14327 | + let mut edit = NumberEdit::new(12); | |
| 14328 | + assert_eq!(edit.text, "12"); | |
| 14329 | + edit.backspace(); | |
| 14330 | + edit.digit(8); | |
| 14331 | + assert_eq!(edit.text, "18"); | |
| 14332 | + assert_eq!(edit.commit(), Some(18)); | |
| 14333 | + // A card nobody has typed a number into opens empty: zero is not a | |
| 14334 | + // bitrate anyone chose. | |
| 14335 | + assert_eq!(NumberEdit::new(0).text, ""); | |
| 14336 | + | |
| 14337 | + // Out of range is refused *in words* and the digits stay put: clamping | |
| 14338 | + // 45 to 20 would write a bitrate the user never typed. | |
| 14339 | + let mut edit = NumberEdit::new(0); | |
| 14340 | + for digit in [4, 5] { | |
| 14341 | + edit.digit(digit); | |
| 14342 | + } | |
| 14343 | + assert_eq!(edit.commit(), None); | |
| 14344 | + assert_eq!(edit.text, "45", "a refusal keeps what was typed"); | |
| 14345 | + let refusal = edit.refusal.clone().expect("a refusal says why"); | |
| 14346 | + assert!(refusal.contains("20"), "{refusal}"); | |
| 14347 | + assert!(edit.detail().starts_with("45▏"), "{}", edit.detail()); | |
| 14348 | + assert!(edit.detail().contains(&refusal)); | |
| 14349 | + // And is fixable in place, which is the whole point of a field. | |
| 14350 | + edit.backspace(); | |
| 14351 | + assert_eq!(edit.refusal, None, "the reason went with the digit"); | |
| 14352 | + assert_eq!(edit.commit(), Some(4)); | |
| 14353 | + | |
| 14354 | + // Empty, zero, and past the digit cap: each its own reason, none of | |
| 14355 | + // them silent. | |
| 14356 | + assert!(commit_mbps("").is_err()); | |
| 14357 | + assert!(commit_mbps("0").unwrap_err().contains("not a rate")); | |
| 14358 | + assert_eq!(commit_mbps("1"), Ok(MBPS_MIN)); | |
| 14359 | + assert_eq!(commit_mbps("20"), Ok(MBPS_MAX)); | |
| 14360 | + assert!(commit_mbps("21").is_err()); | |
| 14361 | + let mut edit = NumberEdit::new(0); | |
| 14362 | + for digit in [9, 9, 9, 9] { | |
| 14363 | + edit.digit(digit); | |
| 14364 | + } | |
| 14365 | + assert_eq!(edit.text, "999", "the cap holds"); | |
| 14366 | + assert!(edit.refusal.is_some(), "and says it is holding"); | |
| 14367 | + // Never past what a u64 bitrate can be built from -- the committed | |
| 14368 | + // number is the only one that reaches the engine, and it is bounded. | |
| 14369 | + assert!(u64::from(MBPS_MAX) * 1_000_000 < u64::from(u32::MAX)); | |
| 14370 | + assert_eq!(MBPS_DIGITS, 3); | |
| 14371 | + | |
| 14372 | + // The arrows step inside the range and stop at both ends: a walk | |
| 14373 | + // through the legal numbers, never a way out of them. | |
| 14374 | + let mut edit = NumberEdit::new(0); | |
| 14375 | + edit.step(1); | |
| 14376 | + assert_eq!(edit.text, MBPS_MIN.to_string(), "empty starts at the floor"); | |
| 14377 | + edit.step(-1); | |
| 14378 | + assert_eq!(edit.text, MBPS_MIN.to_string()); | |
| 14379 | + let mut edit = NumberEdit::new(MBPS_MAX); | |
| 14380 | + edit.step(1); | |
| 14381 | + assert_eq!(edit.text, MBPS_MAX.to_string()); | |
| 14382 | + edit.step(-1); | |
| 14383 | + assert_eq!(edit.text, (MBPS_MAX - 1).to_string()); | |
| 14384 | + // A step past a refused number clears the refusal with it. | |
| 14385 | + let mut edit = NumberEdit::new(0); | |
| 14386 | + edit.digit(4); | |
| 14387 | + edit.digit(5); | |
| 14388 | + assert_eq!(edit.commit(), None); | |
| 14389 | + edit.step(-1); | |
| 14390 | + assert_eq!(edit.refusal, None); | |
| 14391 | + assert_eq!(edit.text, MBPS_MAX.to_string(), "back inside the range"); | |
| 14392 | + | |
| 14393 | + // The hint the field shows when there is nothing to refuse names both | |
| 14394 | + // ways out of it. | |
| 14395 | + let detail = NumberEdit::new(6).detail(); | |
| 14396 | + assert!(detail.contains("enter") && detail.contains("esc"), "{detail}"); | |
| 14397 | + assert!(detail.starts_with("6▏"), "{detail}"); | |
| 14155 | 14398 | } |
| 14156 | 14399 | |
| 14157 | 14400 | #[test] |
| @@ -15596,6 +15839,7 @@ fn main() { | ||
| 15596 | 15839 | // bitrate the picture asks for. |
| 15597 | 15840 | quality: Quality::Auto, |
| 15598 | 15841 | custom_mbps: 0, |
| 15842 | + mbps_edit: None, | |
| 15599 | 15843 | // ...and the rate the sound has always been written at. |
| 15600 | 15844 | audio_kbps: DEFAULT_AUDIO_KBPS, |
| 15601 | 15845 | // Picture and sound, which is what an export was before |