Skip to content

💡 Main-axis space distribution (space-between / around / evenly) #73

@natemoo-re

Description

@natemoo-re

Is your feature request related to a problem?

layout.alignX/layout.alignY only model three main-axis positions: start (0), center (2), end (1). There's no way to distribute free space between children the way flexbox does. Any layout that wants items spread across a row currently needs hand-positioned spacers.

Describe the solution you'd like

Expand the layout enums to add distribution modes that split free space across inter-child gaps, mirroring the CSS justify-content property: space-between (3), space-around (4), space-evenly (5).

const node = open("row", {
  layout: {
    width: grow(),
    direction: "ltr",
    alignX: 3,
  },
}); // space-between

For the two-child width-10 case: space-between gives A B (x=0, x=9); space-evenly splits three equal gaps of (10-2)/3 into A B (x=2, x=6); space-around puts half-gaps on the ends. Rounds to whole cells deterministically, applies to both axes (alignX for ltr, alignY for ttb). Should follow the alignment string-literal refactor in #42 (re: #3).

Describe alternatives you've considered

Fake it JS-side by measuring children and emitting fixed-width spacers, but those are baked at encode time so they don't reflow on resize, force the caller to re-measure every frame, and info.get(id).bounds won't reflect a real distribution—it reconstructs layout logic outside the engine.

Additional context

Failing test case on nm/repro/justify-space (test · diff). The wire already carries 3/4/5 unchanged (ops.ts:118, unpacked at src/clayterm.c:514-515); the gap is likely the engine's on-axis alignment switch (clay/clay.h:2971-2975 for x, :2986-2990 for y), which handles only LEFT/CENTER and lets everything else hit default: break, collapsing 3/4/5 to end.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions