diff --git a/crates/app/src/tests/cards.rs b/crates/app/src/tests/cards.rs index e83a42f..9a0632d 100644 --- a/crates/app/src/tests/cards.rs +++ b/crates/app/src/tests/cards.rs @@ -2,6 +2,7 @@ //! colour and speed bars, the silence scan, the choices and the export. use super::*; +use std::sync::atomic::Ordering; /// FAULT 2's general shape (not just the source dot's menu): `overlaid()` /// refuses every key while `context_menu`/`library_menu`/`picker` is `Some`, @@ -1674,3 +1675,45 @@ fn every_card_opener_closes_every_other_card_through_one_path() { ); } } + +/// Regression: a builder moved every card's how-to prose off the card body +/// onto a `?` glyph tooltip on the card head (`dark_card_head`), to answer +/// the complaint that the body read "like a terminal screen". But `Tip` +/// stands aside for *every* tooltip while `OVERLAID` is set, and a card +/// being open is exactly what sets `OVERLAID` -- so the `?`'s own help could +/// never paint while the card that owns it was on screen (driven proof: +/// dwelling the pointer on it for 5-6s at four coordinates changed zero +/// pixels). `OverlayTip`/`tip_may_paint` is the fix: a tip anchored on the +/// overlay itself is exempt. This pins both halves so an eighth card can't +/// reintroduce either half of the bug. +#[test] +fn a_cards_own_help_paints_while_the_card_is_open_but_the_ui_under_it_stays_quiet() { + OVERLAID.store(true, Ordering::Relaxed); + assert!( + tip_may_paint(true), + "a tip anchored on the overlay itself (a card head's own `?`) must \ + still paint while its own card is open, or the help nobody wanted \ + permanent becomes help nobody can ever read" + ); + assert!( + !tip_may_paint(false), + "a tip on the *underlying* UI must still stand aside while a card/menu \ + is up over it -- OVERLAID's original purpose, which the overlay \ + exemption must not weaken" + ); + OVERLAID.store(false, Ordering::Relaxed); + assert!(tip_may_paint(false), "with nothing overlaid, an ordinary tip paints too"); + + // Structural half: every card routes its head through `dark_card_head`, + // so checking its one help-tooltip call site covers all seven cards (and + // any future eighth) at once -- it must build an `OverlayTip`, not a + // plain `Tip`, or this whole fix is undone by construction. + let cards_src = src_text("ui/cards.rs"); + let head_fn_at = cards_src.find("fn dark_card_head(").expect("dark_card_head"); + let head_fn = &cards_src[head_fn_at..head_fn_at + 1200]; + assert!( + head_fn.contains("OverlayTip(h.clone())"), + "dark_card_head's own `?` tooltip no longer builds an OverlayTip -- the \ + card-head help is unreadable again while its card is open" + ); +} diff --git a/crates/app/src/tests/mod.rs b/crates/app/src/tests/mod.rs index b94c805..358d0d4 100644 --- a/crates/app/src/tests/mod.rs +++ b/crates/app/src/tests/mod.rs @@ -38,6 +38,7 @@ use super::{ px_below, STATUS_SUCCESS, STATUS_WARNING, notice_tone, proxies_to_start, push_notice, typed, unseen_paths, unseen_sources, whole_take, window_title, + OVERLAID, tip_may_paint, }; use super::{ diff --git a/crates/app/src/ui/cards.rs b/crates/app/src/ui/cards.rs index 63dff69..88d552e 100644 --- a/crates/app/src/ui/cards.rs +++ b/crates/app/src/ui/cards.rs @@ -76,7 +76,7 @@ fn dark_card_head(verb: &str, meta: Option, help: Option impl IntoElement { /// sixteenth would be forgotten. pub(crate) static OVERLAID: AtomicBool = AtomicBool::new(false); +/// Whether a tip is cleared to paint: an ordinary tip stands aside whenever +/// `OVERLAID` is set (a card/menu is up over the underlying UI it belongs +/// to), but a tip *anchored on the overlay itself* -- the `?` glyph on a +/// card's own head, say -- was never the case `OVERLAID` meant to catch, so +/// it paints regardless. One predicate, so [`Tip`] and [`OverlayTip`] can't +/// drift apart on what "overlaid" is supposed to mean. +pub(crate) fn tip_may_paint(anchored_on_overlay: bool) -> bool { + anchored_on_overlay || !OVERLAID.load(Ordering::Relaxed) +} + +/// DESIGN §4: "Notices, menus, chips, cues, and tooltips are all the same +/// plate" -- canvas-on-panel, 2px radius, the room's own type +/// (`ui::type_scale`), not a bordered box in an ad hoc size. +fn tip_plate(text: &SharedString) -> Div { + let style = crate::ui::type_scale::label(crate::ui::type_scale::LABEL_ROW_PX, gpui::FontWeight::MEDIUM); + div() + .px(px(8.)) + .py(px(4.)) + .rounded(px(2.)) + .bg(rgb(DARK_CANVAS())) + .font(style.font) + .text_size(style.size) + .text_color(rgb(INK1())) + .child(text.clone()) +} + /// A tooltip is a view in gpui and nothing smaller, so this is the smallest one /// that carries a line of text. It paints outside the window's element tree and /// therefore owns its colours. @@ -277,27 +303,28 @@ impl Render for Tip { fn render(&mut self, _: &mut Window, _: &mut Context) -> impl IntoElement { // A card or a menu is up: nothing. A line of text over the items of the // menu that just opened under the pointer is the card being painted - // over by the window it covers. - if OVERLAID.load(Ordering::Relaxed) { + // over by the window it covers. (This struct is every tooltip on the + // *underlying* UI -- grepped: `timeline.rs`, `library.rs`, + // `overlays.rs`, `spine_stance.rs`, `dock_stance.rs`, + // `timeband_stance.rs`, `preview.rs`, here -- so the fix belongs here + // once, not per call site.) + if !tip_may_paint(false) { return div(); } - // DESIGN §4: "Notices, menus, chips, cues, and tooltips are all the - // same plate" -- canvas-on-panel, 2px radius, the room's own type - // (`ui::type_scale`), not a bordered box in an ad hoc size. This one - // struct is every tooltip in the app (grepped: `timeline.rs`, - // `library.rs`, `overlays.rs`, `spine_stance.rs`, `dock_stance.rs`, - // `timeband_stance.rs`, `preview.rs`, here), so the fix belongs here - // once, not per call site. - let style = crate::ui::type_scale::label(crate::ui::type_scale::LABEL_ROW_PX, gpui::FontWeight::MEDIUM); - div() - .px(px(8.)) - .py(px(4.)) - .rounded(px(2.)) - .bg(rgb(DARK_CANVAS())) - .font(style.font) - .text_size(style.size) - .text_color(rgb(INK1())) - .child(self.0.clone()) + tip_plate(&self.0) + } +} + +/// A tip anchored on the overlay itself -- a card's own `?` glyph, drawn on +/// its own card head. `OVERLAID` exists to hide a [`Tip`] on the UI *under* +/// a card while the card sits over it; a tip painted on the card is not +/// that case, so it is exempt (`tip_may_paint(true)` is always `true`). +/// Everything else about it is [`Tip`]'s own plate. +pub(crate) struct OverlayTip(pub(crate) SharedString); + +impl Render for OverlayTip { + fn render(&mut self, _: &mut Window, _: &mut Context) -> impl IntoElement { + tip_plate(&self.0) } }