[GH-ISSUE #283] TreeView scrolling hooks #218

Closed
opened 2026-03-04 01:03:04 +03:00 by kerem · 2 comments
Owner

Originally created by @ollien on GitHub (May 18, 2019).
Original GitHub issue: https://github.com/rivo/tview/issues/283

It doesn't appear there's a way to hook into the scrolling of the tree view. I'm trying to make a tree that will load lazily, so it would be really nice if I could hook into the scrolling to detect when I need to load more information. Right now, it looks like I can use TreeView.GetCurrentNode, but I don't see a mechanism to determine if that node is actually visible on the screen, or how close to the bottom the current node is.

In an ideal world, it would be really nice if there could be hooks to catch scrolling events for TreeView, or at least some way to tell if the user has a current node that is close to the bottom of the screen (and thus necessitating the fetching of new information).

Originally created by @ollien on GitHub (May 18, 2019). Original GitHub issue: https://github.com/rivo/tview/issues/283 It doesn't appear there's a way to hook into the scrolling of the tree view. I'm trying to make a tree that will load lazily, so it would be really nice if I could hook into the scrolling to detect when I need to load more information. Right now, it looks like I can use `TreeView.GetCurrentNode`, but I don't see a mechanism to determine if that node is actually visible on the screen, or how close to the bottom the current node is. In an ideal world, it would be really nice if there could be hooks to catch scrolling events for `TreeView`, or at least some way to tell if the user has a current node that is close to the bottom of the screen (and thus necessitating the fetching of new information).
kerem closed this issue 2026-03-04 01:03:05 +03:00
Author
Owner

@rivo commented on GitHub (Jun 9, 2019):

The latest commit adds two functions GetScrollOffset() and GetRowCount() to the TreeView primitive. This, together with Box.GetInnerRect(), will allow you to determine which part of the tree structure is currently shown. As you'll see in the documentation, the new functions' return values will only be up to date after the tree view has been drawn. I would suggest that you use Application.SetAfterDrawFunc() to check if there were any changes to these values and then act accordingly.

Let me know in case you still have any questions.

<!-- gh-comment-id:500226541 --> @rivo commented on GitHub (Jun 9, 2019): The latest commit adds two functions [`GetScrollOffset()`](https://godoc.org/github.com/rivo/tview#TreeView.GetScrollOffset) and [`GetRowCount()`](https://godoc.org/github.com/rivo/tview#TreeView.GetRowCount) to the `TreeView` primitive. This, together with [`Box.GetInnerRect()`](https://godoc.org/github.com/rivo/tview#Box.GetInnerRect), will allow you to determine which part of the tree structure is currently shown. As you'll see in the documentation, the new functions' return values will only be up to date after the tree view has been drawn. I would suggest that you use [`Application.SetAfterDrawFunc()`](https://godoc.org/github.com/rivo/tview#Application.SetAfterDrawFunc) to check if there were any changes to these values and then act accordingly. Let me know in case you still have any questions.
Author
Owner

@ollien commented on GitHub (Jun 16, 2019):

@rivo I can't make GetRowCount return anything other than 0. Here's a minimal example that reproduces the issue.

I suspect the culprit is that t.nodes is set to nil after drawing

github.com/rivo/tview@b62197ade4/treeview.go (L569-L571)

Indeed, if I remove this, I get a non-zero result. I can open a PR with this, but I'm going to do more poking to see if there are any undesirable side-effects of doing so. Check out #308.

<!-- gh-comment-id:502412305 --> @ollien commented on GitHub (Jun 16, 2019): @rivo I can't make `GetRowCount` return anything other than 0. [Here's a minimal example that reproduces the issue](https://gist.github.com/ollien/b771d02cda542682ee338e1c736c4d2d). I suspect the culprit is that `t.nodes` is set to `nil` after drawing https://github.com/rivo/tview/blob/b62197ade4121742db57ebd456b1f4d84f2b35dc/treeview.go#L569-L571 Indeed, if I remove this, I get a non-zero result. ~I can open a PR with this, but I'm going to do more poking to see if there are any undesirable side-effects of doing so.~ Check out #308.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#218
No description provided.