forge
Explore
Log in

Don't you dare go Hollow

Expose Darkroom control hitmap

Browse files at this commit

7f7f103084686e7e3f62d21f7bcd6e93359576d7Ahmet Kaan GümüşParent: 9a27ee6
  • feat
    • expose Darkroom control hitmap
Show full message
✨ feat: expose Darkroom control hitmap
crates/app/src/tests/layout.rsmodified+6 -0
@@ -2660,6 +2660,12 @@ fn every_action_has_a_darkroom_widget_home_or_explicit_owner() {
26602660 let mentioned = darkroom.contains(&format!("ActionId::{name}"))
26612661 || (action == ActionId::Resolution && darkroom.contains("Pick::Resolution"))
26622662 || (action == ActionId::SubtitleStyle && darkroom.contains("open_subtitle_style(cx)"));
2663+ let hitmap_id = crate::ui::hitmap::action_id(action);
2664+ assert_eq!(
2665+ hitmap_id,
2666+ format!("action.{name}"),
2667+ "ActionId::{name} has a Darkroom widget home but no stable hitmap id"
2668+ );
26632669 assert!(
26642670 mentioned,
26652671 "ActionId::{name} is bound to a chord but has no visible affordance \
crates/app/src/ui/bench_stance.rsmodified+64 -0
@@ -38,6 +38,7 @@
3838 //! `nudge_cut` and friends still act on `Player::selected` directly, with no
3939 //! element under the pointer required, and stay untouched by any of this.
4040
41+use crate::ui::hitmap;
4142 use crate::ui::type_scale::{self, Typeset};
4243 use crate::ui::widgets::*;
4344 use crate::*;
@@ -306,6 +307,15 @@ fn clip_box(
306307 move |_, _, _, cx| cx.new(|_| Tip(ghost.clone()))
307308 },
308309 )
310+ .children(hitmap::dynamic(
311+ move || {
312+ (
313+ format!("clip.{}.{}.{}", lane.label(), lane.ord, idx),
314+ "Timeline clip".into(),
315+ )
316+ },
317+ true,
318+ ))
309319 // The two edge strips a drag lengthens or shortens the clip by
310320 // (`Player::start_trim`), gated on the same `trims(span)` floor the
311321 // legacy strips use -- a clip too narrow to aim at keeps its whole
@@ -507,6 +517,15 @@ fn clip_box(
507517 this.pick((lane, idx), false, cx);
508518 this.dissolve_selected(cx);
509519 }))
520+ .children(hitmap::dynamic(
521+ move || {
522+ (
523+ format!("clip.{}.{}.{}.dissolve", lane.label(), lane.ord, idx),
524+ "Toggle dissolve".into(),
525+ )
526+ },
527+ true,
528+ ))
510529 .child(dissolve_glyph()),
511530 )
512531 })
@@ -627,6 +646,15 @@ fn sub_box(
627646 move |_, _, _, cx| cx.new(|_| Tip(ghost.clone()))
628647 },
629648 )
649+ .children(hitmap::dynamic(
650+ move || {
651+ (
652+ format!("subtitle.{}.{}.{}", lane.label(), lane.ord, idx),
653+ "Timeline subtitle".into(),
654+ )
655+ },
656+ true,
657+ ))
630658 // The same edge-trim strips a clip gets, on the same [`trims`] floor.
631659 .children(
632660 [Edge::Start, Edge::End]
@@ -823,6 +851,15 @@ fn lane_row(
823851 .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
824852 this.act_lane(ActionId::Mix, lane, cx);
825853 }))
854+ .children(hitmap::dynamic(
855+ move || {
856+ (
857+ format!("lane.{}.mix", lane.label()),
858+ format!("Mix {}", lane.label()),
859+ )
860+ },
861+ true,
862+ ))
826863 .child("≋")
827864 .child(
828865 div()
@@ -855,6 +892,15 @@ fn lane_row(
855892 .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
856893 this.show_sub_lane(lane, cx);
857894 }))
895+ .children(hitmap::dynamic(
896+ move || {
897+ (
898+ format!("lane.{}.subtitles", lane.label()),
899+ format!("Show {}", lane.label()),
900+ )
901+ },
902+ true,
903+ ))
858904 .child("◉"),
859905 )
860906 })
@@ -887,6 +933,15 @@ fn lane_row(
887933 .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
888934 this.act_lane(action, lane, cx);
889935 }))
936+ .children(hitmap::dynamic(
937+ move || {
938+ (
939+ format!("lane.{}.remove", lane.label()),
940+ format!("Remove {}", lane.label()),
941+ )
942+ },
943+ player.enable(action, None).yes(),
944+ ))
890945 .child("×")
891946 .child(
892947 div()
@@ -1010,6 +1065,15 @@ fn lane_row(
10101065 cx.stop_propagation();
10111066 this.timeline_wheel(event, cx);
10121067 }))
1068+ .children(hitmap::dynamic(
1069+ move || {
1070+ (
1071+ format!("lane.{}.bed", lane.label()),
1072+ format!("{} timeline bed", lane.label()),
1073+ )
1074+ },
1075+ true,
1076+ ))
10131077 .children(boxes)
10141078 .children(sub_boxes)
10151079 // The shadow of the row in flight (`Player::ghost`, set by
crates/app/src/ui/cards.rsmodified+2 -0
@@ -1,5 +1,6 @@
11 //! The property cards -- docked into the inspector, or floated when modal.
22
3+use crate::ui::hitmap;
34 use crate::ui::type_scale::{self, Typeset};
45 use crate::ui::widgets::*;
56 use crate::*;
@@ -121,6 +122,7 @@ fn dark_card_head(
121122 .into()
122123 })
123124 .child(if max { "▣ m" } else { "⤢ m" })
125+ .children(hitmap::control("card.maximize", "Toggle card size", true))
124126 }))
125127 .child(
126128 div()
crates/app/src/ui/dock_stance.rsmodified+34 -0
@@ -11,6 +11,7 @@
1111 //! still supply the row facts ([`library_rows`], [`source_tint`],
1212 //! [`clip_middle`]...), only the anatomy around them is new.
1313
14+use crate::ui::hitmap;
1415 use crate::ui::type_scale::{self, Typeset, head, label, mono};
1516 use crate::*;
1617 use gpui::FontWeight;
@@ -136,6 +137,7 @@ fn ghost_verb(
136137 .hover(|s| s.bg(rgb(DARK_RAISED())).text_color(rgb(INK1())))
137138 .on_click(on_click)
138139 })
140+ .children(hitmap::action(action, on))
139141 .child(
140142 div()
141143 .font(label_style.font)
@@ -184,6 +186,7 @@ fn dock_tab(
184186 save(this.dock_src_active);
185187 cx.notify();
186188 }))
189+ .children(hitmap::control(id, label_text, true))
187190 .child(
188191 div()
189192 .font(style.font)
@@ -374,6 +377,10 @@ fn source_row(
374377 cx.new(|_| Tip(ghost.clone()))
375378 })
376379 })
380+ .children(hitmap::dynamic(
381+ move || (format!("source.{i}.row"), "Source row".into()),
382+ usable,
383+ ))
377384 .child(
378385 div()
379386 .flex()
@@ -463,6 +470,10 @@ fn source_row(
463470 },
464471 ))
465472 })
473+ .children(hitmap::dynamic(
474+ move || (format!("source.{i}.add"), "Add at playhead".into()),
475+ can_insert,
476+ ))
466477 .tooltip(move |_, cx| {
467478 cx.new(|_| {
468479 Tip(
@@ -508,6 +519,10 @@ fn source_row(
508519 cx.stop_propagation();
509520 this.toggle_proxy(&proxy_path, proxy_stops, cx);
510521 }))
522+ .children(hitmap::dynamic(
523+ move || (format!("source.{i}.proxy"), "Toggle proxy".into()),
524+ !proxy_waiting,
525+ ))
511526 .child(
512527 div()
513528 .font(style.font)
@@ -644,6 +659,15 @@ fn subtitle_palette(player: &Player, cx: &mut Context<Player>) -> Option<AnyElem
644659 cx.stop_propagation();
645660 this.remove_subtitle_track(track, cx);
646661 }))
662+ .children(hitmap::dynamic(
663+ move || {
664+ (
665+ format!("subtitle.{track}.remove"),
666+ "Remove subtitle".into(),
667+ )
668+ },
669+ true,
670+ ))
647671 .child("×"),
648672 )
649673 })
@@ -671,6 +695,15 @@ fn subtitle_palette(player: &Player, cx: &mut Context<Player>) -> Option<AnyElem
671695 }
672696 cx.notify();
673697 }))
698+ .children(hitmap::dynamic(
699+ move || {
700+ (
701+ format!("subtitle-group.{group_ord}.fold"),
702+ "Toggle subtitle group".into(),
703+ )
704+ },
705+ true,
706+ ))
674707 .child(if folded { "▸" } else { "▾" })
675708 .when_some(tint, |d, tint| {
676709 d.child(
@@ -798,6 +831,7 @@ fn sources_tab(player: &Player, cx: &mut Context<Player>) -> impl IntoElement {
798831 this.dock_filter_edit = true;
799832 cx.notify();
800833 }))
834+ .children(hitmap::control("dock.filter", "Filter sources", true))
801835 .child(match player.dock_filter.is_empty() {
802836 true => "⌕ type to filter — name, codec, unused…".to_string(),
803837 false => format!("⌕ {filter_text}"),
crates/app/src/ui/hitmap.rsadded+160 -0
@@ -0,0 +1,160 @@
1+//! Machine-readable bounds for the Darkroom's pointer controls.
2+use crate::ActionId;
3+
4+use gpui::*;
5+use std::{
6+ cell::RefCell,
7+ fmt::Write as _,
8+ fs,
9+ path::{Path, PathBuf},
10+ sync::LazyLock,
11+ time::{Duration, Instant},
12+};
13+
14+const WRITE_INTERVAL: Duration = Duration::from_millis(250);
15+
16+struct Target {
17+ id: String,
18+ label: String,
19+ bounds: Bounds<Pixels>,
20+ enabled: bool,
21+}
22+
23+#[derive(Default)]
24+struct State {
25+ targets: Vec<Target>,
26+ last_write: Option<Instant>,
27+}
28+
29+thread_local! {
30+ static STATE: RefCell<State> = RefCell::new(State::default());
31+}
32+
33+fn output_path() -> Option<&'static Path> {
34+ static PATH: LazyLock<Option<PathBuf>> =
35+ LazyLock::new(|| std::env::var_os("EDITH_HITMAP").map(PathBuf::from));
36+ PATH.as_deref()
37+}
38+
39+/// Clears the current-frame controls before descendants record their laid-out
40+/// bounds, then writes the completed frame after all descendants prepaint.
41+pub(crate) fn frame() -> Option<impl IntoElement> {
42+ output_path()?;
43+ Some(
44+ canvas(
45+ |_, _, _| STATE.with(|state| state.borrow_mut().targets.clear()),
46+ |_, _, _, _| flush(),
47+ )
48+ .absolute()
49+ .size_full(),
50+ )
51+}
52+
53+/// An invisible child that records a control's final window-relative bounds.
54+pub(crate) fn control(
55+ id: &'static str,
56+ label: &'static str,
57+ enabled: bool,
58+) -> Option<impl IntoElement> {
59+ dynamic(|| (id.into(), label.into()), enabled)
60+}
61+
62+/// Dynamic controls defer identifier allocation until instrumentation is on.
63+pub(crate) fn dynamic(
64+ target: impl FnOnce() -> (String, String),
65+ enabled: bool,
66+) -> Option<impl IntoElement> {
67+ output_path()?;
68+ let (id, label) = target();
69+ Some(
70+ canvas(
71+ move |bounds, _, _| {
72+ STATE.with(|state| {
73+ state.borrow_mut().targets.push(Target {
74+ id,
75+ label,
76+ bounds,
77+ enabled,
78+ });
79+ });
80+ },
81+ |_, _, _, _| (),
82+ )
83+ .absolute()
84+ .size_full(),
85+ )
86+}
87+
88+fn flush() {
89+ let Some(path) = output_path() else {
90+ return;
91+ };
92+ let now = Instant::now();
93+ let body = STATE.with(|state| {
94+ let mut state = state.borrow_mut();
95+ if state
96+ .last_write
97+ .is_some_and(|last| now.duration_since(last) < WRITE_INTERVAL)
98+ {
99+ return None;
100+ }
101+ state.last_write = Some(now);
102+ let mut json = String::from("[");
103+ for (i, target) in state.targets.iter().enumerate() {
104+ if i != 0 {
105+ json.push(',');
106+ }
107+ json.push_str("{\"id\":");
108+ json_string(&mut json, &target.id);
109+ json.push_str(",\"label\":");
110+ json_string(&mut json, &target.label);
111+ let bounds = target.bounds;
112+ let _ = write!(
113+ json,
114+ ",\"x\":{},\"y\":{},\"w\":{},\"h\":{},\"enabled\":{}",
115+ f32::from(bounds.origin.x),
116+ f32::from(bounds.origin.y),
117+ f32::from(bounds.size.width),
118+ f32::from(bounds.size.height),
119+ target.enabled,
120+ );
121+ json.push('}');
122+ }
123+ json.push(']');
124+ Some(json)
125+ });
126+ let Some(body) = body else {
127+ return;
128+ };
129+ let temp = path.with_extension(format!("hitmap-{}.tmp", std::process::id()));
130+ if fs::write(&temp, body).is_ok() {
131+ let _ = fs::rename(temp, path);
132+ }
133+}
134+
135+fn json_string(json: &mut String, value: &str) {
136+ json.push('"');
137+ for c in value.chars() {
138+ match c {
139+ '"' => json.push_str("\\\""),
140+ '\\' => json.push_str("\\\\"),
141+ '\n' => json.push_str("\\n"),
142+ '\r' => json.push_str("\\r"),
143+ '\t' => json.push_str("\\t"),
144+ c if c <= '\u{1f}' => {
145+ let _ = write!(json, "\\u{:04x}", c as u32);
146+ }
147+ c => json.push(c),
148+ }
149+ }
150+ json.push('"');
151+}
152+
153+pub(crate) fn action_id(action: ActionId) -> String {
154+ format!("action.{action:?}")
155+}
156+
157+/// Records an action control under the action name it dispatches.
158+pub(crate) fn action(action: ActionId, enabled: bool) -> Option<impl IntoElement> {
159+ dynamic(move || (action_id(action), action.label().into()), enabled)
160+}
crates/app/src/ui/mod.rsmodified+1 -0
@@ -6,6 +6,7 @@
66 pub mod bench_stance;
77 pub mod cards;
88 pub mod dock_stance;
9+pub mod hitmap;
910 pub mod inspector;
1011 pub mod library;
1112 pub mod overlays;
crates/app/src/ui/overlays.rsmodified+6 -0
@@ -1,5 +1,6 @@
11 //! The bars and the floating cards that are not inspector sections.
22
3+use crate::ui::hitmap;
34 use crate::ui::stance::menu_floor;
45 use crate::ui::type_scale::{self, Typeset};
56 use crate::ui::widgets::*;
@@ -695,6 +696,7 @@ impl Player {
695696 },
696697 ))
697698 })
699+ .children(hitmap::action(action, enabled))
698700 .into_any_element(),
699701 );
700702 }
@@ -903,6 +905,10 @@ impl Player {
903905 .on_click(
904906 cx.listener(move |this, _: &ClickEvent, _, cx| this.choose(choice, cx)),
905907 )
908+ .children(hitmap::dynamic(
909+ move || (format!("picker.choice.{n}"), "Choose setting value".into()),
910+ true,
911+ ))
906912 .into_any_element()
907913 })
908914 .collect();
crates/app/src/ui/settings_stance.rsmodified+2 -0
@@ -32,6 +32,7 @@
3232 //! since nothing in [`engine::project::Project`] holds a place to persist an
3333 //! override into.
3434
35+use crate::ui::hitmap;
3536 use crate::ui::type_scale;
3637 use crate::*;
3738 use engine::colorspace::ContentLight;
@@ -147,6 +148,7 @@ fn row_full(
147148 .hover(|s| s.bg(rgb(DARK_RAISED())))
148149 .on_click(on_click)
149150 })
151+ .children(hitmap::control(id, label_text, !exporting))
150152 .child(
151153 div()
152154 .font(label_style.font)
crates/app/src/ui/spine_stance.rsmodified+3 -0
@@ -4,6 +4,7 @@
44 //! drew. `stance.rs::spine()` keeps the panel frame (width, surface,
55 //! border); this module owns the rows inside it.
66
7+use crate::ui::hitmap;
78 use crate::ui::type_scale::{self, Typeset};
89 use crate::*;
910
@@ -81,6 +82,7 @@ fn glyph(
8182 }),
8283 )
8384 })
85+ .children(hitmap::action(action, on))
8486 .child(
8587 div()
8688 .line_height(relative(1.05))
@@ -141,6 +143,7 @@ fn trim_control(active: bool, player: &Player, cx: &mut Context<Player>) -> impl
141143 this.act(action, window, cx)
142144 }))
143145 })
146+ .children(hitmap::action(action, on))
144147 .child(
145148 div()
146149 .line_height(relative(1.05))
crates/app/src/ui/stance.rsmodified+2 -0
@@ -10,6 +10,7 @@
1010
1111 use crate::ui::bench_stance;
1212 use crate::ui::dock_stance;
13+use crate::ui::hitmap;
1314 use crate::ui::settings_stance;
1415 use crate::ui::spine_stance;
1516 use crate::ui::timeband_stance;
@@ -959,6 +960,7 @@ pub(crate) fn render(
959960 .size_full()
960961 .flex()
961962 .bg(rgb(DARK_CANVAS()))
963+ .children(hitmap::frame())
962964 .child(mouse_exit_listener(cx))
963965 .child(spine(player, cx))
964966 .child(
crates/app/src/ui/timeband_stance.rsmodified+17 -0
@@ -8,6 +8,7 @@
88 //! close to the mock's ~20px reading. Every size in this module comes from
99 //! `ui::type_scale` (role, not a bare `px()` literal).
1010
11+use crate::ui::hitmap;
1112 use crate::ui::type_scale::{self, label, mono};
1213 use crate::*;
1314 use gpui::FontWeight;
@@ -70,6 +71,7 @@ fn ghost(
7071 .on_click(cx.listener(move |this, _: &ClickEvent, window, cx| {
7172 this.act(action, window, cx);
7273 }))
74+ .children(hitmap::action(action, player.enable(action, None).yes()))
7375 .font(glyph_style.font)
7476 .text_size(glyph_style.size)
7577 .text_color(rgb(if active { INK1() } else { INK2() }))
@@ -351,6 +353,7 @@ fn contact_strip(player: &Player, position: f64, cx: &mut Context<Player>) -> im
351353 MouseButton::Left,
352354 cx.listener(|_, _, _, _| PAN_ANCHOR.with(|a| a.set(None))),
353355 )
356+ .children(hitmap::control("timeline.contact-strip", "Timeline contact strip", true))
354357 .child(bounds_probe(strip_bounds))
355358 // Baseline: a quiet hairline under the real traces below it, so an
356359 // audio-free stretch of film still reads as film rather than gap.
@@ -456,6 +459,7 @@ fn grip(id: &'static str, left: bool, top: bool) -> impl IntoElement {
456459 PAN_ANCHOR.with(|a| a.set(Some(f32::from(event.position.x))));
457460 cx.stop_propagation();
458461 })
462+ .children(hitmap::control(id, "Timeline viewport grip", true))
459463 }
460464
461465 /// The Export chip (MOCK-SPEC "Export chip", DESIGN §4): the room's single
@@ -494,6 +498,14 @@ fn export_chip(player: &Player, cx: &mut Context<Player>) -> impl IntoElement {
494498 }
495499 cx.notify();
496500 }))
501+ .children(hitmap::action(
502+ if exporting {
503+ ActionId::CancelExport
504+ } else {
505+ ActionId::Export
506+ },
507+ true,
508+ ))
497509 .child(
498510 div()
499511 .font(label_style.font)
@@ -541,6 +553,7 @@ fn volume_slider(player: &Player, cx: &mut Context<Player>) -> impl IntoElement
541553 )
542554 .child(bounds_probe(player.volume_bar.clone()))
543555 })
556+ .children(hitmap::control("timeline.volume", "Volume", enabled))
544557 .child(
545558 div()
546559 .w_full()
@@ -771,6 +784,10 @@ fn save_verb(player: &Player, cx: &mut Context<Player>) -> impl IntoElement {
771784 .on_click(cx.listener(|this, _: &ClickEvent, window, cx| {
772785 this.act(ActionId::Save, window, cx);
773786 }))
787+ .children(hitmap::action(
788+ ActionId::Save,
789+ player.enable(ActionId::Save, None).yes(),
790+ ))
774791 .child(
775792 div()
776793 .font(label_style.font)