Giter VIP home page Giter VIP logo

Comments (5)

vlaaad avatar vlaaad commented on June 20, 2024 1

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.

kxygk avatar kxygk commented on June 20, 2024 1

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.

kxygk avatar kxygk commented on June 20, 2024

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.

vlaaad avatar vlaaad commented on June 20, 2024

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.

vlaaad avatar vlaaad commented on June 20, 2024

Good luck :)

from cljfx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.