Skip to content

Wrapping helper function #99

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

Merged
merged 5 commits into from
Dec 4, 2020
Merged

Conversation

FoamyGuy
Copy link
Contributor

I think this helper function was originally the PyPortal library.

If we move it to here we can make use of it in all of the various different portal libraries as well as directly from user code. This will make it easier to wrap text for different sized displays.

@FoamyGuy
Copy link
Contributor Author

@kmatch98 raised a great point in discord: One thing that needs to be tested and hasn't yet is how this code behaves when the supplied text has few enough spaces that it can't break cleanly without splitting a word.

@FoamyGuy
Copy link
Contributor Author

I tried it out and it turns out that it doesn't wrap if it doesn't find a space. I removed the spaces from the first line of text in the wrap example:
image

It should probably have some kind of fail over to use a hyphen when it can't break at a space. As is it could allow the text to run off the screen. Though it is probably somewhat rare to find text this long in the wild with no space

@FoamyGuy
Copy link
Contributor Author

The new commit addresses this by breaking the long word into chunks and combining them with hyphens as needed.

Here is how the previous example looks now:
image

@ladyada
Copy link
Member

ladyada commented Nov 22, 2020

nice! @makermelissa may be helpful to factor this out of portal libs

Copy link
Collaborator

@makermelissa makermelissa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with my refactored PortalBase library. It adds hyphens as noted. I was going to request a parameter for specifying whether to add them or not, but after thinking about it, I think it's fine.

@makermelissa makermelissa merged commit 9bc4d2b into adafruit:master Dec 4, 2020
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Dec 5, 2020
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.

3 participants