Headings to overlines, Code, Kbd and KbdCombo on gpui keystrokes, Highlight, MiddleEllipsis and EllipsisTooltip, links, eight formatted values on jiff with a typographic minus, CopyableText, SelectableText, Emoji, a TeX subset, rolling AnimatedNumber, Typewriter, tonal GradientText, ShimmerText. Gallery probes now hug their targets. Codex gpt-6-astra (max): PASS in round 2.
28 lines
831 B
Rust
28 lines
831 B
Rust
use std::collections::HashMap;
|
|
|
|
use ely_gpui_component::primitives::Measure;
|
|
use gpui::{App, Bounds, Div, Global, IntoElement, ParentElement, Pixels, Styled, div};
|
|
|
|
/// Window bounds of named demo elements, for scripted capture.
|
|
#[derive(Default)]
|
|
pub struct Probes(HashMap<&'static str, Bounds<Pixels>>);
|
|
|
|
impl Global for Probes {}
|
|
|
|
impl Probes {
|
|
pub fn get(key: &str, cx: &App) -> Option<Bounds<Pixels>> {
|
|
cx.try_global::<Probes>()
|
|
.and_then(|probes| probes.0.get(key).copied())
|
|
}
|
|
}
|
|
|
|
/// Wraps `element`, sized to it, so scripts can find it by `key`.
|
|
pub fn probe(key: &'static str, element: impl IntoElement) -> Div {
|
|
div().flex().child(
|
|
Measure::new(key, move |bounds, _, cx| {
|
|
cx.default_global::<Probes>().0.insert(key, bounds);
|
|
})
|
|
.child(element),
|
|
)
|
|
}
|