EdJoPaTo / tui-rs-tree-widget

Tree Widget for ratatui
https://crates.io/crates/tui-tree-widget
MIT License
79 stars 22 forks source link

Modify text of a leaf #39

Open dvdsk opened 3 months ago

dvdsk commented 3 months ago

Hi, I would like to use tui-rs-tree to display sensor readings. In addition of using the tree to browse the sensor information I would like to display the current value in the tree, like this:

Right now I have to rebuild the whole tree to update these values as I see no way to edit the text of a TreeItem. The docs of TreeItem do speak of the ability to change an identifier: https://docs.rs/tui-tree-widget/0.20.0/tui_tree_widget/struct.TreeItem.html#method.child_mut

Am I missing something? And if not could you please add the ability to change the text of a TreeItem

EdJoPaTo commented 3 months ago

The idea of the tui-rs widgets where being short-lived and to not keep the data in the background. On each render the content that should be displayed is referenced in the entities like ListItem or TreeItem and dropped after the render. It was never the idea to keep data long term.

The docs of TreeItem do speak of the ability to change an identifier: https://docs.rs/tui-tree-widget/0.20.0/tui_tree_widget/struct.TreeItem.html#method.child_mut

You can add more children which, but you currently can not update the identifier (and shouldn't because of the stated reason). I think it would be correct to adapt that comment.

And if not could you please add the ability to change the text of a TreeItem

I'm not sure yet whether I would like that… It would be better to keep the data and the way to display it separated. On the other hand, the widgets seem to get more into the direction of keeping their state so it might be worth looking into keeping the state… :thinking: