From d55192d6f1064e2eb334f69baaa3d0e07fe3e08f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 9 Sep 2026 20:53:06 +0300 Subject: [PATCH] =?UTF-8?q?wip(tooltips):=20shared=20tooltip=20helper=20+?= =?UTF-8?q?=20first=20sites=20=E2=80=94=20capped=20mid-work?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/app/src/tests/layout.rs | 113 +++++++++++++++++++++++++++ crates/app/src/ui/bench_stance.rs | 16 ++++ crates/app/src/ui/cards.rs | 7 ++ crates/app/src/ui/dock_stance.rs | 30 +++---- crates/app/src/ui/overlays.rs | 3 + crates/app/src/ui/preview.rs | 1 + crates/app/src/ui/spine_stance.rs | 15 ++-- crates/app/src/ui/stance.rs | 1 + crates/app/src/ui/timeband_stance.rs | 7 ++ crates/app/src/ui/widgets.rs | 55 ++++++++++++- 10 files changed, 220 insertions(+), 28 deletions(-) diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index 373915f..8be7e85 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -3447,3 +3447,116 @@ fn the_only_hue_in_the_export_section_is_the_av1_gpu_notice() { ); } } + +/// Every control the hitmap names wears a hover line (the user, 2026-09-09, +/// over a screenshot of the time band: "each and every button needs hover +/// over information ... I don't know some of them"). The hitmap already +/// carries the pair a plate needs -- an id and a label -- so the sweep walks +/// the same emitters: a builder chain that records a control and never calls +/// `.tooltip` is a glyph the user cannot name. +/// +/// A scan and not a render: this crate has no gpui window in its tests, so +/// the function body is the finest grain available. One control may emit two +/// hitmap ids (a row and the selection inside it), which is what +/// `DOUBLE_NAMED` allows for, by name and with its reason. +#[test] +fn every_hitmap_control_wears_a_hover_line() { + // (file, fn, ids beyond the first that name the SAME control) + const DOUBLE_NAMED: &[(&str, &str, usize)] = &[( + "dock_stance.rs", + "subtitle_tab_rows", + // `subtitle.N.M.row` and `subtitle.N.M.select` are one row: the + // second id is the harness's aim point for picking it. + 1, + )]; + let mut controls = 0; + let mut naked = Vec::new(); + for path in source_files() { + let text = std::fs::read_to_string(&path).expect("a source file"); + if !text.contains("hitmap::") { + continue; + } + let file = path + .file_name() + .and_then(|n| n.to_str()) + .expect("a file name") + .to_string(); + let mut at = 0; + while let Some(found) = text[at..].find("fn ") { + let start = at + found; + at = start + 3; + let name: String = text[at..] + .chars() + .take_while(|c| c.is_alphanumeric() || *c == '_') + .collect(); + if name.is_empty() { + continue; + } + let Some(open) = text[at..].find('{').map(|i| at + i) else { + continue; + }; + let mut depth = 0usize; + let mut end = text.len(); + for (i, c) in text[open..].char_indices() { + match c { + '{' => depth += 1, + '}' => { + depth -= 1; + if depth == 0 { + end = open + i; + break; + } + } + _ => (), + } + } + let body = &text[start..end]; + let emitters = ["hitmap::control(", "hitmap::dynamic(", "hitmap::action("] + .iter() + .map(|needle| body.matches(needle).count()) + .sum::(); + if emitters == 0 { + continue; + } + controls += emitters; + let allowed = DOUBLE_NAMED + .iter() + .find(|(f, n, _)| *f == file && *n == name) + .map_or(0, |(_, _, extra)| *extra); + let tips = body.matches(".tooltip(").count(); + if tips + allowed < emitters { + naked.push(format!( + "{file}::{name} -- {emitters} hitmap controls, {tips} tooltips" + )); + } + } + } + assert!( + controls >= 40, + "the hover sweep found only {controls} controls -- it has gone blind" + ); + assert!( + naked.is_empty(), + "controls with no hover line (attach `widgets::tip_hover`/`action_hover` \ + in the shared constructor): {naked:#?}" + ); +} + +/// The one hover shape for the whole room: ` · `, and a control +/// the state refuses says why instead of naming a stroke that will not fire +/// (DESIGN §4/§8 -- a tooltip is not a sentence). +#[test] +fn a_hover_line_is_a_name_and_a_chord() { + use crate::ui::widgets::tip_line; + assert_eq!( + tip_line("One frame forward", "right", None), + "One frame forward · right" + ); + assert_eq!( + tip_line("Split", "s", Some("nothing selected")), + "Split · nothing selected" + ); + // `Keymap::chord`'s unbound badge is not a stroke. + assert_eq!(tip_line("Add files", "--", None), "Add files"); + assert_eq!(tip_line("Source", "", None), "Source"); +} diff --git a/crates/app/src/ui/bench_stance.rs b/crates/app/src/ui/bench_stance.rs index de4eb48..5bdc16a 100644 --- a/crates/app/src/ui/bench_stance.rs +++ b/crates/app/src/ui/bench_stance.rs @@ -337,6 +337,7 @@ fn clip_box( move |_, _, _, cx| cx.new(|_| Tip(ghost.clone())) }, ) + .tooltip(crate::ui::widgets::tip_hover("Clip", "drag to move", None)) .children(hitmap::dynamic( move || { ( @@ -357,6 +358,12 @@ fn clip_box( .filter(|_| trims(span)) .map(|edge| { let mut zone = div() + // An id only so the strip can carry a hover plate -- + // gpui's `.tooltip` lives on a stateful div. + .id(( + "bench-clip-trim", + (lane.ord * 1000 + idx) * 2 + usize::from(edge == Edge::End), + )) .absolute() .top_0() .h_full() @@ -379,6 +386,7 @@ fn clip_box( this.open_menu(lane, idx, event.position, cx); }), ) + .tooltip(crate::ui::widgets::tip_hover("Trim clip edge", "drag", None)) .children(hitmap::dynamic( move || { ( @@ -580,6 +588,10 @@ fn clip_box( d.children([Edge::Start, Edge::End].into_iter().map(|edge| { let is_in = edge == Edge::Start; let mut handle = div() + .id(( + "bench-clip-fade", + (lane.ord * 1000 + idx) * 2 + usize::from(!is_in), + )) .absolute() .top_0() .w(px(FADE_HANDLE_W)) @@ -593,6 +605,7 @@ fn clip_box( this.start_fade_drag(lane, idx, is_in, event.position.x, cx); }), ) + .tooltip(crate::ui::widgets::tip_hover("Fade handle", "drag", None)) .children(hitmap::dynamic( move || { ( @@ -713,6 +726,7 @@ fn sub_box( move |_, _, _, cx| cx.new(|_| Tip(ghost.clone())) }, ) + .tooltip(crate::ui::widgets::tip_hover("Subtitle", "drag to move", None)) .children(hitmap::dynamic( move || { ( @@ -893,6 +907,7 @@ fn lane_row( .on_drag(LaneDrag(lane), move |_, _, _, cx| { cx.new(|_| Tip(head_ghost.clone())) }) + .tooltip(crate::ui::widgets::tip_hover("Reorder lane", "drag", None)) .children(hitmap::dynamic( move || { ( @@ -1189,6 +1204,7 @@ fn lane_row( this.preview_ghost_pick(track, lane, event.event.position.x, cx); }), ) + .tooltip(crate::ui::widgets::tip_hover("Lane bed", "drop media here", None)) .children(hitmap::dynamic( move || { ( diff --git a/crates/app/src/ui/cards.rs b/crates/app/src/ui/cards.rs index 2c9185a..3fa96ac 100644 --- a/crates/app/src/ui/cards.rs +++ b/crates/app/src/ui/cards.rs @@ -121,6 +121,7 @@ fn dark_card_head( .into() }) .child(if max { "▣ m" } else { "⤢ m" }) + .tooltip(crate::ui::widgets::overlay_tip_hover("Toggle card size", "", None)) .children(hitmap::control("card.maximize", "Toggle card size", true)) })) .child( @@ -205,6 +206,11 @@ fn dark_step_glyph( .cursor_pointer() .hover(|s| s.bg(rgb(DARK_RAISED()))) .on_click(on_click) + .tooltip(crate::ui::widgets::overlay_tip_hover( + if plus { "Step up" } else { "Step down" }, + "", + None, + )) .children(hitmap.flatten()) .child(dark_row_value(if plus { "+" } else { "−" })) } @@ -236,6 +242,7 @@ fn dark_ghost_button( .cursor_pointer() .hover(|s| s.bg(rgb(DARK_RAISED()))) .on_click(on_click) + .tooltip(crate::ui::widgets::overlay_tip_hover(&text, chord, None)) .children(hitmap.flatten()) .child( div() diff --git a/crates/app/src/ui/dock_stance.rs b/crates/app/src/ui/dock_stance.rs index 1bcd98d..34921b2 100644 --- a/crates/app/src/ui/dock_stance.rs +++ b/crates/app/src/ui/dock_stance.rs @@ -118,7 +118,6 @@ fn ghost_verb( verb_label: &'static str, action: ActionId, active: bool, - hint: &str, player: &Player, on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static, ) -> Option { @@ -127,11 +126,6 @@ fn ghost_verb( return None; } let key = player.keymap.chord(action); - let say: SharedString = match enabled.why() { - Some(why) => format!("{key} — {why}"), - None => format!("{key} — {hint}"), - } - .into(); let on = enabled.yes(); let label_style = label(type_scale::LABEL_ROW_PX, FontWeight::MEDIUM); let chord_style = mono(type_scale::CHORD_METADATA_MIN_PX, FontWeight::MEDIUM); @@ -146,7 +140,10 @@ fn ghost_verb( .px(px(8.)) .rounded(px(3.)) .when(active, |d| d.bg(rgb(DARK_RAISED()))) - .tooltip(move |_, cx| cx.new(|_| Tip(say.clone())).into()) + // One hover line for the whole room (`widgets::tip_line`): the + // verb and its stroke, not the sentence this row used to carry + // (DESIGN §8 -- a tooltip is not instructional prose). + .tooltip(crate::ui::widgets::action_hover(player, action)) .when(!on, |d| d.opacity(0.4).cursor_not_allowed()) .when(on, |d| { d.cursor_pointer() @@ -203,6 +200,7 @@ fn dock_tab( save(this.dock_src_active); cx.notify(); })) + .tooltip(crate::ui::widgets::tip_hover(&format!("Show {}", label_text.to_lowercase()), "", None)) .children(hitmap::control(id, label_text, true)) .child( div() @@ -408,6 +406,7 @@ fn source_row( cx.new(|_| Tip(ghost.clone())) }) }) + .tooltip(crate::ui::widgets::tip_hover("Source", "drag to a lane", None)) .children(hitmap::dynamic( move || (format!("source.{i}.row"), "Source row".into()), usable, @@ -734,6 +733,7 @@ fn subtitle_tab_rows(player: &Player, cx: &mut Context) -> (usize, Vec) -> (usize, Vec) -> (usize, Vec) - this.dock_filter_edit = true; cx.notify(); })) + .tooltip(crate::ui::widgets::tip_hover("Filter sources", "type to narrow", None)) .children(hitmap::control("dock.filter", "Filter sources", true)) .child(match player.dock_filter.is_empty() { true => "⌕ filter".to_string(), @@ -1052,6 +1055,7 @@ fn sources_tab(player: &Player, window: &mut Window, cx: &mut Context) - this.library_tab = tab; cx.notify(); })) + .tooltip(crate::ui::widgets::tip_hover(&format!("Show {} only", tab.label().to_lowercase()), "", None)) .children(hitmap::dynamic( move || { ( @@ -1132,7 +1136,6 @@ fn sources_tab(player: &Player, window: &mut Window, cx: &mut Context) - "Add files", ActionId::AddFiles, false, - "adds a file to this list — or drop one on the window", player, cx.listener(|this, _: &ClickEvent, _, cx| this.pick_and_import(cx)), )) @@ -1141,7 +1144,6 @@ fn sources_tab(player: &Player, window: &mut Window, cx: &mut Context) - "Paste path", ActionId::PasteFilePath, false, - "imports the file named on the clipboard", player, cx.listener(|this, _: &ClickEvent, _, cx| this.paste_file_path(cx)), )) @@ -1156,7 +1158,6 @@ fn sources_tab(player: &Player, window: &mut Window, cx: &mut Context) - "Import subtitles", ActionId::ImportSubtitles, false, - "reads an .srt/.ass file onto a subtitle lane", player, cx.listener(|this, _: &ClickEvent, window, cx| { this.act(ActionId::ImportSubtitles, window, cx) @@ -1217,6 +1218,7 @@ fn transition_row(player: &Player, cx: &mut Context) -> Option) -> Option format!("theme.{n}.row"), false => format!("picker.choice.{n}"), @@ -547,6 +549,7 @@ impl Player { .on_click( cx.listener(move |this, _: &ClickEvent, _, cx| this.choose(choice, cx)), ) + .tooltip(crate::ui::widgets::overlay_tip_hover(&row_tip, "", None)) .children(hitmap::dynamic( move || (hitmap_id, hitmap_label.to_string()), true, diff --git a/crates/app/src/ui/preview.rs b/crates/app/src/ui/preview.rs index e650557..e6d70bd 100644 --- a/crates/app/src/ui/preview.rs +++ b/crates/app/src/ui/preview.rs @@ -49,6 +49,7 @@ impl Player { .cursor_pointer() .hover(|s| s.bg(rgb(DARK_RAISED()))) .on_click(cx.listener(|this, _: &ClickEvent, _, cx| this.close_preview(cx))) + .tooltip(crate::ui::widgets::tip_hover("Stop preview", "esc", None)) .children(hitmap::control("preview.stop", "Stop preview", true)) .child(div().text_color(rgb(INK2())).child("Stop")) .child( diff --git a/crates/app/src/ui/spine_stance.rs b/crates/app/src/ui/spine_stance.rs index 3481281..83fc56c 100644 --- a/crates/app/src/ui/spine_stance.rs +++ b/crates/app/src/ui/spine_stance.rs @@ -91,11 +91,10 @@ fn glyph_sized( // action answers to, and the keys overlay ([`crate::ui::stance`]) is // still where the full truth lives. let full = player.keymap.display(action); - let say: SharedString = match enabled.why() { - Some(why) => format!("{full} — {why}"), - None => format!("{full} — {}", action.label()), - } - .into(); + // The room's one hover shape (`widgets::tip_line`): the name first, then + // the strokes -- `display`'s every stroke here rather than the compact + // badge, since the spine's glyph is already showing the compact one. + let say = crate::ui::widgets::tip_line(action.label(), &full, enabled.why()); let compact = player.keymap.chord(action); let on = enabled.yes(); div() @@ -158,11 +157,7 @@ fn trim_control(active: bool, player: &Player, cx: &mut Context) -> impl let half = |id: &'static str, txt: &'static str, action: ActionId, cx: &mut Context| { let enabled = player.enable(action, None); let full = player.keymap.display(action); - let say: SharedString = match enabled.why() { - Some(why) => format!("{full} — {why}"), - None => format!("{full} — {}", action.label()), - } - .into(); + let say = crate::ui::widgets::tip_line(action.label(), &full, enabled.why()); let on = enabled.yes(); div() .id(id) diff --git a/crates/app/src/ui/stance.rs b/crates/app/src/ui/stance.rs index 20b470f..2501f44 100644 --- a/crates/app/src/ui/stance.rs +++ b/crates/app/src/ui/stance.rs @@ -442,6 +442,7 @@ fn ghost( .rounded(px(3.)) .cursor_pointer() .hover(|s| s.bg(rgb(DARK_RAISED())).text_color(rgb(INK1()))) + .tooltip(crate::ui::widgets::action_hover(player, action)) .on_click(cx.listener(move |this, _: &ClickEvent, window, cx| this.act(action, window, cx))) .type_style(type_scale::label( type_scale::LABEL_ROW_PX, diff --git a/crates/app/src/ui/timeband_stance.rs b/crates/app/src/ui/timeband_stance.rs index f1e8bc3..d8d9595 100644 --- a/crates/app/src/ui/timeband_stance.rs +++ b/crates/app/src/ui/timeband_stance.rs @@ -165,6 +165,10 @@ fn ghost( this.act(action, window, cx); })) .children(hitmap::action(action, player.enable(action, None).yes())) + // The glyphs nobody could name (`|◂`, `∞`, `‹|`): the hover line is built + // where the ghost is, so a glyph added to this band tomorrow cannot + // ship without one. + .tooltip(crate::ui::widgets::action_hover(player, action)) .font(glyph_style.font) .text_size(glyph_style.size) .text_color(rgb(if active { INK1() } else { INK2() })) @@ -571,6 +575,7 @@ fn grip(id: &'static str, left: bool, top: bool) -> impl IntoElement { PAN_ANCHOR.with(|a| a.set(Some(f32::from(event.position.x)))); cx.stop_propagation(); }) + .tooltip(crate::ui::widgets::tip_hover("Pan the timeline window", "drag", None)) .children(hitmap::control(id, "Timeline viewport grip", true)) } @@ -610,6 +615,7 @@ fn export_chip(player: &Player, cx: &mut Context) -> impl IntoElement { } cx.notify(); })) + .tooltip(crate::ui::widgets::action_hover(player, if exporting { ActionId::CancelExport } else { ActionId::Export })) .children(hitmap::action( if exporting { ActionId::CancelExport @@ -928,6 +934,7 @@ fn save_verb(player: &Player, cx: &mut Context) -> impl IntoElement { .on_click(cx.listener(|this, _: &ClickEvent, window, cx| { this.act(ActionId::Save, window, cx); })) + .tooltip(crate::ui::widgets::action_hover(player, ActionId::Save)) .children(hitmap::action( ActionId::Save, player.enable(ActionId::Save, None).yes(), diff --git a/crates/app/src/ui/widgets.rs b/crates/app/src/ui/widgets.rs index ea73829..b8c63a7 100644 --- a/crates/app/src/ui/widgets.rs +++ b/crates/app/src/ui/widgets.rs @@ -122,6 +122,59 @@ pub(crate) fn dissolve_glyph() -> impl IntoElement { .size_full() } +/// The hover line every control in the room wears (the user, 2026-09-09: +/// "each and every button gets hover over information" -- nobody could name +/// the band's own glyphs). One shape, built from the same pair the hitmap +/// already names the control by: ` · `, DESIGN §4's "every +/// command wears its chord" and §8's no-prose rule -- never a sentence. A +/// control the current state refuses says *why* in the chord's place: naming +/// a stroke that will not fire is the lie §4 forbids. +pub(crate) fn tip_line(name: &str, chord: &str, why: Option<&str>) -> SharedString { + match why { + Some(why) => format!("{name} · {why}"), + // `Keymap::chord`'s own "unbound" badge: a glyph with no stroke says + // its name and stops, rather than wearing `--` as if that were one. + None if chord.is_empty() || chord == "--" => name.to_string(), + None => format!("{name} · {chord}"), + } + .into() +} + +/// [`tip_line`] in the shape gpui's `.tooltip` takes. Every shared control +/// constructor attaches this rather than building its own plate, which is +/// what keeps the next control from shipping without a hover line. +pub(crate) fn tip_hover( + name: &str, + chord: &str, + why: Option<&str>, +) -> impl Fn(&mut Window, &mut App) -> gpui::AnyView + use<> { + let say = tip_line(name, chord, why); + move |_, cx| cx.new(|_| Tip(say.clone())).into() +} + +/// [`tip_hover`] for a control drawn *on* a card or a menu, where an +/// ordinary [`Tip`] stands aside (`OVERLAID`) and would show nothing. +pub(crate) fn overlay_tip_hover( + name: &str, + chord: &str, + why: Option<&str>, +) -> impl Fn(&mut Window, &mut App) -> gpui::AnyView + use<> { + let say = tip_line(name, chord, why); + move |_, cx| cx.new(|_| OverlayTip(say.clone())).into() +} + +/// [`tip_hover`] for a control that dispatches an action: the name and the +/// stroke are read live off the keymap and the enable state, so a rebind or +/// a refusal can never leave a stale plate under the pointer. +pub(crate) fn action_hover( + player: &Player, + action: ActionId, +) -> impl Fn(&mut Window, &mut App) -> gpui::AnyView + use<> { + let enabled = player.enable(action, None); + let chord = player.keymap.chord(action); + tip_hover(action.label(), &chord, enabled.why()) +} + /// A toolbar button: its glyph, its name, and its key on hover. `id` only buys /// `on_click` and the tooltip -- it is still not focusable, so the root's own /// key listener keeps working after a press, and the click lands on mouse-up @@ -146,7 +199,7 @@ pub(crate) fn control( on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static, ) -> impl IntoElement { let label = label.into(); - let tip: SharedString = format!("{label} — {shortcut}").into(); + let tip = tip_line(&label, &shortcut, None); div() .id(id) .flex_none()