-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
recursively expand all child leaves. #31
Comments
im not entirely sure I entirely understand what you are trying to accomplish so my answer might not perfectly fit. But this is what came to mind when reading it: You can open a lot of items but you need open the parent items too. On mqttui I did something like that: maybe it’s a good idea to include something like that into here? |
That could work, I'm basically trying to visualize json. When I press a button I want to expand the parent aswell as all it's children. Basically call open() I think with the parent and all it's children. I had trouble filtering my vec of items because I couldn't get the identifier out of a TreeItem. But this might just be a misunderstanding of the library. (I'm also still learning Rust so maybe I just misunderstood how it worked.) In a related note my tree could be very large and I noticed that when I have to copy it in Tree::new() during every render this would be very slow. So I was wondering if you are suppose to create a new Tree object during every render or if you have to persist it somewhere and just call .render() every iteration? I have a local fork where I changed Tree to take a reference to a vec of items instead of moving it in there. |
As this is one of the issues I created some benchmarks and performance improvements on rendering. Interestingly the item creating is the one which takes longer, so there are also improvements needed. The basic idea of a TreeItem is to only be a thin wrapper around the original data referencing it when possible. So the original data should be persisted and the TreeItem should only exist a short amount of time. The benchmarks suggest that the item creating takes longer than I hoped, so this should be improved. Also as a side note: I moved the JSON handling of
Hm… yes… It would be possible to create a What I currently think is about the item creation. When the items are created the identifier is also known. This is how I did the search feature for mqttui: check the base data structure what should be opened, create the identifiers from that and use Guess all the options currently are… not really helpful. |
I was using a a structure like this
But instead of using TreeItem as a wrapper around my data I had a function that parsed serde_json into One thing I want to note though when you visualise a json tree (my function is almost identical to what you do here, but one difference is that I apply styles to the object while I'm parsing them. This is a feature that's pretty important to me as a I like color coding to help visualize my data while debugging. But the main issue I had in my first approach which you also have is when you try to visualize array's and objects this information get's lost atm. I have a pretty hacky method where I just add a leaf containing a single char to show it's an array/object. Example from my current impl.
Maybe you know of a better way to visualize this object/array information? |
Just as a side note, I added colorisation to the json stuff b038779 (still unreleased and probably not the best for performance yet) |
To give an update on this issue: With the upcoming The JSON data in your case is known to you, so it will be possible to get the identifiers from the data directly. For the benchmarks I created a somewhat horrible function for that. It's definitely not perfect but suits the need of the benchmark in the current state. Will probably be optimized in the future. tui-rs-tree-widget/benches/bench.rs Lines 86 to 111 in 81692d0
|
I would like to add an event handler that opens all child leaves when a parent leave is selected. Currently it seems to only be possible to open 1 level? I have a local fork where I make
identifier
public on Item this lets me create filters but getting the currently selected item and using it's identifier to filter my tree state.Would there be interest in my creating a PR for this, or possibly making identifier a field that's accessible from outside the crate not sure if this currently is possible?
The text was updated successfully, but these errors were encountered: