Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
name = "egui_json_tree"
version = "0.11.0"
authors = ["Duncan MacKinnon <dmackdev@gmail.com>"]
edition = "2021"
edition = "2024"
rust-version = "1.85"
description = "An interactive JSON tree visualiser for egui, with search and highlight functionality."
repository = "https://github.com/dmackdev/egui_json_tree"
license = "MIT OR Apache-2.0"
Expand All @@ -11,12 +12,12 @@ categories = ["gui", "visualization"]
include = ["src/*.rs", "LICENSE-MIT", "LICENSE-APACHE", "Cargo.toml"]

[dependencies]
egui = { version = "0.31", default-features = false }
egui = { version = "0.32", default-features = false }
serde_json = { version = "1", optional = true }
simd-json = { version = "0.13", optional = true }

[dev-dependencies]
eframe = "0.31"
eframe = "0.32"

[features]
default = ["serde_json"]
Expand Down
7 changes: 4 additions & 3 deletions examples/demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
name = "demo"
version = "0.1.0"
authors = ["Duncan MacKinnon <dmackdev@gmail.com>"]
edition = "2021"
edition = "2024"
rust-version = "1.85"
license = "MIT OR Apache-2.0"
publish = false

[dependencies]
eframe = "0.31"
egui = { version = "0.31", default-features = false }
eframe = "0.32"
egui = { version = "0.32", default-features = false }
egui_json_tree = { path = "../../" }
serde_json = { version = "1" }

Expand Down
4 changes: 1 addition & 3 deletions examples/demo/src/apps/copy_to_clipboard.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use egui::{CursorIcon, Ui};
use egui_json_tree::{render::DefaultRender, JsonTree};
use egui_json_tree::{JsonTree, render::DefaultRender};
use serde_json::Value;

use super::Show;
Expand Down Expand Up @@ -34,15 +34,13 @@ impl Show for CopyToClipboardExample {
if !pointer.is_empty() && ui.button("Copy path").clicked() {
println!("{}", pointer);
ui.ctx().copy_text(pointer);
ui.close_menu();
}

if ui.button("Copy contents").clicked() {
if let Ok(pretty_str) = serde_json::to_string_pretty(context.value()) {
println!("{}", pretty_str);
ui.ctx().copy_text(pretty_str);
}
ui.close_menu();
}
});
})
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/src/apps/custom_input.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use egui::{RichText, Ui};
use egui_json_tree::JsonTree;
use serde_json::{json, Value};
use serde_json::{Value, json};

use super::Show;

Expand Down
14 changes: 3 additions & 11 deletions examples/demo/src/apps/editor.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
use std::str::FromStr;

use egui::{
CursorIcon, Margin, TextEdit, Ui,
text::{CCursor, CCursorRange},
vec2, CursorIcon, Margin, TextEdit, Ui,
vec2,
};
use egui_json_tree::{
DefaultExpand, JsonTree, JsonTreeStyle, ToggleButtonsState,
delimiters::ExpandableDelimiter,
pointer::JsonPointerSegment,
render::{
DefaultRender, RenderBaseValueContext, RenderContext, RenderExpandableDelimiterContext,
RenderPropertyContext,
},
DefaultExpand, JsonTree, JsonTreeStyle, ToggleButtonsState,
};
use serde_json::Value;

Expand Down Expand Up @@ -167,7 +168,6 @@ impl Editor {
if let Some(state) = context.collapsing_state.as_mut() {
state.set_open(true);
}
ui.close_menu();
}

if context.value.is_array() && ui.button("Add to array").clicked() {
Expand All @@ -177,7 +177,6 @@ impl Editor {
if let Some(state) = context.collapsing_state.as_mut() {
state.set_open(true);
}
ui.close_menu();
}

if let Some(parent) = context.pointer.parent() {
Expand All @@ -190,7 +189,6 @@ impl Editor {
request_focus: true,
is_new_key: false,
}));
ui.close_menu()
}
}

