egui_json_tree/lib.rs
1//! An interactive JSON tree visualiser for [`egui`](https://github.com/emilk/egui), with search and highlight functionality.
2//!
3//! See the demo [source code](https://github.com/dmackdev/egui_json_tree/blob/master/examples/demo) and [webpage](https://dmackdev.github.io/egui_json_tree) for detailed use cases, including:
4//! - Automatic expansion of arrays/objects and highlighting, based on search term matches.
5//! - Copying JSON paths and values to the clipboard.
6//! - A JSON editor UI.
7//!
8//! # Usage
9//! ```rust
10//! # use egui::{Color32};
11//! # use egui_json_tree::{
12//! # render::{
13//! # DefaultRender, RenderBaseValueContext, RenderContext, RenderExpandableDelimiterContext,
14//! # RenderPropertyContext,
15//! # },
16//! # DefaultExpand, JsonTree, JsonTreeStyle, JsonTreeVisuals, ToggleButtonsState
17//! # };
18//! # egui::__run_test_ui(|ui| {
19//! let value = serde_json::json!({ "foo": "bar", "fizz": [1, 2, 3]});
20//!
21//! // Simple:
22//! JsonTree::new("simple-tree", &value).show(ui);
23//!
24//! // Customised:
25//! let response = JsonTree::new("customised-tree", &value)
26//! .style(
27//! JsonTreeStyle::new()
28//! .abbreviate_root(true) // Show {...} when the root object is collapsed.
29//! .toggle_buttons_state(ToggleButtonsState::VisibleDisabled)
30//! .visuals(JsonTreeVisuals {
31//! bool_color: Color32::YELLOW,
32//! ..Default::default()
33//! }),
34//! )
35//! .default_expand(DefaultExpand::All)
36//! .on_render(|ui, ctx| {
37//! // Customise rendering of the JsonTree, and/or handle interactions.
38//! match ctx {
39//! RenderContext::Property(ctx) => {
40//! ctx.render_default(ui).context_menu(|ui| {
41//! // Show a context menu when right clicking
42//! // an array index or object key.
43//! });
44//! }
45//! RenderContext::BaseValue(ctx) => {
46//! // Show a button after non-recursive JSON values.
47//! ctx.render_default(ui);
48//! if ui.small_button("+").clicked() {
49//! // ...
50//! }
51//! }
52//! RenderContext::ExpandableDelimiter(ctx) => {
53//! // Render array brackets and object braces as normal.
54//! ctx.render_default(ui);
55//! }
56//! };
57//! })
58//! .show(ui);
59//!
60//! // Reset the expanded state of all arrays/objects to respect the `default_expand` setting.
61//! response.reset_expanded(ui);
62//! # });
63//! ```
64//!
65//! # Supported JSON Types
66//!
67//! [`JsonTree`] can visualise any type that implements [`ToJsonTreeValue`](trait@value::ToJsonTreeValue).
68//! See the table of crate features below for provided implementations.
69//!
70//! | Feature/Dependency | JSON Type | Default |
71//! | ------------------ | ------------------------- | ------- |
72//! | `serde_json` | `serde_json::Value` | Yes |
73//! | `simd_json` | `simd_json::owned::Value` | No |
74//!
75//! If you wish to use a different JSON type, see the [`value`](mod@value) module,
76//! and disable default features in your `Cargo.toml` if you do not need the `serde_json` dependency.
77mod default_expand;
78mod node;
79mod response;
80mod search;
81mod style;
82mod toggle_buttons_state;
83mod tree;
84
85pub mod delimiters;
86pub mod pointer;
87pub mod render;
88pub mod value;
89
90pub use default_expand::DefaultExpand;
91pub use response::JsonTreeResponse;
92pub use style::{
93 JsonTreeMaxWidth, JsonTreeStyle, JsonTreeVisuals, JsonTreeWrapping, JsonTreeWrappingConfig,
94};
95pub use toggle_buttons_state::ToggleButtonsState;
96pub use tree::JsonTree;