cljfx

https://github.com/cljfx/cljfx
2021-01-07T04:01:51.242700Z

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

2021-01-07T04:02:26.243200Z

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

2021-01-07T04:02:33.243400Z

does that seem reasonable?

vlaaad 2021-01-07T07:26:05.243900Z

what do you need node access for?

2021-01-07T19:01:34.245200Z

@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

2021-01-07T19:08:20.245700Z

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)

2021-01-07T19:19:25.248100Z

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???>

vlaaad 2021-01-07T20:49:23.249200Z

@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

vlaaad 2021-01-07T20:54:01.251800Z

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

vlaaad 2021-01-07T20:55:25.253400Z

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 ...)}}