Repository navigation
[CTX-1858] feat(lua,render): cross-axis align for bounded Lua UI composition - #3198
Conversation
…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.
|
Warning Review limit reachedYou'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. View limit details
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. |
Xuepoo
left a comment
There was a problem hiding this comment.
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.
- No duplication — PASS.
UI_STYLE_FIELDSalready carriedgapbefore this PR andbitty-renderalready applied it; the band-rootaligndistribution 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. - Closed set + typed refusal — PASS.
parse_style_align(crates/bitty-lua/src/ui_style.rs:438) accepts exactlystart|center|end, rejects a non-string, an over-cap value and any other spelling throughE_UI_COMPONENT_INVALID; there is no clamp and no best-effort default.UI_STYLE_FIELDSis now eight names (ui_style.rs:250-259). - Kind guard — PASS.
style.alignis refused on kinds that place no adjacent children and accepts a declaredstartas the no-op there (crates/bitty-lua/src/ui_rich.rs:473-486; testsui_rich.rs:1103,:1172). startis today, byte for byte — PASS.ScenePaintStyle::is_inertnow includesmatches!(self.align, SceneStyleAlign::Start)(crates/bitty-render/src/scene.rs:1136), so an absent style and a declaredstartkeep the directpaint_nodepath;a_declared_start_paints_the_same_list_as_an_absent_alignpins it.- Never out of the box — PASS.
SceneStyleAlign::offsetderives slack withsaturating_suband maps start/center/end to0,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_boxcovers the pathological width. The reported regression (padding subtracted before the sharedStyledguard) is fixed withsaturating_suband stays covered by the pre-existingpadding_past_the_leaf_clips_the_child_away. - Budgets and presentation — PASS. Paint-only: measure changes only through the pre-existing
gappath, the ring frame is unchanged,SCENE_STYLE_SCHEMA_VERSIONstays 2, a non-startalign 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. - Discrimination — PASS. Two mutants in the lane's own scratch copy with a separate
CARGO_TARGET_DIR: reverting the paint hunk reddensscene_style_paint.rs:710/735andlua_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 thebitty-luabuild atui_style.rs:1012. The lane worktree was never mutated to prove it. - Residual (not blocking) —
bitty-terminal-docs/specifications/lua-ui-composition-reconciliation.md:195is stale forgapand now foralign; that belongs to its own docs PR, not this one.
No blocking findings.
VERDICT: APPROVE
Gap established by symbol before coding
Base:
origin/mainat1c24b01c. This lane's brief offered two slices —gap/spacingoralign. Both halves of that pair had already landed, so the symbols say what was still missing:crates/bitty-lua/src/ui_style.rs:202UI_STYLE_FIELDSpadding,radius,border,border_token,min_width,max_width,gap) — noaligngapparse / capui_style.rs:762(style_count),ui_style.rs:251UI_STYLE_MAX_GAP_CELLS90deb814)gapkind guardcrates/bitty-lua/src/ui_rich.rs:453-466(composes_siblings)crates/bitty-rich/src/scene.rs:389SceneNodeStyle,:403gap_cells,:538is_flatcrates/bitty-render/src/scene.rs:1143measure_gapped,:1323paint_gapped,:1347paint_row,:1404paint_column,:1566Styledarmcrates/bitty-runtime/src/scene_bridge.rs:164-180scene_style_ofui_style.rs:322+UiAlign,crates/bitty-lua/src/ui.rs:966-1034, pinned off the style table bycrates/bitty-runtime/tests/scene_style_vocabulary.rs:150-1595ce903c4)lua_ui_style_vocab.rs:296,ui_style.rs:1304alignrefused:unsupported scene style field 'align'So:
gapshipped 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 ofalign, distinct from the band distribution.What now ships
style = { align = "start" | "center" | "end" }onui.richscene nodes (bitty#2191).Row,Column, orListon the axis its siblings do not advance: aRowwalks horizontally, so placement is vertical; aColumn/Listwalks vertically, so placement is horizontal.padding, clipped to the allocation the node was handed — so a placement can never land outside the frame the border ring draws.min_widthis what makes horizontal slack exist on aColumn; a parent clip narrows the placement to the visible box.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.startis today. A declaredstartand an absentalignare both flat: no wrapper node, no op, byte-identical paint list.measurepath is untouched.UiStyleAlign(wire) →SceneStyleAlign(scene model) →ChildFlow(render walk), names pinned name-for-name by the drift gate inscene_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 (newcrates/bitty-runtime/tests/lua_ui_style_align.rs,crates/bitty-render/tests/scene_style_paint.rs, unit tests inui_style.rs/ui_rich.rs/scene.rs/scene_bridge.rs).SCENE_STYLE_SCHEMA_VERSIONstays2: no newSceneNodevariant, only a defaulted field onSceneNodeStylewhose default renders identically (the same reasoningmin_width/max_widthused in #3186).The band root's
alignis unchanged: still a four-value distribution onUiNode::Row, still refused as a top-level rich field byreject_band_only_fields(ui_rich.rs:543). The two surfaces can never meet on one node — thestyletable is hosted onui.rich'sterminalslot, where no node is the band root — and each refuses the other's exclusive spelling (space-betweenis not a placement; astyletable on a band node is dropped and reported).Refusals (typed
E_UI_COMPONENT_INVALID, nothing stored)spacing,width,height,margin,align_itemsinvalid scene style value for field 'align'space-between(the distribution's exclusive value) andCenter/END/centrestarton a kind with no adjacent children —Text,Block,Image,CodeBlock,Table,Rule— naming the kind; a declaredstartstays legal and inert thereBudgets untouched
UI_MAX_NODES2048,UI_MAX_DEPTH16,UI_MAX_TEXT_BYTES256 KiB, 64 blocks per generation,SCN-1..5— all unchanged; no new cap constant was added (the closed set is the bound).alignretains no string, so it charges nothing toSCN-3/SCN-4. A non-startdeclaration costs the existingStyledwrapper: one node and one depth level, exactly likegap.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/bittywith its ownCARGO_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
Styledarm feedsSceneStyleAlign::Startinstead ofstyle.align, so the key parses and crosses but nothing offsets a child):crates/bitty-render/tests/scene_style_paint.rs:710a_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:735a_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:176an_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:203an_aligned_column_pushes_its_children_to_the_far_edge— redlua_ui_style_align.rs:220an_aligned_list_composes_like_a_column— redlua_ui_style_align.rs:256an_aligned_row_places_its_children_on_the_vertical_axis— redlua_ui_style_align.rs:306alignment_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:627a_hand_built_aligned_scene_node_is_admitted_and_painted— red:left: [(0, 0, "ab")],right: [(0, 4, "ab")]Totals:
scene_style_paint21 passed / 2 failed;lua_ui_style_align9 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-luaunit-test build refuses (E0277atui_style.rs:1012, the key-set pin) andlua_ui_style_aligngoes 2 passed / 13 failed, with the accept, refusal, and byte-identity tests all red by name.Restored afterwards (
rsyncfrom the lane back into the scratch copy); the lane tree is the only one that carries the change.Gates (all exit 0)
Not in this slice
bitty-terminal-docs/specifications/lua-ui-composition-reconciliation.md:195still says nogap/size/cross-axis alignment field exists (stale forgaptoo). That is its own docs PR, not this lane.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