Skip to content

openpencil: align leaves by a baseline the host gives them - #6

Merged
dannote merged 1 commit into
openpencil/taffyfrom
openpencil/leaf-baselines
Nov 26, 2026
Merged

dannote merged 1 commit into
openpencil/taffyfrom
openpencil/leaf-baselines

Conversation

@dannote

@dannote dannote commented Nov 26, 2026

Copy link
Copy Markdown
Member

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

  • LayoutNode gains baseline, 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.
  • Taffy's own baseline alignment does the rest, as Figma does: a nested box aligns by its first child's baseline, and each wrapped line by its own. A leaf without a baseline still aligns by its bottom edge.
  • A leaf with a baseline keeps its record index even when it is not measured, since a text with a fixed size is not measured and still has a baseline.

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.
  • The expected positions are Figma's, measured on the same row: text 19 px down, the box 11 px, the nested box 9 px.

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.
@coderabbitai

coderabbitai Bot commented Nov 26, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

LayoutNode now stores an optional baseline, which the host serializes for childless nodes. The record stride increases from 54 to 55. The Rust layout callback applies finite baselines to leaf layout and returns zero size for unmeasured nodes. Tests cover baseline alignment for wrapped and unwrapped flex rows.

Merge Risk: Minimal · up to a6033

This change lets the host give leaf nodes a baseline so flex rows align the way Figma does. No concrete merge-blocking risk was found, and leaves without a baseline keep aligning by their bottom edge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: leaves are aligned by a baseline that the host provides. The changeset adds a baseline field to LayoutNode, writes it to the record, and passes it to Taffy for leaf la…
Description check Passed The description follows the template. It has an Objective section that explains the baseline mismatch with Figma, with measured expected positions. It also covers what changed, validation steps, and t…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: leaves are aligned by a baseline that the host provides. The changeset adds a baseline field to LayoutNode, writes it to the record, and passes it to Taffy for leaf layout, so the title matches the primary change. It is specific and concise.

Full details: Description check

Explanation

The description follows the template. It has an Objective section that explains the baseline mismatch with Figma, with measured expected positions. It also covers what changed, validation steps, and that no Taffy code changed. The template's Context section is not labeled, but the description covers its content through the Taffy and fixture notes. The Feedback wanted section is optional and can be omitted. The changelog requirement is not addressed. The change touches only the openpencil binding, which is not described as an external library change, so this may not apply. The author should confirm that.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • 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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between eeb0e4e and a60337d.

Files selected for processing: 3

  • openpencil/host/index.test.ts
  • openpencil/host/index.ts
  • openpencil/src/lib.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@dannote
dannote merged commit e20c1cf into openpencil/taffy Nov 26, 2026
32 checks passed
dannote added a commit to open-pencil/open-pencil that referenced this pull request Nov 26, 2026
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.
AKEB pushed a commit to AKEB/open-pencil that referenced this pull request Nov 26, 2026
…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.
@dannote
dannote deleted the openpencil/leaf-baselines branch November 26, 2026 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant