Skip to content

Add element dimensions to RenderResult#18

Closed
cowboyd wants to merge 1 commit into
mainfrom
feat/render-info
Closed

Add element dimensions to RenderResult#18
cowboyd wants to merge 1 commit into
mainfrom
feat/render-info

Conversation

@cowboyd
Copy link
Copy Markdown
Contributor

@cowboyd cowboyd commented Apr 17, 2026

Motivation

Higher-level frameworks need access to computed element bounding boxes after layout — for example, to implement scroll containers, floating tooltips, or dirty-region tracking. Currently the only post-layout data available from render() is pointer events. Element dimensions are computed internally but never exposed.

Approach

Adds an info: Map<string, RenderInfo> field to RenderResult, keyed by element id. Each RenderInfo contains a dimensions object with x, y, width, height — the element's computed bounding box in character cells, zero-indexed from the layout root.

C side: During reduce(), each named element's string and Clay_ElementId are recorded in a static table. After Clay_EndLayout(), bounding boxes are resolved via Clay_GetElementData(). Seven new WASM exports provide access to the count, name strings, and bounding box floats.

TypeScript side: term-native.ts gains getElementInfo() which reads the WASM exports into typed objects. term.ts builds the Map<string, RenderInfo> from those and includes it in the return value.

Elements with empty-string ids are excluded. When duplicate ids exist, only the first element's data appears.

Alternate Designs

Considered using userData on Clay_ElementDeclaration to tag elements, then reading bounding boxes from render commands. This fails for elements without visible properties (no bg/border) since they produce no render commands. The Clay_GetElementData() approach works for all elements.

Adds a `info: Map<string, RenderInfo>` field to RenderResult that
provides post-layout bounding boxes for every named element. Each
RenderInfo contains dimensions (x, y, width, height) zero-indexed
from the layout root.

On the C side, element names and Clay_ElementIds are recorded during
layout, then resolved via Clay_GetElementData() after Clay_EndLayout()
to extract computed bounding boxes. New WASM exports expose the
results to TypeScript.
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 17, 2026

Open in StackBlitz

npm i https://pkg.pr.new/clayterm@18

commit: ae2023d

@cowboyd
Copy link
Copy Markdown
Contributor Author

cowboyd commented Apr 17, 2026

superseded by #22

@cowboyd cowboyd closed this Apr 17, 2026
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