Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Wrap text to fit canvas screen (See related posts)

Pys60 provide you with 3 types for app.body
- Text
- ListBox
- Canvas

Sometimes you want some text and image together, you need to
use canvas. However, there's no way to calculate the length
of text and wrap them properly. Simo's dashboard provide a
solution to this using his akntextutils C++ extension.
from akntextutils import wrap_text_to_array

# long_str is a long string to be wrapped
lines = wrap_text_to_array(long_str, 'dense', 176)

x, y = 2, 0
for line in lines:
   y += 14
   canvas.text((x, y), line, font='dense')

You need to create an account or log in to post comments to this site.


Click here to browse all 5137 code snippets

Related Posts