Fork me on GitHub
#cljfx
<
2020-09-24
>
bartuka20:09:35

hello, I started to test some ideas with cljfx today and I could not find a way to use webview to loadContent instead of opening an url

bartuka20:09:22

do you guys have some ideas on that?

vlaaad21:09:40

hmm, I had some snippet somewhere, you need a custom prop for that

bartuka21:09:48

That would be great, I saw the example in the repo but was not totally clear the directions to go forward

bartuka21:09:59

Example using url

vlaaad21:09:13

(require '[cljfx.api :as fx]
         '[cljfx.prop :as fx.prop]
         '[cljfx.mutator :as fx.mutator]
         '[cljfx.lifecycle :as fx.lifecycle])

(def ext-with-html
  (fx/make-ext-with-props
    {:html (fx.prop/make
             (fx.mutator/setter #(.loadContent (.getEngine ^javafx.scene.web.WebView %1) %2))
             fx.lifecycle/scalar)}))

(fx/on-fx-thread
  (fx/create-component
    {:fx/type :stage
     :showing true
     :scene {:fx/type :scene
             :root {:fx/type ext-with-html
                    :props {:html "<h1>hello html!</h1>"}
                    :desc {:fx/type :web-view}}}}))

bartuka21:09:53

Oh! great! I will test right now

bartuka22:09:49

Thanks @vlaaad. Works just fine