forge
Explore
Log in

Don't you dare go Hollow

A menu offers what applies, fits the window, and nothing paints over it

Browse files at this commit

8a2e8137345a782453e427d113b215ce8731ebdcAhmet Kaan GümüşParent: c52b667
  • fix
    • a menu offers what applies, fits the window, and nothing paints over it
Show full message
🖱️ fix(ui): a menu offers what applies, fits the window, and nothing paints over it

A right-click on an audio clip listed a grade and a fit policy, and the one
row the user named -- "Detach the sound from the picture" -- read as a video
item on a waveform. Both menus take their rows from an oracle now and from
nothing else: `menu_items` filters the action registry through `enable`, and
`row_items` does the same for a library row through `row_enable`, so an item
cannot appear where it does not apply by being added to a list alone. The
detach is worded from neither half, because it takes the pair apart.

The clip menu was capped at twelve rows whatever the window, so a menu opened
low in a 720 px window put everything past the fit policy behind a scroll
nobody was told about. `menu_rows_h` gives the list the room the window has,
and the card is placed by the very height it is drawn to.

A tooltip already on screen when a menu opens stays on screen in gpui --
occluding the surface under it does not take it back (`div.rs`, its own TODO)
-- so the tip stands aside instead: one flag, read by every hover label in the
window. The scrims occlude as well, which is what stops a new one appearing.

