Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I made a similar library earlier this year. It builds as C or C++ and is only two files (MIT license): https://github.com/randrew/layout

The API is similar to Yoga. I hadn't seen Yoga before, and I'm surprised at how similar it is. It seems like Yoga is about the same age (or older?) than my Layout library.

It's meant to be easily embedded into existing software, such as game engines, OpenGL-based tools, custom GUI libraries, etc. without requiring its own complicated build system. Its API and layout engine seems to work in a way similar to Yoga, but it doesn't have pre-made bindings for any existing GUI toolkits. There is, however, an example binding for the Lua scripting language.

API comparison:

Yoga:

    YGNodeRef root = YGNodeNew();
    YGNodeStyleSetWidth(root, 500);
    YGNodeStyleSetHeight(root, 120);
    YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);

    YGNodeRef image = YGNodeNew();
    YGNodeStyleSetWidth(image, 80);
    YGNodeStyleSetMargin(image, YGEdgeEnd, 20);
    YGNodeInsertChild(root, image, 0);
Layout:

    lay_context ctx;
    lay_init_context(&ctx);
    lay_id root = lay_item(&ctx);
    lay_set_size_xy(&ctx, root, 500, 120);
    lay_set_contain(&ctx, root, LAY_ROW);

    lay_id image = lay_item(&ctx);
    lay_set_size_xy(&ctx, image, 80, 0);
    lay_set_margins_ltrb(&ctx, image, 0, 0, 20, 0);
    lay_insert(&ctx, root, image);
The Layout library can handle laying out tens of thousands of items in a few microseconds, so I would expect Yoga to have similar performance. (Layout is meant to work stutter-free and waste-free with layouts that could be animated or changing every frame in a game engine.)

One major difference I noticed, though, is that Yoga seems to allocate for each individual node, whereas Layout uses a single resizable contiguous buffer. This is gives it pretty good CPU cache performance (writes are all in their own separate region of the buffer) and allows you to do complete rebuilds of the layout hierarchy without any heap allocations. It's nice if you have a dynamic layout and want to keep the layout calculations fast/cheap. It might be interesting to do benchmarks of the two libraries in different scenarios.

Are there any other libraries similar to Yoga and Layout?



Hey, this looks really good - I'll give a shot at using this in MOAI! Thanks for that!


Thanks. Leave a message or issue on GitHub if you have any problems and I'll try to fix it. I've only used it in my own software, so there's a chance you will encounter some shortcoming or bug that I haven't.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: