GPUI Box GitHub

Components / structured

JsonView builder

A collapsible view of a structured value.

A builder is RenderOnce. Construct and mount it in one expression.

use gpui_kit::structured::JsonView;

Reviewed in json-view.

Also drawn by reading-direction, which arranges components rather than reviewing them.

Construct
new(ident: impl Into<Ident>, value: JsonValue) -> Self
Options

Chain onto the value.

root_label(label: impl Into<SharedString>) -> Self
expanded(paths: impl IntoIterator<Item = SharedString>) -> Self
expanded_paths<S: AsRef<str>>(paths: &[S]) -> Self
selected(path: impl Into<SharedString>) -> Self
visible_rows(rows: usize) -> Self
row_height(height: f32) -> Self
on_toggle(handler: impl Fn(SharedString, bool, &mut Window, &mut App) + 'static) -> Self
on_select(handler: impl Fn(SharedString, &mut Window, &mut App) + 'static) -> Self
Queries

Only answer; they change nothing.

disclosed_paths(cx: &App) -> Vec<SharedString>
Example · json-view
fn json_view(_window: &mut Window, cx: &mut App) -> AnyElement {
    let theme = cx.theme().clone();
    stack(&theme)
        .w(px(520.0))
        .child(
            JsonView::new("scene.json", scene_document())
                .expanded_paths(&["credentials", "request", "request/headers", "steps"])
                .selected("request/method")
                .on_toggle(|_, _, _, _| {})
                .on_select(|_, _, _| {}),
        )
        .into_any_element()
}

Source: crates/gpui-kit/src/structured/json_view.rs