membrane

2025-04-28T09:08:28.388279Z

I am trying to render SVG with the Skia backend using membrane.skia/svg. I got images to render. However, <text> elements are not rendered. I found a comment in SkSVGDOM mentioning that font manager needs to be specified otherwise text will not be displayed: https://github.com/google/skia/blob/b5ad54043bed93367fbf4a399424fca635d1d7a4/modules/svg/include/SkSVGDOM.h#L30-L35 In the bindings I don't see the Builder being implemented: https://github.com/phronmophobic/membrane/blob/dbebbe215bf397966603243936f894446e18a66b/src/membrane/skia.clj#L1100-L1105 What would it take to add support for the setFontManager method? Are the bindings written manually, or is there some auto-generation involved?

2025-04-29T07:59:38.284269Z

yay, it works, charts have now labels

🎉 1
phronmophobic 2025-04-28T17:13:25.531269Z

The bindings are manually written. It wasn't too much trouble to set the font manager, https://github.com/phronmophobic/membrane/commit/50434e1e7fd563aed207ac55371da06e5c38df59. The change seemed to fix things locally. I'll try to make a release later today. Thanks for tracking down the cause! The font manager for skia used to be handled implicitly. I assume the font manager became a required parameter when skia no longer automatically provided a font manager.

2025-04-28T17:51:06.826219Z

Sweet, that's a quick turnaround! 🎉 When I tried to build skia locally last time, it failed to fetch some dependencies, so I will wait for the build to confirm on my side, but no rush.

phronmophobic 2025-04-28T19:25:33.263239Z

Rebuilding now...

phronmophobic 2025-04-28T21:01:33.909259Z

Ok, it should be fixed in skialib "0.17-beta"

2025-04-28T11:12:12.398199Z

Is there an example or details on how to use scrolling? I found basic/scrollview component, it needs explicit scroll-bounds. If a scroll container is a component rendered in a layout like flex-layout it has dynamic dimensions. Are there some conventions to measure or pass down dimensions calculated by the layout?

phronmophobic 2025-04-28T18:15:43.362749Z

There are lots of examples for scrolling. Unfortunately, there's not much documentation. There's a lot of flexibility for how and when to do layout. Can you provide a bit more context for what you're trying to achieve? I think I could give a better answer with a bit more context.

2025-04-28T18:52:04.172039Z

I am hacking on a work in progress data visualization library. I have some example charts. I can get them to scroll if I hard code the size: https://github.com/dundalek/clj-compost/blob/c7140adaea7faa61f28b0c28401fdca8b0d3e8f8/examples/membrane/src/examples/membrane.clj#L113 Which looks like:

🆒 1
2025-04-28T18:52:09.306489Z

I would like the scrollable area to fill all remaining space of the window and therefore the scrollbar to stick to the edge.

phronmophobic 2025-04-28T18:58:14.024889Z

You'll want to want to set the :include-container-info key to true when calling skia/run. That will pass the container size to the top level component, app. You can then fetch the container size from the context like:

(let [[cw ch :as size] (:membrane.stretch/container-size context)]
  ...)

phronmophobic 2025-04-28T19:03:15.410009Z

I haven't tested this code, but it could look something like:

(defui sidebar [_]
  (ui/label "Sidebar placeholder"))

(defui chart-examples [{:keys [width height]}]
  (let [body (apply ui/vertical-layout
                    (->> examples
                         (mapcat (fn [[label viz]]
                                   [(ui/label label)
                                    (compost-svg {:viz viz
                                                  :width 600
                                                  :height 300})]))))
        body (if container-size
               (basic/scrollview
                {:body body
                 :$body nil
                 :scroll-bounds [width height]})
               body)]
    body))

(defui app [_]
  (let [[cw ch] (:membrane.stretch/container-size context)
        sidebar-view (sidebar {})
        [sw sh] (ui/bounds sidebar-view)

        chart-width (- cw sw)
        chart-height (- ch sh)]
    (ui/horizontal-layout
     sidebar-view
     (chart-examples {:width chart-width
                      :height chart-height}))))

phronmophobic 2025-04-28T19:04:48.643729Z

In general, I don't really like scrollviews. They have their place (eg. tableviews), but imo they are way overused. I have noticed that the first question I get from folks trying membrane is something related to scrollviews 🤷 .

🙂 1
phronmophobic 2025-04-28T19:05:38.097229Z

You can do the scrollview here, but I might suggest aspect filling the remaining space with the chart rather than using a scrollview.

phronmophobic 2025-04-28T19:07:40.744669Z

I think there's still a lot of room for improvement for supporting space filling UIs in membrane. It's a multi level problem though. I think some of the improvement will be better documentation, some improvements will be better layout components in the standard library, some improvements will be better techniques, and some improvements will be for various tools.

2025-04-28T19:09:10.303509Z

I guess people me included are set a bit in the web way, it is hard to break old habits.

2025-04-28T19:10:07.093129Z

Horizontally I can fill it, vertically I think the scroll is suitable here because it is a showcase of multiple charts.

phronmophobic 2025-04-28T19:10:56.663659Z

There's a lot of flexibility for how to do layout since layout isn't coupled to a main thread. I still haven't quite figured out what the best practices should be.

phronmophobic 2025-04-28T19:11:47.649909Z

I haven't had any performance issues, but I like the idea of making it easy to push layout work to compile time.

2025-04-28T19:11:48.985829Z

In the example I included a placeholder sidebar component, how can I measure its width so that I can subtract it from the window container size?

phronmophobic 2025-04-28T19:12:27.934009Z

It's in the example code above.

(defui app [_]
  (let [[cw ch] (:membrane.stretch/container-size context)
        sidebar-view (sidebar {})
        [sw sh] (ui/bounds sidebar-view)

        chart-width (- cw sw)
        chart-height (- ch sh)]
    (ui/horizontal-layout
     sidebar-view
     (chart-examples {:width chart-width
                      :height chart-height}))))

phronmophobic 2025-04-28T19:12:41.828839Z

You can just call ui/bounds on any view (on any thread).

phronmophobic 2025-04-28T19:13:13.330849Z

there's also ui/width and ui/height.

2025-04-28T19:13:45.332389Z

sorry, I overlooked that

phronmophobic 2025-04-28T19:14:07.159079Z

no problem. I'm also realizing I subtracted the sidebar height in the example, which is wrong.

2025-04-28T19:22:46.754819Z

great, I also copied subtracting 7 pixel offset for scrollbar from Easel's component picker and it looks as expected now. Thanks for the help 🙏

phronmophobic 2025-04-28T19:23:22.983899Z

Yea, I need to fix that too. 🤦‍♂️