-
Notifications
You must be signed in to change notification settings - Fork 38
Adding the wrap_by_pixels function #111
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
Conversation
id kinda prefer the list-return version - can you adapt it to match? |
@FoamyGuy I'll test this sometime in the next few days |
I ran several scenarios to sort out the behavior with miscellaneous white space. I found one bug that adds a leading newline. The other two things may be your planned behavior, so my only suggestion is to add a couple lines of documentation to clarify how newlines and leading/trailing whitespace is treated. Bug?Input string: For DocumentationInput string: For DocumentationInput string: |
Thanks for looking into this @kmatch98! Definitely a bug on the first one. I lean toward bug on Agreed about documenting the removal of leading and trailing spaces. For leading spaces the I'll work on making these changes to fix and document the above. |
@FoamyGuy Currently pretty swamped with other stuff so I'm not sure when I'm gonna get to this. If you're fine waiting a bit (looking like a week at least) I'd still be down to review this, but otherwise I won't be offended if someone else reviews it |
Okay, I think this is ready for review again. The latest commits resolve the issues noted above in the following ways:
|
I tested and the this fixes the issues mentioned above. I also verified that the leading and trailing spaces are now retained. I checked the operation of the text = "CircuitPython is a programming language"
print(wrap_text_to_pixels(text, WRAP_WIDTH, font, indent0="*", indent1="-")) Output:
Thanks for these fixes! |
Nice catch @kmatch98, thank you! The latest commit resolves it, the returned list no longer has an extra item in it. |
I verified this update, it definitely solves the problem. Thanks for getting this merged into the library and fixing all these details! Looks good to me. |
There was a problem hiding this 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 on a PyPortal Titano
Updating https://github.com/adafruit/Adafruit_CircuitPython_DS18X20 to 1.3.4 from 1.3.3: > Merge pull request adafruit/Adafruit_CircuitPython_DS18X20#21 from adafruit/dherrada-patch-1 Updating https://github.com/adafruit/Adafruit_CircuitPython_EPD to 2.8.0 from 2.7.2: > Merge pull request adafruit/Adafruit_CircuitPython_EPD#45 from makermelissa/master Updating https://github.com/adafruit/Adafruit_CircuitPython_GPS to 3.7.0 from 3.6.8: > Merge pull request adafruit/Adafruit_CircuitPython_GPS#54 from lesamouraipourpre/parse-gsa-and-gsv Updating https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display to 3.10.6 from 3.10.5: > Merge pull request adafruit/Adafruit_CircuitPython_RGB_Display#90 from makermelissa/master Updating https://github.com/adafruit/Adafruit_CircuitPython_SSD1306 to 2.11.0 from 2.10.2: > Merge pull request adafruit/Adafruit_CircuitPython_SSD1306#57 from adamcandy/add-page-addressing-mode Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Button to 1.5.2 from 1.5.1: > Merge pull request adafruit/Adafruit_CircuitPython_Display_Button#27 from FoamyGuy/resizeable_button Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Text to 2.15.0 from 2.14.0: > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#111 from FoamyGuy/wrap_by_pixels Updating https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation to 2.5.3 from 2.5.2: > Merge pull request adafruit/Adafruit_CircuitPython_LED_Animation#75 from adafruit/REUSE > Hardcoded Black and REUSE versions > Added pre-commit-config file > Added pre-commit and SPDX copyright Updating https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT to 5.0.3 from 5.0.2: > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#65 from brentru/update-cpython-example
Jeff wrote this nice helper function for wrapping text to a number of pixels instead of characters.
This PR adds that function as well as an example that illustrates it's usage.
One quirk worth consideration is that the new wrap_by_pixels function returns a string with newlines inserted. Whereas the older wrap_by_characters function returns a list of the lines, and joining with the newline is left up to the code using it. I think I like the way this one does it better with the string. But the other one came from the PyPortal libraries originally, perhaps there is something in them that is using the list. Maybe it would be worthwhile to add a parameter to both that controls this behavior?