Greetings of the Season to you all!
I have a question about the "right" way to handle word-wrapping static
text within a window. In my application, I have lots of places where
I need to include what amounts to a wx.StaticText control within a
window, and have its position and size controlled by a wx.Sizer. The
string to display can sometimes be short, but other times might
consist of up to, say, a hundred words of text, so the text needs to
word-wrap nicely to fit within the space allocated to it by the sizer
(which, it appears, means that wx.StaticText isn't suitable, as it
doesn't appear to word-wrap correctly when running under MS Windows).
I also can't use an uneditable wx.TextCtrl, because the height of the
control must vary according to how many lines of text it uses.
Ideally, the text should adjust the word-wrapping dynamically if the
user resizes the frame. And, of course, this needs to work on both
the Mac and MS Windows.
I've done some digging through the mailing list archives, and it
appears that this isn't easy to do -- but surely it's something that
people need quite often. I avoided the problem initially by
hard-coding newlines into the text to display, but when I went to port
my application from Windows to the Mac the windows all look ugly
because the text sizes and character widths are all different. It now
looks like I either need a generic solution, or else include separate
versions of each string to display, with newlines embedded in
different places, for each playform. Urgh!
How have others handled this problem? Is there a generic solution to
making sure this works correctly across all platforms? I've had a go
at creating my own "WrappingStaticTextCtrl" class based on
wx.lib.stattext.GenStaticText, but it's a bit of an ugly hack and
doesn't really work all that well. There must be a better way. Any
suggestions?
Thanks,
- Erik.