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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ let response = JsonTree::new("customised-tree", &value)
})
.default_expand(DefaultExpand::All)
.abbreviate_root(true) // Show {...} when the root object is collapsed.
.toggle_buttons_state(ToggleButtonsState::VisibleDisabled)
.on_render(|ui, ctx| {
// Customise rendering of the JsonTree, and/or handle interactions.
match ctx {
Expand Down
52 changes: 50 additions & 2 deletions examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use egui_json_tree::{
DefaultRender, RenderBaseValueContext, RenderContext, RenderExpandableDelimiterContext,
RenderPropertyContext,
},
DefaultExpand, JsonTree,
DefaultExpand, JsonTree, ToggleButtonsState,
};
use serde_json::{json, Value};

Expand Down Expand Up @@ -625,6 +625,53 @@ impl Show for JsonEditorExample {
}
}

struct ToggleButtonsCustomisationDemo {
value: Value,
toggle_buttons_state: ToggleButtonsState,
}

impl ToggleButtonsCustomisationDemo {
fn new(value: Value) -> Self {
Self {
value,
toggle_buttons_state: Default::default(),
}
}
}

impl Show for ToggleButtonsCustomisationDemo {
fn title(&self) -> &'static str {
"Toggle Buttons Customisation"
}

fn show(&mut self, ui: &mut Ui) {
ui.vertical(|ui| {
ui.horizontal(|ui| {
ui.selectable_value(
&mut self.toggle_buttons_state,
ToggleButtonsState::VisibleEnabled,
"Visible and enabled",
);
ui.selectable_value(
&mut self.toggle_buttons_state,
ToggleButtonsState::VisibleDisabled,
"Visible and disabled",
);
ui.selectable_value(
&mut self.toggle_buttons_state,
ToggleButtonsState::Hidden,
"Hidden",
);
});

JsonTree::new("show", &self.value)
.default_expand(DefaultExpand::All)
.toggle_buttons_state(self.toggle_buttons_state)
.show(ui);
});
}
}

struct DemoApp {
examples: Vec<Box<dyn Show>>,
open_example_idx: Option<usize>,
Expand Down Expand Up @@ -655,7 +702,8 @@ impl Default for DemoApp {
Box::new(CustomExample::new("Custom Input")),
Box::new(SearchExample::new(complex_object.clone())),
Box::new(CopyToClipboardExample::new(complex_object.clone())),
Box::new(JsonEditorExample::new(complex_object)),
Box::new(JsonEditorExample::new(complex_object.clone())),
Box::new(ToggleButtonsCustomisationDemo::new(complex_object)),
],
open_example_idx: None,
}
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! # DefaultRender, RenderBaseValueContext, RenderContext, RenderExpandableDelimiterContext,
//! # RenderPropertyContext,
//! # },
//! # DefaultExpand, JsonTree, JsonTreeStyle
//! # DefaultExpand, JsonTree, JsonTreeStyle, ToggleButtonsState
//! # };
//! # egui::__run_test_ui(|ui| {
//! let value = serde_json::json!({ "foo": "bar", "fizz": [1, 2, 3]});
Expand All @@ -24,6 +24,7 @@
//! })
//! .default_expand(DefaultExpand::All)
//! .abbreviate_root(true) // Show {...} when the root object is collapsed.
//! .toggle_buttons_state(ToggleButtonsState::VisibleDisabled)
//! .on_render(|ui, ctx| {
//! // Customise rendering of the JsonTree, and/or handle interactions.
//! match ctx {
Expand Down Expand Up @@ -76,6 +77,7 @@ mod node;
mod response;
mod search;
mod style;
mod toggle_buttons_state;
mod tree;

pub mod delimiters;
Expand All @@ -86,4 +88,5 @@ pub mod value;
pub use default_expand::DefaultExpand;
pub use response::JsonTreeResponse;
pub use style::JsonTreeStyle;
pub use toggle_buttons_state::ToggleButtonsState;
pub use tree::JsonTree;
Loading