Conversation
Alpaq92
added a commit
to Alpaq92/Onlay
that referenced
this pull request
Sep 10, 2026
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#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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds:
lay_set_paddingslay_set_paddings_ltrblay_get_paddingslay_get_paddings_ltrbThis acts as the opposite of margin.
Allows us to avoid creating a secondary container item with a margin to achieve the same thing and do it all in 1 item.
This mirrors my C# implementation here: codecat/Nimble.Layout#1