Skip to content

Add RenderInfo with lazy element bounds lookup#22

Merged
cowboyd merged 1 commit into
mainfrom
feat/render-info-v2
Apr 17, 2026
Merged

Add RenderInfo with lazy element bounds lookup#22
cowboyd merged 1 commit into
mainfrom
feat/render-info-v2

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 scroll containers, floating tooltips, or dirty-region tracking. Element IDs are now stable (hashed with seed 0), so callers can look up any element by id after rendering.

Approach

Adds a single WASM export get_element_bounds(name, len, out) that hashes the id string, calls Clay_GetElementData(), and writes the bounding box to a float buffer. No tables, no globals — one function handles the lookup.

On the TypeScript side, RenderResult gains an info: RenderInfo field with a lazy get(id) method that calls into WASM on demand:

interface RenderInfo {
  get(id: string): ElementInfo | undefined;
}

interface ElementInfo {
  bounds: BoundingBox;
}

interface BoundingBox {
  x: number;
  y: number;
  width: number;
  height: number;
}

Querying an unknown or empty-string id returns undefined.

Alternate Designs

Earlier iterations materialized the full map eagerly using global tables and seven accessor functions. The lazy approach is simpler — one WASM export, no state, callers only pay for what they query.

@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@22

commit: a9eec48

@cowboyd cowboyd force-pushed the feat/render-info-v2 branch from e814a6e to 10462b3 Compare April 17, 2026 21:29
@cowboyd cowboyd force-pushed the feat/render-info-v2 branch 2 times, most recently from d175c5a to 2e33415 Compare April 17, 2026 21:38
Adds an `info: RenderInfo` field to RenderResult that provides
on-demand access to element bounding boxes after layout. Callers
query by element id via `info.get(id)`, which calls into WASM to
hash the id and look up the computed bounds via Clay_GetElementData().

A single WASM export handles the lookup — no tables or globals.
Uses the typedef struct infrastructure for BoundingBox field offsets.
@cowboyd cowboyd force-pushed the feat/render-info-v2 branch from 2e33415 to a9eec48 Compare April 17, 2026 21:40
@cowboyd cowboyd merged commit a1ae74c into main Apr 17, 2026
5 checks passed
@cowboyd cowboyd deleted the feat/render-info-v2 branch April 17, 2026 21:42
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