[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Good code for text wrapping?



On Tuesday 16 September 2008 03:11:45 René Dudfield wrote:
> The cookbook has this entry, but it doesn't work with new lines.
> http://www.pygame.org/wiki/TextWrapping
>
> Anyone have any code like this that supports new lines?

Is this any use to you?
https://kamaelia.svn.sourceforge.net/svnroot/kamaelia/trunk/Code/Python/Kamaelia/Kamaelia/UI/Pygame/Text.py

The code can be used by itself but will look a little odd - it's got a
slightly wierd way of getting a surface to display on inside "initPygame"
and the equivalent of pygame.flip() is in the end of "updateLine" (the redraw
request), but other than than it's pretty normal normal code. 

(The reason for the oddity is because it allows pygame based components to be
written as if they own the whole display, and then to be changed slightly in
small steps to share the display)

To see what it looks like quickly, it'd probably be easiest to grab the latest 
kamaelia release:
    http://edit.kamaelia.org/release/Kamaelia-0.6.0-rc7.tar.gz

Do the usual setup.py dance, and then:
~/Kamaelia-0.6.0-rc7> cd Examples/SimpleGraphicalApps/TextBox/
~/Kamaelia-0.6.0-rc7/Examples/SimpleGraphicalApps/TextBox> ./Textbox_TextDisplayer_Demo.py

Handles different font sizes etc happily. Only supports left justified text at 
the moment.


Michael.