Skip to content
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

BitmapText .textWidth only correct after render? #3461

Closed
KidScripty opened this issue Dec 13, 2016 · 4 comments
Closed

BitmapText .textWidth only correct after render? #3461

KidScripty opened this issue Dec 13, 2016 · 4 comments
Labels
📢 Accepting PRs Would welcome a PR from the community. 🕷 Bug Verified that it’s actually a legit bug that exists in the current release. 💾 v4.x (Legacy) Legacy version 4 support

Comments

@KidScripty
Copy link

After setting the .text property of a BitmapText, the .textWidth is incorrect until after a render. Had to use requestAnimationFrame() to wait when doing re positioning calculations. Is this expected behavior?

@themoonrat
Copy link
Member

Err, it's expected behaviour right now because that's what the code does, but we can make it better ;)

You see, text isn't updated until it's renderered for performance reasons. Imagine you had a counter, counting up super fast. You wouldn't want to re-create each number in the text class because it's only when it's rendered that you need it to show the right thing.

The normal Text class, for example, makes sure that when you try to get the width of it, it updates the text outside of the rendering loop, to make sure that the value returned is accurate and up to date. BitmapText is not doing this (but it should).

Whilst a fix is created, you can call .updateText() on the object before querying .textWidth. This should give you the accurate measurement without having to wait for a rAF

@themoonrat themoonrat added Difficulty: Easy 📢 Accepting PRs Would welcome a PR from the community. 🕷 Bug Verified that it’s actually a legit bug that exists in the current release. 💾 v4.x (Legacy) Legacy version 4 support labels Dec 13, 2016
@themoonrat
Copy link
Member

the fix would be to make the current .textWidth a private ._textWidth, create a read only getter called .textWidth, which calls .validate() before returning ._textWidth;

for the getter of .width (and height),, I believe it should call .updateTransform() before returning the width

@KidScripty
Copy link
Author

.validate is what I was looking for. Thanks :). I'll implement + pr later this evening if I get a chance.

@lock
Copy link

lock bot commented Feb 24, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Feb 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
📢 Accepting PRs Would welcome a PR from the community. 🕷 Bug Verified that it’s actually a legit bug that exists in the current release. 💾 v4.x (Legacy) Legacy version 4 support
Projects
None yet
Development

No branches or pull requests

2 participants