Add element dimensions to RenderResult#18
Closed
cowboyd wants to merge 1 commit into
Closed
Conversation
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.
commit: |
Contributor
Author
|
superseded by #22 |
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 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 toRenderResult, keyed by element id. EachRenderInfocontains adimensionsobject withx,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 andClay_ElementIdare recorded in a static table. AfterClay_EndLayout(), bounding boxes are resolved viaClay_GetElementData(). Seven new WASM exports provide access to the count, name strings, and bounding box floats.TypeScript side:
term-native.tsgainsgetElementInfo()which reads the WASM exports into typed objects.term.tsbuilds theMap<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
userDataonClay_ElementDeclarationto 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. TheClay_GetElementData()approach works for all elements.