dmackdev/egui_json_tree

Non-interactive json tree view?

Closed this issue · 3 comments

This is a cool crate! Came across it while thinking through "is there a simple way to represent a debug view (field names and values) in egui?"

This seems like a good starting point in conjuction with serde and serde_json. For my use case I would like to display a json representation of a struct's name and full, expanded fields/values, but without interactive controls like the search bar and other control widgets. Is it possible to configure this sort of behavior in your crate? I've poked around the code a bit and got some sense of the configurability (I see you can style it and looks like there's stuff to configure expansion) but didn't go deep enough to get a clear picture of "can interactivity be disabled."

Hey, thanks - glad you think so!

BTW, the search bar is not built into the tree. The search bar and buttons in that example are rendered separately from the JsonTree. The only other kind of UI element in the JsonTree visualisation aside than the JSON data itself, is the triangle icon for expanding/collapsing objects and arrays. This is the default icon used by the egui::CollapsingHeader widget.

I think right now, the easiest and closest you can get to disabling interactivity is to wrap the JsonTree in a disabled UI scope, and expand all objects/arrays by default:

ui.add_enabled_ui(false, |ui| {
    JsonTree::new("id", &json!({"foo": "bar"}))
        .default_expand(DefaultExpand::All)
        .show(ui);
});

This will expand everything in the JSON document and make it non-interactive. However, this also results in the colours appearing faded due to the default egui styling for non-interactive widgets. I have only had a quick look, but it looks like it might not be currently possible to configure the non-interactive widget styling (emilk/egui#2848).

It could be useful if JsonTree exposed a interactive(bool) builder method to disable interactivity in a way that was independent of the non-interactive widget styling. Also, if JsonTree exposed a method to configure the collapsing header icon, then interactivity could be disabled by not rendering an icon at all (as well as allowing custom icons).

I will have a further look into these options.

Hey @molenick, apologies for the delay.

I have started working on supporting a non-interactive view - you can follow progress on #24. I have added a new demo to the examples titled "Non Interactive" which demonstrates disabling the triangular toggle icons in the tree and showing the JSON document fully expanded. This disables only the toggle icons in isolation, so the rest of the tree appears with full opacity as normal.

I will have a look into an option to support hiding the icon completely as well, and aim to publish a new release this weekend.

I am wrapping up #24, which adds support for configuring the toggle buttons to behave in one of 3 states: visible and enabled, visible and disabled, or hidden.

See the PR for a screen recording from the new demo in the examples.

Thanks for raising this issue!