Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
c71490a
Use generics to be able to expose the actual JSON type the tree rende…
dmackdev Jun 7, 2024
4058022
Add RenderHooks abstraction
dmackdev Jun 7, 2024
4c1de44
Store RenderHooks within JsonTreeConfig
dmackdev Jun 7, 2024
295afdd
Move all rendering to RenderHooks
dmackdev Jun 7, 2024
64b8182
Use &str instead of &String for response callback
dmackdev Jun 7, 2024
d2c7daf
Call response_callback when rendering value
dmackdev Jun 7, 2024
7316a3f
Call response_callback when rendering key
dmackdev Jun 7, 2024
cde8667
Implicitly call response callback when rendering collapsed delimiters
dmackdev Jun 8, 2024
1270761
Remove unused background colour param from render punc
dmackdev Jun 8, 2024
2f9c7bb
Store style within RenderHooks
dmackdev Jun 8, 2024
bbcf3f7
Revert response callback param type to maintain backwards compatibility
dmackdev Jun 8, 2024
4138f7c
start to on_render_value hook
dmackdev Jun 8, 2024
41cefb6
change on render value hook to return optional response, in case you …
dmackdev Jun 8, 2024
80533db
pass &dyn Display to only convert to string if needed for rendering v…
dmackdev Jun 8, 2024
ef4da35
add on_render_value_if hook to only register hook based on the condition
dmackdev Jun 8, 2024
27cb405
add NestedProperty to capture either object key strings or array nume…
dmackdev Jun 8, 2024
d249425
add missing explicit lifetimes
dmackdev Jun 9, 2024
c3002f5
move pointer string to RenderHooks
dmackdev Jun 9, 2024
4b0b781
move search term to render hooks
dmackdev Jun 9, 2024
b4bd79f
add lifetimes for references used throughout the recursion
dmackdev Jun 9, 2024
4a75e4d
get rid of extra &str argument in render value callback. add path_seg…
dmackdev Jun 9, 2024
31c3604
add JsonPointer newtype
dmackdev Jun 10, 2024
c01aa36
add on_post_render_value method
dmackdev Jun 10, 2024
b29d71b
axe parent, use NestedProperty
dmackdev Jun 10, 2024
b06de09
move pointer segment string conversion to NestedProperty to avoid ext…
dmackdev Jun 10, 2024
6577837
use RenderKeyContext
dmackdev Jun 10, 2024
9878463
use RenderPuncContext
dmackdev Jun 10, 2024
4dd11f8
add render key hook
dmackdev Jun 10, 2024
eb291fe
remove uneeded check
dmackdev Jun 10, 2024
e6ddf10
rename arg
dmackdev Jun 10, 2024
fcfd988
add response hook (with intention to deprecate response_callback)
dmackdev Jun 10, 2024
5160a37
make render_hooks mod pub
dmackdev Jun 10, 2024
994283e
update tests to use on_response hook
dmackdev Jun 10, 2024
6059a41
wrap RenderHooks in JsonTreeRenderer
dmackdev Jun 11, 2024
de4a35e
rename mod
dmackdev Jun 11, 2024
15dd38c
move NestedProperty
dmackdev Jun 11, 2024
c67777d
rename NestedProperty to JsonPointerSegment
dmackdev Jun 11, 2024
8d3d198
use trait ToJsonPointerString
dmackdev Jun 11, 2024
fda570b
remove response_callback and all but one render hook
dmackdev Jun 13, 2024
f0b6f19
move search term/style back out of renderer
dmackdev Jun 13, 2024
a3f526a
implement DefaultRender trait for pub RenderContexts to use normal re…
dmackdev Jun 13, 2024
bf95624
move comma space to separate render punc call
dmackdev Jun 13, 2024
ec9ae9b
separate Punc into ExpandablePunc and SpacingPunc
dmackdev Jun 13, 2024
ae60c63
remove uneeded extra functions
dmackdev Jun 13, 2024
8c4c457
remove uneeded clone
dmackdev Jun 13, 2024
04677d5
split render punc into separate method for expandable/spacing
dmackdev Jun 14, 2024
96f1824
remove on_response hook in favour of on_render hook
dmackdev Jun 15, 2024
cec7d63
move render contexts instead of taking ref
dmackdev Jun 15, 2024
5223cb8
collapse RenderHooks into JsonTreeRenderer
dmackdev Jun 15, 2024
120c26c
revise punc enums
dmackdev Jun 15, 2024
726036b
rename punc->delimiter
dmackdev Jun 15, 2024
d877bb3
rename key->property
dmackdev Jun 15, 2024
82e1f09
adjust visibility and derives
dmackdev Jun 15, 2024
483db29
remove unnecessary trait bound on ToJsonTreeValue
dmackdev Jun 15, 2024
de3f438
add value that property points to for RenderPropertyContext
dmackdev Jun 15, 2024
2f76e4b
update tests
dmackdev Jun 15, 2024
f4f7d6d
update doc example
dmackdev Jun 15, 2024
1dea8fc
add JSON value ref to RenderExpandableDelimiterContext
dmackdev Jun 15, 2024
d70afd6
add RenderContext::value convenience method
dmackdev Jun 15, 2024
6fe8998
fix: correct pointer for the immediate children of the root document …
dmackdev Jun 15, 2024
69af487
update demo
dmackdev Jun 15, 2024
67896dc
add workflow job to test simd_json
dmackdev Jun 15, 2024
c3899ce
fix: corrected value for render call
dmackdev Jun 15, 2024
bbbad14
fix and update tests to always assert on captured JSON value
dmackdev Jun 15, 2024
f37cb0c
use ui.small_button
dmackdev Jun 16, 2024
3f2d47b
change add to arr/obj buttons to plus signs
dmackdev Jun 16, 2024
fae0e4f
update examples to show one at a time and take full panel
dmackdev Jun 16, 2024
6a35c9a
add edit object key functionality to example
dmackdev Jun 16, 2024
ccfcd2f
restore root pointer check on demo (cant set empty string in egui cop…
dmackdev Jun 17, 2024
97b2fc9
update object keys in demo for readability
dmackdev Jun 17, 2024
b3159ca
update edit json demo to use context menus and one operation at a time
dmackdev Jun 20, 2024
d2990d0
add justfile
dmackdev Jun 22, 2024
cf81b7a
add context menu cursor icon on hover
dmackdev Jun 22, 2024
0d76505
impl Display instead of ToString for JsonPointerSegment
dmackdev Jun 23, 2024
bc97677
update docs
dmackdev Jun 23, 2024
6c7a81d
remove ToJsonPointerString trait
dmackdev Jun 23, 2024
0685b84
update pointer docs
dmackdev Jun 23, 2024
0631f51
rename render context for base values
dmackdev Jun 23, 2024
829c1ac
update on_render docs
dmackdev Jun 23, 2024
46d5c0c
update docs and readme
dmackdev Jun 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
run: cargo build
- name: Test
run: cargo test
- name: Test json_tree_test for simd_json feature
run: cargo test --features=simd_json --no-default-features --test json_tree_test
- name: Clippy
run: cargo clippy
- name: Format
Expand Down
46 changes: 38 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ An interactive JSON tree visualiser for `egui`, with search and highlight functi
## Usage

```rust
use egui::{Color32};
use egui_json_tree::{DefaultExpand, JsonTree, JsonTreeStyle};

let value = serde_json::json!({ "foo": "bar", "fizz": [1, 2, 3]});

// Simple:
Expand All @@ -30,19 +27,52 @@ let response = JsonTree::new("customised-tree", &value)
..Default::default()
})
.default_expand(DefaultExpand::All)
.response_callback(|response, json_pointer_string| {
// Handle interactions within the JsonTree.
})
.abbreviate_root(true) // Show {...} when the root object is collapsed.
.on_render(|ui, ctx| {
// Customise rendering of the JsonTree, and/or handle interactions.
match ctx {
RenderContext::Property(ctx) => {
ctx.render_default(ui).context_menu(|ui| {
// Show a context menu when right clicking
// an array index or object key.
});
}
RenderContext::BaseValue(ctx) => {
// Show a button after non-recursive JSON values.
ctx.render_default(ui);
if ui.small_button("+").clicked() {
// ...
}
}
RenderContext::ExpandableDelimiter(ctx) => {
// Render array brackets and object braces as normal.
ctx.render_default(ui);
}
};
})
.show(ui);

// Reset the expanded state of all arrays/objects to respect the `default_expand` setting.
response.reset_expanded(ui);
```

See [demo.rs](./examples/demo.rs) and run the examples for more detailed use cases, including the search match highlight/auto expand functionality, and how to copy JSON paths and values to the clipboard.
See [demo.rs](./examples/demo.rs) and run the examples for more detailed use cases, including:

- Automatic expansion of arrays/objects and highlighting, based on search term matches.
- Copying JSON paths and values to the clipboard.
- A JSON editor UI.

## Supported JSON Types

`JsonTree` can visualise any type that implements `value::ToJsonTreeValue`.
See the table of crate features below for provided implementations.

| Feature | JSON Type | Default |
| ------------ | ------------------------- | ------- |
| `serde_json` | `serde_json::Value` | Yes |
| `simd_json` | `simd_json::owned::Value` | No |

`JsonTree` can visualise any type that implements `value::ToJsonTreeValue`. Implementations to support `serde_json::Value` (enabled by default by the crate feature `serde_json`) and `simd_json::owned::Value` (optionally enabled by the crate feature `simd_json`) are provided with this crate. If you wish to use a different JSON type, see the `value` module, and disable default features in your `Cargo.toml` if you do not need the `serde_json` dependency.
If you wish to use a different JSON type, see the `value` module, and disable default features in your `Cargo.toml` if you do not need the `serde_json` dependency.

## Run Examples

Expand Down
Loading