A menu offers what applies, fits the window, and nothing paints over it
Browse files at this commit8a2e8137345a782453e427d113b215ce8731ebdcParent: c52b667- fix
- a menu offers what applies, fits the window, and nothing paints over it
2 changed files +441 -125
- crates/app/src/keymap.rs +4 -1
- crates/app/src/main.rs +437 -124
crates/app/src/keymap.rsmodified+4 -1
| @@ -125,7 +125,10 @@ impl ActionId { | ||
| 125 | 125 | ActionId::Paste => "Paste", |
| 126 | 126 | ActionId::Cut => "Cut", |
| 127 | 127 | ActionId::Regroup => "Regroup", |
| 128 | - ActionId::Detach => "Detach the sound from the picture", | |
| 128 | + // Neither half's action: it takes the *pair* apart, and the menu | |
| 129 | + // that offers it hangs on whichever half was right-clicked -- worded | |
| 130 | + // from the picture's side it read as a video item on an audio clip. | |
| 131 | + ActionId::Detach => "Ungroup the picture and the sound", | |
| 129 | 132 | ActionId::Group => "Group with the clip on another track", |
| 130 | 133 | ActionId::Select => "Select the clip under the playhead (again for the next lane)", |
| 131 | 134 | ActionId::SelectNext => "Select the next clip in the lane", |
crates/app/src/main.rsmodified+437 -124
| @@ -7,6 +7,7 @@ use std::collections::HashMap; | ||
| 7 | 7 | use std::path::{Path, PathBuf}; |
| 8 | 8 | use std::rc::Rc; |
| 9 | 9 | use std::sync::Arc; |
| 10 | +use std::sync::atomic::{AtomicBool, Ordering}; | |
| 10 | 11 | use std::time::{Duration, Instant}; |
| 11 | 12 | |
| 12 | 13 | use engine::audio::StreamInfo; |
| @@ -134,7 +135,13 @@ const RULER_HIT_H: f32 = HIT_MIN; | ||
| 134 | 135 | const TIME_W: f32 = 200.; |
| 135 | 136 | /// The keybindings card: a row per action, a title and a status line, inside a |
| 136 | 137 | /// 360 px tall window. The rows are click targets, so `HIT_MIN` binds them too. |
| 137 | -const KEYS_W: f32 = 320.; | |
| 138 | +/// Wider than the export card, and for the same reason that one is wider than | |
| 139 | +/// this used to be: at 320 the longest labels ("Remove the last video track (it | |
| 140 | +/// must be empty)") ran straight over the stroke printed at the other end of | |
| 141 | +/// their row. Every label in the registry fits beside its stroke here, and the | |
| 142 | +/// one that cannot -- a row waiting for a key to be pressed -- truncates rather | |
| 143 | +/// than overprinting. Still inside the 640 px floor. | |
| 144 | +const KEYS_W: f32 = 480.; | |
| 138 | 145 | const KEYS_ROW_H: f32 = HIT_MIN; |
| 139 | 146 | /// How much of the row list is on screen at once; past this it scrolls. What |
| 140 | 147 | /// keeps the card inside the smallest window no matter how many actions the |
| @@ -168,11 +175,6 @@ const EXPORT_FIXED_H: f32 = 17. + 28. + 15. + 30. + CONTROL_H + 4. + 10. + 24.; | ||
| 168 | 175 | const MENU_W: f32 = 260.; |
| 169 | 176 | const MENU_ROW_H: f32 = HIT_MIN; |
| 170 | 177 | const MENU_PAD: f32 = 6.; |
| 171 | -/// How much of the item list is on screen at once, capped and scrolling like the | |
| 172 | -/// keybindings and export lists: every action the pointer can reach is an item | |
| 173 | -/// here, and a menu taller than the 640x360 floor would hang its last items off | |
| 174 | -/// the bottom edge, where nobody can click them. | |
| 175 | -const MENU_ROWS_H: f32 = 12. * MENU_ROW_H; | |
| 176 | 178 | |
| 177 | 179 | /// The subtitle over the picture: white on a black plate, because a cue is read |
| 178 | 180 | /// against whatever the film happens to be showing under it and the chrome's own |
| @@ -500,6 +502,18 @@ fn clip_width(span: f32) -> f32 { | ||
| 500 | 502 | span.max(HIT_MIN) |
| 501 | 503 | } |
| 502 | 504 | |
| 505 | +/// The sheet a card or a menu is painted on: the whole window, and the mouse | |
| 506 | +/// stops at it. Occluding is what tells gpui that nothing under this sheet is | |
| 507 | +/// hovered any more (`Hitbox::is_hovered`) -- without it the window carries on | |
| 508 | +/// hovering behind an open menu and pops *its* tooltip over the menu's items, | |
| 509 | +/// which is a card being painted over by the thing it covers. | |
| 510 | +/// | |
| 511 | +/// Every card and every menu takes its sheet from here, so no surface can be | |
| 512 | +/// drawn over the top of one by having been given a plain scrim. | |
| 513 | +fn scrim() -> Div { | |
| 514 | + div().absolute().inset_0().occlude() | |
| 515 | +} | |
| 516 | + | |
| 503 | 517 | /// A press that stops here. What every card's body hands its scrim: the scrim |
| 504 | 518 | /// closes the card on a press, and the card is painted after it, so this listener |
| 505 | 519 | /// runs first (gpui dispatches topmost-first, window.rs:3705) and a press meant |
| @@ -618,8 +632,11 @@ impl RowItem { | ||
| 618 | 632 | /// the item will do to the timeline, so nothing here is a surprise. |
| 619 | 633 | fn hint(self) -> &'static str { |
| 620 | 634 | match self { |
| 621 | - Self::Add => "inserts the whole file", | |
| 622 | - Self::Remove => "only if nothing plays it", | |
| 635 | + // Short enough to sit beside its label inside `MENU_W`, the clip | |
| 636 | + // menu's rule for a refusal: this column truncates, and a hint cut | |
| 637 | + // off mid-word says less than a shorter one. | |
| 638 | + Self::Add => "the whole file", | |
| 639 | + Self::Remove => "nothing plays it", | |
| 623 | 640 | Self::Reveal => "file manager", |
| 624 | 641 | Self::Properties => "…", |
| 625 | 642 | } |
| @@ -1703,29 +1720,76 @@ impl Player { | ||
| 1703 | 1720 | /// |
| 1704 | 1721 | /// The player's half of [`enable`]: it reads the state, the table decides. |
| 1705 | 1722 | fn enable(&self, action: ActionId, on: Option<(Lane, usize)>) -> Enable { |
| 1723 | + enable(action, self.ctx(on)) | |
| 1724 | + } | |
| 1725 | + | |
| 1726 | + /// The state every one of those questions is asked against, read off the | |
| 1727 | + /// player once: [`menu_items`] filters a whole menu with it, so the rows a | |
| 1728 | + /// menu draws and the answers it dims them by come from the same reading. | |
| 1729 | + fn ctx(&self, on: Option<(Lane, usize)>) -> Ctx { | |
| 1706 | 1730 | let Some(session) = &self.session else { |
| 1707 | - return enable(action, Ctx::default()); | |
| 1731 | + return Ctx::default(); | |
| 1708 | 1732 | }; |
| 1709 | 1733 | let clip = on |
| 1710 | 1734 | .or(self.selected) |
| 1711 | 1735 | .and_then(|(lane, idx)| session.lane_clips(lane).get(idx).map(|clip| (*clip, lane))); |
| 1712 | - enable( | |
| 1713 | - action, | |
| 1714 | - Ctx { | |
| 1715 | - clip, | |
| 1716 | - image: clip.is_some_and(|(clip, _)| { | |
| 1717 | - session | |
| 1718 | - .sources() | |
| 1719 | - .get(clip.source) | |
| 1720 | - .is_some_and(|s| engine::is_image(&s.path)) | |
| 1721 | - }), | |
| 1722 | - playhead: frame_at(session.now(), self.fps), | |
| 1723 | - timeline: true, | |
| 1724 | - clipboard: self.clipboard.is_some(), | |
| 1725 | - subtitles: !session.subtitles().is_empty(), | |
| 1726 | - exporting: self.exporting().is_some(), | |
| 1727 | - }, | |
| 1728 | - ) | |
| 1736 | + Ctx { | |
| 1737 | + clip, | |
| 1738 | + image: clip.is_some_and(|(clip, _)| { | |
| 1739 | + session | |
| 1740 | + .sources() | |
| 1741 | + .get(clip.source) | |
| 1742 | + .is_some_and(|s| engine::is_image(&s.path)) | |
| 1743 | + }), | |
| 1744 | + playhead: frame_at(session.now(), self.fps), | |
| 1745 | + timeline: true, | |
| 1746 | + clipboard: self.clipboard.is_some(), | |
| 1747 | + subtitles: !session.subtitles().is_empty(), | |
| 1748 | + exporting: self.exporting().is_some(), | |
| 1749 | + } | |
| 1750 | + } | |
| 1751 | + | |
| 1752 | + /// The same reading for a library row: whether this file can join this | |
| 1753 | + /// timeline -- the very answer the list greys the row by, so the menu over a | |
| 1754 | + /// row and the row under it cannot disagree -- and how many clips play it. | |
| 1755 | + /// [`Player::ctx`] for the other panel. | |
| 1756 | + fn row_ctx(&self, path: &Path, stream: usize) -> RowCtx { | |
| 1757 | + let placed = self.session.as_ref().map_or(0, |session| { | |
| 1758 | + let of_row = session | |
| 1759 | + .sources() | |
| 1760 | + .iter() | |
| 1761 | + .position(|s| s.path == path && s.audio_stream == stream); | |
| 1762 | + of_row.map_or(0, |idx| { | |
| 1763 | + session | |
| 1764 | + .lanes() | |
| 1765 | + .into_iter() | |
| 1766 | + .flat_map(|lane| session.lane_clips(lane)) | |
| 1767 | + .filter(|c| c.source == idx) | |
| 1768 | + .count() | |
| 1769 | + }) | |
| 1770 | + }); | |
| 1771 | + let sources = self | |
| 1772 | + .session | |
| 1773 | + .as_ref() | |
| 1774 | + .map_or(&[][..], PlaybackSession::sources); | |
| 1775 | + RowCtx { | |
| 1776 | + timeline: self.session.is_some(), | |
| 1777 | + exporting: self.exporting().is_some(), | |
| 1778 | + usable: library_rows( | |
| 1779 | + sources, | |
| 1780 | + &self.streams, | |
| 1781 | + &self.decoders, | |
| 1782 | + self.timeline_audio(), | |
| 1783 | + |path| { | |
| 1784 | + self.session | |
| 1785 | + .as_ref() | |
| 1786 | + .map_or(0, |session| session.file_frames(path)) | |
| 1787 | + }, | |
| 1788 | + ) | |
| 1789 | + .iter() | |
| 1790 | + .any(|row| row.path == path && row.stream == stream && row.unusable.is_none()), | |
| 1791 | + placed, | |
| 1792 | + } | |
| 1729 | 1793 | } |
| 1730 | 1794 | |
| 1731 | 1795 | /// The one place a clip becomes *the* selected one: a click, a right-click |
| @@ -2704,6 +2768,17 @@ impl Player { | ||
| 2704 | 2768 | /// Whether a card owns the window. While one does the timeline under it is |
| 2705 | 2769 | /// out of reach, so a right-click there opens no menu -- the same rule the |
| 2706 | 2770 | /// key handler and the drop target already follow. |
| 2771 | + /// Whether anything at all is drawn over the window -- a card, a menu or an | |
| 2772 | + /// open list. What the hover labels stand aside for ([`OVERLAID`]): a | |
| 2773 | + /// tooltip belongs to the surface the pointer is on, and while one of these | |
| 2774 | + /// is up that surface is behind it. | |
| 2775 | + fn overlaid(&self) -> bool { | |
| 2776 | + self.modal() | |
| 2777 | + || self.context_menu.is_some() | |
| 2778 | + || self.library_menu.is_some() | |
| 2779 | + || self.picker.is_some() | |
| 2780 | + } | |
| 2781 | + | |
| 2707 | 2782 | fn modal(&self) -> bool { |
| 2708 | 2783 | self.keys_open |
| 2709 | 2784 | || self.export_open |
| @@ -4801,6 +4876,9 @@ impl Render for Player { | ||
| 4801 | 4876 | session.tick(); |
| 4802 | 4877 | } |
| 4803 | 4878 | self.pump(window); |
| 4879 | + // What every hover label asks before it paints: a card or a menu is | |
| 4880 | + // drawn over whatever the pointer is resting on. | |
| 4881 | + OVERLAID.store(self.overlaid(), Ordering::Relaxed); | |
| 4804 | 4882 | // A cleared seek is a frame delivered, which is the one readiness signal |
| 4805 | 4883 | // there is: whatever a slider drag held back is written here. |
| 4806 | 4884 | if self.seek_since.is_none() { |
| @@ -7004,6 +7082,12 @@ impl Player { | ||
| 7004 | 7082 | .flex() |
| 7005 | 7083 | .min_h(px(KEYS_ROW_H)) |
| 7006 | 7084 | .items_center() |
| 7085 | + // One line, cut where the stroke's column | |
| 7086 | + // starts: a label longer than the room it has | |
| 7087 | + // printed straight over the stroke beside it, | |
| 7088 | + // and two overprinted words are less readable | |
| 7089 | + // than one truncated one. | |
| 7090 | + .truncate() | |
| 7007 | 7091 | .child(action.label()) |
| 7008 | 7092 | // The reason rides on the label rather than in |
| 7009 | 7093 | // the stroke column, which the rebind half |
| @@ -7068,9 +7152,7 @@ impl Player { | ||
| 7068 | 7152 | }); |
| 7069 | 7153 | } |
| 7070 | 7154 | Some( |
| 7071 | - div() | |
| 7072 | - .absolute() | |
| 7073 | - .inset_0() | |
| 7155 | + scrim() | |
| 7074 | 7156 | .flex() |
| 7075 | 7157 | .justify_center() |
| 7076 | 7158 | .items_center() |
| @@ -7147,6 +7229,15 @@ impl Player { | ||
| 7147 | 7229 | .flex_col() |
| 7148 | 7230 | .gap(px(2.)) |
| 7149 | 7231 | .max_h(px(KEYS_ROWS_H)) |
| 7232 | + // The line the list scrolls under: a row half | |
| 7233 | + // out of the viewport sat against the search | |
| 7234 | + // line with nothing between them, and read as a | |
| 7235 | + // row painted over the heading rather than as a | |
| 7236 | + // list with more above it. | |
| 7237 | + .mt(px(4.)) | |
| 7238 | + .border_t_1() | |
| 7239 | + .border_color(rgb(CHROME)) | |
| 7240 | + .pt(px(4.)) | |
| 7150 | 7241 | .overflow_y_scroll() |
| 7151 | 7242 | // The wheel's offset and the arrow keys' are |
| 7152 | 7243 | // the same one, so the two cannot disagree |
| @@ -7578,9 +7669,7 @@ impl Player { | ||
| 7578 | 7669 | None => "Export".into(), |
| 7579 | 7670 | }; |
| 7580 | 7671 | Some( |
| 7581 | - div() | |
| 7582 | - .absolute() | |
| 7583 | - .inset_0() | |
| 7672 | + scrim() | |
| 7584 | 7673 | .flex() |
| 7585 | 7674 | .justify_center() |
| 7586 | 7675 | .items_center() |
| @@ -7881,9 +7970,7 @@ impl Player { | ||
| 7881 | 7970 | // corner as the 20 Hz tick, and the two lines above it (+6 and -6) |
| 7882 | 7971 | // already say what the box is worth per pixel. |
| 7883 | 7972 | Some( |
| 7884 | - div() | |
| 7885 | - .absolute() | |
| 7886 | - .inset_0() | |
| 7973 | + scrim() | |
| 7887 | 7974 | .flex() |
| 7888 | 7975 | .justify_center() |
| 7889 | 7976 | .items_center() |
| @@ -8208,9 +8295,7 @@ impl Player { | ||
| 8208 | 8295 | }) |
| 8209 | 8296 | .collect(); |
| 8210 | 8297 | Some( |
| 8211 | - div() | |
| 8212 | - .absolute() | |
| 8213 | - .inset_0() | |
| 8298 | + scrim() | |
| 8214 | 8299 | .flex() |
| 8215 | 8300 | .justify_center() |
| 8216 | 8301 | .items_center() |
| @@ -8326,9 +8411,7 @@ impl Player { | ||
| 8326 | 8411 | }) |
| 8327 | 8412 | .collect(); |
| 8328 | 8413 | Some( |
| 8329 | - div() | |
| 8330 | - .absolute() | |
| 8331 | - .inset_0() | |
| 8414 | + scrim() | |
| 8332 | 8415 | .flex() |
| 8333 | 8416 | .justify_center() |
| 8334 | 8417 | .items_center() |
| @@ -8525,9 +8608,7 @@ impl Player { | ||
| 8525 | 8608 | }) |
| 8526 | 8609 | .collect(); |
| 8527 | 8610 | Some( |
| 8528 | - div() | |
| 8529 | - .absolute() | |
| 8530 | - .inset_0() | |
| 8611 | + scrim() | |
| 8531 | 8612 | .flex() |
| 8532 | 8613 | .justify_center() |
| 8533 | 8614 | .items_center() |
| @@ -8740,9 +8821,7 @@ impl Player { | ||
| 8740 | 8821 | .child(text) |
| 8741 | 8822 | }; |
| 8742 | 8823 | Some( |
| 8743 | - div() | |
| 8744 | - .absolute() | |
| 8745 | - .inset_0() | |
| 8824 | + scrim() | |
| 8746 | 8825 | .flex() |
| 8747 | 8826 | .justify_center() |
| 8748 | 8827 | .items_start() |
| @@ -8832,6 +8911,8 @@ impl Player { | ||
| 8832 | 8911 | .rounded(px(3.)) |
| 8833 | 8912 | }; |
| 8834 | 8913 | let mut rows: Vec<AnyElement> = Vec::new(); |
| 8914 | + // What every item of this menu is answered from, read once. | |
| 8915 | + let ctx = self.row_ctx(&path, menu.stream); | |
| 8835 | 8916 | if menu.details { |
| 8836 | 8917 | // What the library knows about this row and nothing probed for the |
| 8837 | 8918 | // card: the streams table is filled once per file at import. |
| @@ -8846,20 +8927,7 @@ impl Player { | ||
| 8846 | 8927 | // How many clips play from this exact row -- the number that |
| 8847 | 8928 | // decides whether Remove is refused, so the card answers the |
| 8848 | 8929 | // question the refusal would otherwise raise. |
| 8849 | - let placed = self.session.as_ref().map_or(0, |session| { | |
| 8850 | - let of_row = session | |
| 8851 | - .sources() | |
| 8852 | - .iter() | |
| 8853 | - .position(|s| s.path == path && s.audio_stream == menu.stream); | |
| 8854 | - of_row.map_or(0, |idx| { | |
| 8855 | - session | |
| 8856 | - .lanes() | |
| 8857 | - .into_iter() | |
| 8858 | - .flat_map(|lane| session.lane_clips(lane)) | |
| 8859 | - .filter(|c| c.source == idx) | |
| 8860 | - .count() | |
| 8861 | - }) | |
| 8862 | - }); | |
| 8930 | + let placed = ctx.placed; | |
| 8863 | 8931 | // A still is described by what it has -- a picture, a size, and a |
| 8864 | 8932 | // longest it may be held for -- where a media file is described by |
| 8865 | 8933 | // its streams and its length. Same card, the rows that mean |
| @@ -8903,19 +8971,23 @@ impl Player { | ||
| 8903 | 8971 | ); |
| 8904 | 8972 | } |
| 8905 | 8973 | } else { |
| 8906 | - // Everything but Add works without a timeline open -- and with no | |
| 8907 | - // timeline there are no rows to right-click at all, so this is the | |
| 8908 | - // export guard's shape and not a second policy. | |
| 8909 | - let live = self.session.is_some() && self.exporting().is_none(); | |
| 8910 | - for item in ROW_ITEMS { | |
| 8911 | - let enabled = match item { | |
| 8912 | - RowItem::Add | RowItem::Remove => live, | |
| 8913 | - RowItem::Reveal | RowItem::Properties => true, | |
| 8914 | - }; | |
| 8974 | + // The oracle's list, exactly as the clip menu takes its rows from | |
| 8975 | + // `menu_items`: an item that means nothing for the file that was | |
| 8976 | + // right-clicked is not a row, and one this moment refuses is drawn | |
| 8977 | + // dimmed and says why in place of its hint. | |
| 8978 | + for item in row_items(ctx) { | |
| 8979 | + let refusal = row_enable(item, ctx); | |
| 8980 | + let enabled = refusal.yes(); | |
| 8915 | 8981 | rows.push( |
| 8916 | 8982 | row(rows.len()) |
| 8917 | 8983 | .child(item.label()) |
| 8918 | - .child(div().text_color(rgb(INK_DIM)).child(item.hint())) | |
| 8984 | + .child( | |
| 8985 | + div() | |
| 8986 | + .min_w(px(0.)) | |
| 8987 | + .truncate() | |
| 8988 | + .text_color(rgb(INK_DIM)) | |
| 8989 | + .child(refusal.why().unwrap_or_else(|| item.hint())), | |
| 8990 | + ) | |
| 8919 | 8991 | .when(!enabled, |d| d.opacity(0.4).cursor_not_allowed()) |
| 8920 | 8992 | .when(enabled, |d| { |
| 8921 | 8993 | d.cursor_pointer() |
| @@ -8928,16 +9000,13 @@ impl Player { | ||
| 8928 | 9000 | ); |
| 8929 | 9001 | } |
| 8930 | 9002 | } |
| 8931 | - let (x, y) = menu_at( | |
| 8932 | - menu.at, | |
| 8933 | - viewport, | |
| 8934 | - MENU_PAD * 2. + rows.len() as f32 * MENU_ROW_H, | |
| 8935 | - ); | |
| 9003 | + // Placed by the height it is drawn to, and drawn to what the window has | |
| 9004 | + // room for -- the clip menu's rule, one function for all three. | |
| 9005 | + let list_h = menu_rows_h(rows.len(), viewport); | |
| 9006 | + let (x, y) = menu_at(menu.at, viewport, MENU_PAD * 2. + list_h); | |
| 8936 | 9007 | let full: SharedString = path.display().to_string().into(); |
| 8937 | 9008 | Some( |
| 8938 | - div() | |
| 8939 | - .absolute() | |
| 8940 | - .inset_0() | |
| 9009 | + scrim() | |
| 8941 | 9010 | .on_mouse_down( |
| 8942 | 9011 | MouseButton::Left, |
| 8943 | 9012 | cx.listener(|this, _: &MouseDownEvent, _, cx| { |
| @@ -8978,7 +9047,18 @@ impl Player { | ||
| 8978 | 9047 | .when(menu.details, |d| { |
| 8979 | 9048 | d.tooltip(move |_, cx| cx.new(|_| Tip(full.clone())).into()) |
| 8980 | 9049 | }) |
| 8981 | - .children(rows), | |
| 9050 | + // Scrolls where the window has no room for the list, | |
| 9051 | + // like the clip menu's -- an item hanging off the bottom | |
| 9052 | + // edge is an item nobody can click. | |
| 9053 | + .child( | |
| 9054 | + div() | |
| 9055 | + .id("library-menu-rows") | |
| 9056 | + .flex() | |
| 9057 | + .flex_col() | |
| 9058 | + .max_h(px(list_h)) | |
| 9059 | + .overflow_y_scroll() | |
| 9060 | + .children(rows), | |
| 9061 | + ), | |
| 8982 | 9062 | ), |
| 8983 | 9063 | ) |
| 8984 | 9064 | } |
| @@ -9053,20 +9133,19 @@ impl Player { | ||
| 9053 | 9133 | ); |
| 9054 | 9134 | } |
| 9055 | 9135 | } else { |
| 9056 | - for action in MENU_ITEMS { | |
| 9136 | + // A grade on a waveform, an equalizer on a picture, a silence scan | |
| 9137 | + // on a still: things that do not exist for what was right-clicked, | |
| 9138 | + // so the menu is the list of what this clip can do rather than the | |
| 9139 | + // registry with most of it struck through. One filter, in | |
| 9140 | + // `menu_items`, so there is no second answer to keep in step. The | |
| 9141 | + // state refusals below stay, dimmed and saying why -- the next | |
| 9142 | + // click of the playhead lights them. | |
| 9143 | + let ctx = self.ctx(Some((menu.lane, menu.idx))); | |
| 9144 | + for action in menu_items(ctx) { | |
| 9057 | 9145 | // The registry's own answer, the same one the actions card |
| 9058 | 9146 | // dims a row with -- and a row that takes no click says *why* |
| 9059 | 9147 | // rather than printing a stroke that would do nothing. |
| 9060 | - let refusal = self.enable(action, Some((menu.lane, menu.idx))); | |
| 9061 | - // A grade on a waveform, an equalizer on a picture, a silence | |
| 9062 | - // scan on a still: things that do not exist for what was | |
| 9063 | - // right-clicked, so the menu is the list of what this clip can | |
| 9064 | - // do rather than the registry with most of it struck through. | |
| 9065 | - // The state refusals below stay, dimmed and saying why -- the | |
| 9066 | - // next click of the playhead lights them. | |
| 9067 | - if !refusal.listed() { | |
| 9068 | - continue; | |
| 9069 | - } | |
| 9148 | + let refusal = enable(action, ctx); | |
| 9070 | 9149 | let enabled = refusal.yes(); |
| 9071 | 9150 | // The one item that is not about this clip says so, and says it |
| 9072 | 9151 | // here rather than in the registry: the stroke is global too, |
| @@ -9137,19 +9216,14 @@ impl Player { | ||
| 9137 | 9216 | .into_any_element(), |
| 9138 | 9217 | ); |
| 9139 | 9218 | } |
| 9140 | - let (x, y) = menu_at( | |
| 9141 | - menu.at, | |
| 9142 | - viewport, | |
| 9143 | - // The cap once the list is longer than it: past that the list | |
| 9144 | - // scrolls and the card stops growing, exactly as the keybindings and | |
| 9145 | - // export lists do. | |
| 9146 | - MENU_PAD * 2. + (rows.len() as f32 * MENU_ROW_H).min(MENU_ROWS_H), | |
| 9147 | - ); | |
| 9219 | + // The height the card is *placed* by and the height its list is drawn | |
| 9220 | + // to are one number: placed by a taller one, the card would hang off the | |
| 9221 | + // window's floor -- the very thing the clamp is for. | |
| 9222 | + let list_h = menu_rows_h(rows.len(), viewport); | |
| 9223 | + let (x, y) = menu_at(menu.at, viewport, MENU_PAD * 2. + list_h); | |
| 9148 | 9224 | let full: SharedString = source.path.display().to_string().into(); |
| 9149 | 9225 | Some( |
| 9150 | - div() | |
| 9151 | - .absolute() | |
| 9152 | - .inset_0() | |
| 9226 | + scrim() | |
| 9153 | 9227 | // Click away closes it, either button, and the press is |
| 9154 | 9228 | // swallowed so nothing under the menu also takes it. No tint, |
| 9155 | 9229 | // unlike the modal cards: the timeline this menu is about has |
| @@ -9206,7 +9280,7 @@ impl Player { | ||
| 9206 | 9280 | .id("menu-rows") |
| 9207 | 9281 | .flex() |
| 9208 | 9282 | .flex_col() |
| 9209 | - .max_h(px(MENU_ROWS_H)) | |
| 9283 | + .max_h(px(list_h)) | |
| 9210 | 9284 | .overflow_y_scroll() |
| 9211 | 9285 | .children(rows), |
| 9212 | 9286 | ), |
| @@ -9282,17 +9356,12 @@ impl Player { | ||
| 9282 | 9356 | .into_any_element() |
| 9283 | 9357 | }) |
| 9284 | 9358 | .collect(); |
| 9285 | - let (x, y) = menu_at( | |
| 9286 | - picker.at, | |
| 9287 | - viewport, | |
| 9288 | - // Past the cap the list scrolls and the card stops growing, exactly | |
| 9289 | - // as the menus and the export list do. | |
| 9290 | - MENU_PAD * 2. + (rows.len() as f32 * MENU_ROW_H).min(MENU_ROWS_H), | |
| 9291 | - ); | |
| 9359 | + // The window's own room, and the list scrolls only where the window has | |
| 9360 | + // none -- the clip menu's rule, one function for both. | |
| 9361 | + let list_h = menu_rows_h(rows.len(), viewport); | |
| 9362 | + let (x, y) = menu_at(picker.at, viewport, MENU_PAD * 2. + list_h); | |
| 9292 | 9363 | Some( |
| 9293 | - div() | |
| 9294 | - .absolute() | |
| 9295 | - .inset_0() | |
| 9364 | + scrim() | |
| 9296 | 9365 | // Click away closes it, either button, swallowed so nothing |
| 9297 | 9366 | // under the list also takes the press -- the clip menu's rule. |
| 9298 | 9367 | .on_mouse_down( |
| @@ -9337,7 +9406,7 @@ impl Player { | ||
| 9337 | 9406 | .id("picker-rows") |
| 9338 | 9407 | .flex() |
| 9339 | 9408 | .flex_col() |
| 9340 | - .max_h(px(MENU_ROWS_H)) | |
| 9409 | + .max_h(px(list_h)) | |
| 9341 | 9410 | .overflow_y_scroll() |
| 9342 | 9411 | .children(rows), |
| 9343 | 9412 | ), |
| @@ -10832,6 +10901,72 @@ fn enable(action: ActionId, ctx: Ctx) -> Enable { | ||
| 10832 | 10901 | } |
| 10833 | 10902 | } |
| 10834 | 10903 | |
| 10904 | +/// The rows a clip menu draws, for the clip it was opened on: the registry | |
| 10905 | +/// filtered by the one availability oracle, and the *only* way that menu is | |
| 10906 | +/// built. An action that means nothing for what was right-clicked -- a grade on | |
| 10907 | +/// a waveform, an equalizer on a picture -- is not a row at all, so a future | |
| 10908 | +/// action cannot appear where it does not apply by being added to | |
| 10909 | +/// [`MENU_ITEMS`] alone. | |
| 10910 | +fn menu_items(ctx: Ctx) -> Vec<ActionId> { | |
| 10911 | + MENU_ITEMS | |
| 10912 | + .into_iter() | |
| 10913 | + .filter(|&action| enable(action, ctx).listed()) | |
| 10914 | + .collect() | |
| 10915 | +} | |
| 10916 | + | |
| 10917 | +/// What a library row's items are asked *about*: the file that was | |
| 10918 | +/// right-clicked and the little of the editor's state the answers need. The | |
| 10919 | +/// library's [`Ctx`], handed in for the same reason. | |
| 10920 | +#[derive(Clone, Copy, Default)] | |
| 10921 | +struct RowCtx { | |
| 10922 | + /// A timeline to put it on. | |
| 10923 | + timeline: bool, | |
| 10924 | + exporting: bool, | |
| 10925 | + /// This row can join *this* timeline: what greys it in the list, and what | |
| 10926 | + /// the engine would otherwise refuse the Add with after the click. | |
| 10927 | + usable: bool, | |
| 10928 | + /// How many clips play this exact row -- a source with any is one the | |
| 10929 | + /// engine will not take out of the list. | |
| 10930 | + placed: usize, | |
| 10931 | +} | |
| 10932 | + | |
| 10933 | +/// Whether a library row's item can be asked for. The library's half of | |
| 10934 | +/// [`enable`], and the same rule: one table, no second policy in the render. | |
| 10935 | +fn row_enable(item: RowItem, ctx: RowCtx) -> Enable { | |
| 10936 | + match item { | |
| 10937 | + // The two that change the timeline, so an export reading it stops them | |
| 10938 | + // both -- the key handler's rule, applied to a menu. | |
| 10939 | + RowItem::Add | RowItem::Remove if ctx.exporting => Enable::No("an export is running"), | |
| 10940 | + RowItem::Add | RowItem::Remove if !ctx.timeline => Enable::No("no timeline open"), | |
| 10941 | + // Dimmed and saying why rather than clicked and refused afterwards: the | |
| 10942 | + // row's own grey already says the file cannot join this timeline. | |
| 10943 | + RowItem::Add if !ctx.usable => Enable::No("it cannot join this one"), | |
| 10944 | + RowItem::Remove if ctx.placed > 0 => Enable::No("clips play it"), | |
| 10945 | + // Neither of these touches the timeline: a file can be found on disk and | |
| 10946 | + // described whatever the editor is doing, with no timeline at all. | |
| 10947 | + _ => Enable::Yes, | |
| 10948 | + } | |
| 10949 | +} | |
| 10950 | + | |
| 10951 | +/// The rows a library menu draws, for the row it was opened on -- the clip | |
| 10952 | +/// menu's [`menu_items`] on the other panel, and the only way that menu is | |
| 10953 | +/// built. | |
| 10954 | +fn row_items(ctx: RowCtx) -> Vec<RowItem> { | |
| 10955 | + ROW_ITEMS | |
| 10956 | + .into_iter() | |
| 10957 | + .filter(|&item| row_enable(item, ctx).listed()) | |
| 10958 | + .collect() | |
| 10959 | +} | |
| 10960 | + | |
| 10961 | +/// How tall a menu's list may draw: the whole of it where the window has room, | |
| 10962 | +/// and what the window has where it has not -- only then does the list scroll. | |
| 10963 | +/// A cap fixed at twelve rows put the last items behind a scroll on a window | |
| 10964 | +/// with room to spare, which reads as a menu cut off by the bottom edge. | |
| 10965 | +fn menu_rows_h(rows: usize, viewport: Size<Pixels>) -> f32 { | |
| 10966 | + let room = f32::from(viewport.height) - MENU_PAD * 2.; | |
| 10967 | + (rows as f32 * MENU_ROW_H).min(room.max(MENU_ROW_H)) | |
| 10968 | +} | |
| 10969 | + | |
| 10835 | 10970 | /// Where the menu actually hangs: at the pointer, pulled back inside the window |
| 10836 | 10971 | /// when it would not fit -- an item off the bottom edge is an item nobody can |
| 10837 | 10972 | /// click. Never negative, so a window smaller than the menu loses the bottom of |
| @@ -12612,6 +12747,19 @@ fn separator() -> impl IntoElement { | ||
| 12612 | 12747 | .bg(rgb(HOVER)) |
| 12613 | 12748 | } |
| 12614 | 12749 | |
| 12750 | +/// Whether a card or a menu is drawn over the window, as the hover labels see | |
| 12751 | +/// it: written once a frame by [`Player::render`], read by every [`Tip`] before | |
| 12752 | +/// it paints. | |
| 12753 | +/// | |
| 12754 | +/// A tooltip already on screen when an overlay opens *stays* on screen in gpui: | |
| 12755 | +/// occluding the surface under it does not take it back, because the check that | |
| 12756 | +/// keeps it visible works off the element's absolute bounds and knows nothing | |
| 12757 | +/// about what was painted over it (`div.rs::handle_tooltip_mouse_move`, its own | |
| 12758 | +/// TODO). So the tip is what has to stand aside -- here, once, for every hover | |
| 12759 | +/// label in this window, rather than at fifteen call sites of which the | |
| 12760 | +/// sixteenth would be forgotten. | |
| 12761 | +static OVERLAID: AtomicBool = AtomicBool::new(false); | |
| 12762 | + | |
| 12615 | 12763 | /// A tooltip is a view in gpui and nothing smaller, so this is the smallest one |
| 12616 | 12764 | /// that carries a line of text. It paints outside the window's element tree and |
| 12617 | 12765 | /// therefore owns its colours. |
| @@ -12619,6 +12767,12 @@ struct Tip(SharedString); | ||
| 12619 | 12767 | |
| 12620 | 12768 | impl Render for Tip { |
| 12621 | 12769 | fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement { |
| 12770 | + // A card or a menu is up: nothing. A line of text over the items of the | |
| 12771 | + // menu that just opened under the pointer is the card being painted | |
| 12772 | + // over by the window it covers. | |
| 12773 | + if OVERLAID.load(Ordering::Relaxed) { | |
| 12774 | + return div(); | |
| 12775 | + } | |
| 12622 | 12776 | div() |
| 12623 | 12777 | .px(px(6.)) |
| 12624 | 12778 | .py(px(3.)) |
| @@ -13378,7 +13532,7 @@ mod tests { | ||
| 13378 | 13532 | Format, HEADER_GAP, HEADER_H, HEADER_W, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, INK, |
| 13379 | 13533 | INK_DIM, KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, KeyRow, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX, |
| 13380 | 13534 | LETTERBOX, LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_PAD, MENU_ROW_H, |
| 13381 | - MBPS_DIGITS, MBPS_MAX, MBPS_MIN, MENU_ROWS_H, MENU_W, NO_FILE, NumberEdit, PANEL_H, | |
| 13535 | + MBPS_DIGITS, MBPS_MAX, MBPS_MIN, MENU_W, NO_FILE, NumberEdit, PANEL_H, ROW_ITEMS, RowCtx, RowItem, | |
| 13382 | 13536 | Quality, ROW_H, RULER_HIT_H, SELECTED, SILENCE_ROWS, |
| 13383 | 13537 | SOURCE_TINTS, SPEED_PRESETS, SPEED_STEP, SURFACE, SWATCH_W, Source, Speed, StreamInfo, |
| 13384 | 13538 | Transport, VOLUME_W, Volume, WAVE_BPS, WAVE_COL, WAVE_COLS_MAX, Wave, band_label, |
| @@ -13389,8 +13543,8 @@ mod tests { | ||
| 13389 | 13543 | format_line, format_refusal, fps_choices, fps_label, frac_along, frac_down, frame_at, |
| 13390 | 13544 | frame_rate_ladder, histogram, |
| 13391 | 13545 | inserted_band, is_bare_modifier, is_project, keymap, keys_filter, keys_rows, lanes_h, |
| 13392 | - marked, menu_at, next_audio_kbps, next_container, normalise, nothing_to_play, panel_h, project_path, | |
| 13393 | - retarget, scrub_due, show_label, silence_rate, snap_cue, snap_marks, snapped, | |
| 13546 | + marked, menu_at, menu_items, menu_rows_h, next_audio_kbps, next_container, normalise, nothing_to_play, panel_h, project_path, | |
| 13547 | + retarget, row_enable, row_items, scrub_due, show_label, silence_rate, snap_cue, snap_marks, snapped, | |
| 13394 | 13548 | source_tint, span_partner, speed_at, summary_head, summary_tail, timecode, transport, |
| 13395 | 13549 | typed, unseen_paths, unseen_sources, |
| 13396 | 13550 | whole_take, window_title, |
| @@ -13954,21 +14108,178 @@ mod tests { | ||
| 13954 | 14108 | assert_ne!(keymap.display(action), "unbound", "{action:?}"); |
| 13955 | 14109 | } |
| 13956 | 14110 | // ...and the whole card still fits the 640x360 floor, however many items |
| 13957 | - // it grows to: the list is what scrolls past the cap, never the card. | |
| 14111 | + // it grows to: the list is what scrolls where the window is too short | |
| 14112 | + // for it, never the card that grows. | |
| 13958 | 14113 | let items = MENU_ITEMS.len() + 1; // Properties |
| 13959 | - assert!(MENU_PAD * 2. + MENU_ROWS_H <= 360., "menu too tall"); | |
| 14114 | + let floor = size(px(640.), px(360.)); | |
| 14115 | + assert!(MENU_PAD * 2. + menu_rows_h(items, floor) <= 360., "too tall"); | |
| 13960 | 14116 | assert!( |
| 13961 | - MENU_ROWS_H / MENU_ROW_H >= 12., | |
| 13962 | - "too few items visible to scan" | |
| 14117 | + menu_rows_h(items, floor) / MENU_ROW_H >= 12., | |
| 14118 | + "too few items visible to scan on the smallest window" | |
| 13963 | 14119 | ); |
| 13964 | 14120 | assert_eq!( |
| 13965 | - menu_at(point(px(0.), px(0.)), size(px(640.), px(360.)), { | |
| 13966 | - MENU_PAD * 2. + (items as f32 * MENU_ROW_H).min(MENU_ROWS_H) | |
| 14121 | + menu_at(point(px(0.), px(0.)), floor, { | |
| 14122 | + MENU_PAD * 2. + menu_rows_h(items, floor) | |
| 13967 | 14123 | }), |
| 13968 | 14124 | (0., 0.) |
| 13969 | 14125 | ); |
| 13970 | 14126 | } |
| 13971 | 14127 | |
| 14128 | + /// Both menus, at the two things they can be opened on, and the box each | |
| 14129 | + /// one is drawn in. Two rules, and the render obeys them by *calling* what | |
| 14130 | + /// this calls -- [`menu_items`] and [`row_items`] are the only lists either | |
| 14131 | + /// menu is built from, and [`menu_rows_h`] is the height each is both placed | |
| 14132 | + /// by and drawn to: | |
| 14133 | + /// | |
| 14134 | + /// 1. a row exists only where the oracle lists the action for the very thing | |
| 14135 | + /// that was right-clicked, so an item can never offer a video action on a | |
| 14136 | + /// waveform (the complaint this comes from) and a new action added to | |
| 14137 | + /// `MENU_ITEMS` cannot appear where it does not apply; | |
| 14138 | + /// 2. the whole card is inside the window, wherever it was opened and | |
| 14139 | + /// however long the list -- a menu drawn past the bottom edge is a menu | |
| 14140 | + /// whose last items nobody can click. | |
| 14141 | + #[test] | |
| 14142 | + fn a_menu_offers_only_what_applies_and_is_drawn_inside_the_window() { | |
| 14143 | + use keymap::ActionId; | |
| 14144 | + let clip = Clip { | |
| 14145 | + start: 30, | |
| 14146 | + in_frame: 0, | |
| 14147 | + out_frame: 60, | |
| 14148 | + source: 0, | |
| 14149 | + link: Some(1), | |
| 14150 | + eq: None, | |
| 14151 | + color: None, | |
| 14152 | + fit: FitPolicy::default(), | |
| 14153 | + speed: Speed::NORMAL, | |
| 14154 | + }; | |
| 14155 | + let ctx = |lane, image| Ctx { | |
| 14156 | + clip: Some((clip, lane)), | |
| 14157 | + image, | |
| 14158 | + playhead: 60, | |
| 14159 | + timeline: true, | |
| 14160 | + ..Ctx::default() | |
| 14161 | + }; | |
| 14162 | + // The oracle is the whole of what the menu draws: every item it lists is | |
| 14163 | + // one the oracle would list, and every item it leaves out is one the | |
| 14164 | + // oracle hides -- there is no third answer, and no hand-written list. | |
| 14165 | + for (lane, image) in [(Lane::V1, false), (Lane::A1, false), (Lane::V1, true)] { | |
| 14166 | + let ctx = ctx(lane, image); | |
| 14167 | + let rows = menu_items(ctx); | |
| 14168 | + for action in MENU_ITEMS { | |
| 14169 | + assert_eq!( | |
| 14170 | + rows.contains(&action), | |
| 14171 | + enable(action, ctx).listed(), | |
| 14172 | + "{action:?} on {lane:?}, image={image}" | |
| 14173 | + ); | |
| 14174 | + } | |
| 14175 | + } | |
| 14176 | + // Sound has no picture settings; picture has no equalizer of its own; a | |
| 14177 | + // still has no sound to scan. The user's own words: an audio clip must | |
| 14178 | + // not be offered what only a picture can be given. | |
| 14179 | + let sound = menu_items(ctx(Lane::A1, false)); | |
| 14180 | + assert!(!sound.contains(&ActionId::Color), "{sound:?}"); | |
| 14181 | + assert!(!sound.contains(&ActionId::Fit), "{sound:?}"); | |
| 14182 | + assert!(sound.contains(&ActionId::Equalizer)); | |
| 14183 | + let picture = menu_items(ctx(Lane::V1, false)); | |
| 14184 | + assert!(!picture.contains(&ActionId::Equalizer), "{picture:?}"); | |
| 14185 | + assert!(picture.contains(&ActionId::Color)); | |
| 14186 | + assert!(!menu_items(ctx(Lane::V1, true)).contains(&ActionId::Silence)); | |
| 14187 | + // The library menu is the same rule on the other panel: its items come | |
| 14188 | + // off `row_items` and nothing else, and the two that change the timeline | |
| 14189 | + // say why rather than being clicked and refused afterwards. | |
| 14190 | + let live = RowCtx { | |
| 14191 | + timeline: true, | |
| 14192 | + usable: true, | |
| 14193 | + ..RowCtx::default() | |
| 14194 | + }; | |
| 14195 | + for ctx in [ | |
| 14196 | + live, | |
| 14197 | + RowCtx { | |
| 14198 | + usable: false, | |
| 14199 | + ..live | |
| 14200 | + }, | |
| 14201 | + RowCtx { placed: 2, ..live }, | |
| 14202 | + RowCtx { | |
| 14203 | + exporting: true, | |
| 14204 | + ..live | |
| 14205 | + }, | |
| 14206 | + RowCtx::default(), | |
| 14207 | + ] { | |
| 14208 | + let rows = row_items(ctx); | |
| 14209 | + for item in ROW_ITEMS { | |
| 14210 | + assert_eq!(rows.contains(&item), row_enable(item, ctx).listed()); | |
| 14211 | + } | |
| 14212 | + // Whatever the state, the two that need neither timeline nor edit | |
| 14213 | + // list are offered: a file is always describable and findable. | |
| 14214 | + assert!(row_enable(RowItem::Reveal, ctx).yes()); | |
| 14215 | + assert!(row_enable(RowItem::Properties, ctx).yes()); | |
| 14216 | + } | |
| 14217 | + assert!(row_enable(RowItem::Add, live).yes()); | |
| 14218 | + assert!( | |
| 14219 | + !row_enable( | |
| 14220 | + RowItem::Add, | |
| 14221 | + RowCtx { | |
| 14222 | + usable: false, | |
| 14223 | + ..live | |
| 14224 | + } | |
| 14225 | + ) | |
| 14226 | + .yes(), | |
| 14227 | + "a file that cannot join this timeline is not an Add anybody can ask for" | |
| 14228 | + ); | |
| 14229 | + assert!(!row_enable(RowItem::Remove, RowCtx { placed: 1, ..live }).yes()); | |
| 14230 | + assert!(!row_enable(RowItem::Add, RowCtx::default()).yes()); | |
| 14231 | + // Every refusal is short enough to sit in the hint column beside its | |
| 14232 | + // label, the clip menu's rule. | |
| 14233 | + for item in ROW_ITEMS { | |
| 14234 | + for ctx in [live, RowCtx::default()] { | |
| 14235 | + if let Some(why) = row_enable(item, ctx).why() { | |
| 14236 | + assert!(!why.is_empty() && why.len() <= 30, "{why:?}"); | |
| 14237 | + } | |
| 14238 | + } | |
| 14239 | + } | |
| 14240 | + // ...and the box. Every window from the floor up, every corner of it, | |
| 14241 | + // and every list length either menu can have: the card is placed by | |
| 14242 | + // `MENU_PAD * 2 + menu_rows_h` and drawn to it, so this is the card. | |
| 14243 | + for viewport in [ | |
| 14244 | + size(px(640.), px(360.)), | |
| 14245 | + size(px(800.), px(600.)), | |
| 14246 | + size(px(1280.), px(690.)), | |
| 14247 | + // Smaller than the floor the layout is sized for: it still may not | |
| 14248 | + // draw outside the window it has. | |
| 14249 | + size(px(320.), px(200.)), | |
| 14250 | + ] { | |
| 14251 | + for rows in 1..=MENU_ITEMS.len() + 1 { | |
| 14252 | + let h = MENU_PAD * 2. + menu_rows_h(rows, viewport); | |
| 14253 | + for at in [ | |
| 14254 | + point(px(0.), px(0.)), | |
| 14255 | + point(px(10.), px(10.)), | |
| 14256 | + // The click that started all this: low in the window, where | |
| 14257 | + // the menu used to hang off the bottom edge. | |
| 14258 | + point(px(0.), viewport.height - px(4.)), | |
| 14259 | + point(viewport.width - px(4.), viewport.height - px(4.)), | |
| 14260 | + point(viewport.width * 2., viewport.height * 2.), | |
| 14261 | + ] { | |
| 14262 | + let (x, y) = menu_at(at, viewport, h); | |
| 14263 | + assert!(x >= 0. && y >= 0., "{x},{y} outside {viewport:?}"); | |
| 14264 | + assert!( | |
| 14265 | + x + MENU_W <= f32::from(viewport.width) + 0.01, | |
| 14266 | + "{rows} rows at {at:?} hang off the right of {viewport:?}" | |
| 14267 | + ); | |
| 14268 | + assert!( | |
| 14269 | + y + h <= f32::from(viewport.height) + 0.01, | |
| 14270 | + "{rows} rows at {at:?} hang off the bottom of {viewport:?}" | |
| 14271 | + ); | |
| 14272 | + } | |
| 14273 | + } | |
| 14274 | + } | |
| 14275 | + // On any window with the room, the whole list is drawn rather than | |
| 14276 | + // twelve rows of it and a scroll nobody is told about. | |
| 14277 | + let items = MENU_ITEMS.len() + 1; | |
| 14278 | + let real = size(px(1280.), px(690.)); | |
| 14279 | + assert_eq!(menu_rows_h(items, real), items as f32 * MENU_ROW_H); | |
| 14280 | + assert!(menu_rows_h(items, size(px(640.), px(360.))) < items as f32 * MENU_ROW_H); | |
| 14281 | + } | |
| 14282 | + | |
| 13972 | 14283 | /// The other half of the keys menu's guarantee, and the audit this batch was |
| 13973 | 14284 | /// asked for kept as a test: no action may be a stroke and nothing else. |
| 13974 | 14285 | /// The actions card answers it for all of them at once -- its rows come off |
| @@ -15605,8 +15916,10 @@ mod tests { | ||
| 15605 | 15916 | let search = 15.; // 11 px text, one line: it never wraps |
| 15606 | 15917 | let gaps = 4. * 2.; |
| 15607 | 15918 | let padding = 24.; |
| 15919 | + // The line the list scrolls under: margin, rule, padding. | |
| 15920 | + let separator = 4. + 1. + 4.; | |
| 15608 | 15921 | assert!( |
| 15609 | - title + status + search + KEYS_ROWS_H + gaps + padding <= 360., | |
| 15922 | + title + status + search + separator + KEYS_ROWS_H + gaps + padding <= 360., | |
| 15610 | 15923 | "card too tall" |
| 15611 | 15924 | ); |
| 15612 | 15925 | // ...and the list is the only part that grows with the editor, so the |