diff --git a/Cargo.toml b/Cargo.toml index 6d153a8..e5bce27 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,8 @@ name = "egui_json_tree" version = "0.11.0" authors = ["Duncan MacKinnon "] -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" @@ -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"] diff --git a/examples/demo/Cargo.toml b/examples/demo/Cargo.toml index adb2677..1c7b2d8 100644 --- a/examples/demo/Cargo.toml +++ b/examples/demo/Cargo.toml @@ -2,13 +2,14 @@ name = "demo" version = "0.1.0" authors = ["Duncan MacKinnon "] -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" } diff --git a/examples/demo/src/apps/copy_to_clipboard.rs b/examples/demo/src/apps/copy_to_clipboard.rs index 1921949..3fabf8e 100644 --- a/examples/demo/src/apps/copy_to_clipboard.rs +++ b/examples/demo/src/apps/copy_to_clipboard.rs @@ -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; @@ -34,7 +34,6 @@ 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() { @@ -42,7 +41,6 @@ impl Show for CopyToClipboardExample { println!("{}", pretty_str); ui.ctx().copy_text(pretty_str); } - ui.close_menu(); } }); }) diff --git a/examples/demo/src/apps/custom_input.rs b/examples/demo/src/apps/custom_input.rs index ba7b165..46458de 100644 --- a/examples/demo/src/apps/custom_input.rs +++ b/examples/demo/src/apps/custom_input.rs @@ -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; diff --git a/examples/demo/src/apps/editor.rs b/examples/demo/src/apps/editor.rs index fc14fc9..ebc3b3e 100644 --- a/examples/demo/src/apps/editor.rs +++ b/examples/demo/src/apps/editor.rs @@ -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; @@ -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() { @@ -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() { @@ -190,7 +189,6 @@ impl Editor { request_focus: true, is_new_key: false, })); - ui.close_menu() } } @@ -206,7 +204,6 @@ impl Editor { }, }; self.edit_events.push(event); - ui.close_menu(); } } }); @@ -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()) { @@ -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))) => { @@ -246,7 +241,6 @@ impl Editor { array_pointer: parent.to_json_pointer_string(), idx: *idx, }); - ui.close_menu(); } } _ => {} @@ -273,7 +267,6 @@ impl Editor { pointer: context.pointer.to_json_pointer_string(), }); context.collapsing_state.set_open(true); - ui.close_menu(); } }); } @@ -290,7 +283,6 @@ impl Editor { pointer: context.pointer.to_json_pointer_string(), }); context.collapsing_state.set_open(true); - ui.close_menu(); } }); } diff --git a/examples/demo/src/apps/wrapping.rs b/examples/demo/src/apps/wrapping.rs index 70ad4be..9775dd9 100644 --- a/examples/demo/src/apps/wrapping.rs +++ b/examples/demo/src/apps/wrapping.rs @@ -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)); } }); diff --git a/examples/demo/src/main.rs b/examples/demo/src/main.rs index e202ea9..8fac0a4 100644 --- a/examples/demo/src/main.rs +++ b/examples/demo/src/main.rs @@ -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; diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 0eefd31..71db649 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -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"] diff --git a/src/node.rs b/src/node.rs index b65c279..6946b2c 100644 --- a/src/node.rs +++ b/src/node.rs @@ -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, @@ -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> { diff --git a/src/pointer.rs b/src/pointer.rs index e670350..1a873a4 100644 --- a/src/pointer.rs +++ b/src/pointer.rs @@ -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 `/`. @@ -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), @@ -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) => { diff --git a/src/render.rs b/src/render.rs index 15c90b4..4e76990 100644 --- a/src/render.rs +++ b/src/render.rs @@ -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. @@ -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 DefaultRender for RenderContext<'_, '_, T> { fn render_default(&self, ui: &mut Ui) -> Response { match self { RenderContext::Property(context) => context.render_default(ui), @@ -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 { @@ -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 DefaultRender for RenderPropertyContext<'_, '_, T> { fn render_default(&self, ui: &mut Ui) -> Response { render_property(ui, self.style, &self.property, self.search_term) } @@ -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 DefaultRender for RenderBaseValueContext<'_, '_, T> { fn render_default(&self, ui: &mut Ui) -> Response { render_value( ui, @@ -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 DefaultRender for RenderExpandableDelimiterContext<'_, '_, T> { fn render_default(&self, ui: &mut Ui) -> Response { render_delimiter(ui, self.style, self.delimiter.as_ref()) } @@ -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()) } @@ -159,7 +159,7 @@ pub(crate) struct JsonTreeRenderer<'a, T: ToJsonTreeValue> { pub(crate) render_hook: Option>>, } -impl<'a, T: ToJsonTreeValue> Default for JsonTreeRenderer<'a, T> { +impl Default for JsonTreeRenderer<'_, T> { fn default() -> Self { Self { render_hook: None } } @@ -334,11 +334,11 @@ impl PropertyLayoutJobCreator { } } -impl<'a> +impl ComputerMut< ( &JsonTreeVisuals, - &JsonPointerSegment<'a>, + &JsonPointerSegment<'_>, Option<&SearchTerm>, &FontId, ), diff --git a/src/response.rs b/src/response.rs index 24fbf84..0443c2d 100644 --- a/src/response.rs +++ b/src/response.rs @@ -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 { diff --git a/src/style.rs b/src/style.rs index ee4d134..bbe8b90 100644 --- a/src/style.rs +++ b/src/style.rs @@ -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)] diff --git a/src/tree.rs b/src/tree.rs index e626d3f..4ac8dc8 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -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; @@ -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 Default for JsonTreeConfig<'_, T> { fn default() -> Self { Self { style: Default::default(), diff --git a/tests/json_tree_test.rs b/tests/json_tree_test.rs index 7ace240..23dbf6c 100644 --- a/tests/json_tree_test.rs +++ b/tests/json_tree_test.rs @@ -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};