Well, so it’s time for me to finally try TornadoFX...
# tornadofx
o
Well, so it’s time for me to finally try TornadoFX 🙂 I’ve set it up and it shows hello world, but now I’m trying to create a view with a parameter, and I don’t see how to do it. Any hints? Didn’t find anything in the guide…
I basically want to create a TreeView, but passing root as a parameter.
g
@orangy TornadoFX expects you to declare your parameters in your view:
Copy code
class MyTreeView : Fragment() {
     val myParam : T by param()
     override val root = treeview { ... }
}
and instantiate them via:
Copy code
val myTreeView = find<MyTreeView>(params = mapOf(
    MyTreeView::myParam to value
))
I have a preference for passing these in the constructor instead and it seems that's functionally equivalent AFAICT.
o
Huh… So for a View specified in App arguments, how do I set params?
g
o
Well, find<View> did work in
init
block of an App
g
yeah, I think find is valid within any EventTarget. It seems like those extension methods walk up the
Node
hierarchy to find the scope.
e
@orangy Instead of passing parameters you should look into injected ViewModels and Scopes. Unless somebody else elaborates I'll try to later tonight, not in front of a computer right now 🙂
o
I’ve switched to bound properties already 🙂
I dig it from simplest imperative stuff to declarative
e
Haha, great 🙂 Sorry, really busy these days, I hate not having time to answer everyone
o
np, I’ve already implemented binding with debouncing, so I’m learning 🙂