add return values to drawString & drawStringMaxWidth #365
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.
The idea is, to give the calling code a bit more information about what was drawn.
drawString() will return the number of characters that have been drawn before the display ended, so that the calling code can use this to draw the rest of the string into a new line, or to implement some kind of horizontal scrolling.
drawStringMaxWidth() will return the number of characters drawn in the first line, so that the calling code can start drawing with the second line in the next iteration, to implement a kind of vertical scrolling.
To get the counting of UTF-8 characters right, I removed utf8ascii() and instead convert the strings on the fly while processing. This might save some runtime memory (the copy that holds the decoded string is not needed anymore) and slightly reduce code size, but I have not measured this extensively.
When breaking up lines in drawStringMaxWidth(), trailing and leading spaces in each line are now removed, leading to smoother display, e.g. in TEXT_ALIGN_CENTER mode. This is the only change that might be visible when the other new features (return codes) are not used. Other than that, the code should display identically with unchanged usage.
This is intended as a draft / suggestion for discussion, not necessarily as a finished solution (even though it works well with my test cases ;-))