Expand All @@ -206,7 +204,6 @@ impl Editor {
},
};
self.edit_events.push(event);
ui.close_menu();
}
}
});
Expand All @@ -227,7 +224,6 @@ impl Editor {
new_value_input: context.value.to_string(),
request_focus: true,
}));
ui.close_menu();
}

match (context.pointer.parent(), context.pointer.last()) {
Expand All @@ -237,7 +233,6 @@ impl Editor {
object_pointer: parent.to_json_pointer_string(),
key: key.to_string(),
});
ui.close_menu();
}
}
(Some(parent), Some(JsonPointerSegment::Index(idx))) => {
Expand All @@ -246,7 +241,6 @@ impl Editor {
array_pointer: parent.to_json_pointer_string(),
idx: *idx,
});
ui.close_menu();
}
}
_ => {}
Expand All @@ -273,7 +267,6 @@ impl Editor {
pointer: context.pointer.to_json_pointer_string(),
});
context.collapsing_state.set_open(true);
ui.close_menu();
}
});
}
Expand All @@ -290,7 +283,6 @@ impl Editor {
pointer: context.pointer.to_json_pointer_string(),
});
context.collapsing_state.set_open(true);
ui.close_menu();
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/src/apps/wrapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl WrappingExample {
{
self.wrap.max_width = JsonTreeMaxWidth::Points(100.0);
}
if let JsonTreeMaxWidth::Points(ref mut pts) = &mut self.wrap.max_width {
if let JsonTreeMaxWidth::Points(pts) = &mut self.wrap.max_width {
ui.add(DragValue::new(pts).speed(10.0).range(100.0..=10000.0));
}
});
Expand Down
4 changes: 2 additions & 2 deletions examples/demo/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use apps::{
copy_to_clipboard::CopyToClipboardExample, custom_input::CustomExample,
Example, Show, copy_to_clipboard::CopyToClipboardExample, custom_input::CustomExample,
editor::JsonEditorExample, search::SearchExample,
toggle_buttons::ToggleButtonsCustomisationDemo, wrapping::WrappingExample, Example, Show,
toggle_buttons::ToggleButtonsCustomisationDemo, wrapping::WrappingExample,
};
use serde_json::json;

Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
# to the user in the error, instead of "error: invalid channel name '[toolchain]'".

[toolchain]
channel = "1.81.0"
channel = "1.85.0"
components = ["rustfmt", "clippy"]
targets = ["wasm32-unknown-unknown"]
6 changes: 3 additions & 3 deletions src/node.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::collections::HashSet;

use egui::{
collapsing_header::{paint_default_icon, CollapsingState},
Id, Ui,
collapsing_header::{CollapsingState, paint_default_icon},
};

