Why SetFocus returns Application?
https://github.com/rivo/tview/blob/9994674d60a85d2c18e2192ef58195fff743091f/application.go#L705
It doesn't seem logical to return Application. What is it for?
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
Yea, well, but I could not find where SetFocus is used this way.
https://github.com/rivo/tview/blob/9994674d60a85d2c18e2192ef58195fff743091f/demos/form/main.go#L10-L17
Yea, well, but I could not find where
SetFocusis used this way.
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... :shrug: :wink:
SetFocus should be passed to input handlers.
https://github.com/rivo/tview/blob/9994674d60a85d2c18e2192ef58195fff743091f/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?
The hierarchy is top-down. Application knows about other primitives but primitives don't know Application directly. They get what they need, when they need it (like here, a setFocus function), but otherwise they don't need a reference to the Application object.
Is there a way for primitive to directly receive the Application handler?
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 Application to find out.
Not as part of the tview library. Most users will probably keep a package-global reference somewhere in their application.
Fair enough. So SetFocus returns Application so that the call can be chained with other methods. Not for passing Application around. Thanks for the explanations.