Coded (MONOSPACE) text wrap

NOTE: this only looks good on monospace text. source code pro is monospace since all the characters are the same width. sans-serif is not because, for example, the “i” is not the same width as the “w”. the number of characters will be wrapped well, but it doesn’t account for different widths.

this is a function that makes line breaks in a string based on a width. it also chops words up when it’s longer than the width, adding dashes to the end.

some cool stuff it does

speed

Don’t want to do this manually?

much better :D

cuts words off when needed

Screen Shot 2021-05-07 at 10.42.40 AM

safeguard thingy

a width of less than 2 would crash the code. but there’s a safety here so that you don’t make a mistake. sorta. it doesn’t stop the program, it returns a different string instead. i should probably make it raise an error.

of course, it’s not that good code-wise. there is repeated code in there that caused a few mistakes that i eventually fixed. but i’m still quite proud of it, and i hope it comes in handy.

no, this is not copied off the internet. i did make this with my head.

credit is optional if you want to use or edit it, but it would be appreciated.

text wrap5-7-2021_10-36-58.wick (46.2 KB)

1 Like

:+1: :+1: :+1:
nice

I made something similar here
but instead of checking number of letters I checked text box width to solve the not monospace issue.
When the box gets bigger than allowed I modify the text and check again width

1 Like