I this an alternative to REBL ?
> Where datafy-and-nav based tools like REBL pretend that atoms are single-element vectors, Reveal never obscures evaluation results, even the metadata.
I've only been using REBL for a few days but I found the "kiler" feature so far was support for tap>
s. It is quite nice to put a tap> anywhere to see intermediate results (previously I'd litter the code with print statements). Also the tap allowing you to navigate the object is amazing. But yeah, it takes a while to recognize one is dealing with a datafied thing as opposed to the actual thing. I'm still learning how to read datafications.
Yeah, it's can be seen as alternative to REBL. Yes, tap> is great! It's pretty well supported in Reveal
hi everybody! is there a way of adding a callback that gets called after a component render so I can check the dimensions it got? something like componentDidMount in react?
Hi! I haven't implemented it, and haven't had a need for that so far. What is your use case?
I'm migrating a diagram application I created in reagent/re-frame to cljfx. I'm rendering different dynamic in content nodes so I don't know the bounding box before the render (imagine they have text with different lengths)
it would be great to know the bounding boxes after the nodes had been rendered, so I can update the state with that info
does it make sense?
Not sure I understand, what do you mean by different dynamic in content nodes?
like when you add content to a div, you don't know the final size until it has been rendered (unless your are fixing it's with and height)
as an example I'm currently rendering a bunch of
(defn node-cmp [{:keys [fx/context node]}]
{:fx/type :text
:translate-x (:x node)
:translate-y (:y node)
:wrapping-width (:w node)
:text (str node)})
since text length is different for every node I don't know the height until it gets rendered
so with dynamic nodes I mean they are going to take the size of their contents, in this case they are text but they are going to be groups
Hmm, but why do you need text height? Why is it not enough using javafx layouts like v-box or grid-pane?
but even using a pane, if I put a bunch of text inside it how do I know the final box size after render?
I need width and height of whatever nodes I rendered because I need to draw lines that link different nodes, so I need the boxes dimensions
Ah, I see, so it's a non-standard layout. Hmm, let me think...
that is the re-frame app, you can look at the screenshots to have an idea
(fx/on-fx-thread
(fx/create-component
{:fx/type :stage
:showing true
:scene {:fx/type :scene
:root {:fx/type :v-box
:children [{:fx/type fx/ext-on-instance-lifecycle
:on-created #(prn (.getHeight (.getLayoutBounds %)))
:desc {:fx/type :text
:wrapping-width 100
:text (str (range 100))}}]}}}))
every node has layout bounds, you can observe it in on-createdbut you probably need to save it to app context as well?
oh I think that will work! that on-created is just what I was looking for
thanks a lot!
can your text change?
for a given node
yeah I will probably also need a on-updated
no, on updated won't work: it's for instance changes — when component described by :desc
starts returning different node
oh ok, any ideas if there is something for that purpose?
sorry I'm just learning my way around javafx
usually for getters there are observable properties, so you can use them as well:
(fx/on-fx-thread
(fx/create-component
{:fx/type :stage
:showing true
:scene {:fx/type :scene
:root {:fx/type :v-box
:children [{:fx/type fx/ext-on-instance-lifecycle
:on-created (fn [^javafx.scene.text.Text text]
(prn (.getLayoutBounds text))
(.addListener (.layoutBoundsProperty text)
(reify javafx.beans.value.ChangeListener
(changed [_ _ _ v]
(prn v)))))
:desc {:fx/type :text
:wrapping-width 100
:text (str (range 100))}}]}}}))
the problem is, you'll probably want to dispatch events updating db from this callback, which might introduce unnecessary coupling with event handler, so ideally you'd want to have a prop observing layout bounds
I think for my case it will work, I'll give it a try, I will leave some notes and will came later and see if I can figure out the prop creation
thanks again @vlaaad!
you are welcome!
@jpmonettas FYI, I tried creating :on-layout-bounds-changed
prop:
(def text
(cljfx.composite/describe javafx.scene.text.Text
:ctor []
:props (merge cljfx.fx.text/props
(cljfx.composite/props javafx.scene.text.Text
:on-layout-bounds-changed [:property-change-listener cljfx.lifecycle/change-listener]))))
(fx/on-fx-thread
(fx/create-component
{:fx/type :stage
:showing true
:scene {:fx/type :scene
:root {:fx/type :v-box
:children [{:fx/type text ;; notice: text, not :text
:on-layout-bounds-changed {::event ::bounds-changed}
:wrapping-width 100
:text (str (range 100))}]}}}))
Unfortunately, it'll be invoked only when bounds change, so you'll still need to invoke event handler manually when text is created. I don't have a complete solution so far.I think that is enough for what I'm trying to do, thx!
is there a function for dispatching a event from a component when not using the map solution? calling directly the ev handler function will not send the context
that's what I was worried about 🙂
do you use fx/create-app
?
yes
it returns map with renderer and handler. That handler will send the context
oh ok, will work around it like that, thx!