Add RenderInfo with lazy element bounds lookup#22
Merged
Conversation
commit: |
e814a6e to
10462b3
Compare
d175c5a to
2e33415
Compare
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.
2e33415 to
a9eec48
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, callsClay_GetElementData(), and writes the bounding box to a float buffer. No tables, no globals — one function handles the lookup.On the TypeScript side,
RenderResultgains aninfo: RenderInfofield with a lazyget(id)method that calls into WASM on demand: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.