A card closes and a short clip is hittable without the keyboard
Browse files at this commit8e2a297deb591860a1428323020646b3ba29a095Parent: 4f4dcb4- fix
- a card closes and a short clip is hittable without the keyboard
1 changed file +248 -35
- crates/app/src/main.rs +248 -35
crates/app/src/main.rsmodified+248 -35
| @@ -192,9 +192,10 @@ const SUB_BOTTOM: f32 = 8.; | |||
| 192 | /// the cues are and nothing on it can be dragged -- `HIT_MIN` binds targets, and | 192 | /// the cues are and nothing on it can be dragged -- `HIT_MIN` binds targets, and |
| 193 | /// this row has none. | 193 | /// this row has none. |
| 194 | const SUB_LANE_H: f32 = 16.; | 194 | const SUB_LANE_H: f32 = 16.; |
| 195 | -/// A cue narrower than this is still drawn this wide: a one-frame cue on a | 195 | +/// A mark narrower than this is still drawn this wide: a one-frame cue on a |
| 196 | /// zoomed-out bed is worth a fraction of a pixel, and a mark nobody can see says | 196 | /// zoomed-out bed is worth a fraction of a pixel, and a mark nobody can see says |
| 197 | -/// the track is empty. | 197 | +/// the track is empty. The silence preview's marks are floored by it too -- they |
| 198 | +/// are the same kind of thing, a picture of where something is and no target. | ||
| 198 | const SUB_CUE_MIN_W: f32 = 2.; | 199 | const SUB_CUE_MIN_W: f32 = 2.; |
| 199 | /// How much of the subtitle list in the library column is on screen at once, | 200 | /// How much of the subtitle list in the library column is on screen at once, |
| 200 | /// past which it scrolls -- the media list above it is what keeps the height. | 201 | /// past which it scrolls -- the media list above it is what keeps the height. |
| @@ -485,6 +486,29 @@ fn trims(width: f32) -> bool { | |||
| 485 | width >= 3. * EDGE_W | 486 | width >= 3. * EDGE_W |
| 486 | } | 487 | } |
| 487 | 488 | ||
| 489 | +/// How wide a clip's box is *drawn*, given the width its own length is worth | ||
| 490 | +/// (`span`). Never under [`HIT_MIN`], even where that is wider than the clip is | ||
| 491 | +/// long: zoomed far out a short take is worth a fraction of a pixel, and a box | ||
| 492 | +/// nobody can put a pointer on is a clip that cannot be selected, dragged, given | ||
| 493 | +/// a menu or reached at all -- which is strictly worse than one drawn a few | ||
| 494 | +/// pixels too wide. The same call [`cue_box`] makes for a mark, and what every | ||
| 495 | +/// editor draws. | ||
| 496 | +/// | ||
| 497 | +/// A drawing only: [`Scale::time_at`] still reads the bed, so a press inside the | ||
| 498 | +/// padding names the frame it points at, and the box's head is the clip's own. | ||
| 499 | +fn clip_width(span: f32) -> f32 { | ||
| 500 | + span.max(HIT_MIN) | ||
| 501 | +} | ||
| 502 | + | ||
| 503 | +/// A press that stops here. What every card's body hands its scrim: the scrim | ||
| 504 | +/// closes the card on a press, and the card is painted after it, so this listener | ||
| 505 | +/// runs first (gpui dispatches topmost-first, window.rs:3705) and a press meant | ||
| 506 | +/// for a button never closes the card out from under its own click -- the rule | ||
| 507 | +/// the menus already follow ([`Player::library_card`]). | ||
| 508 | +fn swallow(_: &MouseDownEvent, _: &mut Window, cx: &mut App) { | ||
| 509 | + cx.stop_propagation(); | ||
| 510 | +} | ||
| 511 | + | ||
| 488 | /// How close to an edge a dragged clip has to be let go for it to land *on* it: | 512 | /// How close to an edge a dragged clip has to be let go for it to land *on* it: |
| 489 | /// the snap every timeline has, in pixels rather than frames so that it feels | 513 | /// the snap every timeline has, in pixels rather than frames so that it feels |
| 490 | /// the same at every zoom. Narrower than [`EDGE_W`] -- a hand aiming between two | 514 | /// the same at every zoom. Narrower than [`EDGE_W`] -- a hand aiming between two |
| @@ -2691,6 +2715,35 @@ impl Player { | |||
| 2691 | || self.exporting().is_some() | 2715 | || self.exporting().is_some() |
| 2692 | } | 2716 | } |
| 2693 | 2717 | ||
| 2718 | + /// The pointer's way out of whatever card is up: what every scrim's press | ||
| 2719 | + /// calls, so `esc` is *a* way out and never the only one. One list, and the | ||
| 2720 | + /// same one [`Player::modal`] reads -- a card that can be counted there but | ||
| 2721 | + /// not closed here is a card a hand alone cannot shut, which is what | ||
| 2722 | + /// `every_card_closes_without_the_keyboard` fails on. | ||
| 2723 | + /// | ||
| 2724 | + /// Every card at once because only one is ever up (`export_open`): closing | ||
| 2725 | + /// "the" card and closing all of them are the same act. | ||
| 2726 | + fn close_card(&mut self) { | ||
| 2727 | + self.keys_open = false; | ||
| 2728 | + self.keys_search.clear(); | ||
| 2729 | + self.rebinding = None; | ||
| 2730 | + self.export_open = false; | ||
| 2731 | + // The two things typed *into* the export card go with it: a field left | ||
| 2732 | + // open would take the next keystroke for a card that is gone. | ||
| 2733 | + self.mbps_edit = None; | ||
| 2734 | + self.picker = None; | ||
| 2735 | + self.eq_open = None; | ||
| 2736 | + self.eq_dragging = false; | ||
| 2737 | + self.color_open = None; | ||
| 2738 | + self.speed_open = None; | ||
| 2739 | + // Marks and a running scan go with this one, which is why it is a call | ||
| 2740 | + // and not an assignment ([`Player::close_silence`]). | ||
| 2741 | + if self.silence_open.is_some() { | ||
| 2742 | + self.close_silence(); | ||
| 2743 | + } | ||
| 2744 | + self.mix_open = false; | ||
| 2745 | + } | ||
| 2746 | + | ||
| 2694 | /// Which of [`Repeat`]'s three the window is in, for the hold gate at the | 2747 | /// Which of [`Repeat`]'s three the window is in, for the hold gate at the |
| 2695 | /// top of the key handler. Not [`Player::modal`]: that asks whether an | 2748 | /// top of the key handler. Not [`Player::modal`]: that asks whether an |
| 2696 | /// overlay is up at all, and here the cards with sliders in them are | 2749 | /// overlay is up at all, and here the cards with sliders in them are |
| @@ -6911,7 +6964,7 @@ impl Player { | |||
| 6911 | // left under it -- a filter that found nothing has to say so, or the | 6964 | // left under it -- a filter that found nothing has to say so, or the |
| 6912 | // card reads as a list that lost its rows. | 6965 | // card reads as a list that lost its rows. |
| 6913 | let search = if self.keys_search.is_empty() { | 6966 | let search = if self.keys_search.is_empty() { |
| 6914 | - "search: type to filter · ↑ ↓ scroll the list".to_string() | 6967 | + "search: type to filter · ↑ ↓ scroll the list · a click away closes".to_string() |
| 6915 | } else { | 6968 | } else { |
| 6916 | let rows = found | 6969 | let rows = found |
| 6917 | .iter() | 6970 | .iter() |
| @@ -7022,14 +7075,22 @@ impl Player { | |||
| 7022 | .justify_center() | 7075 | .justify_center() |
| 7023 | .items_center() | 7076 | .items_center() |
| 7024 | // The picture behind is out of reach, and looks it. The press is | 7077 | // The picture behind is out of reach, and looks it. The press is |
| 7025 | - // swallowed here so a button under the scrim cannot take it. | 7078 | + // swallowed here so a button under the scrim cannot take it -- |
| 7079 | + // and it closes the card on the way, which is the pointer's exit | ||
| 7080 | + // from every card here ([`Player::close_card`]). | ||
| 7026 | .bg(rgba(0x101010cc)) | 7081 | .bg(rgba(0x101010cc)) |
| 7027 | - .on_mouse_down(MouseButton::Left, |_: &MouseDownEvent, _, cx| { | 7082 | + .on_mouse_down( |
| 7028 | - cx.stop_propagation() | 7083 | + MouseButton::Left, |
| 7029 | - }) | 7084 | + cx.listener(|this, _: &MouseDownEvent, _, cx| { |
| 7085 | + this.close_card(); | ||
| 7086 | + cx.notify(); | ||
| 7087 | + cx.stop_propagation(); | ||
| 7088 | + }), | ||
| 7089 | + ) | ||
| 7030 | .child( | 7090 | .child( |
| 7031 | div() | 7091 | div() |
| 7032 | .w(px(KEYS_W)) | 7092 | .w(px(KEYS_W)) |
| 7093 | + .on_mouse_down(MouseButton::Left, swallow) | ||
| 7033 | .flex() | 7094 | .flex() |
| 7034 | .flex_col() | 7095 | .flex_col() |
| 7035 | .gap(px(2.)) | 7096 | .gap(px(2.)) |
| @@ -7524,12 +7585,19 @@ impl Player { | |||
| 7524 | .justify_center() | 7585 | .justify_center() |
| 7525 | .items_center() | 7586 | .items_center() |
| 7526 | .bg(rgba(0x101010cc)) | 7587 | .bg(rgba(0x101010cc)) |
| 7527 | - .on_mouse_down(MouseButton::Left, |_: &MouseDownEvent, _, cx| { | 7588 | + // Click away closes it, as on every card here. |
| 7528 | - cx.stop_propagation() | 7589 | + .on_mouse_down( |
| 7529 | - }) | 7590 | + MouseButton::Left, |
| 7591 | + cx.listener(|this, _: &MouseDownEvent, _, cx| { | ||
| 7592 | + this.close_card(); | ||
| 7593 | + cx.notify(); | ||
| 7594 | + cx.stop_propagation(); | ||
| 7595 | + }), | ||
| 7596 | + ) | ||
| 7530 | .child( | 7597 | .child( |
| 7531 | div() | 7598 | div() |
| 7532 | .w(px(EXPORT_W)) | 7599 | .w(px(EXPORT_W)) |
| 7600 | + .on_mouse_down(MouseButton::Left, swallow) | ||
| 7533 | .flex() | 7601 | .flex() |
| 7534 | .flex_col() | 7602 | .flex_col() |
| 7535 | .gap(px(2.)) | 7603 | .gap(px(2.)) |
| @@ -7561,7 +7629,7 @@ impl Player { | |||
| 7561 | } | 7629 | } |
| 7562 | (None, Some(notice)) => notice.clone(), | 7630 | (None, Some(notice)) => notice.clone(), |
| 7563 | (None, None) => "the keys are on the rows · enter exports · \ | 7631 | (None, None) => "the keys are on the rows · enter exports · \ |
| 7564 | - esc closes · g/r change the layout" | 7632 | + a click away or esc closes · g/r change the layout" |
| 7565 | .into(), | 7633 | .into(), |
| 7566 | }), | 7634 | }), |
| 7567 | ) | 7635 | ) |
| @@ -7820,12 +7888,19 @@ impl Player { | |||
| 7820 | .justify_center() | 7888 | .justify_center() |
| 7821 | .items_center() | 7889 | .items_center() |
| 7822 | .bg(rgba(0x101010cc)) | 7890 | .bg(rgba(0x101010cc)) |
| 7823 | - .on_mouse_down(MouseButton::Left, |_: &MouseDownEvent, _, cx| { | 7891 | + // Click away closes it, as on every card here. |
| 7824 | - cx.stop_propagation() | 7892 | + .on_mouse_down( |
| 7825 | - }) | 7893 | + MouseButton::Left, |
| 7894 | + cx.listener(|this, _: &MouseDownEvent, _, cx| { | ||
| 7895 | + this.close_card(); | ||
| 7896 | + cx.notify(); | ||
| 7897 | + cx.stop_propagation(); | ||
| 7898 | + }), | ||
| 7899 | + ) | ||
| 7826 | .child( | 7900 | .child( |
| 7827 | div() | 7901 | div() |
| 7828 | .w(px(eq_card_w(f32::from(viewport.width)))) | 7902 | .w(px(eq_card_w(f32::from(viewport.width)))) |
| 7903 | + .on_mouse_down(MouseButton::Left, swallow) | ||
| 7829 | .flex() | 7904 | .flex() |
| 7830 | .flex_col() | 7905 | .flex_col() |
| 7831 | .gap(px(2.)) | 7906 | .gap(px(2.)) |
| @@ -7846,7 +7921,7 @@ impl Player { | |||
| 7846 | .text_size(px(11.)) | 7921 | .text_size(px(11.)) |
| 7847 | .text_color(rgb(INK_DIM)) | 7922 | .text_color(rgb(INK_DIM)) |
| 7848 | .child(self.notice.clone().unwrap_or_else(|| { | 7923 | .child(self.notice.clone().unwrap_or_else(|| { |
| 7849 | - "drag a handle, or a digit picks a band — ←→ moves it, ↑↓ its gain, shift+←→ its width; a adds, x removes, f flattens it, r all, s spectrum, esc closes".into() | 7924 | + "drag a handle, or a digit picks a band — ←→ moves it, ↑↓ its gain, shift+←→ its width; a adds, x removes, f flattens it, r all, s spectrum; a click away or esc closes".into() |
| 7850 | })), | 7925 | })), |
| 7851 | ) | 7926 | ) |
| 7852 | .child(graph) | 7927 | .child(graph) |
| @@ -8140,12 +8215,19 @@ impl Player { | |||
| 8140 | .justify_center() | 8215 | .justify_center() |
| 8141 | .items_center() | 8216 | .items_center() |
| 8142 | .bg(rgba(0x101010cc)) | 8217 | .bg(rgba(0x101010cc)) |
| 8143 | - .on_mouse_down(MouseButton::Left, |_: &MouseDownEvent, _, cx| { | 8218 | + // Click away closes it, as on every card here. |
| 8144 | - cx.stop_propagation() | 8219 | + .on_mouse_down( |
| 8145 | - }) | 8220 | + MouseButton::Left, |
| 8221 | + cx.listener(|this, _: &MouseDownEvent, _, cx| { | ||
| 8222 | + this.close_card(); | ||
| 8223 | + cx.notify(); | ||
| 8224 | + cx.stop_propagation(); | ||
| 8225 | + }), | ||
| 8226 | + ) | ||
| 8146 | .child( | 8227 | .child( |
| 8147 | div() | 8228 | div() |
| 8148 | .w(px(COLOR_W)) | 8229 | .w(px(COLOR_W)) |
| 8230 | + .on_mouse_down(MouseButton::Left, swallow) | ||
| 8149 | .flex() | 8231 | .flex() |
| 8150 | .flex_col() | 8232 | .flex_col() |
| 8151 | .gap(px(2.)) | 8233 | .gap(px(2.)) |
| @@ -8164,7 +8246,7 @@ impl Player { | |||
| 8164 | .text_size(px(11.)) | 8246 | .text_size(px(11.)) |
| 8165 | .text_color(rgb(INK_DIM)) | 8247 | .text_color(rgb(INK_DIM)) |
| 8166 | .child( | 8248 | .child( |
| 8167 | - "drag a bar, or ↑↓ picks one and ←→ moves it, r resets — esc closes", | 8249 | + "drag a bar, or ↑↓ picks one and ←→ moves it, r resets — a click away or esc closes", |
| 8168 | ), | 8250 | ), |
| 8169 | ) | 8251 | ) |
| 8170 | // The frame as it is being graded, over the controls | 8252 | // The frame as it is being graded, over the controls |
| @@ -8251,12 +8333,19 @@ impl Player { | |||
| 8251 | .justify_center() | 8333 | .justify_center() |
| 8252 | .items_center() | 8334 | .items_center() |
| 8253 | .bg(rgba(0x101010cc)) | 8335 | .bg(rgba(0x101010cc)) |
| 8254 | - .on_mouse_down(MouseButton::Left, |_: &MouseDownEvent, _, cx| { | 8336 | + // Click away closes it, as on every card here. |
| 8255 | - cx.stop_propagation() | 8337 | + .on_mouse_down( |
| 8256 | - }) | 8338 | + MouseButton::Left, |
| 8339 | + cx.listener(|this, _: &MouseDownEvent, _, cx| { | ||
| 8340 | + this.close_card(); | ||
| 8341 | + cx.notify(); | ||
| 8342 | + cx.stop_propagation(); | ||
| 8343 | + }), | ||
| 8344 | + ) | ||
| 8257 | .child( | 8345 | .child( |
| 8258 | div() | 8346 | div() |
| 8259 | .w(px(COLOR_W)) | 8347 | .w(px(COLOR_W)) |
| 8348 | + .on_mouse_down(MouseButton::Left, swallow) | ||
| 8260 | .flex() | 8349 | .flex() |
| 8261 | .flex_col() | 8350 | .flex_col() |
| 8262 | .gap(px(6.)) | 8351 | .gap(px(6.)) |
| @@ -8275,7 +8364,7 @@ impl Player { | |||
| 8275 | .text_size(px(11.)) | 8364 | .text_size(px(11.)) |
| 8276 | .text_color(rgb(INK_DIM)) | 8365 | .text_color(rgb(INK_DIM)) |
| 8277 | .child( | 8366 | .child( |
| 8278 | - "drag the bar or ←→ moves it, r is 1.00x — the pitch moves with the rate; esc closes", | 8367 | + "drag the bar or ←→ moves it, r is 1.00x — the pitch moves with the rate; a click away or esc closes", |
| 8279 | ), | 8368 | ), |
| 8280 | ) | 8369 | ) |
| 8281 | .child( | 8370 | .child( |
| @@ -8443,12 +8532,19 @@ impl Player { | |||
| 8443 | .justify_center() | 8532 | .justify_center() |
| 8444 | .items_center() | 8533 | .items_center() |
| 8445 | .bg(rgba(0x101010cc)) | 8534 | .bg(rgba(0x101010cc)) |
| 8446 | - .on_mouse_down(MouseButton::Left, |_: &MouseDownEvent, _, cx| { | 8535 | + // Click away closes it, as on every card here. |
| 8447 | - cx.stop_propagation() | 8536 | + .on_mouse_down( |
| 8448 | - }) | 8537 | + MouseButton::Left, |
| 8538 | + cx.listener(|this, _: &MouseDownEvent, _, cx| { | ||
| 8539 | + this.close_card(); | ||
| 8540 | + cx.notify(); | ||
| 8541 | + cx.stop_propagation(); | ||
| 8542 | + }), | ||
| 8543 | + ) | ||
| 8449 | .child( | 8544 | .child( |
| 8450 | div() | 8545 | div() |
| 8451 | .w(px(COLOR_W)) | 8546 | .w(px(COLOR_W)) |
| 8547 | + .on_mouse_down(MouseButton::Left, swallow) | ||
| 8452 | .max_h(px(360. - 24.)) | 8548 | .max_h(px(360. - 24.)) |
| 8453 | .flex() | 8549 | .flex() |
| 8454 | .flex_col() | 8550 | .flex_col() |
| @@ -8469,7 +8565,7 @@ impl Player { | |||
| 8469 | .text_size(px(11.)) | 8565 | .text_size(px(11.)) |
| 8470 | .text_color(rgb(INK_DIM)) | 8566 | .text_color(rgb(INK_DIM)) |
| 8471 | .child( | 8567 | .child( |
| 8472 | - "− and + move a setting, or ↑↓ picks one and ←→ moves it (hold to run it) — a track fader moves everything on that track; esc closes", | 8568 | + "− and + move a setting, or ↑↓ picks one and ←→ moves it (hold to run it) — a track fader moves everything on that track; a click away or esc closes", |
| 8473 | ), | 8569 | ), |
| 8474 | ) | 8570 | ) |
| 8475 | .child( | 8571 | .child( |
| @@ -8654,12 +8750,20 @@ impl Player { | |||
| 8654 | // Light enough to read the lanes and the marks on them through: | 8750 | // Light enough to read the lanes and the marks on them through: |
| 8655 | // the preview is the point of this card. | 8751 | // the preview is the point of this card. |
| 8656 | .bg(rgba(0x10101055)) | 8752 | .bg(rgba(0x10101055)) |
| 8657 | - .on_mouse_down(MouseButton::Left, |_: &MouseDownEvent, _, cx| { | 8753 | + // Click away closes it, as on every card here -- and the marks |
| 8658 | - cx.stop_propagation() | 8754 | + // go with it, which is what makes this one a call and not a flag. |
| 8659 | - }) | 8755 | + .on_mouse_down( |
| 8756 | + MouseButton::Left, | ||
| 8757 | + cx.listener(|this, _: &MouseDownEvent, _, cx| { | ||
| 8758 | + this.close_card(); | ||
| 8759 | + cx.notify(); | ||
| 8760 | + cx.stop_propagation(); | ||
| 8761 | + }), | ||
| 8762 | + ) | ||
| 8660 | .child( | 8763 | .child( |
| 8661 | div() | 8764 | div() |
| 8662 | .w(px(COLOR_W)) | 8765 | .w(px(COLOR_W)) |
| 8766 | + .on_mouse_down(MouseButton::Left, swallow) | ||
| 8663 | .flex() | 8767 | .flex() |
| 8664 | .flex_col() | 8768 | .flex_col() |
| 8665 | .gap(px(6.)) | 8769 | .gap(px(6.)) |
| @@ -8678,7 +8782,7 @@ impl Player { | |||
| 8678 | .text_size(px(11.)) | 8782 | .text_size(px(11.)) |
| 8679 | .text_color(rgb(INK_DIM)) | 8783 | .text_color(rgb(INK_DIM)) |
| 8680 | .child( | 8784 | .child( |
| 8681 | - "− and + move a setting, or ↑↓ picks one and ←→ moves it (hold to run it) — the marks on the lane are what would go; esc closes", | 8785 | + "− and + move a setting, or ↑↓ picks one and ←→ moves it (hold to run it) — the marks on the lane are what would go; a click away or esc closes", |
| 8682 | ), | 8786 | ), |
| 8683 | ) | 8787 | ) |
| 8684 | .children(rows) | 8788 | .children(rows) |
| @@ -9617,7 +9721,11 @@ impl Player { | |||
| 9617 | // streams of one file are two sources, and the library | 9721 | // streams of one file are two sources, and the library |
| 9618 | // gives them one swatch because they are one file. | 9722 | // gives them one swatch because they are one file. |
| 9619 | let tint = self.clip_tint(clip.source); | 9723 | let tint = self.clip_tint(clip.source); |
| 9620 | - let width = scale.width_px(len); | 9724 | + // What the clip is worth in pixels, and how wide its box |
| 9725 | + // is drawn -- the two part company on a take too short | ||
| 9726 | + // to be hit at this zoom ([`clip_width`]). | ||
| 9727 | + let span = scale.width_px(len); | ||
| 9728 | + let width = clip_width(span); | ||
| 9621 | let left = scale.px_at(start); | 9729 | let left = scale.px_at(start); |
| 9622 | // The slice of this box that is on the bed: where its | 9730 | // The slice of this box that is on the bed: where its |
| 9623 | // name, its badge and its waveform go, so none of the | 9731 | // name, its badge and its waveform go, so none of the |
| @@ -9720,10 +9828,17 @@ impl Player { | |||
| 9720 | // them, which is what keeps one gesture one thing: | 9828 | // them, which is what keeps one gesture one thing: |
| 9721 | // a press here trims, a press anywhere else on the | 9829 | // a press here trims, a press anywhere else on the |
| 9722 | // box still starts the move to another lane. | 9830 | // box still starts the move to another lane. |
| 9831 | + // | ||
| 9832 | + // Asked of the clip's own width and not of the box's | ||
| 9833 | + // floor: a take drawn at `HIT_MIN` because it is | ||
| 9834 | + // shorter than that has no *pixels* to trim by -- one | ||
| 9835 | + // would move it by seconds -- so it keeps all of its | ||
| 9836 | + // padded box as a body to select and drag by, and is | ||
| 9837 | + // trimmed after zooming in, exactly as [`trims`] says. | ||
| 9723 | .children( | 9838 | .children( |
| 9724 | [Edge::Start, Edge::End] | 9839 | [Edge::Start, Edge::End] |
| 9725 | .into_iter() | 9840 | .into_iter() |
| 9726 | - .filter(|_| trims(width)) | 9841 | + .filter(|_| trims(span)) |
| 9727 | .map(|edge| { | 9842 | .map(|edge| { |
| 9728 | let mut zone = div() | 9843 | let mut zone = div() |
| 9729 | .absolute() | 9844 | .absolute() |
| @@ -9869,7 +9984,14 @@ impl Player { | |||
| 9869 | .top_0() | 9984 | .top_0() |
| 9870 | .h_full() | 9985 | .h_full() |
| 9871 | .left(px(scale.px_at(f64::from(at) / self.fps))) | 9986 | .left(px(scale.px_at(f64::from(at) / self.fps))) |
| 9872 | - .w(px(scale.width_px(f64::from(len) / self.fps))) | 9987 | + // Floored like a cue's mark and for the same |
| 9988 | + // reason: a half-second silence on a zoomed- | ||
| 9989 | + // out bed rounds to nothing, and a preview | ||
| 9990 | + // that draws nothing reads as a scan that | ||
| 9991 | + // found nothing. | ||
| 9992 | + .w(px(scale | ||
| 9993 | + .width_px(f64::from(len) / self.fps) | ||
| 9994 | + .max(SUB_CUE_MIN_W))) | ||
| 9873 | .bg(rgba(0x4a9effaa)) | 9995 | .bg(rgba(0x4a9effaa)) |
| 9874 | }), | 9996 | }), |
| 9875 | ) | 9997 | ) |
| @@ -13283,7 +13405,7 @@ mod tests { | |||
| 13283 | Landing, arrival, launch_queue, | 13405 | Landing, arrival, launch_queue, |
| 13284 | read_ahead, scan_plan, seek_line, silence_line, stash_or_write, | 13406 | read_ahead, scan_plan, seek_line, silence_line, stash_or_write, |
| 13285 | repeats, resolution_choices, resolution_ladder, span_label, tone_choices, tone_label, | 13407 | repeats, resolution_choices, resolution_ladder, span_label, tone_choices, tone_label, |
| 13286 | - trimmed_clip, trims, unscannable, | 13408 | + clip_width, trimmed_clip, trims, unscannable, |
| 13287 | visible_slice, | 13409 | visible_slice, |
| 13288 | }; | 13410 | }; |
| 13289 | use super::{ | 13411 | use super::{ |
| @@ -13922,6 +14044,97 @@ mod tests { | |||
| 13922 | } | 14044 | } |
| 13923 | } | 14045 | } |
| 13924 | 14046 | ||
| 14047 | + /// The other half of "getting out of a card is a `Reach::Gesture`": the | ||
| 14048 | + /// gesture has to exist. Every card's scrim closes it on a press, so a hand | ||
| 14049 | + /// that never touches the keyboard can shut every one of them -- for seven | ||
| 14050 | + /// cards `esc` was the only exit, which is the same complaint as an action | ||
| 14051 | + /// reachable by stroke alone, said about the way out instead of the way in. | ||
| 14052 | + /// | ||
| 14053 | + /// Read off [`Player::modal`] rather than off a list written here: a card | ||
| 14054 | + /// counted there and not closed by [`Player::close_card`] fails this test | ||
| 14055 | + /// the day it is added, which is the only way the two stay in step. | ||
| 14056 | + #[test] | ||
| 14057 | + fn every_card_closes_without_the_keyboard() { | ||
| 14058 | + let source = include_str!("main.rs") | ||
| 14059 | + .split("#[cfg(test)]") | ||
| 14060 | + .next() | ||
| 14061 | + .unwrap(); | ||
| 14062 | + // A fn's source, up to the next one: enough of a body to scan. | ||
| 14063 | + let body = |name: &str| -> &str { | ||
| 14064 | + let at = source | ||
| 14065 | + .find(&format!("fn {name}(")) | ||
| 14066 | + .unwrap_or_else(|| panic!("no fn {name} in main.rs")); | ||
| 14067 | + let rest = &source[at..]; | ||
| 14068 | + &rest[..rest[1..].find("\n fn ").map_or(rest.len(), |e| e + 1)] | ||
| 14069 | + }; | ||
| 14070 | + for card in [ | ||
| 14071 | + "keys_overlay", | ||
| 14072 | + "export_card", | ||
| 14073 | + "eq_card", | ||
| 14074 | + "color_card", | ||
| 14075 | + "speed_card", | ||
| 14076 | + "mix_card", | ||
| 14077 | + "silence_card", | ||
| 14078 | + ] { | ||
| 14079 | + let src = body(card); | ||
| 14080 | + assert!( | ||
| 14081 | + src.contains("this.close_card()"), | ||
| 14082 | + "{card}'s scrim swallows the press without closing the card: \ | ||
| 14083 | + escape is the only way out of it" | ||
| 14084 | + ); | ||
| 14085 | + assert!( | ||
| 14086 | + src.contains("MouseButton::Left, swallow"), | ||
| 14087 | + "{card}'s body does not swallow its own presses, so a press on \ | ||
| 14088 | + one of its controls would close the card under itself" | ||
| 14089 | + ); | ||
| 14090 | + } | ||
| 14091 | + // ...and every state that makes the window modal is a state that press | ||
| 14092 | + // clears. `exporting()` is not one of them: a running export is a job | ||
| 14093 | + // with a cancel button, not a card with a scrim. | ||
| 14094 | + let close = body("close_card"); | ||
| 14095 | + for field in body("modal").split("self.").skip(1).filter_map(|rest| { | ||
| 14096 | + let name: String = rest | ||
| 14097 | + .chars() | ||
| 14098 | + .take_while(|c| c.is_alphanumeric() || *c == '_') | ||
| 14099 | + .collect(); | ||
| 14100 | + (!rest[name.len()..].starts_with('(')).then_some(name) | ||
| 14101 | + }) { | ||
| 14102 | + assert!( | ||
| 14103 | + close.contains(&format!("self.{field}")), | ||
| 14104 | + "{field} makes the window modal and `close_card` leaves it set: \ | ||
| 14105 | + that card cannot be closed by pointer" | ||
| 14106 | + ); | ||
| 14107 | + } | ||
| 14108 | + } | ||
| 14109 | + | ||
| 14110 | + /// A clip too short to hit is still a clip: at a far zoom-out its box is | ||
| 14111 | + /// drawn [`HIT_MIN`] wide rather than the fraction of a pixel it is worth, | ||
| 14112 | + /// because a box nobody can put a pointer on cannot be selected, dragged, | ||
| 14113 | + /// trimmed or given a menu -- and an invisible unselectable take is strictly | ||
| 14114 | + /// worse than one drawn a few pixels too wide. | ||
| 14115 | + #[test] | ||
| 14116 | + fn a_clip_box_is_never_narrower_than_its_target() { | ||
| 14117 | + // Two seconds on a bed showing an hour: a fifth of a pixel. | ||
| 14118 | + let far = Scale { | ||
| 14119 | + pps: 0.1, | ||
| 14120 | + start: 0., | ||
| 14121 | + }; | ||
| 14122 | + assert!(far.width_px(2.) < 1., "the fixture is not zoomed out enough"); | ||
| 14123 | + assert_eq!(clip_width(far.width_px(2.)), HIT_MIN); | ||
| 14124 | + // Zero is the floor's own case: a clip trimmed to nothing, and the | ||
| 14125 | + // width a lane draws before its first frame is measured. | ||
| 14126 | + assert_eq!(clip_width(0.), HIT_MIN); | ||
| 14127 | + // What is already wide enough keeps its own width, to the pixel: the | ||
| 14128 | + // floor is a floor and never a resize. | ||
| 14129 | + let near = Scale::default(); | ||
| 14130 | + assert_eq!(clip_width(near.width_px(5.)), near.width_px(5.)); | ||
| 14131 | + // ...and the padding is not trimmable: the strips are asked of the | ||
| 14132 | + // clip's own width, so a box drawn wider than its length keeps all of | ||
| 14133 | + // that box as a body to select and drag by ([`trims`]). | ||
| 14134 | + assert!(!trims(far.width_px(2.))); | ||
| 14135 | + assert!(clip_width(far.width_px(2.)) >= HIT_MIN); | ||
| 14136 | + } | ||
| 14137 | + | ||
| 13925 | /// What the Detach and Group items do to a real timeline: a music video's | 14138 | /// What the Detach and Group items do to a real timeline: a music video's |
| 13926 | /// sound comes off its picture, Delete on the loose half takes that half | 14139 | /// sound comes off its picture, Delete on the loose half takes that half |
| 13927 | /// only, undo puts both back, and Group makes the two one take again -- | 14140 | /// only, undo puts both back, and Group makes the two one take again -- |