@vlaaad Any thoughts on using scenebuilder to generate fxml, then consume the fxml in cljfx? I’m exploring the space myself right now but am curious, have you put much thought into it or is it anywhere on the cljfx roadmap?
I have no experience with scene builder unfortunately. I was asked about it before though, so I thought briefly about it, and it was one of the reasons I added fx/ext-instance-factory
, so you can add support for loading it if you need it:
(defn fxml-view [{:keys [resource]}]
{:fx/type fx/ext-instance-factory
:create #(FXMLLoader/load (io/resource resource))})
Usually when you use fxml, you need to lookup some nodes by ids, and this is where fx/ext-on-instance-lifecycle
will come in handy:
(defn my-fxml-component []
{:fx/type fx/ext-on-instance-lifecycle
:on-created (fn [^Node node]
(let [button (.lookup node "#button")]
...))
:desc {:fx/type fxml-view :resource "/my-component.fxml"}})
(didn't try to run this code, just an example)
Note that cljfx itself does not depend on javafx-fxml, so you'll have to add that dependency yourself. This is because I consider fxml not idiomatic cljfx. The way I see it, both cljfx's descriptions and fxml attempt to solve the same problem of declaratively specifying layout. Differences in their solutions are:
- fxml is static, meaning it's just a layout without state, so after loading it you usually lookup some nodes by id and attach behaviour to them, which stops being declarative and starts being imperative once you start integrating fxml in an app
- cljfx descriptions are dynamic, meaning you can change them and observe these changes in running app (see https://github.com/cljfx/cljfx/blob/master/examples/e12_interactive_development.clj), which is not that far from ui builder, and has a huge advantage of being an actual live app instead of static pieces of it.
I thought a good alternative might be a tool that converts fxml to cljfx descriptions.
What do you think? What is your use case for scene builder?Having visual builder is nice though...
The usecase is making ugly tools on the fly
I had never seen the Node.lookup method before, it looks fantastic
I think that has been a big missing link for me.
I want to make simple visual tools on the fly when working on my actual business problem. Lets say I need a UI to list documents out of lucene that match a series of search terms. I could do that at the repl but it would be extremely verbose, instead I could make a visual tool whos sole responsibility is to handle search.