forge
Explore
Log in

Don't you dare go Hollow

wip(tooltips): sort chip plate + one-to-one gate

Browse files at this commit

98a56367f05fc556029815ca769bba6e78dada5fAhmet Kaan GümüşParent: d55192d
crates/app/src/tests/layout.rsmodified+50 -56
@@ -3456,19 +3456,32 @@ fn the_only_hue_in_the_export_section_is_the_av1_gpu_notice() {
3456 /// `.tooltip` is a glyph the user cannot name.3456 /// `.tooltip` is a glyph the user cannot name.
3457 ///3457 ///
3458 /// A scan and not a render: this crate has no gpui window in its tests, so3458 /// A scan and not a render: this crate has no gpui window in its tests, so
3459-/// the function body is the finest grain available. One control may emit two3459+/// the text is the finest grain available. Each emitter must claim a
3460-/// hitmap ids (a row and the selection inside it), which is what3460+/// `.tooltip(` of *its own* within [`REACH`] lines -- one to one, nearest
3461-/// `DOUBLE_NAMED` allows for, by name and with its reason.3461+/// first. Counting them per function instead let an unrelated plate (the
3462+/// empty-dock hint) pay for a control that had none: `dock.sort.cycle` sat
3463+/// bare under a green gate until this pairing was written.
3464+///
3465+/// Controls outside the hitmap are outside this gate by charter. Named for
3466+/// the record, since each is a control the pointer can press: a card's own
3467+/// picker rows (colour/transform/mix/subtitle/silence bands, the speed
3468+/// chips) and the two menus' rows, all of which already read as
3469+/// `<label> <value-or-chord>` on the row itself -- a plate would repeat the
3470+/// row it hangs off, which is DESIGN §8's prose rule the other way round.
3462 #[test]3471 #[test]
3463 fn every_hitmap_control_wears_a_hover_line() {3472 fn every_hitmap_control_wears_a_hover_line() {
3464- // (file, fn, ids beyond the first that name the SAME control)3473+ /// How far from a control's `hitmap::` line its plate may be attached.
3465- const DOUBLE_NAMED: &[(&str, &str, usize)] = &[(3474+ /// A builder chain runs long here (the contact strip's tooltip sits 65
3466- "dock_stance.rs",3475+ /// lines above its emitter), so the reach is generous; what it buys is
3467- "subtitle_tab_rows",3476+ /// that a plate can be spent only once.
3468- // `subtitle.N.M.row` and `subtitle.N.M.select` are one row: the3477+ const REACH: usize = 80;
3469- // second id is the harness's aim point for picking it.3478+ // Ids that name a control a *previous* emitter in the same chain already
3470- 1,3479+ // plated -- the second id is the harness's aim point, not a second
3471- )];3480+ // control -- with the reason each is exempt.
3481+ const DOUBLE_NAMED: &[&str] = &[
3482+ // `subtitle.N.M.row` and `subtitle.N.M.select` are one row.
3483+ ".select\")",
3484+ ];
3472 let mut controls = 0;3485 let mut controls = 0;
3473 let mut naked = Vec::new();3486 let mut naked = Vec::new();
3474 for path in source_files() {3487 for path in source_files() {
@@ -3481,53 +3494,33 @@ fn every_hitmap_control_wears_a_hover_line() {
3481 .and_then(|n| n.to_str())3494 .and_then(|n| n.to_str())
3482 .expect("a file name")3495 .expect("a file name")
3483 .to_string();3496 .to_string();
3484- let mut at = 0;3497+ let lines: Vec<&str> = text.lines().collect();
3485- while let Some(found) = text[at..].find("fn ") {3498+ let mut tips: Vec<(usize, bool)> = lines
3486- let start = at + found;3499+ .iter()
3487- at = start + 3;3500+ .enumerate()
3488- let name: String = text[at..]3501+ .filter(|(_, l)| l.contains(".tooltip("))
3489- .chars()3502+ .map(|(i, _)| (i, false))
3490- .take_while(|c| c.is_alphanumeric() || *c == '_')3503+ .collect();
3491- .collect();3504+ for (i, line) in lines.iter().enumerate() {
3492- if name.is_empty() {3505+ let emitter = ["hitmap::control(", "hitmap::dynamic(", "hitmap::action("]
3493- continue;3506+ .iter()
3494- }3507+ .any(|needle| line.contains(needle));
3495- let Some(open) = text[at..].find('{').map(|i| at + i) else {3508+ if !emitter {
3496 continue;3509 continue;
3497- };
3498- let mut depth = 0usize;
3499- let mut end = text.len();
3500- for (i, c) in text[open..].char_indices() {
3501- match c {
3502- '{' => depth += 1,
3503- '}' => {
3504- depth -= 1;
3505- if depth == 0 {
3506- end = open + i;
3507- break;
3508- }
3509- }
3510- _ => (),
3511- }
3512 }3510 }
3513- let body = &text[start..end];3511+ // The id a `dynamic` builds sits a line or three below its call.
3514- let emitters = ["hitmap::control(", "hitmap::dynamic(", "hitmap::action("]3512+ let head = lines[i..(i + 6).min(lines.len())].join("\n");
3515- .iter()3513+ if DOUBLE_NAMED.iter().any(|id| head.contains(id)) {
3516- .map(|needle| body.matches(needle).count())
3517- .sum::<usize>();
3518- if emitters == 0 {
3519 continue;3514 continue;
3520 }3515 }
3521- controls += emitters;3516+ controls += 1;
3522- let allowed = DOUBLE_NAMED3517+ let mut free: Vec<usize> = (0..tips.len())
3523- .iter()3518+ .filter(|n| !tips[*n].1 && tips[*n].0.abs_diff(i) <= REACH)
3524- .find(|(f, n, _)| *f == file && *n == name)3519+ .collect();
3525- .map_or(0, |(_, _, extra)| *extra);3520+ free.sort_by_key(|n| tips[*n].0.abs_diff(i));
3526- let tips = body.matches(".tooltip(").count();3521+ match free.first() {
3527- if tips + allowed < emitters {3522+ Some(n) => tips[*n].1 = true,
3528- naked.push(format!(3523+ None => naked.push(format!("{file}:{}: {}", i + 1, line.trim())),
3529- "{file}::{name} -- {emitters} hitmap controls, {tips} tooltips"
3530- ));
3531 }3524 }
3532 }3525 }
3533 }3526 }
@@ -3537,8 +3530,9 @@ fn every_hitmap_control_wears_a_hover_line() {
3537 );3530 );
3538 assert!(3531 assert!(
3539 naked.is_empty(),3532 naked.is_empty(),
3540- "controls with no hover line (attach `widgets::tip_hover`/`action_hover` \3533+ "controls with no hover line of their own (attach \
3541- in the shared constructor): {naked:#?}"3534+ `widgets::tip_hover`/`action_hover` in the chain that emits the \
3535+ hitmap id): {naked:#?}"
3542 );3536 );
3543 }3537 }
3544 3538
crates/app/src/ui/dock_stance.rsmodified+1 -0
@@ -1085,6 +1085,7 @@ fn sources_tab(player: &Player, window: &mut Window, cx: &mut Context<Player>) -
1085 .text_color(rgb(INK2()))1085 .text_color(rgb(INK2()))
1086 .cursor_pointer()1086 .cursor_pointer()
1087 .hover(|s| s.bg(rgb(DARK_RAISED())).text_color(rgb(INK1())))1087 .hover(|s| s.bg(rgb(DARK_RAISED())).text_color(rgb(INK1())))
1088+ .tooltip(crate::ui::widgets::tip_hover("Sort sources", "click to cycle", None))
1088 .on_click(cx.listener(|this, _: &ClickEvent, _, cx| {1089 .on_click(cx.listener(|this, _: &ClickEvent, _, cx| {
1089 this.dock_sort = this.dock_sort.next();1090 this.dock_sort = this.dock_sort.next();
1090 cx.notify();1091 cx.notify();