membrane

https://github.com/phronmophobic/membrane
phronmophobic 2021-03-23T18:24:40.030900Z

I pulled in the changes last night. Works great. I then got side tracked investigating crashes when you try to open, close, then open a new window. It's definitely possible since I do that all the time with skia. There were some https://github.com/JetBrains/skija/issues/62#issuecomment-804621280 I found in skija, but it seems like lwgl's glfw integration also doesn't support opening multiple windows. I build everything at the repl, so that would drive me crazy. @jjttjj, Can you open multiple windows with skija on Windows? Is that something that would help your workflow?

2021-03-23T18:40:58.033Z

I can open multiple windows currently on windows with skija, it works for me now with membane.skija/run (if i do it in a future). I do also hit the occasional jvm crash though when closing windows or shortly after

phronmophobic 2021-03-23T18:41:33.033500Z

Ah ok. Well, hopefully those crashes will be fixed in the next release.

2021-03-23T18:42:41.034400Z

cool! yeah I'm used to them and they aren't a big deal 🙂 it doesn't seem to happen every time.

phronmophobic 2021-03-23T18:43:14.035500Z

I was able to reliably trigger it by opening a window, closing it, and the calling (System/gc)

phronmophobic 2021-03-23T18:43:38.036Z

I think (hope) those crashes will be fixed. There may be others.

2021-03-23T18:44:16.036500Z

Oh interesting, I'm not on windows now but I'll test that out in a bit when I get to my main computer

phronmophobic 2021-03-23T18:44:43.037200Z

No hurry. I also have a Windows Virtual Box vm that I sometimes check.

2021-03-23T18:45:40.038200Z

Thanks for pulling in the changes too! I know they're kinda underwhelming but i was thinking it's maybe worth getting the changes in incrementally

phronmophobic 2021-03-23T18:46:18.038500Z

Thanks for the patch!

2021-03-23T18:48:44.039700Z

Unrelated but I've had in the back of my mind the idea of trying to implement a generic layout element thing in membrane, something like hoplon/ui https://github.com/jumblerg/ui

phronmophobic 2021-03-23T18:50:50.041200Z

That would be neat. vertical-layout and horizontal-layout are very bare bones.

2021-03-23T18:53:06.043200Z

I used that briefly awhile ago and it was always a nice way to code up layouts to me. I'm guessing it would just involve a pane function that would generate some data bottom up and then rendered by some higher level construct (to allow children to be rendered in terms of their parent). The hard part probably is managing the state changes though, as always

phronmophobic 2021-03-23T18:54:46.043600Z

It seems like the layout could be a pure function

phronmophobic 2021-03-23T18:55:07.044Z

similar to vertical-layout

2021-03-23T19:01:12.045500Z

Oh yeah, looking at that now and it seems like a great starting point, don't now why I didn't think of that

phronmophobic 2021-03-23T19:01:40.046Z

another option is to make it a component:

(defn do-my-layout [props drawables]
  ;; layout element with ui/translate or similar
  
  )

(defrecord MyLayout [props drawables]
  IOrigin
  (-origin [this]
    [0 0])

  IChildren
  (-children [this]
    (do-my-layout props drawables))

  IBounds
  (-bounds [this]
    (bounds (do-my-layout props drawables))))

(defn my-layout [props & drawables]
  (MyLayout. props drawables))
;; use
(my-layout {:vertical true :left 20} (ui/label "hi")})

phronmophobic 2021-03-23T19:05:14.048300Z

One idea I've had, but haven't needed to implement is making standard caches available: • A per-frame cache that gets blown away after every frame • A cache that evicts data that wasn't used when drawing the previous frame

phronmophobic 2021-03-23T19:05:43.048800Z

One of the main reasons I haven't is that it hasn't been necessary for the UIs I've built so far.

2021-03-23T19:07:54.049800Z

Thanks that code sketch is useful!

phronmophobic 2021-03-23T19:09:15.051400Z

Memoizing layout functions works really well since everything is value based

2021-03-23T19:09:21.051700Z

What would be put in those caches? I'm not immediately seeing it

phronmophobic 2021-03-23T19:11:27.053500Z

The result of do-my-layout. If the child elements are changing every frame, then memoizing doesn't help, but if the child elements usually stay the same every frame, then memoizing will save a lot of duplicate effort recalculating layouts every frame

2021-03-23T19:11:54.053800Z

Oh yeah, that makes sense