The actions card was 320 px wide with labels that were not: "Remove the last
video track (it must be empty)" printed straight over the stroke beside it. It
is 480 now, its labels truncate rather than overprint, and the list scrolls
under a rule instead of against the search line.
crates/app/src/keymap.rsmodified+4 -1
@@ -125,7 +125,10 @@ impl ActionId {
125125 ActionId::Paste => "Paste",
126126 ActionId::Cut => "Cut",
127127 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",
129132 ActionId::Group => "Group with the clip on another track",
130133 ActionId::Select => "Select the clip under the playhead (again for the next lane)",
131134 ActionId::SelectNext => "Select the next clip in the lane",
crates/app/src/main.rsmodified+437 -124
@@ -7,6 +7,7 @@ use std::collections::HashMap;
77 use std::path::{Path, PathBuf};
88 use std::rc::Rc;
99 use std::sync::Arc;
10+use std::sync::atomic::{AtomicBool, Ordering};
1011 use std::time::{Duration, Instant};
1112
1213 use engine::audio::StreamInfo;
@@ -134,7 +135,13 @@ const RULER_HIT_H: f32 = HIT_MIN;
134135 const TIME_W: f32 = 200.;
135136 /// The keybindings card: a row per action, a title and a status line, inside a
136137 /// 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.;
138145 const KEYS_ROW_H: f32 = HIT_MIN;
139146 /// How much of the row list is on screen at once; past this it scrolls. What
140147 /// 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.;
168175 const MENU_W: f32 = 260.;
169176 const MENU_ROW_H: f32 = HIT_MIN;
170177 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;
176178
177179 /// The subtitle over the picture: white on a black plate, because a cue is read
178180 /// 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 {
500502 span.max(HIT_MIN)
501503 }
502504
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+
503517 /// A press that stops here. What every card's body hands its scrim: the scrim
504518 /// closes the card on a press, and the card is painted after it, so this listener
505519 /// runs first (gpui dispatches topmost-first, window.rs:3705) and a press meant
@@ -618,8 +632,11 @@ impl RowItem {
618632 /// the item will do to the timeline, so nothing here is a surprise.
619633 fn hint(self) -> &'static str {
620634 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",
623640 Self::Reveal => "file manager",
624641 Self::Properties => "…",
625642 }
@@ -1703,29 +1720,76 @@ impl Player {
17031720 ///
17041721 /// The player's half of [`enable`]: it reads the state, the table decides.
17051722 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 {
17061730 let Some(session) = &self.session else {
1707- return enable(action, Ctx::default());
1731+ return Ctx::default();
17081732 };
17091733 let clip = on
17101734 .or(self.selected)
17111735 .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+ }
17291793 }
17301794
17311795 /// The one place a clip becomes *the* selected one: a click, a right-click
@@ -2704,6 +2768,17 @@ impl Player {
27042768 /// Whether a card owns the window. While one does the timeline under it is
27052769 /// out of reach, so a right-click there opens no menu -- the same rule the
27062770 /// 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+
27072782 fn modal(&self) -> bool {
27082783 self.keys_open
27092784 || self.export_open
@@ -4801,6 +4876,9 @@ impl Render for Player {
48014876 session.tick();
48024877 }
48034878 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);
48044882 // A cleared seek is a frame delivered, which is the one readiness signal
48054883 // there is: whatever a slider drag held back is written here.
48064884 if self.seek_since.is_none() {
@@ -7004,6 +7082,12 @@ impl Player {
70047082 .flex()
70057083 .min_h(px(KEYS_ROW_H))
70067084 .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()
70077091 .child(action.label())
70087092 // The reason rides on the label rather than in
70097093 // the stroke column, which the rebind half
@@ -7068,9 +7152,7 @@ impl Player {
70687152 });
70697153 }
70707154 Some(
7071- div()
7072- .absolute()
7073- .inset_0()
7155+ scrim()
70747156 .flex()
70757157 .justify_center()
70767158 .items_center()
@@ -7147,6 +7229,15 @@ impl Player {
71477229 .flex_col()
71487230 .gap(px(2.))
71497231 .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.))
71507241 .overflow_y_scroll()
71517242 // The wheel's offset and the arrow keys' are
71527243 // the same one, so the two cannot disagree
@@ -7578,9 +7669,7 @@ impl Player {
75787669 None => "Export".into(),
75797670 };
75807671 Some(
7581- div()
7582- .absolute()
7583- .inset_0()
7672+ scrim()
75847673 .flex()
75857674 .justify_center()
75867675 .items_center()
@@ -7881,9 +7970,7 @@ impl Player {
78817970 // corner as the 20 Hz tick, and the two lines above it (+6 and -6)
78827971 // already say what the box is worth per pixel.
78837972 Some(
7884- div()
7885- .absolute()
7886- .inset_0()
7973+ scrim()
78877974 .flex()
78887975 .justify_center()
78897976 .items_center()
@@ -8208,9 +8295,7 @@ impl Player {
82088295 })
82098296 .collect();
82108297 Some(
8211- div()
8212- .absolute()
8213- .inset_0()
8298+ scrim()
82148299 .flex()
82158300 .justify_center()
82168301 .items_center()
@@ -8326,9 +8411,7 @@ impl Player {
83268411 })
83278412 .collect();
83288413 Some(
8329- div()
8330- .absolute()
8331- .inset_0()
8414+ scrim()
83328415 .flex()
83338416 .justify_center()
83348417 .items_center()
@@ -8525,9 +8608,7 @@ impl Player {
85258608 })
85268609 .collect();
85278610 Some(
8528- div()
8529- .absolute()
8530- .inset_0()
8611+ scrim()
85318612 .flex()
85328613 .justify_center()
85338614 .items_center()
@@ -8740,9 +8821,7 @@ impl Player {
87408821 .child(text)
87418822 };
87428823 Some(
8743- div()
8744- .absolute()
8745- .inset_0()
8824+ scrim()
87468825 .flex()
87478826 .justify_center()
87488827 .items_start()
@@ -8832,6 +8911,8 @@ impl Player {
88328911 .rounded(px(3.))
88338912 };
88348913 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);
88358916 if menu.details {
88368917 // What the library knows about this row and nothing probed for the
88378918 // card: the streams table is filled once per file at import.
@@ -8846,20 +8927,7 @@ impl Player {
88468927 // How many clips play from this exact row -- the number that
88478928 // decides whether Remove is refused, so the card answers the
88488929 // 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;
88638931 // A still is described by what it has -- a picture, a size, and a
88648932 // longest it may be held for -- where a media file is described by
88658933 // its streams and its length. Same card, the rows that mean
@@ -8903,19 +8971,23 @@ impl Player {
89038971 );
89048972 }
89058973 } 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();
89158981 rows.push(
89168982 row(rows.len())
89178983 .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+ )
89198991 .when(!enabled, |d| d.opacity(0.4).cursor_not_allowed())
89208992 .when(enabled, |d| {
89218993 d.cursor_pointer()
@@ -8928,16 +9000,13 @@ impl Player {
89289000 );
89299001 }
89309002 }
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);
89369007 let full: SharedString = path.display().to_string().into();
89379008 Some(
8938- div()
8939- .absolute()
8940- .inset_0()
9009+ scrim()
89419010 .on_mouse_down(
89429011 MouseButton::Left,
89439012 cx.listener(|this, _: &MouseDownEvent, _, cx| {
@@ -8978,7 +9047,18 @@ impl Player {
89789047 .when(menu.details, |d| {
89799048 d.tooltip(move |_, cx| cx.new(|_| Tip(full.clone())).into())
89809049 })
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+ ),
89829062 ),
89839063 )
89849064 }
@@ -9053,20 +9133,19 @@ impl Player {
90539133 );
90549134 }
90559135 } 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) {
90579145 // The registry's own answer, the same one the actions card
90589146 // dims a row with -- and a row that takes no click says *why*
90599147 // 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);
90709149 let enabled = refusal.yes();
90719150 // The one item that is not about this clip says so, and says it
90729151 // here rather than in the registry: the stroke is global too,
@@ -9137,19 +9216,14 @@ impl Player {
91379216 .into_any_element(),
91389217 );
91399218 }
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);
91489224 let full: SharedString = source.path.display().to_string().into();
91499225 Some(
9150- div()
9151- .absolute()
9152- .inset_0()
9226+ scrim()
91539227 // Click away closes it, either button, and the press is
91549228 // swallowed so nothing under the menu also takes it. No tint,
91559229 // unlike the modal cards: the timeline this menu is about has
@@ -9206,7 +9280,7 @@ impl Player {
92069280 .id("menu-rows")
92079281 .flex()
92089282 .flex_col()
9209- .max_h(px(MENU_ROWS_H))
9283+ .max_h(px(list_h))
92109284 .overflow_y_scroll()
92119285 .children(rows),
92129286 ),
@@ -9282,17 +9356,12 @@ impl Player {
92829356 .into_any_element()
92839357 })
92849358 .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);
92929363 Some(
9293- div()
9294- .absolute()
9295- .inset_0()
9364+ scrim()
92969365 // Click away closes it, either button, swallowed so nothing
92979366 // under the list also takes the press -- the clip menu's rule.
92989367 .on_mouse_down(
@@ -9337,7 +9406,7 @@ impl Player {
93379406 .id("picker-rows")
93389407 .flex()
93399408 .flex_col()
9340- .max_h(px(MENU_ROWS_H))
9409+ .max_h(px(list_h))
93419410 .overflow_y_scroll()
93429411 .children(rows),
93439412 ),
@@ -10832,6 +10901,72 @@ fn enable(action: ActionId, ctx: Ctx) -> Enable {
1083210901 }
1083310902 }
1083410903
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+
1083510970 /// Where the menu actually hangs: at the pointer, pulled back inside the window
1083610971 /// when it would not fit -- an item off the bottom edge is an item nobody can
1083710972 /// click. Never negative, so a window smaller than the menu loses the bottom of
@@ -12612,6 +12747,19 @@ fn separator() -> impl IntoElement {
1261212747 .bg(rgb(HOVER))
1261312748 }
1261412749
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+
1261512763 /// A tooltip is a view in gpui and nothing smaller, so this is the smallest one
1261612764 /// that carries a line of text. It paints outside the window's element tree and
1261712765 /// therefore owns its colours.
@@ -12619,6 +12767,12 @@ struct Tip(SharedString);
1261912767
1262012768 impl Render for Tip {
1262112769 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+ }
1262212776 div()
1262312777 .px(px(6.))
1262412778 .py(px(3.))
@@ -13378,7 +13532,7 @@ mod tests {
1337813532 Format, HEADER_GAP, HEADER_H, HEADER_W, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, INK,
1337913533 INK_DIM, KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, KeyRow, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX,
1338013534 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,
1338213536 Quality, ROW_H, RULER_HIT_H, SELECTED, SILENCE_ROWS,
1338313537 SOURCE_TINTS, SPEED_PRESETS, SPEED_STEP, SURFACE, SWATCH_W, Source, Speed, StreamInfo,
1338413538 Transport, VOLUME_W, Volume, WAVE_BPS, WAVE_COL, WAVE_COLS_MAX, Wave, band_label,
@@ -13389,8 +13543,8 @@ mod tests {
1338913543 format_line, format_refusal, fps_choices, fps_label, frac_along, frac_down, frame_at,
1339013544 frame_rate_ladder, histogram,
1339113545 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,
1339413548 source_tint, span_partner, speed_at, summary_head, summary_tail, timecode, transport,
1339513549 typed, unseen_paths, unseen_sources,
1339613550 whole_take, window_title,
@@ -13954,21 +14108,178 @@ mod tests {
1395414108 assert_ne!(keymap.display(action), "unbound", "{action:?}");
1395514109 }
1395614110 // ...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.
1395814113 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");
1396014116 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"
1396314119 );
1396414120 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)
1396714123 }),
1396814124 (0., 0.)
1396914125 );
1397014126 }
1397114127
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+
1397214283 /// The other half of the keys menu's guarantee, and the audit this batch was
1397314284 /// asked for kept as a test: no action may be a stroke and nothing else.
1397414285 /// The actions card answers it for all of them at once -- its rows come off
@@ -15605,8 +15916,10 @@ mod tests {
1560515916 let search = 15.; // 11 px text, one line: it never wraps
1560615917 let gaps = 4. * 2.;
1560715918 let padding = 24.;
15919+ // The line the list scrolls under: margin, rule, padding.
15920+ let separator = 4. + 1. + 4.;
1560815921 assert!(
15609- title + status + search + KEYS_ROWS_H + gaps + padding <= 360.,
15922+ title + status + search + separator + KEYS_ROWS_H + gaps + padding <= 360.,
1561015923 "card too tall"
1561115924 );
1561215925 // ...and the list is the only part that grows with the editor, so the