Fork me on GitHub
#cljfx
<
2020-09-17
>
jjttjj13:09:41

When I try to add a stylesheet with cljfx css, components no longer work for me, running any code which should show a view fails silently, and no longer works until I restart the jvm, even if i remove the stylesheet from the scene afterwards. Does this sound familiar to anyone? I'm on windows and java 13

(def style
  (css/register ::style
    (let [padding    10
          text-color "#111111"]

      ;; you can put style settings that you need to access from code at keyword keys in a
      ;; style map and access them directly in an app

      {::padding    padding
       ::text-color text-color

       ;; string key ".root" defines `.root` selector with these rules: `-fx-padding: 10;`

       ".root"   {:-fx-padding padding}
       ".label"  {:-fx-text-fill text-color
                  :-fx-wrap-text true}
       ".button" {:-fx-text-fill text-color
                  ;; vector values are space-separated
                  :-fx-padding   ["4px" "8px"]
                  ;; nested string key defines new selector: `.button:hover`
                  ":hover"       {:-fx-text-fill :black}}})))

(fx/on-fx-thread
  (fx/create-component
    {:fx/type :stage
     :showing true
     :title   "Cljfx example"
     :width   300
     :height  100
     :scene   {:fx/type :scene
               :stylesheets [(::css/url style)]

               :root    {:fx/type   :v-box
                         :alignment :center
                         :children  [{:fx/type :label
                                      :text    "Hello world"}]}}}))

dhodnett16:09:52

@U064UGEUQ - your code worked for me when I added :style-class ["label"] to the label node my env: Win10, Java 14.0.2 cljfx 1.7.10, clojure 1.10.1 :scene   {:fx/type :scene           :stylesheets [(::css/url style)]           :root    {:fx/type   :v-box                     :alignment :center                     :children  [{:fx/type :label                                 :style-class ["label"]                                 :text    "Hello world"}]}}

jjttjj17:09:31

hmm, still not working for me

vlaaad17:09:23

I have never seen anything like that

vlaaad17:09:30

What is the result of evaluating (System/getProperty "java.protocol.handler.pkgs" "")?

jjttjj17:09:11

"|cljfx.css"

vlaaad17:09:29

can you try setting it to just cljfx.css ?

jjttjj17:09:46

Sure one sec

jjttjj17:09:27

Still nothing

vlaaad17:09:33

hmm, maybe there are some error logs somewhere? 🙂

vlaaad17:09:14

I tried the code on windows with java 14 and it works...

jjttjj17:09:18

Yeah I'm wondering where the errors are going haha. I can try Java 14 out later tonight

vlaaad17:09:52

what version of java 13 do you use? 13? 13.0.1? 13.0.2?

vlaaad19:09:26

Worked for me on windows with 13.0.1 JDK:

PS C:\Users\Vlaaad> clj -Sdeps "{:deps {cljfx/cljfx {:mvn/version """"1.7.10""""} cljfx/css {:mvn/version """"1.1.0""""}}}"
Clojure 1.10.1
user=> (System/getProperty "java.version")
"13.0.1"
user=> (require '[cljfx.css :as css] '[cljfx.api :as fx])
nil
user=> (def style
  (css/register ::style
                (let [padding    10
                      text-color "#ff1111"]
                  ;; you can put style settings that you need to access from code at keyword keys in a
                  ;; style map and access them directly in an app
                  {::padding    padding
                   ::text-color text-color
                   ;; string key ".root" defines `.root` selector with these rules: `-fx-padding: 10;`
                   ".root"   {:-fx-padding padding}
                   ".label"  {:-fx-text-fill text-color
                              :-fx-wrap-text true}
                   ".button" {:-fx-text-fill text-color
                              ;; vector values are space-separated
                              :-fx-padding   ["4px" "8px"]
                              ;; nested string key defines new selector: `.button:hover`
                              ":hover"       {:-fx-text-fill :black}}})))
#'user/style
user=> (fx/on-fx-thread
  (fx/create-component
    {:fx/type :stage
     :showing true
     :title   "Cljfx example"
     :width   300
     :height  100
     :scene   {:fx/type :scene
               :stylesheets [(::css/url style)]
               :root    {:fx/type   :v-box
                         :alignment :center
                         :children  [{:fx/type :label
                                      :text    "Hello world"}]}}}))
#object[clojure.lang.Delay 0x373052b5 {:status :pending, :val nil}]
user=>

vlaaad19:09:53

I downloaded the JDK from here https://jdk.java.net/archive/

jjttjj19:09:43

Thanks for all the research! I'll take another look at it in a bit, I'm probably doing something dumb

jjttjj17:09:10

Ok I finally tracked this down. By default I use a repl that starts a sub-repl that uses fipp as a printer, like this

(binding [*print-length* 20
           *print-level* 10]
   (main/repl
     :caught pst
     :print fipp
     ))
For some reason, this is what was causing the issue with the stylesheet. If I remove this it works.

vlaaad17:09:46

hmm, I have no idea how that could affect the css...

vlaaad17:09:25

was that because of subrepl, or because of fipp printer?

jjttjj18:09:36

Oh yeah, good point, it's due to the subrepl. it fails being called after (main/repl). For what it's worth I'm using inf-clojure in emacs

vlaaad18:09:37

I can't quit emacs 😄

vlaaad18:09:34

actually, I can

vlaaad18:09:19

but I only used spacemacs, and still have PTSD from how broken it is all the time

jjttjj18:09:24

I feel the same way 🙂 I've tried every other editor but nothing else sticks with me