Hey all, it might be a silly question as I'm new to cljfx and JavaFX in general, yet I seem unable to figure out how to get hold of the javafx.application.Application instance in, say, a cljfx event handler... does cljfx.api/create-app have an instance of the Application class constructed at some point at all?
Hm... skimmed through the cljfx code and it seems an Application instance is not created at all, which after reading more of JavaFX docs actually makes sense. Please ignore the above question. O:-)
Another question I hope someone would help me with.
I need to create a plain JavaFX node instance passing it another node as an argument. Please see the call to .createDefaultApplicationMenu in application-menu below, where about-stage needs to be a plain javafx.stage.Stage instance.
I tried to create the instance with fx/ext-let-refs and pass it down, but all I get in the about-stage property in application-menu is just a cljfx description map, not a Stage instance.
Q: How do I get hold of the underlying Stage instance to pass it further down?
(ns
(:require
[cljfx.api :as fx])
(:import
(de.jangassen MenuToolkit)))
(set! *warn-on-reflection* true)
(def ^:private ^MenuToolkit menu-toolkit
(MenuToolkit/toolkit))
(defn about-stage
[_]
{:fx/type :stage
...})
(defn application-menu
[{:keys [about-stage]}]
{:fx/type fx/ext-instance-factory
:create #(.createDefaultApplicationMenu menu-toolkit "BlahBlah" about-stage)})
(defn menu-bar
[_]
{:fx/type fx/ext-let-refs
:refs {::about-stage {:fx/type about-stage}}
:desc {:fx/type fx/ext-on-instance-lifecycle
:on-created #(.setGlobalMenuBar menu-toolkit %)
:desc {:fx/type :menu-bar
:menus [{:fx/type application-menu
:about-stage {:fx/type fx/ext-get-ref
:ref ::about-stage}}]
:use-system-menu-bar true
:visible true}}}) I ended up putting the instance into an atom from within the :on-created handler of an fx/ext-on-instance-lifecycle, but it doesn't feel right:
(defn menu-bar
[_]
{:fx/type fx/ext-let-refs
:refs {::about-stage {:fx/type fx/ext-on-instance-lifecycle
:on-created #(reset! about-stage-atom %)
:on-deleted #(reset! about-stage-atom nil)
:desc {:fx/type about-stage}}}
Any ideas how to make this better?There is a way to make this better — make a custom prop
when props are applied, they have access to the actual instances
Thanks heaps, this works indeed 🙂 I was able to get rid of the atom mimicking the flow from the linked example. Now I have to wrap my head around it and figure out what it does and how it actually works. Coming from react where one can pass pretty much anything down in props and then do whatever one desires with them in the body of a render function, I was looking to replicate the same in cljfx, but I guess cljfx's description functions are not exactly alike to the render fns in react... 🤔
hmm yeah, probably different things. cljfx acts on 2 levels, components and props; and I did it that way because… well I was mostly trying to make it work somehow and that’s how it turned out
it’s a bit weird, cljfx’s component lifecycle (create/advance/delete) is sort of the same as prop’s mutator lifecycle (assign!/replace!/retract!), maybe there is a design error somewhere
I doubt I can comment on this as my understanding of both JavaFX and cljfx is shallow at best at this point. Yet it's been a mostly pleasant experience so far. Thanks for the immensely good work implementing cljfx. 🙂