Skip to content
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

Tree widget #237

Closed
wants to merge 0 commits into from
Closed

Tree widget #237

wants to merge 0 commits into from

Conversation

namreg
Copy link
Contributor

@namreg namreg commented Apr 18, 2019

Hello, there.
I've created a tree widget for my project. I believe this can be useful for anyone else :)
Let me know, please, what you think about that.

Thanks for the termui project!

@namreg namreg force-pushed the tree-widget branch 2 times, most recently from 7265d73 to 628de8f Compare April 18, 2019 15:09
@namreg
Copy link
Contributor Author

namreg commented Apr 19, 2019

/cc @cjbassi

@srlehn
Copy link

srlehn commented Apr 19, 2019

screenshot of the example:
Auswahl_2019 04 19_12:07:52

@cjbassi
Copy link
Contributor

cjbassi commented Apr 25, 2019

Thanks for the pr! I'd like to merge this but I'll need some time to look over it and possibly suggest any changes.

Copy link
Contributor

@cjbassi cjbassi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks nice. 2 considerations:

  1. How should the cursor be positioned after collapsing a node? Currently it seems like SelectedRow stays the same, but sometimes that leaves no currently visible node selected. Although that might be fine. Just wanted to get some thoughts.

  2. Expand and the other functions that operate on self.rows would potentially operate on an incorrect node if a node is added and Expand is called before the tree is rerendered, since self.rows is only updated in Draw. What if we made self.Nodes private and added a SetNodes method that calls prepareNodes? That would also eliminate calling prepareNodes every draw too.

theme.go Outdated Show resolved Hide resolved
widgets/tree.go Outdated Show resolved Hide resolved
widgets/tree.go Outdated Show resolved Hide resolved
widgets/tree.go Outdated Show resolved Hide resolved
widgets/tree.go Outdated Show resolved Hide resolved
@namreg
Copy link
Contributor Author

namreg commented May 2, 2019

@cjbassi

  1. How should the cursor be positioned after collapsing a node? Currently it seems like SelectedRow stays the same, but sometimes that leaves no currently visible node selected. Although that might be fine. Just wanted to get some thoughts.

I did it intentionally. IMHO, cursor position relates to the line in block area, not to the content is rendered to this area. May be I wrong.

  1. Expand and the other functions that operate on self.rows would potentially operate on an incorrect node if a node is added and Expand is called before the tree is rerendered, since self.rows is only updated in Draw. What if we made self.Nodes private and added a SetNodes method that calls prepareNodes? That would also eliminate calling prepareNodes every draw too.

I like the idea to add public method SetNodes and make property rows private. But we can't rid of the prepareNodes calling before render after that because self.rows contains only visible rows (in our case expanded). Hence, I have moved calling of the prepareNodes to every place where self.rows is changing. Please, let me know what you think about that.

@namreg
Copy link
Contributor Author

namreg commented Jun 6, 2019

gentle ping @cjbassi

@cjbassi
Copy link
Contributor

cjbassi commented Jun 7, 2019

Apologies for the delay, but I haven't forgotten about this! Currently finishing up the school quarter and I should be able to get to this soon.

@namreg
Copy link
Contributor Author

namreg commented Jun 8, 2019 via email

@cjbassi
Copy link
Contributor

cjbassi commented Jul 15, 2019

Sorry for the delay again! Been out of commission a bit due to an injury. I've looked it over again and it LGTM. Changing the widget so that nodes are set with SetNodes looks good. I had to rebase to fix some conflicts but I just merged this and now I'm going to release 3.1. Thanks!

@cjbassi
Copy link
Contributor

cjbassi commented Jul 15, 2019

I accidentally merged before force pushing the PR which is why it says the PR was closed just btw.

cjbassi added a commit that referenced this pull request Jul 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants