@vlaaad Thanks for the great project and super awesome examples and documentation.
@agilecreativity You are welcome 😊
@vlaaad so my situation is this: I spin up a cljfx window, one of the things it contains is a text area to show a log. Separately to any cljfx UI I have a thread that does updates every x seconds or so. I'd like this timer fn to be able to add contents to the log shown by the UI in the text area. So I'm trying to work out how I update my state via the context from outside event handling (while also updating it within event handling). What is the appropriate pattern to follow?
Using normal swap! And so forth I can see my state updating as I expect, but no rendering or fx/sub's are triggered.
In java style javafx it seems one would do the background/io tasks in any which way, then use Platform/runLater to update UI on the javafx thread. But that is directly mutating things etc. Trying to work out what the equivalent way to update state from background thread in cljfx is, and telling it there's new data to render.
hmm, you use create-app
, right?
can you show me your swap!
call?
it should be like (swap! *context fx/swap-context update :log conj new-entry)
or something
Ah. I didn't use fx/swap-context there properly. I seem to be in business.
Glad you got it working 👍
@sundbp I want to warn you about using text areas for logs: they are not suitable for huge amounts of text, and at some point just stop displaying it. Noticed it when doing markdown example: javafx text area can't handle cljfx's readme :)
It's just trailing N lines. I'll limit it to sensible number of lines.
In terms of reading context outside of the UI parts - I'm just using get-in and passing in the first cljfx.context/m key. Looks a bit ugly. Perhaps an indication I should split up my state more..
you can (and should) use fx/sub
outside of UI too
:cljfx.context/m
is implementation detail and you should not rely on it
see https://github.com/cljfx/cljfx/blob/master/README.md#api-stability-public-and-internal-code
Ok. Somehow I thought that wouldn't work. Thanks
Ah. I needed to deref the context atom there to fit the sub api. Outside of the UI flows I have the context as an atom, but inside it not. That was my confusion.
ah, I see
In an event handler - should I use fx/sub to pick out data from context here as well? I assume yes, just confirming :)
yes!
you have it there as a value, by the way
see https://github.com/cljfx/cljfx/blob/master/examples/e18_pure_event_handling/events.clj for example
has anyone come up with an easy way to bundle and distribute an app with Clojure + JavaFX?
I'm pretty naive when it comes to distributing Java apps. I'd like to use cljfx for an internal tool but I can't depend on everyone having JDK 11 / JavaFX installed
we do it at my work using python scripts to assemble jdk (stripped down with jlink) and fat jars into one package.
technology isn't here yet
and this setup isn't enough if you want autoupdates
I guess would be interesting to try to bundle app as jdk + tools.deps + deps.edn that points to "RELEASE" version of your app.
by the way, you don't need to have javafx installed, it's a regular dependency now, not a part of jdk
hehe that could be clever
I'm pretty new to JavaFX. any good resources for laying things out, styling things, etc.?
Ehhh don't really know. I've done cljfx going through javadoc, so mostly code documentation
They also have css reference: https://openjfx.io/javadoc/12/javafx.graphics/javafx/scene/doc-files/cssref.html
I have different layout panes in this example: https://github.com/cljfx/cljfx/blob/master/examples/e07_extra_props.clj