Comments (5)
Hey!
JavaFX disallows reusing the same Node instance in a scene graph multiple times. Because of this, you cannot use fx/ext-instance-factory
to return the same node multiple times, instead, you should create a fresh node every time, e.g.:
(defn
svg
"The actual workmap svg (as a JFX component"
[{:keys [fx/context
svg-string]}]
{:fx/type fx/ext-instance-factory
:create (fn []
(batik-load svg-string))})
from cljfx.
Alright, I'm going to use your implementation for now b/c it serviceable and keeping the code simpler. :) Thank you for your help. I'll shave this yak later and put up a more complete solution here
Your fix does make my larger app non longer resizeable (b/c the redraw is way too slow). I should extend the demo app later to show what I mean. Basically the FranzXaver SVG Nodes can be resized, so if you keep a Node in a subscription context you can reuse the Node and just rescale when your state/window-size changes.
I'll just need to poke around and see how to clone the Nodes in the right place. I still don't really understand why the Node isn't being copied automatically at the moment haha :))
Sorry my demo app is just spread over a bunch of files and not very minimal
from cljfx.
I think I see what you're saying
batik-load
is a slow call and I originally didn't want to reparse the SVG string and regenerate the Node each time. As I understood, with your design the svg
Node will get regenerated with batik-load
only when the :svg-string
key has changed.. right? It seems to accomplish the same result as long as you don't try to redraw the Node many times. I think it'd be suboptimal if you were say reusing a SVG Icon all over an application (and therefore calling batik-load
a bunch).
My original plan was to load the Node once and to then store it in a subscription context. And then I'd reuse the Node directly when I want to draw it some place - but I was unclear on how to force the Node's duplication. Ideally I'd also look to dynamically resize the Node when the window size changes (not something I'm doing in this example though!). Here it'd have to reload and redraw it
I guess my big picture question was, shouldn't the Node have gotten automatically copied/duplicated when you do the svg
function call since things are pass-by-value?
I'm a bit hazy on the details.. maybe doing things my way while also ensuring you are not redrawing the Node when the state/subscription is static is more difficult.
That all said, I do like that with your solution you don't need to save opaque objects in the context.. that does feel more Clojure-y
from cljfx.
Yeah as I understand it won't be re-created unless the SVG string changes. I don't see any way around it because this is how FranzXaver's SvgLoader class works — it only creates nodes from the input stream or file, and the nodes cannot be reused in multiple places. It would be nice if parsing and creating Nodes could be separated into independent steps, but judging by the source code it's not possible.
from cljfx.
Good luck :)
from cljfx.
Related Issues (20)
- depstar is deprecated and archived; switch to tools.build HOT 2
- The example project fails with (UnsupportedOperationException) HOT 6
- Mouseclick and textfield ?
- Support for CheckBoxTreeItem/CheckBoxTreeCell
- Method for adding another context-like property HOT 1
- Runnning examples/e20_markdown_editor results in NullPointerException: HOT 1
- How do I use StyledTextArea or any new class? HOT 2
- Broken encoding for Sanskrit text in WebView HOT 2
- How do I exit the packaged app on window close or menu quit command HOT 2
- Unable to open DISPLAY HOT 4
- Trying to understand the lifecycle again
- Using cljfx with Gradle HOT 2
- Problem using leiningen HOT 2
- how to pass args to constructors HOT 3
- how to set the background of a region HOT 5
- Children: duplicate children added: when using pie-chart and dynamic rendering HOT 3
- behavior of tree cell factory
- Obscure classloader problem in cider HOT 4
- Explanation of mapping between JavaFX properties and component descriptions HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cljfx.