You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! I'm using this crate as a means to build a File System-like viewer. However, I'm having some trouble and maybe am overcomplicating things. I currently have a vector of TreeItems at the top most level, and upon request, like hitting Enter on a particular TreeItem, I will add children to it. I have this working well at 1 layer (i.e i can add children to a parent), but when trying to create another layer of children to an existing child is when things get tricky. I'm currently attempting to recursively build a nested data structure of TreeItems since the value of a selected node is an array of identifiers leading to that node. Is this the recommended approach or am I missing some existing functionality that would make creating this more straight forward?
An example of what I am trying to create is
["one":[//clicking on this key will yield the children ["two", "twenty"]"two":[// clicking on this key will yield children ["three"]"three"]"twenty"]
"ten",]
Appreciate any tips on this!
The text was updated successfully, but these errors were encountered:
Tree structures are surprisingly complicated with Rust. So I fully understand why it feels so hard. I started working on #34 for cases like this, but my whole progress with it got kinda stuck because of rendering glitches with ratatui > 0.26.
In general I would approach a separate data structure and generating the TreeItems on a render (= don't keep them until the next render). In your case the file system already is the separate data structure. So get the open items, and recursively go through the separate data structure, create the children first and then the TreeItem containing them. That seems like a useful approach for me so far. Maybe it helps?
Thanks for the response! I actually got something working based on your feedback. I also took some ideas I saw in the MQTT implementation of this tree-widget that you did. I'm now creating the persistent tree data structure using the ego-tree crate. Then using that, I create my tui-tree-widget items anytime children of a directory are requested. Maybe its a bit inefficient at the moment to completely re-create the tui-tree-widget anytime a change happens in the ego-tree data structure, but for the time being it seems to be fast enough, and works!
Hi! I'm using this crate as a means to build a File System-like viewer. However, I'm having some trouble and maybe am overcomplicating things. I currently have a vector of TreeItems at the top most level, and upon request, like hitting Enter on a particular TreeItem, I will add children to it. I have this working well at 1 layer (i.e i can add children to a parent), but when trying to create another layer of children to an existing child is when things get tricky. I'm currently attempting to recursively build a nested data structure of TreeItems since the value of a selected node is an array of identifiers leading to that node. Is this the recommended approach or am I missing some existing functionality that would make creating this more straight forward?
An example of what I am trying to create is
Appreciate any tips on this!
The text was updated successfully, but these errors were encountered: