-
Notifications
You must be signed in to change notification settings - Fork 38
fix: prevent initial text position jump #764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b16d954
4d33959
ff2a3ae
8973147
bcbc443
be3f007
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,6 +77,28 @@ export class CoreTextNode extends CoreNode implements CoreTextNodeProps { | |
|
|
||
| private _type: 'sdf' | 'canvas' = 'sdf'; // Default to SDF renderer | ||
|
|
||
| /** | ||
| * Only texts whose parent transform/layout depends on measured dimensions | ||
| * need eager layout to avoid an initial position jump. | ||
| */ | ||
| private requiresLayoutForInitialTransform(props: CoreTextNodeProps): boolean { | ||
| const parent = props.parent; | ||
| if (parent === null) { | ||
| return false; | ||
| } | ||
|
|
||
| if ( | ||
| parent.mountX !== 0 || | ||
| parent.mountY !== 0 || | ||
| parent.pivotX !== 0.5 || | ||
| parent.pivotY !== 0.5 | ||
| ) { | ||
| return true; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we returning true when the mount and pivot is being set? |
||
| } | ||
|
|
||
|
Comment on lines
+90
to
+98
|
||
| return parent.autosizer !== null || parent.parentAutosizer !== null; | ||
| } | ||
|
|
||
| constructor( | ||
| stage: Stage, | ||
| props: CoreTextNodeProps, | ||
|
|
@@ -92,6 +114,16 @@ export class CoreTextNode extends CoreNode implements CoreTextNodeProps { | |
| this.textProps = props; | ||
| this._containType = TextConstraint[props.contain]; | ||
|
|
||
| if ( | ||
| (props.forceLoad === true || props.parent !== null) && | ||
| this.requiresLayoutForInitialTransform(props) === true && | ||
| this.fontHandler.isFontLoaded(this.textProps.fontFamily) === true | ||
| ) { | ||
| const resp = this.textRenderer.renderText(this.textProps); | ||
| this.handleRenderResult(resp); | ||
|
|
||
| this._layoutGenerated = true; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the only downside to this is it will also always render text+layouting even if the text is not in visible bounds or is alpha'd out you may potentially be generating a lot of text that isnt even required to be rendered, maybe calling
Comment on lines
+117
to
+125
Comment on lines
+117
to
+125
|
||
|
|
||
| this.setUpdateType(UpdateType.All); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are already doing a parent is null check on the prior if check:
(props.forceLoad === true || props.parent !== null) &&