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

Fixing ReferenceError: totalHeight is not defined throw by textAlign(… #5366

Merged
merged 1 commit into from
Sep 11, 2021

Conversation

malviys
Copy link
Contributor

@malviys malviys commented Jul 28, 2021

Fixing ReferenceError: totalHeight is not defined throw by textAlign(, CENTER) and textAlign(, BOTTOM)
Resolves #5360

Changes:
Removed undefine variable totalHeight from src/core/p5.Renderer.js causing ReferenceError while calling
textAlign_(, CENTER) and textAlign(__, BOTTOM)

PR Checklist

@welcome
Copy link

welcome bot commented Jul 28, 2021

🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. And be sure to add yourself to the list of contributors on the readme page!

@outofambit
Copy link
Contributor

@malviys thank you for working on this! could you please include screenshots of using textAlign to help confirm that we now have the correct behavior (besides not erroring)? thank you!

(also ccing @lawreka in case you have thoughts on the approach here!)

@lawreka
Copy link
Contributor

lawreka commented Aug 24, 2021

Thanks for tagging me here, @outofambit ! It looks like I left these uninitialized variables in when refactoring the text wrapping :(

This fix looks like it does eliminate the ReferenceError, but I'm digging in a little bit into #5146 to see if I missed something important about how totalHeight was used. I would expect in this example that if the text is vertically aligned to the center of the box (where the line is drawn through), the whole multi-line block of text would shift up a little bit.

Screenshot 2021-08-24 at 18 52 34

As it is, only the first line is conforming to the vertical-alignment rule. I would assume also with text-align set to BOTTOM that we don't see the last line aligned with the bottom, but the first line.

If you want to get rid of the error quickly and plan to release soon, this is a good fix, but I'm also happy to revisit the text wrapping function and see what got lost in re-implementation.

@malviys
Copy link
Contributor Author

malviys commented Aug 24, 2021

Here is code screenshot of textAlign. Putting CENTER or BOTTOM as any parameter throws ReferenceError, now it is working fine. @lawreka I checked in source code that variable totalHeight is not declared and used anywhere.

p5 js - reffrence error code
p5 js - reffrence error sketch

@Snowman-s
Copy link

I had been struggling with this problem for a while. Thanks for coming up with a solution!

Here are my thoughts:

Presumably, the totalHeight was the actual height of the text as it was drawn.

This value would have been used to draw the entire text across multiple lines at the specified position, not just a single line.
(In fact, before #5146, totalHeight was declared and used.)

I noticed that it is not easy to calculate the totalHeight, because the height of the text changes for each textWrapStyle.
You probably need to split the text and calculate what the height will be beforehand (if you use totalHeight).

@Snowman-s
Copy link

@malviys @lawreka,

It would be great if you could tell me what the current status of this Pull Request is. Thanks!

@lawreka
Copy link
Contributor

lawreka commented Sep 10, 2021

You probably need to split the text and calculate what the height will be beforehand

Yes, this would require a more in-depth solution, which would probably necessitate its own PR separate from this one. I thought I would have time to work on that when I commented 17 days ago but unfortunately this was not the case :(

what the current status of this Pull Request is

I think that will be up to @outofambit to approve, I'm happy with @malviys solving the error in this PR and to open a new issue/follow-up PR to actually implement the correct vertical alignment.

@outofambit
Copy link
Contributor

hey @lawreka @Snowman-s @malviys! thanks for the great conversation here. it seems like we should merge this PR to fix the immediate error and then follow up with more work to re-implement totalHeight for multiline bottom aligned text areas. i'll merge this now and file an issue to followup on the second part. thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Undefined totalHeight in text function when setting vertical alignment
4 participants