Add text wrapping function #5146
Merged
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.
Resolves #5081
Addresses #4652
Follow-up to #5108
Changes:
Adds textWrap function to specify how lines of text are wrapped within a text box. This requires a max-width set on the text area, specified in text() as parameter
x2
.WORD is the default wrap style, and both styles will still break lines at any line breaks (\n) specified in the original text. The text area max-height parameter (y2) also still applies to wrapped text in both styles, lines of text that do not fit within the text area will not be drawn to the screen.
I may have gone a little overboard adding documentation and examples, specifically the last one with the little screaming stick-man demonstrating the current lack of truncation. He should be removed if additional functionality is added in the future to deal with truncation and hyphenation, but for now I think he shows kind of a fun way to work with #4652.
I also added an example using Chinese characters, since as @dhowe mentioned in discussion, textWrap(CHAR) is essential for displaying text in character-based languages nicely.
Screenshots of the change:

PR Checklist
npm run lint
passes