cljfx

Dave 2025-08-23T19:31:18.006879Z

Has anyone used this library to convert svgs to cljfx components? https://github.com/hervegirod/fxsvgimage I saw this snippet from the https://github.com/cljfx/cljfx/blob/ed0133e95b42f7c2d921d203a5b97525f5f9326d/examples/e20_markdown_editor.clj#L13-L14:

(ns e20-markdown-editor
...
;; does not work any more :(
#_(SvgImageLoaderFactory/install (PrimitiveDimensionProvider.))
So I looked around and found https://github.com/hervegirod/fxsvgimage, which worked okay, but after trying to debug some styling issues, I realized this library wouldn’t work depending on how I when I was calling it. Seems like they pull in swing dependencies if it doesn’t detect a running JavaFX environment: https://github.com/hervegirod/fxsvgimage/blob/fe0cab840d214fb4e2da5e835c3f62c6c1006678/src/core/org/girod/javafx/svgimage/SVGLoader.java#L460-L489. Just a sanity check, is doing something like this idiomatic for cljfx, or is there a better way to go about wrapping this library?
(ns aeonik.controlmap.gui.fx-util
  (:import [javafx.application Platform]))

(defn on-fx-sync
  "Run f on the FX thread, starting the toolkit if needed (no Swing). Returns f's result."
  [f]
  (if (Platform/isFxApplicationThread)
    (f)
    (let [p (promise)]
      (try
        (Platform/runLater #(deliver p (f)))         ;; toolkit already started
        (catch IllegalStateException _               ;; toolkit not started yet
          (Platform/startup #(deliver p (f)))))
      @p)))
(ns aeonik.controlmap.gui.svg-component
  "Production-ready idiomatic cljfx SVG component"
  (:require [cljfx.lifecycle :as lifecycle]
            [cljfx.api :as fx]
            [clojure.string :as str]
            [aeonik.controlmap.gui.fx-util :as fxu])
  (:import [javafx.scene.layout Pane Region]
           [javafx.scene Node]
           [javafx.geometry Orientation]
           [javafx.event EventHandler]
           [org.girod.javafx.svgimage SVGLoader SVGImage]
           [ ByteArrayInputStream]))
...

(defn- load-svg-image ^SVGImage [^String svg]
  (fxu/on-fx-sync #(SVGLoader/load svg)))  ;; <- no JFXPanel, no swing
Or should I just give up and convert the svg to cljfx nodes with a parser/factory combo?