Repository navigation
openpencil: align leaves by a baseline the host gives them - #6
Conversation
A LayoutNode can carry its first baseline, such as a text's first line, which the binding gives Taffy as the leaf's, so baseline alignment places text by its baseline, nested boxes by their first child's, and each wrapped line by its own. A leaf without one still aligns by its bottom edge.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
open-pencil/taffy#6 lets a layout node carry a leaf's first baseline. The Cargo patch moves with the pin, so Blitz builds on the same Taffy.
…n-pencil#2364) * fix: align auto layout text by its first baseline, as Figma does A row aligned by baseline lined its children up by their bottom edges, since the layout engine had no baseline for text. The renderer now measures where a text's first baseline is drawn, and layout gives it to Taffy for text that a row aligns by baseline, itself or through the frames holding it. Taffy aligns the rest as Figma does: a box without text by its bottom edge, a frame by its first line, and each wrapped line by its own baseline. * docs: add the changelog fragment for baseline alignment * build: pin Taffy with leaf baselines open-pencil/taffy#6 lets a layout node carry a leaf's first baseline. The Cargo patch moves with the pin, so Blitz builds on the same Taffy.
Summary
OpenPencil's canvas aligns auto layout children by their bottom edges where Figma aligns them by baseline, because the binding gives Taffy no baseline for a leaf: a measure function returns only a size, and a leaf without a baseline aligns by its bottom. In a row of 32 px and 12 px text with a 20 px box, Figma puts the small text 5 px higher and the box 8 px higher than the canvas does.
What changed
LayoutNodegainsbaseline, a leaf's first baseline from the top of its border box. The host writes it into a new record field, and the binding gives it to Taffy as the leaf's first baseline after laying the leaf out.No Taffy code changes, so there are no fixtures and nothing to send upstream.
AI assistance
Models: Claude Opus 5.5
Validation
openpencil/:cargo fmt --check,cargo clippy --release --locked --target wasm32-unknown-unknown -- -D warnings,bun build.ts,bun run test(11 pass). The two new host tests, a row of text, a box, a fixed-size leaf and a nested box, and a wrapped row, fail when the host leaves the baseline out.