Skip to content

Commit d9c98e9

Browse files
committed
make JsonTreeConfig::style and default_expand Options
1 parent 317ccad commit d9c98e9

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/node.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@ impl<'a, T: ToJsonTreeValue> JsonTreeNode<'a, T> {
4545
persistent_id.with(tree_id.with(path_segments))
4646
};
4747

48+
let style = config.style.unwrap_or_default();
49+
let default_expand = config.default_expand.unwrap_or_default();
50+
4851
let mut path_id_map = HashMap::new();
4952

50-
let (default_expand, search_term) = match config.default_expand {
53+
let (default_expand, search_term) = match default_expand {
5154
DefaultExpand::All => (InnerExpand::All, None),
5255
DefaultExpand::None => (InnerExpand::None, None),
5356
DefaultExpand::ToLevel(l) => (InnerExpand::ToLevel(l), None),
@@ -58,7 +61,7 @@ impl<'a, T: ToJsonTreeValue> JsonTreeNode<'a, T> {
5861
let paths = search_term
5962
.as_ref()
6063
.map(|search_term| {
61-
search_term.find_matching_paths_in(self.value, config.style.abbreviate_root)
64+
search_term.find_matching_paths_in(self.value, style.abbreviate_root)
6265
})
6366
.unwrap_or_default();
6467
(InnerExpand::Paths(paths), search_term)
@@ -69,7 +72,7 @@ impl<'a, T: ToJsonTreeValue> JsonTreeNode<'a, T> {
6972

7073
let node_config = JsonTreeNodeConfig {
7174
default_expand,
72-
style: config.style,
75+
style,
7376
search_term,
7477
};
7578

src/tree.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use egui::{Id, Ui};
88
use std::hash::Hash;
99

1010
pub(crate) struct JsonTreeConfig<'a, T: ToJsonTreeValue> {
11-
pub(crate) style: JsonTreeStyle,
12-
pub(crate) default_expand: DefaultExpand<'a>,
11+
pub(crate) style: Option<JsonTreeStyle>,
12+
pub(crate) default_expand: Option<DefaultExpand<'a>>,
1313
pub(crate) renderer: JsonTreeRenderer<'a, T>,
1414
}
1515

@@ -44,13 +44,13 @@ impl<'a, T: ToJsonTreeValue> JsonTree<'a, T> {
4444

4545
/// Override colors for JSON syntax highlighting, and search match highlighting.
4646
pub fn style(mut self, style: JsonTreeStyle) -> Self {
47-
self.config.style = style;
47+
self.config.style = Some(style);
4848
self
4949
}
5050

5151
/// Override how the [`JsonTree`] expands arrays/objects by default.
5252
pub fn default_expand(mut self, default_expand: DefaultExpand<'a>) -> Self {
53-
self.config.default_expand = default_expand;
53+
self.config.default_expand = Some(default_expand);
5454
self
5555
}
5656

0 commit comments

Comments
 (0)