Fork me on GitHub
#membrane
<
2023-02-20
>
genekim00:02:39

Not urgent — I need to figure out how to get the heights of each room smaller, so I can crank up the density of rooms — is there an easy way I can tighten up the line spacing between the 3x “work remaining” lines? https://github.com/realgenekim/simulator-couch-paint/blob/6c9b6a9833f50f81622e426bb13d9412fefbc23f/src/ui/membrane_ui.clj#L276 Thank you! Another super fun couple of hours making great progress on my app!

genekim00:02:28

Trying :height…. Can you feed in height of < 1.0? Nothing seems to work when I try that.. Hmm… no value I try seems to make a difference… https://github.com/realgenekim/simulator-couch-paint/blob/8ed0afb2f362a9702cf1a1eef5176a0e08507834/src/ui/membrane_ui.clj#L275

genekim00:02:11

Wait a second.. I think it worked. Just didn’t update!

genekim01:02:38

Never mind — it works! 🎉

phronmophobic01:02:49

I was doing the same thing.

phronmophobic01:02:14

Just setting the line :height to 1 seems to tighten everything. For whatever reason, adding emoji adjusts the default :height to something greater than 1.

phronmophobic01:02:24

That might also fix the couch error from earlier

phronmophobic01:02:21

Another gotcha here is that defui components use caching. That means if you update a function that component relies on, it won't re-evaluate the component unless it gets a new value to render. You can force the component to re-evaluate to by re-evaluating any defui component.

genekim01:02:01

Baffled by this one — recording (this time in 4K, is that better?) font-size isn’t being picked up by component. Caching? Okay, let me try that. But, color changes, but not font size? https://capture.dropbox.com/HQelqbh1xxyglXTg (Gimme 30s. will check into repo.)

phronmophobic01:02:46

I bet if you make changes and then re-evaluate any defui component, that it will update everything.

genekim01:02:57

Hmm. I’m reloading entire namespace everytime, which should re-eval all defui, yes?

genekim01:02:54

DOH! Big typo on my part. I think I found it.

phronmophobic01:02:28

oh, right. I think :font-size should be part of the style map.

genekim01:02:58

Yes. Sorry about that!!! Okay, that’s a wrap for today! Wooot! Thx again!

genekim08:02:57

@smith.adriane Got furniture inventory working in about 45m — half the time was modifying the simulator, half was rendering it in membrane. So great!!! https://capture.dropbox.com/NlfuIwVUpN5AuDVQ

genekim08:02:24

Oh, the best part! The number slider as a scrubber! https://capture.dropbox.com/wbNYMpqdTmmzePHm

jlmr09:02:35

@smith.adriane this code fails to compile:

(defui test-defui
  [{:keys [mpos]}]
  (ui/on
   :mouse-move
   (fn [mpos]
     [[::set-mouse-pos $mpos mpos]])
   (ui/label "Hello mouse!")))
The message is: Unable to resolve symbol: $mpos in this context. I can work around it by renaming mpos in the fn to something else. Is this expected behaviour?

phronmophobic19:02:28

Yes, that is expected. $mpos is the reference for the current lexical value of mpos. I can see how it might be convenient for your example to have $mpos refer to the mpos from the outer lexical scope, but I think maintaining that $sym is always the reference for the current lexical value of sym is important for reasoning about more complicated cases.

(defui test-defui
  [{:keys [other-mpos]}]
  (ui/on
   :mouse-move
   (fn [_]
     (let [mpos other-mpos]
       [[::set-mouse-pos $mpos mpos]]))
   (ui/label "Hello mouse!")))

(ui/mouse-move (test-defui {:other-mpos 42}) [ 0 0])
;; ([:ui.membrane-ui/set-mouse-pos [(keypath :other-mpos) []] 42])

jlmr18:02:24

Ok good to know it is expected 🙂

phronmophobic18:02:51

I'm open to changes if there are good reasons, but that's the current rationale.

phronmophobic18:02:01

Or maybe figuring out how to add warnings or better error messages.

jlmr18:02:20

I think a warning would be nice if possible. It took me some time figuring out what was going wrong. And I don’t have a strong opinion yet on whether the current way is good or could be better.

jlmr12:02:54

I’m also trying to get contextual state working. I’ve made the following toy example:

(def the-state (atom {:scale 1.0
                      :subs [{:x 0
                              :y 0
                              :text "hello"}
                             {:x 10
                              :y 10
                              :text "world"}]}))

(defui sub-component
  [{:keys [x y text]}]
  (ui/translate x y
                (ui/label (str text))))

(defeffect ::scale
  [$scale factor]
  (dispatch! :update $scale #(* % factor)))

(defui main-component
  [{:keys [^:membrane.component/contextual scale subs]}]
  (ui/on-key-press
   (fn [k]
     (case k
       "+"
       [[::scale $scale 1.01]]

       "-"
       [[::scale $scale 0.99]]

       []))

   (apply ui/scale scale scale
             (for [sub subs]
               (sub-component sub)))))

(skia/run (component/make-app #'main-component the-state) {:include-container-info true})
I’d like the scale value to propagate to all sub-components. However, with the ^:membrane.component/contextual meta information the app no longer works. How is this supposed to work?

👀 2
phronmophobic19:02:21

contextual state lives under the :membrane.component/context key of the app state.

(defui sub-component
  [{:keys [x y text
           ^:membrane.component/contextual scale]}]
  (ui/on
   :mouse-down
   (fn [_]
     [[:set $scale 3.0]])
   (ui/translate x y
                 (ui/label (str text "-" scale)))))

(defeffect ::scale
  [$scale factor]
  (dispatch! :update $scale #(* % factor)))

(defui main-component
  [{:keys [^:membrane.component/contextual scale
           subs]}]
  (ui/on-key-press
   (fn [k]
     (case k
       "+"
       [[::scale $scale 1.01]]

       "-"
       [[::scale $scale 0.99]]

       []))

   (apply ui/scale scale scale
          (for [sub subs]
            (sub-component sub)))))

(skia/run (make-app #'main-component the-state) {:include-container-info true})

phronmophobic19:02:39

If you want it to live somewhere else, there are options, but it might depend on what you're trying to do.

jlmr18:02:12

Storing it under :membrane.component/context is fine, this works great, thanks!

🎉 2