Hey guys!
I work on Linux and have an minor but a bit annoying issue regarding the interactive development workflow.
All the UI got updated after I evaluated (renderer), but the app window would become a small one, I had to maximize it or drag the window to get larger.
Is it possible to get rid of this? thanks.
Hi Ken! BTW, I donβt use renderer nowadays, ext-watcher replaced it for me. Typically, I trigger a refresh by changing the state atom..
Interesting, the way you describe sounds better than renderer, as I have to trigger it manually.
Thanks Vlad!
But ... it's rarely mentioned in the docs. Here is what AI gives me:
;; Example from cljfx documentation (simplified)
(require '[cljfx.api :as fx])
(def *state (atom {:current-value 0}))
(defn my-component [_]
{:fx/type fx/ext-watcher
:ref *state
::fx/type :label
:text (str "Current state value: " (:current-value @*state))})
;; When *state is updated elsewhere (e.g., (swap! *state update :current-value inc)),
;; the label text will automatically update.
It seems this component would be my root, right?ai fails you here unfortunately
fine π I'm also searching cljfx's code base, trying to figure out something
(defn view [{:keys [value]}]
{:fx/type :label
;:alignment :center
:text (str value)})
(def state (atom 0))
#_(swap! state inc)
(fx/instance
@(fx/on-fx-thread
(fx/create-component
{:fx/type :stage
:showing true
:width 500
:height 600
:scene {:fx/type :scene
:root {:fx/type fx/ext-watcher
:ref state
:desc {:fx/type #'view}}}}
{:fx.opt/type->lifecycle (some-fn fx/keyword->lifecycle #(when (ifn? %) fx.lifecycle/dynamic-fn->dynamic))})))try this example, then uncomment :alignment :center, then, to refresh the view, do (swap! state inc)
Thanks! I'm trying to adapt the code to my existing app, and see if I can make it.
OMG, it works!
And it doesn't have the original annoying window problem
Huge thanks @vlaaad
my pleasure!
I'm wondering, maybe it's better to replace the "interactive dev example" with this approach? It's data driven and we don't have to execute (renderer) manually every now and then.
PS, does it work to apply ext-watcher to the :stage component? It will be perfect as all the ui elements will be under the control of this watcher.
yeah, you can use it as a root
NICE! just tweaked my code a bit that way.
@vlaaad Hi! Is it possible to use ext-many with ext-watcher? I had no luck making it work, it threw an exception: java.lang.IllegalArgumentException: Key must be integer Here is my minimal example:
;;; aka multiple stages
(ns e10-multiple-windows
(:require [cljfx.api :as fx])
(:import [javafx.stage Screen]))
(defn window [{:keys [x y width height]}]
{:fx/type :stage
:always-on-top true
:showing true
:x x
:y y
:width width
:height height
:scene {:fx/type :scene
:root {:fx/type :v-box
:alignment :center
:children [{:fx/type :label
:text (str "Window at [" x ", " y "] "
"with size " width "x" height)}]}}})
(def width 300)
(def height 100)
(def bottom
(-> (Screen/getPrimary)
.getBounds
.getHeight
(- height)))
(def right
(-> (Screen/getPrimary)
.getBounds
.getWidth
(- width)))
(def *state (atom {:x 300 :y 300
:width width :height height}))
(defn window-dispatcher [{state :value}]
#_ ; works
(window state)
#_ ; works
(merge {:fx/type #'window}
state)
;; #_
{:fx/type fx/ext-many
:desc [{:fx/type window
:x 0
:y 0
:width width
:height height}
{:fx/type window
:x 0
:y bottom
:width width
:height height}
{:fx/type window
:x right
:y 0
:width width
:height height}
{:fx/type window
:x right
:y bottom
:width width
:height height}]})
(fx/on-fx-thread
(fx/create-component
{:fx/type fx/ext-watcher
:ref *state
:desc #_{:fx/type #'window-dispatcher}
{:fx/type fx/ext-many
:desc [{:fx/type window
:x 0
:y 0
:width width
:height height}
{:fx/type window
:x 0
:y bottom
:width width
:height height}
{:fx/type window
:x right
:y 0
:width width
:height height}
{:fx/type window
:x right
:y bottom
:width width
:height height}]}}
;; #_
{:fx.opt/type->lifecycle (some-fn fx/keyword->lifecycle
;; fx/fn->lifecycle
#(when (ifn? %)
cljfx.lifecycle/dynamic-fn->dynamic))}))I need a fullscreen transparent window, but it wasn't transparent in fullscreen mode. And I figured that having :style :transparent to :stage can work around it, but I also wanted a :decorated one. So I thought maybe having two :stage windows could fix it.
Hey @vlaaad, I created a pr for updating the interactive dev example at https://github.com/cljfx/cljfx/pull/193 , and a short demo video as well: https://www.youtube.com/watch?v=efnNg4AHKtU What do you think?
Hi Vlad, I've fixed the above issue by removing #' and replacing cljfx.lifecycle/dynamic-fn->dynamic with fx/fn->lifecycle
hey, was working on a project and couldn't find anything for javafx to use fontawesome 7 icons, so i made a minimal lib for cljfx https://clojars.org/org.clojars.zubad/clj-font-awesome