Skip to content

Added padding - #23

Open
codecat wants to merge 1 commit into
randrew:masterfrom
codecat:feature/padding
Open

codecat wants to merge 1 commit into
randrew:masterfrom
codecat:feature/padding

Conversation

@codecat

@codecat codecat commented Sep 13, 2025

Copy link
Copy Markdown

This adds:

  • lay_set_paddings
  • lay_set_paddings_ltrb
  • lay_get_paddings
  • lay_get_paddings_ltrb

This 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

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant