Skip to content

[CTX-1858] feat(lua,render): cross-axis align for bounded Lua UI composition - #3198

Merged
Xuepoo merged 1 commit into
mainfrom
ctx-1858/lua-ui-align
Nov 16, 2026
Merged

Xuepoo merged 1 commit into
mainfrom
ctx-1858/lua-ui-align

Conversation

@Xuepoo

@Xuepoo Xuepoo commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Gap established by symbol before coding

Base: origin/main at 1c24b01c. This lane's brief offered two slices — gap/spacing or align. Both halves of that pair had already landed, so the symbols say what was still missing:

Surface Symbol at base State
wire key set crates/bitty-lua/src/ui_style.rs:202 UI_STYLE_FIELDS 7 keys (padding, radius, border, border_token, min_width, max_width, gap) — no align
gap parse / cap ui_style.rs:762 (style_count), ui_style.rs:251 UI_STYLE_MAX_GAP_CELLS landed (#3188, 90deb814)
gap kind guard crates/bitty-lua/src/ui_rich.rs:453-466 (composes_siblings) landed
model crates/bitty-rich/src/scene.rs:389 SceneNodeStyle, :403 gap_cells, :538 is_flat no placement field
render crates/bitty-render/src/scene.rs:1143 measure_gapped, :1323 paint_gapped, :1347 paint_row, :1404 paint_column, :1566 Styled arm gap wired, no cross-axis offset
bridge crates/bitty-runtime/src/scene_bridge.rs:164-180 scene_style_of gap crosses, no align
band distribution ui_style.rs:322+ UiAlign, crates/bitty-lua/src/ui.rs:966-1034, pinned off the style table by crates/bitty-runtime/tests/scene_style_vocabulary.rs:150-159 landed (#3190, 5ce903c4)
refusal pin lua_ui_style_vocab.rs:296, ui_style.rs:1304 align refused: unsupported scene style field 'align'

So: gap shipped in #3188 and the band-root distribution shipped in #3190. Re-landing either would duplicate shipped work. The still-missing vocabulary in that family is the cross-axis placement the issue's residual calls "cross-axis alignment", which the reader refused loudly. That is this slice — the placement half of align, distinct from the band distribution.

What now ships

style = { align = "start" | "center" | "end" } on ui.rich scene nodes (bitty#2191).

  • Semantics. Places the direct children of a Row, Column, or List on the axis its siblings do not advance: a Row walks horizontally, so placement is vertical; a Column/List walks vertically, so placement is horizontal.
  • Basis. The node's own content box — the declared width range after padding, clipped to the allocation the node was handed — so a placement can never land outside the frame the border ring draws. min_width is what makes horizontal slack exist on a Column; a parent clip narrows the placement to the visible box.
  • Saturating slack. center = slack / 2, end = slack, slack = box - child, never negative: a child as large as its box stays at offset zero and the existing clip remains the only failure mode.
  • start is today. A declared start and an absent align are both flat: no wrapper node, no op, byte-identical paint list.
  • Paint-only. Alignment changes no measured size, so neither the frame, the ring, nor the sibling origin after the container moves. The measure path is untouched.
  • Closed enums end to end. UiStyleAlign (wire) → SceneStyleAlign (scene model) → ChildFlow (render walk), names pinned name-for-name by the drift gate in scene_style_vocabulary.rs.

Touched files: bitty-lua/src/{ui_style.rs,ui_rich.rs,lib.rs}, bitty-rich/src/{scene.rs,lib.rs}, bitty-runtime/src/scene_bridge.rs, bitty-render/src/scene.rs, plus tests (new crates/bitty-runtime/tests/lua_ui_style_align.rs, crates/bitty-render/tests/scene_style_paint.rs, unit tests in ui_style.rs / ui_rich.rs / scene.rs / scene_bridge.rs).

SCENE_STYLE_SCHEMA_VERSION stays 2: no new SceneNode variant, only a defaulted field on SceneNodeStyle whose default renders identically (the same reasoning min_width/max_width used in #3186).

The band root's align is unchanged: still a four-value distribution on UiNode::Row, still refused as a top-level rich field by reject_band_only_fields (ui_rich.rs:543). The two surfaces can never meet on one node — the style table is hosted on ui.rich's terminal slot, where no node is the band root — and each refuses the other's exclusive spelling (space-between is not a placement; a style table on a band node is dropped and reported).

Refusals (typed E_UI_COMPONENT_INVALID, nothing stored)

  • unknown style key — including spacing, width, height, margin, align_items
  • duplicate key (defence in depth: only a hand-built marshalled table can repeat one)
  • wrong type — integer, boolean, float, table, nil are all invalid scene style value for field 'align'
  • unlisted spelling, case-sensitive — including space-between (the distribution's exclusive value) and Center/END/centre
  • oversized value — 33+ bytes refused by length, never echoed
  • non-start on a kind with no adjacent children — Text, Block, Image, CodeBlock, Table, Rule — naming the kind; a declared start stays legal and inert there
  • hand-built over-cap values are refused again at scene admission, so the wire parser is not the only gate

Budgets untouched

UI_MAX_NODES 2048, UI_MAX_DEPTH 16, UI_MAX_TEXT_BYTES 256 KiB, 64 blocks per generation, SCN-1..5 — all unchanged; no new cap constant was added (the closed set is the bound). align retains no string, so it charges nothing to SCN-3/SCN-4. A non-start declaration costs the existing Styled wrapper: one node and one depth level, exactly like gap.

Presentation only: no terminal content, cursor, selection, or scrollback path is read or written; no renderer handle, no GPU, no per-frame Lua, no capability, no command binding.

Discrimination evidence

Scratch copy $HOME/.hermes/cache/scratch/ctx-1858-disc/bitty with its own CARGO_TARGET_DIR=$HOME/.hermes/cache/scratch/ctx-1858-disc/target. The lane worktree was never mutated to prove this; no target dir is shared between the two trees.

Mutant A — production hunk reverted (the Styled arm feeds SceneStyleAlign::Start instead of style.align, so the key parses and crosses but nothing offsets a child):

  • crates/bitty-render/tests/scene_style_paint.rs:710 a_styled_align_offsets_children_inside_the_declared_box — red: left: [(0, 0, "a")], right: [(0, 4, "a")] (align = center)
  • crates/bitty-render/tests/scene_style_paint.rs:735 a_styled_align_places_row_siblings_on_the_vertical_axis — red: align = center must place the short run on row 1: [(0, 0, "a"), (1, 0, "b"), (2, 0, "c"), (0, 1, "x")]
  • crates/bitty-runtime/tests/lua_ui_style_align.rs:176 an_aligned_column_centres_its_children_inside_its_content_box — red: left: [(0, 0, "a"), (1, 0, "abc")], right: [(0, 4, "a"), (1, 3, "abc")]
  • lua_ui_style_align.rs:203 an_aligned_column_pushes_its_children_to_the_far_edge — red
  • lua_ui_style_align.rs:220 an_aligned_list_composes_like_a_column — red
  • lua_ui_style_align.rs:256 an_aligned_row_places_its_children_on_the_vertical_axis — red
  • lua_ui_style_align.rs:306 alignment_composes_with_padding_and_sibling_gap — red: left: [(1, 1, "a"), (3, 1, "bb")], right: [(1, 5, "a"), (3, 4, "bb")]
  • lua_ui_style_align.rs:627 a_hand_built_aligned_scene_node_is_admitted_and_painted — red: left: [(0, 0, "ab")], right: [(0, 4, "ab")]

Totals: scene_style_paint 21 passed / 2 failed; lua_ui_style_align 9 passed / 6 failed. Composed evidence (the_bridged_style_is_the_hand_built_scene_style) and the refusal tests stayed green, which is the point: the mutant only removes the paint application.

Mutant B — the key removed from the closed set (the parse hunk reverted): the bitty-lua unit-test build refuses (E0277 at ui_style.rs:1012, the key-set pin) and lua_ui_style_align goes 2 passed / 13 failed, with the accept, refusal, and byte-identity tests all red by name.

Restored afterwards (rsync from the lane back into the scratch copy); the lane tree is the only one that carries the change.

Gates (all exit 0)

cargo fmt --check
cargo clippy -p bitty-lua -p bitty-runtime -p bitty-rich -p bitty-render --all-targets --offline -- -D warnings
cargo test -p bitty-lua -p bitty-rich -p bitty-render --offline
cargo test -p bitty-runtime --offline --test lua_ui_style_align --test lua_ui_style_vocab \
    --test lua_ui_gap --test scene_style_vocabulary --test lua_ui_style_size \
    --test lua_ui_parity --test band_align
cargo +1.85 check -p bitty-lua --tests --offline
RUSTDOCFLAGS="-D warnings" cargo doc -p bitty-lua -p bitty-rich --no-deps --offline

Not in this slice

  • Docs synchronization: bitty-terminal-docs/specifications/lua-ui-composition-reconciliation.md:195 still says no gap/size/cross-axis alignment field exists (stale for gap too). That is its own docs PR, not this lane.
  • Vertical size constraints (min_height/max_height), interaction-state styling, safe-mode flattening, and headed capsule dogfood remain open on [plugins] Reconcile bounded Lua UI composition API and host parity #2191.

Related #2191

…osition (bitty#2191)

Land the placement half of the `align` vocabulary on the `ui.rich` style
table. `gap` (#3188) and the band-root distribution (#3190) were already at
the base commit, so this slice adds the still-missing cross-axis placement
instead of duplicating them.

`style = { align = "start" | "center" | "end" }` places the direct children
of a Row/Column/List on the axis their siblings do not advance, inside the
node's own content box (declared width range after padding, clipped to the
allocation), so a placement can never leave the frame its ring draws. Slack
is saturating; `start` is the offset-zero walk and stays flat, so an
unstyled tree lowers to a byte-identical paint list. Alignment is paint-only:
it changes no measured size, so the measure path, the ring frame, and the
sibling origin after the container are untouched.

Refusals are typed `E_UI_COMPONENT_INVALID` with nothing stored: unknown
key, duplicate key, wrong type, unlisted/case-variant spelling (including
`space-between`, the band distribution's exclusive value), oversized value,
and a non-`start` value on a kind with no adjacent children. Budgets
(`UI_MAX_*`, `SCN-1..5`) and `SCENE_STYLE_SCHEMA_VERSION` are unchanged.
@Xuepoo Xuepoo added this to the v0.1.0 milestone Nov 16, 2026
@Xuepoo Xuepoo added feat Feature P1 Priority: high area:ui Area: UI / layout labels Nov 16, 2026
@coderabbitai

coderabbitai Bot commented Nov 16, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 53 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d58a7f66-4739-4fbb-a542-f1ecd35500b6
Commits

Reviewing files that changed from the base of the PR and between 1c24b01 and 5658199.

Files selected for processing: 13

  • crates/bitty-lua/src/lib.rs
  • crates/bitty-lua/src/ui_rich.rs
  • crates/bitty-lua/src/ui_style.rs
  • crates/bitty-render/src/scene.rs
  • crates/bitty-render/tests/scene_style_paint.rs
  • crates/bitty-rich/src/lib.rs
  • crates/bitty-rich/src/scene.rs
  • crates/bitty-runtime/src/scene_bridge.rs
  • crates/bitty-runtime/tests/lua_ui_gap.rs
  • crates/bitty-runtime/tests/lua_ui_style_align.rs
  • crates/bitty-runtime/tests/lua_ui_style_size.rs
  • crates/bitty-runtime/tests/lua_ui_style_vocab.rs
  • crates/bitty-runtime/tests/scene_style_vocabulary.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@Xuepoo Xuepoo left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guard review (independent reviewer, different agent from the lane)

Reviewed head 56581999 (base main 1c24b01c). The lane corrected the brief's premise (both briefed candidates were already shipped: gap in #3188, band-root align distribution in #3190) and landed the still-refused half — cross-axis placement — instead. I checked that correction and the slice itself against the tree.

  1. No duplication — PASS. UI_STYLE_FIELDS already carried gap before this PR and bitty-render already applied it; the band-root align distribution stays pinned off the style table (crates/bitty-runtime/tests/scene_style_vocabulary.rs). The key that was still loudly refused is the placement half, which is what this PR adds.
  2. Closed set + typed refusal — PASS. parse_style_align (crates/bitty-lua/src/ui_style.rs:438) accepts exactly start|center|end, rejects a non-string, an over-cap value and any other spelling through E_UI_COMPONENT_INVALID; there is no clamp and no best-effort default. UI_STYLE_FIELDS is now eight names (ui_style.rs:250-259).
  3. Kind guard — PASS. style.align is refused on kinds that place no adjacent children and accepts a declared start as the no-op there (crates/bitty-lua/src/ui_rich.rs:473-486; tests ui_rich.rs:1103, :1172).
  4. start is today, byte for byte — PASS. ScenePaintStyle::is_inert now includes matches!(self.align, SceneStyleAlign::Start) (crates/bitty-render/src/scene.rs:1136), so an absent style and a declared start keep the direct paint_node path; a_declared_start_paints_the_same_list_as_an_absent_align pins it.
  5. Never out of the box — PASS. SceneStyleAlign::offset derives slack with saturating_sub and maps start/center/end to 0, slack/2, slack (crates/bitty-rich/src/scene.rs:304-311), so a child as wide as its box stays at zero and alignment can never contradict the ring frame. an_aligned_child_is_never_pushed_past_its_box covers the pathological width. The reported regression (padding subtracted before the shared Styled guard) is fixed with saturating_sub and stays covered by the pre-existing padding_past_the_leaf_clips_the_child_away.
  6. Budgets and presentation — PASS. Paint-only: measure changes only through the pre-existing gap path, the ring frame is unchanged, SCENE_STYLE_SCHEMA_VERSION stays 2, a non-start align costs exactly one wrapper node (a_non_start_align_costs_exactly_one_wrapper_node_and_no_bytes), and nothing in the diff touches terminal content, cursor, selection or scrollback, or takes a renderer handle.
  7. Discrimination — PASS. Two mutants in the lane's own scratch copy with a separate CARGO_TARGET_DIR: reverting the paint hunk reddens scene_style_paint.rs:710/735 and lua_ui_style_align.rs:176/203/220/256/306/627; removing the key from the closed set reddens 13 of 15 alignment tests and fails the bitty-lua build at ui_style.rs:1012. The lane worktree was never mutated to prove it.
  8. Residual (not blocking) — bitty-terminal-docs/specifications/lua-ui-composition-reconciliation.md:195 is stale for gap and now for align; that belongs to its own docs PR, not this one.

No blocking findings.

VERDICT: APPROVE

@Xuepoo
Xuepoo merged commit 9f407a3 into main Nov 16, 2026
32 of 35 checks passed
@Xuepoo
Xuepoo deleted the ctx-1858/lua-ui-align branch November 16, 2026 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ui Area: UI / layout feat Feature P1 Priority: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant