Skip to content

Resolve missing spaces when long words wrap across a full line. #163

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 3 commits into from
Feb 8, 2022

Conversation

kmatch98
Copy link
Contributor

@kmatch98 kmatch98 commented Feb 7, 2022

This resolves #162

Note: I had to disable "too-many-nested-blocks" to get it to pass pylint. I agree that the logic is difficult to follow, requiring a refactor of the whole thing to resolve (but I'm passing the technical debt forward for now).

My test code:

import terminalio
from adafruit_display_text import bitmap_label, wrap_text_to_pixels

text_string = "CircuitPython is a programming language designed to simplify experimenting and learning to code on low-cost microcontroller boards."
text_string=text_string+("\n\nWith CircuitPython, there are no upfront desktop downloads needed. Once you get your board set up, open any text editor, and start editing code. It's that simple.")

text_string = "CircuitPython is a programming language designed to simplify experimenting"

for width in range(20, 200, 5):
    text_lines = wrap_text_to_pixels(text_string, width, terminalio.FONT)
    print("width: {}".format(width))
    print('text_lines: {}'.format(text_lines))

while True:
    pass

Test result:

code.py output:
width: 20
text_lines: ['Ci-', 'rc-', 'ui-', 'tP-', 'yt-', 'ho-', 'n', 'is', 'a', 'pr-', 'og-', 'ra-', 'mm-', 'in-', 'g', 'la-', 'ng-', 'ua-', 'ge', 'de-', 'si-', 'gn-', 'ed', 'to', 'si-', 'mp-', 'li-', 'fy', 'ex-', 'pe-', 'ri-', 'me-', 'nt-', 'in-', 'g']
width: 25
text_lines: ['Cir-', 'cui-', 'tPy-', 'tho-', 'n is', 'a p-', 'rog-', 'ram-', 'min-', 'g l-', 'ang-', 'uag-', 'e d-', 'esi-', 'gne-', 'd to', 'sim-', 'pli-', 'fy', 'exp-', 'eri-', 'men-', 'tin-', 'g']
width: 30
text_lines: ['Circ-', 'uitP-', 'ytho-', 'n is', 'a pr-', 'ogra-', 'mmin-', 'g la-', 'ngua-', 'ge d-', 'esig-', 'ned', 'to s-', 'impl-', 'ify', 'expe-', 'rime-', 'ntin-', 'g']
width: 35
text_lines: ['Circ-', 'uitP-', 'ytho-', 'n is', 'a pr-', 'ogra-', 'mmin-', 'g la-', 'ngua-', 'ge d-', 'esig-', 'ned', 'to s-', 'impl-', 'ify', 'expe-', 'rime-', 'ntin-', 'g']
width: 40
text_lines: ['Circu-', 'itPyt-', 'hon is', 'a pro-', 'gramm-', 'ing l-', 'angua-', 'ge de-', 'signe-', 'd to', 'simpl-', 'ify e-', 'xperi-', 'menti-', 'ng']
width: 45
text_lines: ['Circui-', 'tPytho-', 'n is a', 'progra-', 'mming', 'langua-', 'ge des-', 'igned', 'to sim-', 'plify', 'experi-', 'mentin-', 'g']
width: 50
text_lines: ['Circuit-', 'Python', 'is a pr-', 'ogrammi-', 'ng', 'language', 'designed', 'to', 'simplify', 'experim-', 'enting']
width: 55
text_lines: ['CircuitP-', 'ython is', 'a progra-', 'mming', 'language', 'designed', 'to', 'simplify', 'experime-', 'nting']
width: 60
text_lines: ['CircuitPy-', 'thon is a', 'programmi-', 'ng', 'language', 'designed', 'to', 'simplify', 'experimen-', 'ting']
width: 65
text_lines: ['CircuitPy-', 'thon is a', 'programmi-', 'ng', 'language', 'designed', 'to', 'simplify', 'experimen-', 'ting']
width: 70
text_lines: ['CircuitPyt-', 'hon is a', 'programming', 'language', 'designed to', 'simplify e-', 'xperimenti-', 'ng']
width: 75
text_lines: ['CircuitPyth-', 'on is a', 'programming', 'language', 'designed to', 'simplify ex-', 'perimenting']
width: 80
text_lines: ['CircuitPython', 'is a', 'programming', 'language', 'designed to', 'simplify', 'experimenting']
width: 85
text_lines: ['CircuitPython', 'is a', 'programming', 'language', 'designed to', 'simplify', 'experimenting']
width: 90
text_lines: ['CircuitPython', 'is a', 'programming', 'language', 'designed to', 'simplify', 'experimenting']
width: 95
text_lines: ['CircuitPython', 'is a', 'programming', 'language', 'designed to', 'simplify', 'experimenting']
width: 100
text_lines: ['CircuitPython is', 'a programming', 'language', 'designed to', 'simplify', 'experimenting']
width: 105
text_lines: ['CircuitPython is', 'a programming', 'language designed', 'to simplify', 'experimenting']
width: 110
text_lines: ['CircuitPython is a', 'programming', 'language designed', 'to simplify', 'experimenting']
width: 115
text_lines: ['CircuitPython is a', 'programming', 'language designed', 'to simplify', 'experimenting']
width: 120
text_lines: ['CircuitPython is a', 'programming', 'language designed', 'to simplify', 'experimenting']
width: 125
text_lines: ['CircuitPython is a', 'programming language', 'designed to simplify', 'experimenting']
width: 130
text_lines: ['CircuitPython is a', 'programming language', 'designed to simplify', 'experimenting']
width: 135
text_lines: ['CircuitPython is a', 'programming language', 'designed to simplify', 'experimenting']
width: 140
text_lines: ['CircuitPython is a', 'programming language', 'designed to simplify', 'experimenting']
width: 145
text_lines: ['CircuitPython is a', 'programming language', 'designed to simplify', 'experimenting']
width: 150
text_lines: ['CircuitPython is a', 'programming language', 'designed to simplify', 'experimenting']
width: 155
text_lines: ['CircuitPython is a', 'programming language', 'designed to simplify', 'experimenting']
width: 160
text_lines: ['CircuitPython is a', 'programming language', 'designed to simplify', 'experimenting']
width: 165
text_lines: ['CircuitPython is a', 'programming language', 'designed to simplify', 'experimenting']
width: 170
text_lines: ['CircuitPython is a', 'programming language', 'designed to simplify', 'experimenting']
width: 175
text_lines: ['CircuitPython is a', 'programming language designed', 'to simplify experimenting']
width: 180
text_lines: ['CircuitPython is a', 'programming language designed', 'to simplify experimenting']
width: 185
text_lines: ['CircuitPython is a programming', 'language designed to simplify', 'experimenting']
width: 190
text_lines: ['CircuitPython is a programming', 'language designed to simplify', 'experimenting']
width: 195
text_lines: ['CircuitPython is a programming', 'language designed to simplify', 'experimenting']

Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

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

Looks good to me. Tested successfully on PyPortal 7.2.0.alpha-1 with the code given here and the wrap to pixels example in the repo.

@FoamyGuy FoamyGuy merged commit 5283f39 into adafruit:main Feb 8, 2022
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Feb 8, 2022
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.

Spaces are deleted when word-wrapping
2 participants