fix: Keep Element layout props and convert Element colors - #352
Open
willeastcott wants to merge 1 commit into
Open
willeastcott wants to merge 1 commit into
willeastcott wants to merge 1 commit into
Conversation
<Element> validated its props with defaults and applied every prop of its schema on each render, in the order of the engine's setters. The defaults of the props that were not given included the margins and their left, bottom, right and top aliases, which come after height, so an image's height and an element's margins were overwritten on every render: a 200 x 100 image came out 200 x 82, and a stretched element with 20 unit margins came out 412 x 214. The schema was also built from a group element, whose color, outline color and shadow color are null, so colors given as strings or arrays were assigned as they were and became NaN. Apply only the props that are given, as Camera, Collision and Render do, the type first and the anchor, pivot and margins before the width and height, as the engine applies them. Build the schema from a text element so its color props are converted, and let color props also take Color objects and four-component arrays. <Screen scaleMode> only allowed "blend", "stretch" and "fit", so the engine's "none" fell back to "blend". Allow "blend" and "none", the two modes the engine has. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 821421e The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
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.
<Element>in 0.11.5 cannot size an image element or take a color string, which makes in-canvas UI in React unreliable beyond auto-sized text. Found while rewriting the User Interface chapter of the User Manual, whose React examples depend on this.Layout props.
<Element>validated its props withvalidatePropsWithDefaultsand applied every prop of its schema on each render, in the order of the engine's setters. The defaults of the props that were not given includemarginand itsleft/bottom/right/topaliases, which come afterheight, so they overwrote the element's rectangle on every render:anchor={[0.5, 0.5, 0.5, 0.5]} width={200} height={100}anchor={[0, 0, 1, 1]} margin={[20, 20, 20, 20]}in a 400 × 300 parentanchor={[0, 1, 1, 1]} margin={[0, 0, 0, 0]} height={50}in a 400 × 300 parentIt now uses
validatePropsPartial, asCamera,CollisionandRenderdo, and appliestypefirst andanchor,pivotand the margins beforewidthandheight, which is the order the engine applies them in. Applyingtypefirst also means props likecolorreach the image or text even when they are written beforetype.Colors. The schema was built from a group element, whose
color,outlineColorandshadowColorarenull, so a color given as"#ff8000"or[1, 0.5, 0]was assigned as it was and the element's color became NaN (it rendered black). The schema is now built from a text element, so those props get the color schema, and the color schema also acceptsColorobjects (the one form that happened to work before) and four-component arrays.<Screen scaleMode>only allowed"blend","stretch"and"fit", so the engine's"none"was replaced by the"blend"default. It now allows"blend"and"none", the engine's two modes;"stretch"and"fit"never existed in the engine, which turns unknown values into"none".Tests: seven new
Elementtests (point-anchored size, split-anchor margins, size after a re-render, hex, array andColorcolors, outline and shadow colors,typeapplied first), all failing before the change, and aScreentest forscaleMode="none". Also checked in Chrome with engine 2.22.4: images, stretched panels and top bars keep their sizes and colors, and positioned labels stay where they are.A changeset is included (patch).
🤖 Generated with Claude Code