[GH-ISSUE #355] Question about Pages.SetChangedFunc() callback #265

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

Originally created by @pktgen on GitHub (Oct 17, 2019).
Original GitHub issue: https://github.com/rivo/tview/issues/355

When I set the callback I do get the callback when a page changes focus. My question is what can I do with the callback as I do not seem to have any context as to what page changed. It seems like the callback should be passing in a values(s) to allows some action based on the change. Maybe I am using it wrong.

Here is what I want to do and maybe you can suggest a different approach.

I have say three pages '1', '2' and '3' using the keyboard numbers to switch pages. When I am on page '3' then press '1' to bring up page '1' I would like page '3' get a callback to shutdown or release resources.

Any suggestions?

Originally created by @pktgen on GitHub (Oct 17, 2019). Original GitHub issue: https://github.com/rivo/tview/issues/355 When I set the callback I do get the callback when a page changes focus. My question is what can I do with the callback as I do not seem to have any context as to what page changed. It seems like the callback should be passing in a values(s) to allows some action based on the change. Maybe I am using it wrong. Here is what I want to do and maybe you can suggest a different approach. I have say three pages '1', '2' and '3' using the keyboard numbers to switch pages. When I am on page '3' then press '1' to bring up page '1' I would like page '3' get a callback to shutdown or release resources. Any suggestions?
kerem closed this issue 2026-03-04 01:03:28 +03:00
Author
Owner

@Bios-Marcel commented on GitHub (Oct 17, 2019):

Could still access the Pages struct from within the callback. That's what I'd at least.

<!-- gh-comment-id:543378434 --> @Bios-Marcel commented on GitHub (Oct 17, 2019): Could still access the Pages struct from within the callback. That's what I'd at least.
Author
Owner

@rivo commented on GitHub (Oct 18, 2019):

Multiple pages can be visible at the same time so there is not really one page that I could supply to that "changed" callback. But you are right in that Pages doesn't provide many functions to inspect its current state. To make your example easier, I added a function GetFrontPage() which should solve your problem. Let me know if this helps.

<!-- gh-comment-id:543731432 --> @rivo commented on GitHub (Oct 18, 2019): Multiple pages can be visible at the same time so there is not really *one* page that I could supply to that "changed" callback. But you are right in that `Pages` doesn't provide many functions to inspect its current state. To make your example easier, I added a function [`GetFrontPage()`](https://godoc.org/github.com/rivo/tview#Pages.GetFrontPage) which should solve your problem. Let me know if this helps.
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#265
No description provided.