How Clay's UI Layout Algorithm Works

262K views · 1 year ago · explainer · intermediate · evergreen

Nic Barker explains how the layout algorithm in Clay, his UI layout library written in C, works. He covers how it sizes and positions elements, and why it needs so little overhead.

HN developers recommend it to people building their own UI layout, and discuss it as an elegant alternative to HTML for app interfaces.

5 comments from Hacker News

x
@xscott2026 · in “You might want to build your WebApp in Canvas instead of HTML”
You might find this video useful or interesting: ▶ this video I've been tempted to do something similar for browser canvas, perhaps with some slightly different choices than he made. His approach uses a very elegant way of looking at things though.
RecommendsView on HN
i
@ibobev2025 · in “How Clay's UI Layout Algorithm Works [video]”
Submitted the video to Hacker News.
RecommendsView on HN
n
@nicbarkeragain2025 · in “How Clay's UI Layout Algorithm Works”
Submitted the video to Hacker News.
RecommendsView on HN
i
@ibobev2025 · in “How Clay's UI Layout Algorithm Works [video]”
Submitted the video to Hacker News.
RecommendsView on HN
c
@catapart2025 · in “Apple unveils new Mac Studio, the most powerful Mac ever, featuring M4 Max”
Not that I intend to scale this in any way, but I'm working on an in-game UI rendered on the canvas, and I am thinking I might be able to hack something together based on this youtuber's library and excellent explainer video[0]. The thought had definitely occurred to me that if someone wanted to really roll up their sleeves and maintain a js port of the library, it would provide a translate-able UI from native C to native JS and back. At least, I can imagine a vite/webpack-like cli that reads the C implementation and spits out a js implementation. Of course, I could also imagine one that reads the C and provides the equivalent html/css/js. And others might scoff "why not just compile the whole C app into wasm", which would certainly be plenty performant in a lot of cases. So I guess I don't know why it isn't already being done, and that usually means I don't know enough about the problems to have any clue what it would actually take to make such things. In any case, I'm also looking forward to a quantum leap in web app UI! I'm not quite as optimistic that it's ever going to happen, I guess, but I can see a lot of benefit, if it did. [0]▶ this video
CitesView on HN