mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 21:35:54 +03:00
[GH-ISSUE #732] Why SetFocus returns Application? #537
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#537
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @abitrolly on GitHub (Jun 5, 2022).
Original GitHub issue: https://github.com/rivo/tview/issues/732
github.com/rivo/tview@9994674d60/application.go (L705)It doesn't seem logical to return Application. What is it for?
@moson-mo commented on GitHub (Jun 6, 2022):
So that you can chain several method calls. Most of the methods do this in this library.
Example (lines 10 to 17):
https://github.com/rivo/tview/blob/master/demos/form/main.go
@abitrolly commented on GitHub (Jun 6, 2022):
Yea, well, but I could not find where
SetFocusis used this way.github.com/rivo/tview@9994674d60/demos/form/main.go (L10-L17)@moson-mo commented on GitHub (Jun 6, 2022):
Well, it probably isn't in any of the examples. If you'd need to, you could though.
Nobody forces you to use the return value of that method... 🤷 😉
@abitrolly commented on GitHub (Jun 6, 2022):
SetFocusshould be passed to input handlers.github.com/rivo/tview@9994674d60/frame.go (L172)So I wonder if it is some kind of hack to pass application pointer to widgets that otherwise do not know where the application is?
@rivo commented on GitHub (Nov 12, 2022):
The hierarchy is top-down.
Applicationknows about other primitives but primitives don't knowApplicationdirectly. They get what they need, when they need it (like here, asetFocusfunction), but otherwise they don't need a reference to theApplicationobject.@abitrolly commented on GitHub (Nov 12, 2022):
Is there a way for primitive to directly receive the
Applicationhandler?Like if I want to pass focus to the previous element in UI, and I don't know which element it was, I could potentially use
Applicationto find out.@rivo commented on GitHub (Nov 13, 2022):
Not as part of the
tviewlibrary. Most users will probably keep a package-global reference somewhere in their application.@abitrolly commented on GitHub (Nov 13, 2022):
Fair enough. So
SetFocusreturnsApplicationso that the call can be chained with other methods. Not for passingApplicationaround. Thanks for the explanations.