use crate::{
delimiters::{SpacingDelimiter, ARRAY_DELIMITERS, OBJECT_DELIMITERS},
DefaultExpand, JsonTree, JsonTreeStyle, ToggleButtonsState,
delimiters::{ARRAY_DELIMITERS, OBJECT_DELIMITERS, SpacingDelimiter},
pointer::{JsonPointer, JsonPointerSegment},
render::{
JsonTreeRenderer, ParentStatus, RenderBaseValueContext, RenderExpandableDelimiterContext,
Expand All @@ -15,7 +16,6 @@ use crate::{
response::JsonTreeResponse,
search::SearchTerm,
value::{ExpandableType, JsonTreeValue, ToJsonTreeValue},
DefaultExpand, JsonTree, JsonTreeStyle, ToggleButtonsState,
};

pub(crate) struct JsonTreeNode<'a, 'b, T: ToJsonTreeValue> {
Expand Down
6 changes: 3 additions & 3 deletions src/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct JsonPointer<'a, 'b>(pub(crate) &'b [JsonPointerSegment<'a>]);

impl<'a, 'b> JsonPointer<'a, 'b> {
impl<'a> JsonPointer<'a, '_> {
/// Returns a JSON Pointer string that can be used to look up specific values within a JSON document, where:
/// - The whole document is identified by the empty string `""`.
/// - A pointer string to a value within the document starts with `/`.
Expand Down Expand Up @@ -43,7 +43,7 @@ pub enum JsonPointerSegment<'a> {
Key(&'a str),
}

impl<'a> fmt::Display for JsonPointerSegment<'a> {
impl fmt::Display for JsonPointerSegment<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
JsonPointerSegment::Key(key) => write!(f, "{}", key),
Expand All @@ -52,7 +52,7 @@ impl<'a> fmt::Display for JsonPointerSegment<'a> {
}
}

impl<'a> JsonPointerSegment<'a> {
impl JsonPointerSegment<'_> {
pub fn to_json_pointer_segment_string(&self) -> String {
match self {
JsonPointerSegment::Key(key) => {
Expand Down
22 changes: 11 additions & 11 deletions src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
use std::fmt::Display;

use egui::{
Color32, FontId, Label, Response, Sense, TextFormat, Ui,
collapsing_header::CollapsingState,
text::LayoutJob,
util::cache::{ComputerMut, FrameCache},
Color32, FontId, Label, Response, Sense, TextFormat, Ui,
};

use crate::{
JsonTreeStyle, JsonTreeVisuals,
delimiters::{ExpandableDelimiter, SpacingDelimiter},
pointer::{JsonPointer, JsonPointerSegment},
search::SearchTerm,
value::{BaseValueType, ToJsonTreeValue},
JsonTreeStyle, JsonTreeVisuals,
};

/// A closure for a user-defined custom rendering implementation.
Expand All @@ -35,7 +35,7 @@ pub enum RenderContext<'a, 'b, T: ToJsonTreeValue> {
ExpandableDelimiter(RenderExpandableDelimiterContext<'a, 'b, T>),
}

impl<'a, 'b, T: ToJsonTreeValue> DefaultRender for RenderContext<'a, 'b, T> {
impl<T: ToJsonTreeValue> DefaultRender for RenderContext<'_, '_, T> {
fn render_default(&self, ui: &mut Ui) -> Response {
match self {
RenderContext::Property(context) => context.render_default(ui),
Expand All @@ -45,7 +45,7 @@ impl<'a, 'b, T: ToJsonTreeValue> DefaultRender for RenderContext<'a, 'b, T> {
}
}

impl<'a, 'b, T: ToJsonTreeValue> RenderContext<'a, 'b, T> {
impl<'a, T: ToJsonTreeValue> RenderContext<'a, '_, T> {
/// Convenience method to access the JSON value involved in this render call.
pub fn value(&self) -> &'a T {
match self {
Expand Down Expand Up @@ -81,7 +81,7 @@ pub struct RenderPropertyContext<'a, 'b, T: ToJsonTreeValue> {
pub(crate) search_term: Option<&'b SearchTerm>,
}

impl<'a, 'b, T: ToJsonTreeValue> DefaultRender for RenderPropertyContext<'a, 'b, T> {
impl<T: ToJsonTreeValue> DefaultRender for RenderPropertyContext<'_, '_, T> {
fn render_default(&self, ui: &mut Ui) -> Response {
render_property(ui, self.style, &self.property, self.search_term)
}
Expand Down Expand Up @@ -110,7 +110,7 @@ pub struct RenderBaseValueContext<'a, 'b, T: ToJsonTreeValue> {
pub(crate) parent_status: ParentStatus,
}

impl<'a, 'b, T: ToJsonTreeValue> DefaultRender for RenderBaseValueContext<'a, 'b, T> {
impl<T: ToJsonTreeValue> DefaultRender for RenderBaseValueContext<'_, '_, T> {
fn render_default(&self, ui: &mut Ui) -> Response {
render_value(
ui,
Expand Down Expand Up @@ -138,7 +138,7 @@ pub struct RenderExpandableDelimiterContext<'a, 'b, T: ToJsonTreeValue> {
pub collapsing_state: &'b mut CollapsingState,
}

impl<'a, 'b, T: ToJsonTreeValue> DefaultRender for RenderExpandableDelimiterContext<'a, 'b, T> {
impl<T: ToJsonTreeValue> DefaultRender for RenderExpandableDelimiterContext<'_, '_, T> {
fn render_default(&self, ui: &mut Ui) -> Response {
render_delimiter(ui, self.style, self.delimiter.as_ref())
}
Expand All @@ -149,7 +149,7 @@ pub(crate) struct RenderSpacingDelimiterContext<'b> {
pub(crate) style: &'b JsonTreeStyle,
}

impl<'b> DefaultRender for RenderSpacingDelimiterContext<'b> {
impl DefaultRender for RenderSpacingDelimiterContext<'_> {
fn render_default(&self, ui: &mut Ui) -> Response {
render_delimiter(ui, self.style, self.delimiter.as_ref())
}
Expand All @@ -159,7 +159,7 @@ pub(crate) struct JsonTreeRenderer<'a, T: ToJsonTreeValue> {
pub(crate) render_hook: Option<Box<RenderHook<'a, T>>>,
}

impl<'a, T: ToJsonTreeValue> Default for JsonTreeRenderer<'a, T> {
impl<T: ToJsonTreeValue> Default for JsonTreeRenderer<'_, T> {
fn default() -> Self {
Self { render_hook: None }
}
Expand Down Expand Up @@ -334,11 +334,11 @@ impl PropertyLayoutJobCreator {
}
}

impl<'a>
impl
ComputerMut<
(
&JsonTreeVisuals,
&JsonPointerSegment<'a>,
&JsonPointerSegment<'_>,
Option<&SearchTerm>,
&FontId,
),
Expand Down
2 changes: 1 addition & 1 deletion src/response.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashSet;

use egui::{collapsing_header::CollapsingState, Id, Ui};
use egui::{Id, Ui, collapsing_header::CollapsingState};

/// The response from showing a [`JsonTree`](crate::JsonTree).
pub struct JsonTreeResponse {
Expand Down
2 changes: 1 addition & 1 deletion src/style.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use egui::{Color32, FontId, TextStyle, Ui};

use crate::{render::ParentStatus, value::BaseValueType, ToggleButtonsState};
use crate::{ToggleButtonsState, render::ParentStatus, value::BaseValueType};

/// Styling configuration to control the appearance of the [`JsonTree`](crate::JsonTree).
#[derive(Debug, Clone, Default)]
Expand Down
4 changes: 2 additions & 2 deletions src/tree.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{
DefaultExpand, JsonTreeResponse, JsonTreeStyle,
node::JsonTreeNode,
render::{JsonTreeRenderer, RenderContext},
value::ToJsonTreeValue,
DefaultExpand, JsonTreeResponse, JsonTreeStyle,
};
use egui::{Id, Ui};
use std::hash::Hash;
Expand All @@ -13,7 +13,7 @@ pub(crate) struct JsonTreeConfig<'a, T: ToJsonTreeValue> {
pub(crate) renderer: JsonTreeRenderer<'a, T>,
}

impl<'a, T: ToJsonTreeValue> Default for JsonTreeConfig<'a, T> {
impl<T: ToJsonTreeValue> Default for JsonTreeConfig<'_, T> {
fn default() -> Self {
Self {
style: Default::default(),
Expand Down
6 changes: 3 additions & 3 deletions tests/json_tree_test.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::sync::Arc;

use egui::{mutex::Mutex, CentralPanel, Context, FontDefinitions, Style};
use egui_json_tree::{render::RenderContext, DefaultExpand, JsonTree, JsonTreeStyle};
use egui::{CentralPanel, Context, FontDefinitions, Style, mutex::Mutex};
use egui_json_tree::{DefaultExpand, JsonTree, JsonTreeStyle, render::RenderContext};
#[cfg(feature = "serde_json")]
use serde_json::{json, Value};
use serde_json::{Value, json};

#[cfg(all(feature = "simd_json", not(feature = "serde_json")))]
use simd_json::{json, owned::Value};
Expand Down