diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index bbd6192..cf8efd1 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -2660,6 +2660,12 @@ fn every_action_has_a_darkroom_widget_home_or_explicit_owner() { let mentioned = darkroom.contains(&format!("ActionId::{name}")) || (action == ActionId::Resolution && darkroom.contains("Pick::Resolution")) || (action == ActionId::SubtitleStyle && darkroom.contains("open_subtitle_style(cx)")); + let hitmap_id = crate::ui::hitmap::action_id(action); + assert_eq!( + hitmap_id, + format!("action.{name}"), + "ActionId::{name} has a Darkroom widget home but no stable hitmap id" + ); assert!( mentioned, "ActionId::{name} is bound to a chord but has no visible affordance \ diff --git a/crates/app/src/ui/bench_stance.rs b/crates/app/src/ui/bench_stance.rs index 69802f7..cf60200 100644 --- a/crates/app/src/ui/bench_stance.rs +++ b/crates/app/src/ui/bench_stance.rs @@ -38,6 +38,7 @@ //! `nudge_cut` and friends still act on `Player::selected` directly, with no //! element under the pointer required, and stay untouched by any of this. +use crate::ui::hitmap; use crate::ui::type_scale::{self, Typeset}; use crate::ui::widgets::*; use crate::*; @@ -306,6 +307,15 @@ fn clip_box( move |_, _, _, cx| cx.new(|_| Tip(ghost.clone())) }, ) + .children(hitmap::dynamic( + move || { + ( + format!("clip.{}.{}.{}", lane.label(), lane.ord, idx), + "Timeline clip".into(), + ) + }, + true, + )) // The two edge strips a drag lengthens or shortens the clip by // (`Player::start_trim`), gated on the same `trims(span)` floor the // legacy strips use -- a clip too narrow to aim at keeps its whole @@ -507,6 +517,15 @@ fn clip_box( this.pick((lane, idx), false, cx); this.dissolve_selected(cx); })) + .children(hitmap::dynamic( + move || { + ( + format!("clip.{}.{}.{}.dissolve", lane.label(), lane.ord, idx), + "Toggle dissolve".into(), + ) + }, + true, + )) .child(dissolve_glyph()), ) }) @@ -627,6 +646,15 @@ fn sub_box( move |_, _, _, cx| cx.new(|_| Tip(ghost.clone())) }, ) + .children(hitmap::dynamic( + move || { + ( + format!("subtitle.{}.{}.{}", lane.label(), lane.ord, idx), + "Timeline subtitle".into(), + ) + }, + true, + )) // The same edge-trim strips a clip gets, on the same [`trims`] floor. .children( [Edge::Start, Edge::End] @@ -823,6 +851,15 @@ fn lane_row( .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { this.act_lane(ActionId::Mix, lane, cx); })) + .children(hitmap::dynamic( + move || { + ( + format!("lane.{}.mix", lane.label()), + format!("Mix {}", lane.label()), + ) + }, + true, + )) .child("≋") .child( div() @@ -855,6 +892,15 @@ fn lane_row( .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { this.show_sub_lane(lane, cx); })) + .children(hitmap::dynamic( + move || { + ( + format!("lane.{}.subtitles", lane.label()), + format!("Show {}", lane.label()), + ) + }, + true, + )) .child("◉"), ) }) @@ -887,6 +933,15 @@ fn lane_row( .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { this.act_lane(action, lane, cx); })) + .children(hitmap::dynamic( + move || { + ( + format!("lane.{}.remove", lane.label()), + format!("Remove {}", lane.label()), + ) + }, + player.enable(action, None).yes(), + )) .child("×") .child( div() @@ -1010,6 +1065,15 @@ fn lane_row( cx.stop_propagation(); this.timeline_wheel(event, cx); })) + .children(hitmap::dynamic( + move || { + ( + format!("lane.{}.bed", lane.label()), + format!("{} timeline bed", lane.label()), + ) + }, + true, + )) .children(boxes) .children(sub_boxes) // The shadow of the row in flight (`Player::ghost`, set by diff --git a/crates/app/src/ui/cards.rs b/crates/app/src/ui/cards.rs index 2ba7bf4..1df4f1f 100644 --- a/crates/app/src/ui/cards.rs +++ b/crates/app/src/ui/cards.rs @@ -1,5 +1,6 @@ //! The property cards -- docked into the inspector, or floated when modal. +use crate::ui::hitmap; use crate::ui::type_scale::{self, Typeset}; use crate::ui::widgets::*; use crate::*; @@ -121,6 +122,7 @@ fn dark_card_head( .into() }) .child(if max { "▣ m" } else { "⤢ m" }) + .children(hitmap::control("card.maximize", "Toggle card size", true)) })) .child( div() diff --git a/crates/app/src/ui/dock_stance.rs b/crates/app/src/ui/dock_stance.rs index b72f541..f245e75 100644 --- a/crates/app/src/ui/dock_stance.rs +++ b/crates/app/src/ui/dock_stance.rs @@ -11,6 +11,7 @@ //! still supply the row facts ([`library_rows`], [`source_tint`], //! [`clip_middle`]...), only the anatomy around them is new. +use crate::ui::hitmap; use crate::ui::type_scale::{self, Typeset, head, label, mono}; use crate::*; use gpui::FontWeight; @@ -136,6 +137,7 @@ fn ghost_verb( .hover(|s| s.bg(rgb(DARK_RAISED())).text_color(rgb(INK1()))) .on_click(on_click) }) + .children(hitmap::action(action, on)) .child( div() .font(label_style.font) @@ -184,6 +186,7 @@ fn dock_tab( save(this.dock_src_active); cx.notify(); })) + .children(hitmap::control(id, label_text, true)) .child( div() .font(style.font) @@ -374,6 +377,10 @@ fn source_row( cx.new(|_| Tip(ghost.clone())) }) }) + .children(hitmap::dynamic( + move || (format!("source.{i}.row"), "Source row".into()), + usable, + )) .child( div() .flex() @@ -463,6 +470,10 @@ fn source_row( }, )) }) + .children(hitmap::dynamic( + move || (format!("source.{i}.add"), "Add at playhead".into()), + can_insert, + )) .tooltip(move |_, cx| { cx.new(|_| { Tip( @@ -508,6 +519,10 @@ fn source_row( cx.stop_propagation(); this.toggle_proxy(&proxy_path, proxy_stops, cx); })) + .children(hitmap::dynamic( + move || (format!("source.{i}.proxy"), "Toggle proxy".into()), + !proxy_waiting, + )) .child( div() .font(style.font) @@ -644,6 +659,15 @@ fn subtitle_palette(player: &Player, cx: &mut Context) -> Option) -> Option) -> impl IntoElement { this.dock_filter_edit = true; cx.notify(); })) + .children(hitmap::control("dock.filter", "Filter sources", true)) .child(match player.dock_filter.is_empty() { true => "⌕ type to filter — name, codec, unused…".to_string(), false => format!("⌕ {filter_text}"), diff --git a/crates/app/src/ui/hitmap.rs b/crates/app/src/ui/hitmap.rs new file mode 100644 index 0000000..5d538d6 --- /dev/null +++ b/crates/app/src/ui/hitmap.rs @@ -0,0 +1,160 @@ +//! Machine-readable bounds for the Darkroom's pointer controls. +use crate::ActionId; + +use gpui::*; +use std::{ + cell::RefCell, + fmt::Write as _, + fs, + path::{Path, PathBuf}, + sync::LazyLock, + time::{Duration, Instant}, +}; + +const WRITE_INTERVAL: Duration = Duration::from_millis(250); + +struct Target { + id: String, + label: String, + bounds: Bounds, + enabled: bool, +} + +#[derive(Default)] +struct State { + targets: Vec, + last_write: Option, +} + +thread_local! { + static STATE: RefCell = RefCell::new(State::default()); +} + +fn output_path() -> Option<&'static Path> { + static PATH: LazyLock> = + LazyLock::new(|| std::env::var_os("EDITH_HITMAP").map(PathBuf::from)); + PATH.as_deref() +} + +/// Clears the current-frame controls before descendants record their laid-out +/// bounds, then writes the completed frame after all descendants prepaint. +pub(crate) fn frame() -> Option { + output_path()?; + Some( + canvas( + |_, _, _| STATE.with(|state| state.borrow_mut().targets.clear()), + |_, _, _, _| flush(), + ) + .absolute() + .size_full(), + ) +} + +/// An invisible child that records a control's final window-relative bounds. +pub(crate) fn control( + id: &'static str, + label: &'static str, + enabled: bool, +) -> Option { + dynamic(|| (id.into(), label.into()), enabled) +} + +/// Dynamic controls defer identifier allocation until instrumentation is on. +pub(crate) fn dynamic( + target: impl FnOnce() -> (String, String), + enabled: bool, +) -> Option { + output_path()?; + let (id, label) = target(); + Some( + canvas( + move |bounds, _, _| { + STATE.with(|state| { + state.borrow_mut().targets.push(Target { + id, + label, + bounds, + enabled, + }); + }); + }, + |_, _, _, _| (), + ) + .absolute() + .size_full(), + ) +} + +fn flush() { + let Some(path) = output_path() else { + return; + }; + let now = Instant::now(); + let body = STATE.with(|state| { + let mut state = state.borrow_mut(); + if state + .last_write + .is_some_and(|last| now.duration_since(last) < WRITE_INTERVAL) + { + return None; + } + state.last_write = Some(now); + let mut json = String::from("["); + for (i, target) in state.targets.iter().enumerate() { + if i != 0 { + json.push(','); + } + json.push_str("{\"id\":"); + json_string(&mut json, &target.id); + json.push_str(",\"label\":"); + json_string(&mut json, &target.label); + let bounds = target.bounds; + let _ = write!( + json, + ",\"x\":{},\"y\":{},\"w\":{},\"h\":{},\"enabled\":{}", + f32::from(bounds.origin.x), + f32::from(bounds.origin.y), + f32::from(bounds.size.width), + f32::from(bounds.size.height), + target.enabled, + ); + json.push('}'); + } + json.push(']'); + Some(json) + }); + let Some(body) = body else { + return; + }; + let temp = path.with_extension(format!("hitmap-{}.tmp", std::process::id())); + if fs::write(&temp, body).is_ok() { + let _ = fs::rename(temp, path); + } +} + +fn json_string(json: &mut String, value: &str) { + json.push('"'); + for c in value.chars() { + match c { + '"' => json.push_str("\\\""), + '\\' => json.push_str("\\\\"), + '\n' => json.push_str("\\n"), + '\r' => json.push_str("\\r"), + '\t' => json.push_str("\\t"), + c if c <= '\u{1f}' => { + let _ = write!(json, "\\u{:04x}", c as u32); + } + c => json.push(c), + } + } + json.push('"'); +} + +pub(crate) fn action_id(action: ActionId) -> String { + format!("action.{action:?}") +} + +/// Records an action control under the action name it dispatches. +pub(crate) fn action(action: ActionId, enabled: bool) -> Option { + dynamic(move || (action_id(action), action.label().into()), enabled) +} diff --git a/crates/app/src/ui/mod.rs b/crates/app/src/ui/mod.rs index 4741449..7386d6d 100644 --- a/crates/app/src/ui/mod.rs +++ b/crates/app/src/ui/mod.rs @@ -6,6 +6,7 @@ pub mod bench_stance; pub mod cards; pub mod dock_stance; +pub mod hitmap; pub mod inspector; pub mod library; pub mod overlays; diff --git a/crates/app/src/ui/overlays.rs b/crates/app/src/ui/overlays.rs index d7260b1..a093498 100644 --- a/crates/app/src/ui/overlays.rs +++ b/crates/app/src/ui/overlays.rs @@ -1,5 +1,6 @@ //! The bars and the floating cards that are not inspector sections. +use crate::ui::hitmap; use crate::ui::stance::menu_floor; use crate::ui::type_scale::{self, Typeset}; use crate::ui::widgets::*; @@ -695,6 +696,7 @@ impl Player { }, )) }) + .children(hitmap::action(action, enabled)) .into_any_element(), ); } @@ -903,6 +905,10 @@ impl Player { .on_click( cx.listener(move |this, _: &ClickEvent, _, cx| this.choose(choice, cx)), ) + .children(hitmap::dynamic( + move || (format!("picker.choice.{n}"), "Choose setting value".into()), + true, + )) .into_any_element() }) .collect(); diff --git a/crates/app/src/ui/settings_stance.rs b/crates/app/src/ui/settings_stance.rs index 71ba086..fd39f33 100644 --- a/crates/app/src/ui/settings_stance.rs +++ b/crates/app/src/ui/settings_stance.rs @@ -32,6 +32,7 @@ //! since nothing in [`engine::project::Project`] holds a place to persist an //! override into. +use crate::ui::hitmap; use crate::ui::type_scale; use crate::*; use engine::colorspace::ContentLight; @@ -147,6 +148,7 @@ fn row_full( .hover(|s| s.bg(rgb(DARK_RAISED()))) .on_click(on_click) }) + .children(hitmap::control(id, label_text, !exporting)) .child( div() .font(label_style.font) diff --git a/crates/app/src/ui/spine_stance.rs b/crates/app/src/ui/spine_stance.rs index 549344b..2786dc1 100644 --- a/crates/app/src/ui/spine_stance.rs +++ b/crates/app/src/ui/spine_stance.rs @@ -4,6 +4,7 @@ //! drew. `stance.rs::spine()` keeps the panel frame (width, surface, //! border); this module owns the rows inside it. +use crate::ui::hitmap; use crate::ui::type_scale::{self, Typeset}; use crate::*; @@ -81,6 +82,7 @@ fn glyph( }), ) }) + .children(hitmap::action(action, on)) .child( div() .line_height(relative(1.05)) @@ -141,6 +143,7 @@ fn trim_control(active: bool, player: &Player, cx: &mut Context) -> impl this.act(action, window, cx) })) }) + .children(hitmap::action(action, on)) .child( div() .line_height(relative(1.05)) diff --git a/crates/app/src/ui/stance.rs b/crates/app/src/ui/stance.rs index c4dd2f7..d4cd187 100644 --- a/crates/app/src/ui/stance.rs +++ b/crates/app/src/ui/stance.rs @@ -10,6 +10,7 @@ use crate::ui::bench_stance; use crate::ui::dock_stance; +use crate::ui::hitmap; use crate::ui::settings_stance; use crate::ui::spine_stance; use crate::ui::timeband_stance; @@ -959,6 +960,7 @@ pub(crate) fn render( .size_full() .flex() .bg(rgb(DARK_CANVAS())) + .children(hitmap::frame()) .child(mouse_exit_listener(cx)) .child(spine(player, cx)) .child( diff --git a/crates/app/src/ui/timeband_stance.rs b/crates/app/src/ui/timeband_stance.rs index 7908048..2d9bff6 100644 --- a/crates/app/src/ui/timeband_stance.rs +++ b/crates/app/src/ui/timeband_stance.rs @@ -8,6 +8,7 @@ //! close to the mock's ~20px reading. Every size in this module comes from //! `ui::type_scale` (role, not a bare `px()` literal). +use crate::ui::hitmap; use crate::ui::type_scale::{self, label, mono}; use crate::*; use gpui::FontWeight; @@ -70,6 +71,7 @@ fn ghost( .on_click(cx.listener(move |this, _: &ClickEvent, window, cx| { this.act(action, window, cx); })) + .children(hitmap::action(action, player.enable(action, None).yes())) .font(glyph_style.font) .text_size(glyph_style.size) .text_color(rgb(if active { INK1() } else { INK2() })) @@ -351,6 +353,7 @@ fn contact_strip(player: &Player, position: f64, cx: &mut Context) -> im MouseButton::Left, cx.listener(|_, _, _, _| PAN_ANCHOR.with(|a| a.set(None))), ) + .children(hitmap::control("timeline.contact-strip", "Timeline contact strip", true)) .child(bounds_probe(strip_bounds)) // Baseline: a quiet hairline under the real traces below it, so an // 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 { PAN_ANCHOR.with(|a| a.set(Some(f32::from(event.position.x)))); cx.stop_propagation(); }) + .children(hitmap::control(id, "Timeline viewport grip", true)) } /// 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) -> impl IntoElement { } cx.notify(); })) + .children(hitmap::action( + if exporting { + ActionId::CancelExport + } else { + ActionId::Export + }, + true, + )) .child( div() .font(label_style.font) @@ -541,6 +553,7 @@ fn volume_slider(player: &Player, cx: &mut Context) -> impl IntoElement ) .child(bounds_probe(player.volume_bar.clone())) }) + .children(hitmap::control("timeline.volume", "Volume", enabled)) .child( div() .w_full() @@ -771,6 +784,10 @@ fn save_verb(player: &Player, cx: &mut Context) -> impl IntoElement { .on_click(cx.listener(|this, _: &ClickEvent, window, cx| { this.act(ActionId::Save, window, cx); })) + .children(hitmap::action( + ActionId::Save, + player.enable(ActionId::Save, None).yes(), + )) .child( div() .font(label_style.font)