DZone 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

Snippets has posted 5883 posts at DZone. View Full User Profile

Wrap Text To Fit Canvas Screen

  • submit to reddit
        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')