Over a million developers have joined DZone.

Wrap Text To Fit Canvas Screen

DZone's Guide to

Wrap Text To Fit Canvas Screen

· ·
Free Resource
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')

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}