fx-clj
fx-clj copied to clipboard
property plugins ?
trafficstars
commit fa67cd754dc2ff0f20074a3450db097ea6e453de sounds like a new and interesting feature
Could you provide any how-to/example for such a property-plugin ?
I'm using it for a custom command system like this:
(definterface ICommand
(getCommand [])
(getCommandData []))
(defonce ^:private cmd-evt-type (EventType. "command"))
(defonce ^:private cmd-evt-types (atom {}))
(defn- get-event-type [cmd-name]
(or (get @cmd-evt-types cmd-name)
(let [evt-type (EventType. cmd-evt-type
(name cmd-name))]
(swap! cmd-evt-types assoc cmd-name evt-type)
evt-type)))
(defn dispatch-command
([cmd-name scene-or-target]
(dispatch-command cmd-name scene-or-target nil))
([cmd-name scene-or-target data]
(let [target (if (instance? Scene scene-or-target)
(.getFocusOwner scene-or-target)
scene-or-target)
evt-type (get-event-type cmd-name)
evt
(proxy [Event ICommand] [scene-or-target target evt-type]
(getCommand [] cmd-name)
(getCommandData [] data))]
(Event/fireEvent target evt))))
(fx-clj.core.extensibility/register-property-plugin!
"cmd"
(fn [node cmd-name handler]
(.addEventHandler node (get-event-type (keyword cmd-name))
(util/event-handler [e]
(handler {:target (.getTarget e)
:node node
:cmd (.getCommand e)
:data (.getCommandData e)})))))
Then, I can write something like:
(build [:some-control {:cmd/copy (fn [e] ...}])
and then bind an accelerator (Ctrl-C) on the scene that calls (dispatch-cmd :copy scene)
Make sure you are using 0.2.0-SNAPSHOT or git master until 0.2.0 release (which hopefully I'll have time for soon - all I really need to do is update docs).