Fork me on GitHub
#cljfx
<
2021-01-07
>
raaon04:01:51

i have an :on-focused-changed handler that needs reference to the Node itself so i reify a ChangeListener:

:fx/type :label
:on-focused-changed
            (reify ChangeListener
              (changed [_this o _ new-val]
                 (let [^Label label (.getBean ^ReadOnlyProperty o)]
                    ...do stuff with label...)
                 ...??? dispatch another event ???...))
but at the end of the event handling i'd like to dispatch another event

raaon04:01:26

my thinking is that i'll just thread my event-handler into my view functions, and directly invoke it

raaon04:01:33

does that seem reasonable?

vlaaad07:01:05

what do you need node access for?

raaon19:01:34

@vlaaad when a node in a scroll pane gains focus, i want to check its bounds and if it's not in view, update the scroll pane to bring it into view

raaon19:01:20

i've got that part working but then need to dispatch an event after this (along the lines of the code structure i posted above)

raaon19:01:25

alternatively, if there were a way to have the source node carry with the event, that would allow me to do it all in an event handler... something like this perhaps ? -> :on-focused-changed {::event/type ::event/handle-focus-change :node <???get-node-ref???>

vlaaad20:01:23

@atdixon yeah I see wat you want, and I think this is a weak spot in cljfx — passing stuff from cljfx env to event listeners

vlaaad20:01:01

All I can offer is a hack: use (fx/make-ext-with-props cljfx.fx.node/props) to create an extension lifecycle that allows specifying any node props. Then you can setup :on-focus-changed twice: first on the node description with your reified change listener, second in extension lifecycle with event dispatch

vlaaad20:01:25

e.g.

(def ext-with-node-props (fx/make-ext-with-props fx.node/props))

{:fx/type ext-with-node-props
 :props {:on-focused-changed {:my-event ::foo}}
 :desc {:fx/type :label
        :on-focused-changed (reify ...)}}