use std::collections::HashMap; use ely_gpui_component::primitives::Measure; use gpui::{App, Bounds, Global, IntoElement, ParentElement, Pixels}; /// Window bounds of named demo elements, for scripted capture. #[derive(Default)] pub struct Probes(HashMap<&'static str, Bounds>); impl Global for Probes {} impl Probes { pub fn get(key: &str, cx: &App) -> Option> { cx.try_global::() .and_then(|probes| probes.0.get(key).copied()) } } /// Wraps `element` so scripts can find it by `key`. pub fn probe(key: &'static str, element: impl IntoElement) -> Measure { Measure::new(key, move |bounds, _, cx| { cx.default_global::().0.insert(key, bounds); }) .child(element) }