A fork of randrew/layout, which is unmaintained and excellent. Three things
were needed by a declarative UI built on it, and one had to be fixed before
any of them could be built at all.
C99 EVERYWHERE. Upstream stores a rect in a GCC vector_size type and falls
back, on MSVC, to a C++ class with operator[] - which forces the whole library
to be compiled as C++ on that toolchain. Both are replaced by a struct holding
an array. The algorithm still indexes by dimension; the only change to the API
is that a rect is read as r.v[0] rather than r[0].
WEIGHTED TRACKS. lay_set_weight gives a filling item its share of the leftover
relative to its siblings, where upstream splits it equally. Weight 0 reads as
1, so an item that says nothing behaves as it did. A size on a weighted item is
a floor rather than a size, which makes one rule out of what CSS spells as
three: a fixed track, a minimum that grows, and a fraction.
GAPS. lay_set_gap puts space between an item's children without putting it
outside them - a row of three has two gaps and no leading or trailing one. It
applies down a wrapped row's lines as well as along them, and it is counted
when a container is sized to its contents, which a container was not: it came
out exactly one gap per child too short.
PADDING, from randrew/layout#23 by codecat, merged and then ported onto the
struct rect. A margin is space outside an item and a padding is space inside
it. The PR is carried as its own commit so its authorship stays where it
belongs.
The upstream tests are not carried: test_layout.c assumes the vector rect.
test_onlay.c replaces them and checks the arithmetic against numbers taken
from a running application rather than from this library - a login card,
weighted columns, floors that grow, template rows, and padding told apart from
margin on both halves, because a padding that only inset the children would
pass a test that looked at the children alone.
Every change is marked // ONLAY: in the source with the reason beside it.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>